Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-02-28 13:39:35 -0500
committerPascal Rapicault2011-03-03 16:35:20 -0500
commitea88d2e22b19a9f914d3acc5f6292216a0a536f3 (patch)
treea2f9dc0c9d2282ba837346994a80327b98031c4d /org.eclipse.m2e.discovery/src
parent07fb9045d55d0f6e56798b52093e8d7e281c60b7 (diff)
downloadm2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.tar.gz
m2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.tar.xz
m2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.zip
Bug 337989 - Discover extensions during project import
Diffstat (limited to 'org.eclipse.m2e.discovery/src')
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java114
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java19
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/RestartInstallOperation.java14
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/startup/UpdateConfigurationStartup.java21
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java12
5 files changed, 157 insertions, 23 deletions
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
index 5f299fe6..7369c408 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
@@ -11,6 +11,7 @@
package org.eclipse.m2e.internal.discovery;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -23,8 +24,24 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
+import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
+import org.eclipse.equinox.internal.p2.ui.ProvUIImages;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizardPage;
+import org.eclipse.equinox.internal.p2.ui.model.AvailableIUElement;
+import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot;
+import org.eclipse.equinox.internal.provisional.configurator.Configurator;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.ProvisioningJob;
+import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
@@ -32,21 +49,27 @@ import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult;
import org.eclipse.m2e.core.internal.lifecyclemapping.MappingMetadataSource;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingElementKey;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDisovery;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadata;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+import org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory;
import org.eclipse.m2e.internal.discovery.operation.MavenDiscoveryInstallOperation;
+import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
+import org.eclipse.m2e.internal.discovery.wizards.MavenDiscoveryInstallWizard;
+import org.eclipse.ui.progress.IProgressConstants;
+import org.eclipse.ui.progress.IProgressConstants2;
+import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
@SuppressWarnings({"restriction", "rawtypes"})
-public class MavenDiscoveryService implements IMavenDisovery, ServiceFactory {
+public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDiscovery, ServiceFactory {
public static class CatalogItemCacheEntry {
private final CatalogItem item;
@@ -216,9 +239,27 @@ public class MavenDiscoveryService implements IMavenDisovery, ServiceFactory {
public void implement(List<IMavenDiscoveryProposal> proposals, IProgressMonitor monitor) {
List<CatalogItem> items = toCatalogItems(proposals);
- MavenDiscoveryInstallOperation op = new MavenDiscoveryInstallOperation(items, false);
+ boolean restart = isRestartRequired(proposals, monitor);
+ final MavenDiscoveryInstallOperation op = new MavenDiscoveryInstallOperation(items, restart);
try {
op.run(monitor);
+
+ if(restart) {
+ ProvisioningUI.getDefaultUI().schedule(op.getOperation().getProvisioningJob(monitor), 0);
+ } else {
+ ProvisioningJob job = op.getOperation().getProvisioningJob(monitor);
+ job.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants.ICON_PROPERTY, ProvUIImages.getImageDescriptor(ProvUIImages.IMG_PROFILE));
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ IStatus status = job.runModal(monitor);
+ if(status.isOK()) {
+ applyProfileChanges();
+ } else {
+ StatusManager.getManager().handle(status);
+ }
+ }
+
} catch(InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -228,6 +269,20 @@ public class MavenDiscoveryService implements IMavenDisovery, ServiceFactory {
}
}
+ private void applyProfileChanges() {
+ Configurator configurator = (Configurator) ServiceHelper.getService(ProvUIActivator.getContext(),
+ Configurator.class.getName());
+ try {
+ configurator.applyConfiguration();
+ } catch(IOException e) {
+ ProvUI.handleException(e, ProvUIMessages.ProvUI_ErrorDuringApplyConfig, StatusManager.LOG | StatusManager.BLOCK);
+ } catch(IllegalStateException e) {
+ IStatus illegalApplyStatus = new Status(IStatus.WARNING, ProvUIActivator.PLUGIN_ID, 0,
+ ProvUIMessages.ProvisioningOperationRunner_CannotApplyChanges, e);
+ ProvUI.reportStatus(illegalApplyStatus, StatusManager.LOG | StatusManager.BLOCK);
+ }
+ }
+
private List<CatalogItem> toCatalogItems(List<IMavenDiscoveryProposal> proposals) {
List<CatalogItem> items = new ArrayList<CatalogItem>();
for(IMavenDiscoveryProposal proposal : proposals) {
@@ -249,4 +304,57 @@ public class MavenDiscoveryService implements IMavenDisovery, ServiceFactory {
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
}
+ /* (non-Javadoc)
+ * @see org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory#getPage(java.util.List, org.eclipse.jface.operation.IRunnableContext)
+ */
+ public IWizardPage getPage(List<IMavenDiscoveryProposal> proposals, IRunnableContext context)
+ throws InvocationTargetException, InterruptedException {
+
+ if(proposals != null && !proposals.isEmpty()) {
+ List<CatalogItem> installableConnectors = new ArrayList<CatalogItem>(proposals.size());
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
+ installableConnectors.add(((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem());
+ }
+ }
+ if(installableConnectors.size() > 0) {
+ MavenDiscoveryInstallOperation op = new MavenDiscoveryInstallOperation(installableConnectors,
+ MavenDiscovery.requireRestart(installableConnectors));
+ context.run(true, true, op);
+
+ RestartInstallOperation operation = op.getOperation();
+ IUElementListRoot root = new IUElementListRoot();
+ ArrayList<AvailableIUElement> list = new ArrayList<AvailableIUElement>(operation.getIUs().size());
+ for(IInstallableUnit iu : operation.getIUs()) {
+ AvailableIUElement element = new AvailableIUElement(root, iu, ProvisioningUI.getDefaultUI().getProfileId(),
+ false);
+ list.add(element);
+ }
+ root.setChildren(list.toArray());
+
+ return new InstallPage(ProvisioningUI.getDefaultUI(), root, operation);
+ }
+ }
+ return null;
+ }
+
+ private static class InstallPage extends InstallWizardPage {
+ private RestartInstallOperation operation;
+
+ private AcceptLicensesWizardPage nextPage;
+
+ public InstallPage(ProvisioningUI ui, IUElementListRoot root, RestartInstallOperation operation) {
+ super(ui, new MavenDiscoveryInstallWizard(ui, operation, operation.getIUs(), null), root, operation);
+ this.operation = operation;
+ }
+
+ public IWizardPage getNextPage() {
+ if(nextPage == null) {
+ nextPage = new AcceptLicensesWizardPage(ProvisioningUI.getDefaultUI().getLicenseManager(), operation.getIUs()
+ .toArray(new IInstallableUnit[operation.getIUs().size()]), operation);
+ nextPage.setWizard(getWizard());
+ }
+ return nextPage;
+ }
+ }
}
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
index 4c6d80b6..009b054f 100644
--- 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
@@ -42,9 +42,7 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.m2e.internal.discovery.DiscoveryActivator;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
import org.eclipse.m2e.internal.discovery.Messages;
-import org.eclipse.m2e.internal.discovery.wizards.MavenDiscoveryUi;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
/*
@@ -63,6 +61,8 @@ public class MavenDiscoveryInstallOperation implements IRunnableWithProgress {
private List<IStatus> statuses = new ArrayList<IStatus>();
+ private RestartInstallOperation operation;
+
public MavenDiscoveryInstallOperation(List<CatalogItem> installableConnectors, boolean restart) {
this.installableConnectors = installableConnectors;
this.restart = restart;
@@ -78,16 +78,10 @@ public class MavenDiscoveryInstallOperation implements IRunnableWithProgress {
checkCancelled(monitor);
- final RestartInstallOperation installOperation = createAndResolve(monitor.newChild(50), ius, new URI[0],
+ operation = createAndResolve(monitor.newChild(50), ius, new URI[0],
restart && MavenDiscovery.requireRestart(installableConnectors));
checkCancelled(monitor);
-
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- MavenDiscoveryUi.openInstallWizard(Arrays.asList(ius), installOperation, null);
- }
- });
} finally {
monitor.done();
}
@@ -99,6 +93,13 @@ public class MavenDiscoveryInstallOperation implements IRunnableWithProgress {
}
/*
+ * Should only be called after a successful call to run
+ */
+ public RestartInstallOperation getOperation() {
+ return operation;
+ }
+
+ /*
* Compute the InstallableUnits & IMetadataRepository
*/
public IInstallableUnit[] computeInstallableUnits(IProgressMonitor progressMonitor) throws CoreException {
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
index 365f2705..5481ddc4 100644
--- 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
@@ -31,9 +31,12 @@ public class RestartInstallOperation extends InstallOperation {
private ProvisioningSession session;
+ private Collection<IInstallableUnit> toInstall;
+
public RestartInstallOperation(ProvisioningSession session, Collection<IInstallableUnit> toInstall) {
super(session, toInstall);
this.session = session;
+ this.toInstall = toInstall;
}
@Override
@@ -56,6 +59,10 @@ public class RestartInstallOperation extends InstallOperation {
this.restartPolicy = restartPolicy;
}
+ public Collection<IInstallableUnit> getIUs() {
+ return toInstall;
+ }
+
/*
* The ProfileModificationJob is wrapped to allow us to know when the job finishes successfully so we can
* ensure that early startup for update configuration is enabled.
@@ -73,7 +80,12 @@ public class RestartInstallOperation extends InstallOperation {
public IStatus runModal(IProgressMonitor monitor) {
IStatus status = job.run(monitor);
if(status.isOK()) {
- UpdateConfigurationStartup.enableStartup();
+ // If the installation doesn't require a restart, launch the reconfiguration now.
+ if(getRestartPolicy() == ProvisioningJob.RESTART_NONE) {
+ UpdateConfigurationStartup.updateConfiguration();
+ } else {
+ UpdateConfigurationStartup.enableStartup();
+ }
}
return status;
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/startup/UpdateConfigurationStartup.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/startup/UpdateConfigurationStartup.java
index 30812a8b..7c11d19c 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/startup/UpdateConfigurationStartup.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/startup/UpdateConfigurationStartup.java
@@ -12,6 +12,7 @@
package org.eclipse.m2e.internal.discovery.startup;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IProject;
@@ -60,6 +61,14 @@ public class UpdateConfigurationStartup implements IStartup {
removeEarlyStartup();
}
+ /*
+ * Configure projects
+ */
+ public static void updateConfiguration() {
+ Collection<IProject> projects = getMarkedProjects();
+ new UpdateConfigurationJob(MavenPlugin.getDefault(), projects.toArray(new IProject[projects.size()])).schedule();
+ }
+
private static void addEarlyStartup() {
String[] disabledEarlyActivation = Workbench.getInstance().getDisabledEarlyActivatedPlugins();
@@ -137,12 +146,20 @@ public class UpdateConfigurationStartup implements IStartup {
*/
public static void saveMarkedProjects() {
StringBuilder sb = new StringBuilder();
+ for(IProject project : getMarkedProjects()) {
+ sb.append(project.getName()).append(IPreferenceConstants.SEPARATOR);
+ }
+ DiscoveryActivator.getDefault().getPreferenceStore().putValue(PROJECT_PREF, sb.toString());
+ }
+
+ private static Collection<IProject> getMarkedProjects() {
+ List<IProject> projects = new ArrayList<IProject>();
MultiStatus status = new MultiStatus(DiscoveryActivator.PLUGIN_ID, 0,
Messages.UpdateConfigurationStartup_MarkerError, null);
for(IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
try {
if(project.findMarkers(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, true, IResource.DEPTH_ONE).length > 0) {
- sb.append(project.getName()).append(IPreferenceConstants.SEPARATOR);
+ projects.add(project);
}
} catch(CoreException e) {
status.add(e.getStatus());
@@ -151,7 +168,7 @@ public class UpdateConfigurationStartup implements IStartup {
if(status.getChildren().length > 0) {
StatusManager.getManager().handle(status);
}
- DiscoveryActivator.getDefault().getPreferenceStore().putValue(PROJECT_PREF, sb.toString());
+ return projects;
}
/*
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
index b7e56449..f357076c 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
@@ -12,7 +12,6 @@
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;
@@ -22,11 +21,8 @@ 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.DiscoveryActivator;
import org.eclipse.m2e.internal.discovery.operation.MavenDiscoveryInstallOperation;
@@ -50,8 +46,9 @@ public abstract class MavenDiscoveryUi {
public static boolean install(List<CatalogItem> descriptors, IRunnableContext context) {
try {
- IRunnableWithProgress runner = new MavenDiscoveryInstallOperation(descriptors, true);
+ MavenDiscoveryInstallOperation runner = new MavenDiscoveryInstallOperation(descriptors, true);
context.run(true, true, runner);
+ openInstallWizard(runner.getOperation());
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, DiscoveryActivator.PLUGIN_ID, NLS.bind(
Messages.ConnectorDiscoveryWizard_installProblems, new Object[] {e.getCause().getMessage()}), e.getCause());
@@ -64,9 +61,8 @@ public abstract class MavenDiscoveryUi {
return true;
}
- public static int openInstallWizard(Collection<IInstallableUnit> initialSelections,
- RestartInstallOperation operation, LoadMetadataRepositoryJob job) {
- MavenDiscoveryInstallWizard wizard = new MavenDiscoveryInstallWizard(ProvisioningUI.getDefaultUI(), operation, initialSelections, job);
+ public static int openInstallWizard(RestartInstallOperation operation) {
+ MavenDiscoveryInstallWizard wizard = new MavenDiscoveryInstallWizard(ProvisioningUI.getDefaultUI(), operation, operation.getIUs(), null);
WizardDialog dialog = new ProvisioningWizardDialog(ProvUI.getDefaultParentShell(), wizard);
dialog.create();
PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IProvHelpContextIds.INSTALL_WIZARD);

Back to the top