refactor progress reporting from dependency on org.eclipse.core.runtime.IProgressMonitor (FELIX-1509)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@981796 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/eclipse/core/sigil.properties b/sigil/eclipse/core/sigil.properties
index defecb4..e9689e1 100644
--- a/sigil/eclipse/core/sigil.properties
+++ b/sigil/eclipse/core/sigil.properties
@@ -25,6 +25,7 @@
 	org.apache.felix.sigil.eclipse.model.repository, \
 	org.apache.felix.sigil.eclipse.model.util, \
 	org.apache.felix.sigil.eclipse.preferences, \
+	org.apache.felix.sigil.eclipse.repository, \
 
 -imports: \
 	org.apache.commons.lang, \
@@ -37,6 +38,7 @@
 	org.apache.felix.sigil.common.model.eclipse, \
 	org.apache.felix.sigil.common.model.osgi, \
 	org.apache.felix.sigil.common.osgi, \
+	org.apache.felix.sigil.common.progress;version=0.9.0, \
 	org.apache.felix.sigil.common.repository, \
 	org.apache.felix.sigil.eclipse, \
 	org.apache.felix.sigil.eclipse.install, \
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java
index 7188cfe..a588a40 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java
@@ -37,10 +37,11 @@
 import org.apache.felix.sigil.common.repository.IResolution;
 import org.apache.felix.sigil.common.repository.ResolutionConfig;
 import org.apache.felix.sigil.common.repository.ResolutionException;
-import org.apache.felix.sigil.common.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.model.project.ISigilModelRoot;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.apache.felix.sigil.eclipse.progress.ProgressAdapter;
+import org.apache.felix.sigil.eclipse.repository.ResolutionMonitorAdapter;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
@@ -186,7 +187,7 @@
             IBundleResolver resolver = SigilCore.getRepositoryManager(sigil).getBundleResolver();
             IResolution resolution = resolver.resolve(element, config,
                 new ResolutionMonitorAdapter(monitor));
-            resolution.synchronize(monitor);
+            resolution.synchronize(new ProgressAdapter(monitor));
             return resolution.getBundles();
         }
         catch (ResolutionException e)
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
index 6efbe9a..aadb284 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
@@ -48,12 +48,13 @@
 import org.apache.felix.sigil.common.repository.IResolution;
 import org.apache.felix.sigil.common.repository.ResolutionConfig;
 import org.apache.felix.sigil.common.repository.ResolutionException;
-import org.apache.felix.sigil.common.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.eclipse.PathUtil;
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.job.ThreadProgressMonitor;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
 import org.apache.felix.sigil.eclipse.model.util.JavaHelper;
+import org.apache.felix.sigil.eclipse.progress.ProgressAdapter;
+import org.apache.felix.sigil.eclipse.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.utils.GlobCompiler;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
@@ -195,7 +196,7 @@
             // pull remote bundles from repositories to be added to classpath
             if (!resolution.isSynchronized())
             {
-                resolution.synchronize(progress.newChild(80));
+                resolution.synchronize(new ProgressAdapter(progress.newChild(80)));
             }
         }
         catch (ResolutionException e)
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
index c01c9d2..fe34711 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/util/JavaHelper.java
@@ -54,10 +54,11 @@
 import org.apache.felix.sigil.common.repository.IResolution;
 import org.apache.felix.sigil.common.repository.ResolutionConfig;
 import org.apache.felix.sigil.common.repository.ResolutionException;
