Add repo URIs to update operation
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 24 Nov 2015 10:59:59 +0000 (11:59 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 24 Nov 2015 11:01:05 +0000 (12:01 +0100)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/UpdateHandler.java

index ecb9d1897b26344a332f680f2da85718fb4430de..4a5f40742ecc82c5c0a2a6ca05d750034cc97ee0 100644 (file)
@@ -1,39 +1,40 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
 package eu.etaxonomy.taxeditor.update;
 
 import java.net.URI;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.OperationCanceledException;
 package eu.etaxonomy.taxeditor.update;
 
 import java.net.URI;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.equinox.internal.p2.ui.ProvUI;
 import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
 import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.core.ProvisionException;
 import org.eclipse.equinox.internal.p2.ui.ProvUI;
 import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
 import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.operations.ProvisioningSession;
 import org.eclipse.equinox.p2.operations.UpdateOperation;
 import org.eclipse.equinox.p2.repository.IRepositoryManager;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
 import org.eclipse.equinox.p2.operations.UpdateOperation;
 import org.eclipse.equinox.p2.repository.IRepositoryManager;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 /**
  * UpdateHandler invokes the check for updates UI
  *
 
 /**
  * UpdateHandler invokes the check for updates UI
  *
- * @since 3.4
  */
 public class UpdateHandler extends PreloadingRepositoryHandler {
 
  */
 public class UpdateHandler extends PreloadingRepositoryHandler {
 
@@ -41,59 +42,69 @@ public class UpdateHandler extends PreloadingRepositoryHandler {
     @Override
     protected void doExecute(LoadMetadataRepositoryJob job) {
 
     @Override
     protected void doExecute(LoadMetadataRepositoryJob job) {
 
-        UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
+        //UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
 
 
-        // check for updates
-        checkForUpdates(operation);
-        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
-            if (UpdateSingleIUWizard.validFor(operation)) {
-                // Special case for only updating a single root
-                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
-                WizardDialog dialog = new WizardDialog(getShell(), wizard);
-                dialog.create();
-                dialog.open();
-            } else {
-                // Open the normal version of the update wizard
-                getProvisioningUI().openUpdateWizard(false, operation, job);
-            }
+        BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
+        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
+        if (reference == null) {
+            MessageDialog.openInformation(
+                    null,
+                    "Information",
+                    "No provisioning agent found.  This application is not set up for updates.");
+            return;
         }
         }
-    }
 
 
+        final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
+        IWorkbench workbench = PlatformUI.getWorkbench();
 
 
-    /**
-     * @param monitor
-     * @return
-     */
-    private IStatus checkForUpdates(UpdateOperation operation) {
+        ProvisioningSession session = new ProvisioningSession(agent);
+        // update all user-visible installable units
+        UpdateOperation operation = new UpdateOperation(session);
 
 
-        // force refresh all the caches before
+        // force refresh all the repository caches before update
         IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
         URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
         IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
         URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+
         for(URI repo : repos) {
             try {
                 metaManager.refreshRepository(repo, null);
             } catch (ProvisionException pe) {
         for(URI repo : repos) {
             try {
                 metaManager.refreshRepository(repo, null);
             } catch (ProvisionException pe) {
-                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
-                        "Error occured while reloading cache.", pe);
+                MessagingUtils.errorDialog("Error reloading repository cache",
+                        this,
+                        pe.getMessage(),
+                        TaxonomicEditorPlugin.PLUGIN_ID,
+                        pe,
+                        true);
+                return;
 
             } catch (OperationCanceledException oce) {
 
             } catch (OperationCanceledException oce) {
-                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
-                        "Error occured while reloading cache.", oce);
+                MessagingUtils.errorDialog("Error reloading repository cache",
+                        this,
+                        oce.getMessage(),
+                        TaxonomicEditorPlugin.PLUGIN_ID,
+                        oce,
+                        true);
+                return;
             }
         }
             }
         }
-        BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
-        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
-        if (reference == null) {
-            IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
-                    "No provisioning agent found.  This application is not set up for updates.");
-            return errorStatus;
-        }
 
 
-        try {
-            return operation.resolveModal(null);
-        } finally {
-            bundleContext.ungetService(reference);
+        // set location of artifact and metadata repo
+        operation.getProvisioningContext().setArtifactRepositories(repos);
+        operation.getProvisioningContext().setMetadataRepositories(repos);
+
+        IStatus status = operation.resolveModal(null);
+
+        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
+            if (UpdateSingleIUWizard.validFor(operation)) {
+                // Special case for only updating a single root
+                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
+                WizardDialog dialog = new WizardDialog(getShell(), wizard);
+                dialog.create();
+                dialog.open();
+            } else {
+                // Open the normal version of the update wizard
+                getProvisioningUI().openUpdateWizard(false, operation, job);
+            }
         }
     }
         }
     }
-
 }
 }