aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-02-28 13:39:35 (EST)
committerPascal Rapicault2011-03-03 16:35:20 (EST)
commitea88d2e22b19a9f914d3acc5f6292216a0a536f3 (patch)
treea2f9dc0c9d2282ba837346994a80327b98031c4d
parent07fb9045d55d0f6e56798b52093e8d7e281c60b7 (diff)
downloadm2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.zip
m2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.tar.gz
m2e-core-ea88d2e22b19a9f914d3acc5f6292216a0a536f3.tar.bz2
Bug 337989 - Discover extensions during project import
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java24
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java13
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/IImportWizardPageFactory.java24
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java40
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java84
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java (renamed from org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDisovery.java)2
-rw-r--r--org.eclipse.m2e.discovery/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.m2e.discovery/OSGI-INF/component.xml3
-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
13 files changed, 299 insertions, 72 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java
index 48eb5f2..72feac1 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java
@@ -17,10 +17,11 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.core.IMavenConstants;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDisovery;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
import org.eclipse.m2e.core.ui.internal.console.MavenConsoleImpl;
import org.eclipse.m2e.core.ui.internal.search.util.IndexSearchEngine;
import org.eclipse.m2e.core.ui.internal.search.util.SearchEngine;
+import org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -87,12 +88,12 @@ public class M2EUIPluginActivator extends AbstractUIPlugin {
}
@SuppressWarnings({"rawtypes", "unchecked"})
- public synchronized IMavenDisovery getMavenDiscovery() {
+ public synchronized IMavenDiscovery getMavenDiscovery() {
// TODO this leaks service references
BundleContext context = getBundle().getBundleContext();
- ServiceReference serviceReference = context.getServiceReference(IMavenDisovery.class.getName());
+ ServiceReference serviceReference = context.getServiceReference(IMavenDiscovery.class.getName());
if(serviceReference != null) {
- return (IMavenDisovery) context.getService(serviceReference);
+ return (IMavenDiscovery) context.getService(serviceReference);
}
return null;
}
@@ -100,8 +101,21 @@ public class M2EUIPluginActivator extends AbstractUIPlugin {
/**
* @param discovery
*/
- public void ungetMavenDiscovery(IMavenDisovery discovery) {
+ public void ungetMavenDiscovery(IMavenDiscovery discovery) {
// TODO Auto-generated method ungetMavenDiscovery
}
+
+ /**
+ * @return
+ */
+ public IImportWizardPageFactory getImportWizardPageFactory() {
+ // TODO this leaks service references
+ BundleContext context = getBundle().getBundleContext();
+ ServiceReference serviceReference = context.getServiceReference(IImportWizardPageFactory.class.getName());
+ if(serviceReference != null) {
+ return (IImportWizardPageFactory) context.getService(serviceReference);
+ }
+ return null;
+ }
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java
index af46a51..a4c6a33 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java
@@ -16,7 +16,7 @@ import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDisovery;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
@@ -33,12 +33,15 @@ public abstract class AbstractMavenProjectWizard extends Wizard {
protected List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>();
- private IMavenDisovery discovery;
+ private IMavenDiscovery discovery;
+
+ private IImportWizardPageFactory pageFactory;
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.selection = selection;
this.importConfiguration = new ProjectImportConfiguration();
this.discovery = M2EUIPluginActivator.getDefault().getMavenDiscovery();
+ this.pageFactory = M2EUIPluginActivator.getDefault().getImportWizardPageFactory();
IWorkingSet workingSet = SelectionUtil.getSelectedWorkingSet(selection);
if(workingSet != null) {
this.workingSets.add(workingSet);
@@ -55,7 +58,11 @@ public abstract class AbstractMavenProjectWizard extends Wizard {
return importConfiguration;
}
- public IMavenDisovery getDiscovery() {
+ public IMavenDiscovery getDiscovery() {
return discovery;
}
+
+ public IImportWizardPageFactory getPageFactory() {
+ return pageFactory;
+ }
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/IImportWizardPageFactory.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/IImportWizardPageFactory.java
new file mode 100644
index 0000000..a3f763f
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/IImportWizardPageFactory.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
+
+@SuppressWarnings("restriction")
+public interface IImportWizardPageFactory {
+
+ public IWizardPage getPage(List<IMavenDiscoveryProposal> proposals, IRunnableContext context)
+ throws InvocationTargetException, InterruptedException;
+
+}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java
index eb34b89..1278d2d 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java
@@ -26,19 +26,17 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingElementKey;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
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.MojoExecutionMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ProjectLifecycleMappingConfiguration;
@@ -86,6 +84,8 @@ public class LifecycleMappingPage extends WizardPage {
private boolean loading = true;
+ private IWizardPage discoveryPage;
+
/**
* Create the wizard.
*/
@@ -336,7 +336,10 @@ public class LifecycleMappingPage extends WizardPage {
// } else {
// mappingConfiguration.removeSelectedProposal(proposal);
// }
-//
+// discoveryPage = null;
+// if(getSelectedDiscoveryProposals().isEmpty()) {
+// //
+// }
// discoverProposals();
// }
// });
@@ -356,7 +359,8 @@ public class LifecycleMappingPage extends WizardPage {
protected void discoverProposals() {
loading = true;
treeViewer.refresh();
- final IMavenDisovery discovery = ((AbstractMavenProjectWizard) getWizard()).getDiscovery();
+ final IMavenDiscovery discovery = ((AbstractMavenProjectWizard) getWizard()).getDiscovery();
+
try {
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -491,6 +495,28 @@ public class LifecycleMappingPage extends WizardPage {
}
return mappingConfiguration.getSelectedProposals();
}
-
+ @Override
+ public IWizardPage getNextPage() {
+ IImportWizardPageFactory discovery = ((AbstractMavenProjectWizard) getWizard()).getPageFactory();
+ if (discovery == null) {
+ return getWizard().getNextPage(this);
+ }
+
+ List<IMavenDiscoveryProposal> proposals = getSelectedDiscoveryProposals();
+ // TODO When selection changes occur we need to make sure we get a new page
+ if(discoveryPage == null && !proposals.isEmpty()) {
+ try {
+ discoveryPage = ((IImportWizardPageFactory) discovery).getPage(proposals, this.getContainer());
+ if(discoveryPage != null) {
+ discoveryPage.setWizard(getWizard());
+ }
+ } catch(InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ } catch(InterruptedException e) {
+ // TODO Auto-generated catch block
+ }
+ }
+ return discoveryPage != null ? discoveryPage : getWizard().getNextPage(this);
+ }
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
index eeb73f2..b8e6feb 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java
@@ -20,11 +20,13 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDisovery;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
@@ -91,37 +93,57 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
return false;
}
- final Collection<MavenProjectInfo> projects = getProjects();
- final List<IMavenDiscoveryProposal> proposals = getMavenDiscoveryProposals();
-
final MavenPlugin plugin = MavenPlugin.getDefault();
-
- Job job = new AbstactCreateMavenProjectJob(Messages.MavenImportWizard_job, workingSets) {
- @Override
- protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
-
- IMavenDisovery discovery = getDiscovery();
-
- boolean restartRequired = false;
-
- if(discovery != null && !proposals.isEmpty()) {
- restartRequired = discovery.isRestartRequired(proposals, monitor);
-
- discovery.implement(proposals, monitor);
+ final List<IMavenDiscoveryProposal> proposals = getMavenDiscoveryProposals();
+ final Collection<MavenProjectInfo> projects = getProjects();
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ public void run(final IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
+ // Use the monitor from run() in order to provide progress to the wizard
+ Job job = new AbstactCreateMavenProjectJob(Messages.MavenImportWizard_job, workingSets) {
+ @Override
+ protected List<IProject> doCreateMavenProjects(IProgressMonitor pm) throws CoreException {
+ SubMonitor monitor = SubMonitor.convert(progressMonitor, 101);
+ try {
+ IMavenDiscovery discovery = getDiscovery();
+
+ boolean restartRequired = false;
+ if(discovery != null && !proposals.isEmpty()) {
+ restartRequired = discovery.isRestartRequired(proposals, monitor);
+ // No restart required, install prior to importing
+ if(!restartRequired) {
+ discovery.implement(proposals, monitor.newChild(50));
+ }
+ }
+ // Import projects
+ monitor.beginTask(Messages.MavenImportWizard_job, proposals.isEmpty() ? 100 : 50);
+ List<IMavenProjectImportResult> results = plugin.getProjectConfigurationManager().importProjects(
+ projects, importConfiguration, monitor.newChild(proposals.isEmpty() ? 100 : 50));
+
+ // Restart required, schedule job
+ if(restartRequired && !proposals.isEmpty()) {
+ discovery.implement(proposals, monitor.newChild(1));
+ }
+
+ return toProjects(results);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ job.setRule(plugin.getProjectConfigurationManager().getRule());
+ job.schedule();
+ job.join();
}
-
- List<IMavenProjectImportResult> results = plugin.getProjectConfigurationManager().importProjects(projects,
- importConfiguration, monitor);
-
- // XXX move up and implement restart
-
- return toProjects(results);
- }
- };
- job.setRule(plugin.getProjectConfigurationManager().getRule());
- job.schedule();
-
- return true;
+ });
+ return true;
+ } catch(InvocationTargetException e) {
+ // TODO This doesn't seem like it should occur
+ } catch(InterruptedException e) {
+ // User cancelled operation, we don't return the
+ }
+ return false;
}
/* (non-Javadoc)
@@ -173,6 +195,4 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
throw new InvocationTargetException(e);
}
}
-
-
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDisovery.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java
index 3d648eb..dc75d4f 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDisovery.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java
@@ -21,7 +21,7 @@ import org.apache.maven.project.MavenProject;
/**
* @author igor
*/
-public interface IMavenDisovery {
+public interface IMavenDiscovery {
/**
* <p>
diff --git a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
index 6b26e94..a6802e7 100644
--- a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
@@ -36,6 +36,7 @@ Import-Package: org.apache.maven.model,
org.eclipse.equinox.internal.p2.ui,
org.eclipse.equinox.internal.p2.ui.dialogs,
org.eclipse.equinox.internal.p2.ui.model,
+ org.eclipse.equinox.internal.provisional.configurator,
org.eclipse.equinox.p2.engine,
org.eclipse.equinox.p2.metadata,
org.eclipse.equinox.p2.repository.metadata,
diff --git a/org.eclipse.m2e.discovery/OSGI-INF/component.xml b/org.eclipse.m2e.discovery/OSGI-INF/component.xml
index 608e7c1..d06f239 100644
--- a/org.eclipse.m2e.discovery/OSGI-INF/component.xml
+++ b/org.eclipse.m2e.discovery/OSGI-INF/component.xml
@@ -2,6 +2,7 @@
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.m2e.internal.discovery.MavenDiscoveryService">
<implementation class="org.eclipse.m2e.internal.discovery.MavenDiscoveryService"/>
<service>
- <provide interface="org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDisovery"/>
+ <provide interface="org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery"/>
+ <provide interface="org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory"/>
</service>
</scr:component>
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 5f299fe..7369c40 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 4c6d80b..009b054 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 365f270..5481ddc 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 30812a8..7c11d19 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 b7e5644..f357076 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);