-import org.apache.felix.sigil.common.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.eclipse.PathUtil;
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.apache.felix.sigil.eclipse.progress.ProgressAdapter;
+import org.apache.felix.sigil.eclipse.repository.ResolutionMonitorAdapter;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -416,7 +417,7 @@
         {
             if (other == null)
             {
-                provider.synchronize(monitor);
+                provider.synchronize(new ProgressAdapter(monitor));
                 return newBundleEntry(provider, rules, attrs, false);
             }
             else
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/progress/ProgressAdapter.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/progress/ProgressAdapter.java
new file mode 100644
index 0000000..06216d0
--- /dev/null
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/progress/ProgressAdapter.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.eclipse.progress;
+
+import org.apache.felix.sigil.common.progress.IProgress;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+
+/**
+ * @author dave
+ *
+ */
+public class ProgressAdapter implements IProgress
+{
+    
+    private final IProgressMonitor monitor;
+    private final SubMonitor sub;
+
+    public ProgressAdapter(IProgressMonitor monitor) {
+        this.monitor = monitor;
+        sub = SubMonitor.convert(monitor);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#done()
+     */
+    public void done()
+    {
+        monitor.done();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#isCanceled()
+     */
+    public boolean isCanceled()
+    {
+        return monitor.isCanceled();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#newChild(int)
+     */
+    public IProgress newChild(int totalWork)
+    {
+        return new ProgressAdapter(sub.newChild(totalWork));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#newTask(int)
+     */
+    public IProgress newTask(int totalWork)
+    {
+        SubMonitor sub = SubMonitor.convert(monitor);
+        return new ProgressAdapter(sub);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#worked(int)
+     */
+    public void worked(int work)
+    {
+        monitor.worked(work);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.sigil.common.progress.IProgress#report(java.lang.String)
+     */
+    public void report(String msg)
+    {
+        sub.subTask(msg);
+    }
+
+}
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/repository/ResolutionMonitorAdapter.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/repository/ResolutionMonitorAdapter.java
new file mode 100644
index 0000000..916c275
--- /dev/null
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/repository/ResolutionMonitorAdapter.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.eclipse.repository;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.apache.felix.sigil.common.model.IModelElement;
+import org.apache.felix.sigil.common.model.eclipse.ISigilBundle;
+import org.apache.felix.sigil.common.repository.IResolutionMonitor;
+
+public class ResolutionMonitorAdapter implements IResolutionMonitor
+{
+
+    private IProgressMonitor monitor;
+
+    public ResolutionMonitorAdapter(IProgressMonitor monitor)
+    {
+        this.monitor = monitor;
+    }
+
+    public boolean isCanceled()
+    {
+        return monitor.isCanceled();
+    }
+
+    public void startResolution(IModelElement requirement)
+    {
+        monitor.subTask("Resolving " + requirement);
+    }
+
+    public void endResolution(IModelElement requirement, ISigilBundle provider)
+    {
+        monitor.subTask((provider == null ? "Failed to resolve " : "Resolved ")
+            + requirement);
+    }
+
+}
diff --git a/sigil/eclipse/ui/sigil.properties b/sigil/eclipse/ui/sigil.properties
index 5b6f3e2..a3e57e9 100644
--- a/sigil/eclipse/ui/sigil.properties
+++ b/sigil/eclipse/ui/sigil.properties
@@ -39,6 +39,7 @@
 	org.apache.felix.sigil.eclipse.model.repository, \
 	org.apache.felix.sigil.eclipse.model.util, \
 	org.apache.felix.sigil.eclipse.preferences, \
+	org.apache.felix.sigil.eclipse.repository;version=0.9.0, \
 	org.apache.felix.sigil.eclipse.ui, \
 	org.apache.felix.sigil.eclipse.ui.actions, \
 	org.apache.felix.sigil.eclipse.ui.util, \
diff --git a/sigil/eclipse/ui/src/org/apache/felix/sigil/eclipse/ui/internal/views/resolution/BundleResolverView.java b/sigil/eclipse/ui/src/org/apache/felix/sigil/eclipse/ui/internal/views/resolution/BundleResolverView.java
index 8cf101a..ad954c5 100644
--- a/sigil/eclipse/ui/src/org/apache/felix/sigil/eclipse/ui/internal/views/resolution/BundleResolverView.java
+++ b/sigil/eclipse/ui/src/org/apache/felix/sigil/eclipse/ui/internal/views/resolution/BundleResolverView.java
@@ -31,9 +31,9 @@
 import org.apache.felix.sigil.common.repository.IResolutionMonitor;
 import org.apache.felix.sigil.common.repository.ResolutionConfig;
 import org.apache.felix.sigil.common.repository.ResolutionException;
-import org.apache.felix.sigil.common.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
+import org.apache.felix.sigil.eclipse.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.eclipse.ui.SigilUI;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;