aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-02-02 10:18:06 (EST)
committerPascal Rapicault2011-02-04 10:25:52 (EST)
commitbf180876374d55778466bcdd10edcb5a31118827 (patch)
treeca867399023261fa9ea9dce565e5a7a4ecc3a59a
parentddc3a49ae0645ed59924aecf88290ee694adddf8 (diff)
downloadm2e-core-bf180876374d55778466bcdd10edcb5a31118827.zip
m2e-core-bf180876374d55778466bcdd10edcb5a31118827.tar.gz
m2e-core-bf180876374d55778466bcdd10edcb5a31118827.tar.bz2
Bug 335486 - Set restart policy for install operations
-rw-r--r--org.eclipse.m2e.discovery/META-INF/MANIFEST.MF18
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java2
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java103
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/RestartInstallOperation.java50
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoveryUi.java71
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/InstallWizard.java46
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryWizard.java5
7 files changed, 290 insertions, 5 deletions
diff --git a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
index ff601ef..1378f56 100644
--- a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
@@ -11,15 +11,23 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.equinox.p2.ui.discovery,
org.eclipse.equinox.p2.discovery,
org.eclipse.equinox.p2.discovery.compatibility,
- org.eclipse.jface,
org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.m2e.core;bundle-version="[0.13.0,0.14.0)",
org.eclipse.core.resources,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.equinox.p2.operations,
+ org.eclipse.equinox.p2.core,
+ org.eclipse.equinox.p2.metadata
Export-Package: org.eclipse.m2e.internal.discovery,
org.eclipse.m2e.internal.discovery.markers,
org.eclipse.m2e.internal.discovery.wizards
-Import-Package: org.apache.maven.artifact.repository.metadata,
- org.apache.maven.model,
- org.apache.maven.plugin
+Import-Package: org.apache.maven.model,
+ org.apache.maven.plugin,
+ org.eclipse.equinox.internal.p2.ui,
+ org.eclipse.equinox.internal.p2.ui.dialogs,
+ org.eclipse.equinox.internal.p2.ui.model,
+ org.eclipse.equinox.p2.engine,
+ org.eclipse.equinox.p2.metadata,
+ org.eclipse.equinox.p2.repository.metadata,
+ org.eclipse.equinox.p2.ui
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
index 38b624a..e77995a 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
@@ -32,6 +32,8 @@ import org.eclipse.ui.internal.Workbench;
@SuppressWarnings("restriction")
public class MavenDiscovery {
+ public static final Tag NO_RESTART_TAG = new Tag("norestart", "norestart"); //$NON-NLS-1$//$NON-NLS-2$
+
public static final Tag APPLICABLE_TAG = new Tag("applicable", Messages.MavenDiscovery_Wizard_Applicable_Tag); //$NON-NLS-1$
private static final Tag EXTRAS_TAG = new Tag("extras", Messages.MavenDiscovery_Wizard_ExtrasTag); //$NON-NLS-1$
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java
new file mode 100644
index 0000000..846b755
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.discovery.operation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
+import org.eclipse.equinox.internal.p2.ui.discovery.operations.DiscoveryInstallOperation;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.ProvisioningJob;
+import org.eclipse.equinox.p2.operations.ProvisioningSession;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.m2e.internal.discovery.MavenDiscovery;
+import org.eclipse.m2e.internal.discovery.wizards.DiscoveryUi;
+import org.eclipse.swt.widgets.Display;
+
+@SuppressWarnings("restriction")
+public class MavenDiscoveryInstallOperation extends DiscoveryInstallOperation {
+ private List<CatalogItem> installableConnectors;
+
+ private ProvisioningSession session;
+ public MavenDiscoveryInstallOperation(List<CatalogItem> installableConnectors) {
+ super(installableConnectors);
+ this.installableConnectors = installableConnectors;
+ this.session = ProvisioningUI.getDefaultUI().getSession();
+ }
+
+ @Override
+ public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
+ try {
+ SubMonitor monitor = SubMonitor.convert(progressMonitor, "Messages.InstallConnectorsJob_task_configuring", 100);
+ try {
+ final IInstallableUnit[] ius = computeInstallableUnits(monitor.newChild(50));
+
+ checkCancelled(monitor);
+
+ final RestartInstallOperation installOperation = resolve(monitor.newChild(50), ius, new URI[0],
+ requireRestart(installableConnectors));
+
+ checkCancelled(monitor);
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ DiscoveryUi.openInstallWizard(Arrays.asList(ius), installOperation, null);
+ }
+ });
+ } finally {
+ monitor.done();
+ }
+ } catch(OperationCanceledException e) {
+ throw new InterruptedException();
+ } catch(Exception e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ public static boolean requireRestart(Iterable<CatalogItem> catalogItems) {
+ for(CatalogItem item : catalogItems) {
+ if(!item.hasTag(MavenDiscovery.NO_RESTART_TAG)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private RestartInstallOperation resolve(IProgressMonitor monitor, final IInstallableUnit[] ius, URI[] repositories,
+ boolean requireRestart) throws CoreException {
+ SubMonitor mon = SubMonitor.convert(monitor, ius.length);
+ try {
+ RestartInstallOperation op = new RestartInstallOperation(session, Arrays.asList(ius));
+ op.setRestartPolicy(requireRestart ? ProvisioningJob.RESTART_ONLY : ProvisioningJob.RESTART_NONE);
+ IStatus operationStatus = op.resolveModal(mon);
+ if(operationStatus.getSeverity() > IStatus.WARNING) {
+ throw new CoreException(operationStatus);
+ }
+ return op;
+ } finally {
+ mon.done();
+ }
+ }
+
+ private void checkCancelled(IProgressMonitor monitor) {
+ if(monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/RestartInstallOperation.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/RestartInstallOperation.java
new file mode 100644
index 0000000..fdd36d5
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/RestartInstallOperation.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.discovery.operation;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.InstallOperation;
+import org.eclipse.equinox.p2.operations.ProfileModificationJob;
+import org.eclipse.equinox.p2.operations.ProvisioningJob;
+import org.eclipse.equinox.p2.operations.ProvisioningSession;
+
+
+/*
+ * This operation allows altering the restart policy for the ProvisioningJob returned from getProvisioningJob calls
+ */
+public class RestartInstallOperation extends InstallOperation {
+
+ private int restartPolicy = ProvisioningJob.RESTART_ONLY;
+
+ public RestartInstallOperation(ProvisioningSession session, Collection<IInstallableUnit> toInstall) {
+ super(session, toInstall);
+ }
+
+ @Override
+ public ProvisioningJob getProvisioningJob(IProgressMonitor monitor) {
+ ProvisioningJob job = super.getProvisioningJob(monitor);
+ if(job != null && job instanceof ProfileModificationJob) {
+ ((ProfileModificationJob) job).setRestartPolicy(restartPolicy);
+ }
+ return job;
+ }
+
+ public int getRestartPolicy() {
+ return restartPolicy;
+ }
+
+ public void setRestartPolicy(int restartPolicy) {
+ this.restartPolicy = restartPolicy;
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoveryUi.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoveryUi.java
new file mode 100644
index 0000000..3c5a2d8
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoveryUi.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ * Sonatype, Inc. - Modified to use local installation operation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.discovery.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
+import org.eclipse.equinox.internal.p2.ui.IProvHelpContextIds;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ProvisioningWizardDialog;
+import org.eclipse.equinox.internal.p2.ui.discovery.wizards.Messages;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.m2e.internal.discovery.operation.MavenDiscoveryInstallOperation;
+import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+/**
+ * @author David Green
+ */
+public abstract class DiscoveryUi {
+
+ public static final String ID_PLUGIN = "org.eclipse.equinox.p2.ui.discovery"; //$NON-NLS-1$
+
+ private DiscoveryUi() {
+ // don't allow clients to instantiate
+ }
+
+ public static boolean install(List<CatalogItem> descriptors, IRunnableContext context) {
+ try {
+ IRunnableWithProgress runner = new MavenDiscoveryInstallOperation(descriptors);
+ context.run(true, true, runner);
+ } catch (InvocationTargetException e) {
+ IStatus status = new Status(IStatus.ERROR, DiscoveryUi.ID_PLUGIN, NLS.bind(Messages.ConnectorDiscoveryWizard_installProblems, new Object[] {e.getCause().getMessage()}), e.getCause());
+ StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
+ return false;
+ } catch (InterruptedException e) {
+ // canceled
+ return false;
+ }
+ return true;
+ }
+
+ public static int openInstallWizard(Collection<IInstallableUnit> initialSelections,
+ RestartInstallOperation operation, LoadMetadataRepositoryJob job) {
+ InstallWizard wizard = new InstallWizard(ProvisioningUI.getDefaultUI(), operation, initialSelections, job);
+ WizardDialog dialog = new ProvisioningWizardDialog(ProvUI.getDefaultParentShell(), wizard);
+ dialog.create();
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IProvHelpContextIds.INSTALL_WIZARD);
+ return dialog.open();
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/InstallWizard.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/InstallWizard.java
new file mode 100644
index 0000000..052ed00
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/InstallWizard.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.internal.discovery.wizards;
+
+import java.util.Collection;
+
+import org.eclipse.equinox.internal.p2.ui.dialogs.PreselectedIUInstallWizard;
+import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
+import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
+
+
+/*
+ * Needed to override getProvisioningContext()
+ */
+public class InstallWizard extends PreselectedIUInstallWizard {
+
+ public InstallWizard(ProvisioningUI ui, RestartInstallOperation operation,
+ Collection<IInstallableUnit> initialSelections, LoadMetadataRepositoryJob job) {
+ super(ui, operation, initialSelections, job);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.internal.p2.ui.dialogs.ProvisioningOperationWizard#getProfileChangeOperation(java.lang.Object[])
+ */
+ @Override
+ protected ProfileChangeOperation getProfileChangeOperation(Object[] elements) {
+ RestartInstallOperation op = new RestartInstallOperation(ui.getSession(), ElementUtils.elementsToIUs(elements));
+ op.setRestartPolicy(((RestartInstallOperation) operation).getRestartPolicy());
+ op.setProfileId(getProfileId());
+ // op.setRootMarkerKey(getRootMarkerKey());
+ op.setProvisioningContext(getProvisioningContext());
+ return op;
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryWizard.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryWizard.java
index af47c74..b937e0b 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryWizard.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryWizard.java
@@ -31,4 +31,9 @@ public class MavenDiscoveryWizard extends DiscoveryWizard {
protected CatalogPage doCreateCatalogPage() {
return new MavenCatalogPage(getCatalog());
}
+
+ @Override
+ public boolean performFinish() {
+ return DiscoveryUi.install(getCatalogPage().getInstallableConnectors(), getContainer());
+ }
}