#5061 Add force refresh of p2 repositories before checking for updates
authorCherian Mathew <c.mathew@bgbm.org>
Wed, 22 Jul 2015 14:23:41 +0000 (16:23 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 23 Jul 2015 13:30:50 +0000 (15:30 +0200)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/P2Util.java

index 9e1731c4cf7cdcc7c73745e5bcf39b1d8ef705b1..0a6fb6395ee0530208f6a66839ed79d4f627685d 100644 (file)
@@ -7,7 +7,6 @@ import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
@@ -16,17 +15,15 @@ import org.eclipse.core.runtime.jobs.JobChangeAdapter;
 import org.eclipse.equinox.internal.p2.ui.ProvUI;
 import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
 import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
-import org.eclipse.equinox.p2.repository.IRepository;
-import org.eclipse.equinox.p2.repository.IRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.core.ProvisionException;
 import org.eclipse.equinox.p2.operations.ProvisioningJob;
 import org.eclipse.equinox.p2.operations.ProvisioningSession;
-import org.eclipse.equinox.p2.operations.RepositoryTracker;
 import org.eclipse.equinox.p2.operations.Update;
 import org.eclipse.equinox.p2.operations.UpdateOperation;
+import org.eclipse.equinox.p2.repository.IRepository;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
@@ -146,7 +143,7 @@ public class P2Util {
      *
      */
     public static void checkForUpdates() {
-        // the main job which performs the update
+
         Job updateJob = new Job("Update Job") {
             @Override
             public IStatus run(IProgressMonitor monitor) {
@@ -162,6 +159,21 @@ public class P2Util {
      */
     private static IStatus doCheckForUpdates(IProgressMonitor monitor) {
 
+     // force refresh all the caches before
+        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
+        URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+        for(URI repo : repos) {
+            try {
+                metaManager.refreshRepository(repo, monitor);
+            } catch (ProvisionException pe) {
+                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
+                        "Error occured while reloading cache.", pe);
+
+            } catch (OperationCanceledException oce) {
+                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
+                        "Error occured while reloading cache.", oce);
+            }
+        }
         BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
         ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
         if (reference == null) {