Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2013-09-30 03:43:34 -0400
committerFred Bricon2013-09-30 09:42:00 -0400
commit798db4c8b2405f58319a5bb899b7bada7f8152b4 (patch)
tree8509da6019abe4b394f35a5ae7ae2d70a6be99a7
parent601f18cf2f007d80e6347217c302989218e96f47 (diff)
downloadm2e-core-798db4c8b2405f58319a5bb899b7bada7f8152b4.tar.gz
m2e-core-798db4c8b2405f58319a5bb899b7bada7f8152b4.tar.xz
m2e-core-798db4c8b2405f58319a5bb899b7bada7f8152b4.zip
409732 : Split lifecycle mapping analysis from project import
The Lifecycle Mapping analysis is now only run after projects are imported, making selection of projects to import much much faster (< 1 sec vs 1-2 min for the wildfly codebase and its 130 projects) After import, lifecycle mapping error markers are collected on imported projects and the discovery service is invoked to find proposals fixing these errors. Caveats : - no proposals are shown anymore in case projects import without errors, making discovery of new/other applicable connectors less obvious. As part of the refactoring the following notable architectural changes were performed : - LM Analysis and Discovery proposals UI are moved to a dedicated Wizard. - LifecycleMappingConfiguration was deprecated in favor of LifecycleMappingDiscoveryRequest -Lifecycle Mapping discovery is now based on a collection of ILifecycleMappingRequirement Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java1
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java9
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/ILifecycleMappingLabelProvider.java9
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/MojoExecutionMappingLabelProvider.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/PackagingTypeMappingLabelProvider.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java27
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/ImportMavenProjectsJob.java113
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingDiscoveryHelper.java158
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java165
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java246
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizard.java321
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java28
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java25
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingConfiguration.java472
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingDiscoveryRequest.java197
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java45
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MarkerUtils.java29
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java10
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java71
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java7
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java8
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java174
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java19
-rw-r--r--org.eclipse.m2e.scm/src/org/eclipse/m2e/scm/internal/wizards/MavenProjectCheckoutJob.java41
25 files changed, 1164 insertions, 1035 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index 3086eeaa..ca0781de 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -894,6 +894,7 @@ public class Messages extends NLS {
public static String AssignWorkingSetDialog_btnFilterAssignedProjects_text;
public static String AssignWorkingSetDialog_btnAssign_text;
+
public static String AssignWorkingSetDialog_btnFilterClosedProjects_text;
static {
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java
index c261f314..2e848b38 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.lifecyclemapping;
@@ -18,7 +21,7 @@ import org.eclipse.osgi.util.NLS;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.ProjectConfiguratorMappingRequirement;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration.LifecycleStrategyMappingRequirement;
@@ -59,7 +62,7 @@ public class AggregateMappingLabelProvider implements ILifecycleMappingLabelProv
throw new IllegalStateException();
}
- public boolean isError(LifecycleMappingConfiguration mappingConfiguration) {
+ public boolean isError(LifecycleMappingDiscoveryRequest mappingConfiguration) {
for(ILifecycleMappingLabelProvider pr : content) {
if(pr.isError(mappingConfiguration)) {
return true;
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/ILifecycleMappingLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/ILifecycleMappingLabelProvider.java
index 7bbfa961..4b0c422f 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/ILifecycleMappingLabelProvider.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/ILifecycleMappingLabelProvider.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.lifecyclemapping;
@@ -13,7 +16,7 @@ import java.util.Collection;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
/**
@@ -28,7 +31,7 @@ public interface ILifecycleMappingLabelProvider {
*/
public String getMavenText();
- public boolean isError(LifecycleMappingConfiguration mappingConfiguration);
+ public boolean isError(LifecycleMappingDiscoveryRequest mappingConfiguration);
public ILifecycleMappingRequirement getKey();
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/MojoExecutionMappingLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/MojoExecutionMappingLabelProvider.java
index 8a0be10d..6b1c9d6b 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/MojoExecutionMappingLabelProvider.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/MojoExecutionMappingLabelProvider.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.lifecyclemapping;
@@ -17,7 +20,7 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ProjectLifecycleMappingConfiguration;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
@@ -53,10 +56,10 @@ public class MojoExecutionMappingLabelProvider implements ILifecycleMappingLabel
/* (non-Javadoc)
* @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#isError()
*/
- public boolean isError(LifecycleMappingConfiguration mappingConfiguration) {
+ public boolean isError(LifecycleMappingDiscoveryRequest mappingConfiguration) {
ILifecycleMappingRequirement requirement = element.getLifecycleMappingRequirement();
return LifecycleMappingFactory.isInterestingPhase(element.getMojoExecutionKey().getLifecyclePhase())
- && !mappingConfiguration.isRequirementSatisfied(requirement, true);
+ && !mappingConfiguration.isRequirementSatisfied(requirement);
}
/* (non-Javadoc)
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/PackagingTypeMappingLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/PackagingTypeMappingLabelProvider.java
index a74a0f84..97d5ccb9 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/PackagingTypeMappingLabelProvider.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/PackagingTypeMappingLabelProvider.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.lifecyclemapping;
@@ -14,7 +17,7 @@ import java.util.Collections;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ProjectLifecycleMappingConfiguration;
@@ -44,8 +47,8 @@ public class PackagingTypeMappingLabelProvider implements ILifecycleMappingLabel
/* (non-Javadoc)
* @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#isError()
*/
- public boolean isError(LifecycleMappingConfiguration mappingConfiguration) {
- return !mappingConfiguration.isRequirementSatisfied(getKey(), true);
+ public boolean isError(LifecycleMappingDiscoveryRequest mappingConfiguration) {
+ return !mappingConfiguration.isRequirementSatisfied(getKey());
}
/* (non-Javadoc)
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java
index 15006e54..7fba9572 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - Return created projects
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.wizards;
@@ -36,11 +40,13 @@ public abstract class AbstractCreateMavenProjectsOperation implements IRunnableW
this.workingSets = workingSets;
}
+ private List<IProject> createdProjects;
+
protected abstract List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException;
// PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(project, new IWorkingSet[] {workingSet});
public static void addToWorkingSets(IProject project, List<IWorkingSet> workingSets) {
- if(workingSets != null && workingSets.size() > 0) {
+ if(workingSets != null && !workingSets.isEmpty()) {
// IAdaptable[] elements = workingSet.adaptElements(new IAdaptable[] {project});
// if(elements.length == 1) {
for(IWorkingSet workingSet : workingSets) {
@@ -69,11 +75,10 @@ public abstract class AbstractCreateMavenProjectsOperation implements IRunnableW
ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
Job.getJobManager().beginRule(rule, monitor);
try {
- List<IProject> projects;
try {
- projects = doCreateMavenProjects(monitor);
- if(projects != null) {
- for(IProject project : projects) {
+ this.createdProjects = doCreateMavenProjects(monitor);
+ if(createdProjects != null && workingSets != null && !workingSets.isEmpty()) {
+ for(IProject project : createdProjects) {
addToWorkingSets(project, workingSets);
}
}
@@ -92,4 +97,14 @@ public abstract class AbstractCreateMavenProjectsOperation implements IRunnableW
}
return new Status(IStatus.ERROR, M2EUIPluginActivator.PLUGIN_ID, t.getMessage(), t);
}
+
+ /**
+ * Returns a list of {@link IProject}s created by this operation.
+ *
+ * @since 1.5.0
+ */
+ public List<IProject> getCreatedProjects() {
+ return createdProjects;
+ }
+
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/ImportMavenProjectsJob.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/ImportMavenProjectsJob.java
new file mode 100644
index 00000000..9c42c5c4
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/ImportMavenProjectsJob.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation (in o.e.m.c.u.i.w.MavenImportWizard)
+ * Red Hat, Inc. - Extracted import workflow as standalone job
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.WorkspaceJob;
+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.core.runtime.SubMonitor;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
+import org.eclipse.m2e.core.project.IMavenProjectImportResult;
+import org.eclipse.m2e.core.project.MavenProjectInfo;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+import org.eclipse.m2e.core.ui.internal.Messages;
+
+
+/**
+ * Workspace Job for importing {@link MavenProjectInfo}s into the workspace. After the projects are imported, if
+ * lifecycle mappings errors have been detected on the imported projects, the Lifecycle Mapping wizard is shown to help
+ * users fix these errors.
+ *
+ * @author Eugene Kuleshov
+ * @author Fred Bricon
+ */
+public class ImportMavenProjectsJob extends WorkspaceJob {
+
+ private List<IWorkingSet> workingSets;
+
+ private Collection<MavenProjectInfo> projects;
+
+ private ProjectImportConfiguration importConfiguration;
+
+ public ImportMavenProjectsJob(Collection<MavenProjectInfo> projects, List<IWorkingSet> workingSets,
+ ProjectImportConfiguration importConfiguration) {
+ super(Messages.MavenImportWizard_job);
+ this.projects = projects;
+ this.workingSets = workingSets;
+ this.importConfiguration = importConfiguration;
+ }
+
+ @Override
+ public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
+
+ final AbstractCreateMavenProjectsOperation importOperation = new AbstractCreateMavenProjectsOperation(workingSets) {
+
+ @Override
+ protected List<IProject> doCreateMavenProjects(IProgressMonitor progressMonitor) throws CoreException {
+ SubMonitor monitor = SubMonitor.convert(progressMonitor, 101);
+ try {
+ List<IMavenProjectImportResult> results = MavenPlugin.getProjectConfigurationManager().importProjects(
+ projects, importConfiguration, monitor.newChild(100));
+ return toProjects(results);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ importOperation.run(monitor);
+ List<IProject> createdProjects = importOperation.getCreatedProjects();
+ //Detect and resolve Lifecycle Mapping issues
+ LifecycleMappingDiscoveryRequest discoveryRequest = LifecycleMappingDiscoveryHelper
+ .createLifecycleMappingDiscoveryRequest(createdProjects, monitor);
+ if(discoveryRequest.isMappingComplete()) {
+ return Status.OK_STATUS;
+ }
+ //LifecycleMappingHelper will discover proposals only if discovery service is available
+ LifecycleMappingDiscoveryHelper.discoverProposals(discoveryRequest, monitor);
+ final MavenDiscoveryProposalWizard proposalWizard = new MavenDiscoveryProposalWizard(createdProjects,
+ discoveryRequest);
+ proposalWizard.init(null, null);
+ //Some errors were detected
+
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), proposalWizard);
+ dialog.open();
+ }
+ });
+ } catch(InvocationTargetException e) {
+ return AbstractCreateMavenProjectsOperation.toStatus(e);
+ } catch(InterruptedException e) {
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingDiscoveryHelper.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingDiscoveryHelper.java
new file mode 100644
index 00000000..b9bc0f71
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingDiscoveryHelper.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.wizards;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
+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.LifecycleMappingDiscoveryRequest;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.ProjectConfiguratorMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration.LifecycleStrategyMappingRequirement;
+import org.eclipse.m2e.core.internal.markers.MarkerUtils;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
+import org.eclipse.m2e.core.ui.internal.Messages;
+
+
+/**
+ * Helper to build {@link LifecycleMappingDiscoveryRequest}s and discover matching Lifecycle Mapping proposals.
+ *
+ * @since 1.5.0
+ * @author Fred Bricon
+ */
+public class LifecycleMappingDiscoveryHelper {
+
+ private LifecycleMappingDiscoveryHelper() {
+ //Helper class
+ }
+
+ /**
+ * Builds a {@link LifecycleMappingDiscoveryRequest} from a project. Unsatisfied {@link ILifecycleMappingRequirement}s
+ * are collected from LifecycleMapping error markers.
+ */
+ public static LifecycleMappingDiscoveryRequest createLifecycleMappingDiscoveryRequest(IProject project,
+ IProgressMonitor monitor) throws CoreException {
+ return createLifecycleMappingDiscoveryRequest(Collections.singleton(project), monitor);
+ }
+
+ /**
+ * Builds a {@link LifecycleMappingDiscoveryRequest} from a collection of {@link IProject}s. For each project,
+ * unsatisfied {@link ILifecycleMappingRequirement}s are collected from LifecycleMapping error markers.
+ */
+ public static LifecycleMappingDiscoveryRequest createLifecycleMappingDiscoveryRequest(Collection<IProject> projects,
+ IProgressMonitor monitor) throws CoreException {
+ LifecycleMappingDiscoveryRequest request = new LifecycleMappingDiscoveryRequest();
+ if(projects != null) {
+ for(IProject p : projects) {
+ if(!p.isAccessible() || !p.hasNature(IMavenConstants.NATURE_ID)) {
+ continue;
+ }
+ IMarker[] lifecycleMappingMarkers = getLifecycleMappingMarkers(p);
+ if(lifecycleMappingMarkers != null && lifecycleMappingMarkers.length > 0) {
+ IMavenProjectFacade facade = getFacade(p, monitor);
+ if(facade != null) {
+ for(IMarker m : lifecycleMappingMarkers) {
+ ILifecycleMappingRequirement req = toLifecycleMappingRequirement(m, facade.getPackaging());
+ if(req != null) {
+ request.addProject(facade, req);
+ }
+ }
+ }
+ }
+ }
+ }
+ return request;
+ }
+
+ private static ILifecycleMappingRequirement toLifecycleMappingRequirement(IMarker marker, String packagingType) {
+ String type = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null);
+ if(type == null) {
+ return null;
+ }
+ ILifecycleMappingRequirement requirement = null;
+ if(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION.equals(type)) {
+ MojoExecutionKey mek = MarkerUtils.getMojoExecution(marker);
+ if(mek != null) {
+ requirement = new MojoExecutionMappingRequirement(mek, packagingType);
+ }
+ } else if(IMavenConstants.EDITOR_HINT_UNKNOWN_LIFECYCLE_ID.equals(type)) {
+ String lifecycleId = getLifecycleId(marker);
+ if(lifecycleId != null) {
+ requirement = new LifecycleStrategyMappingRequirement(null, lifecycleId);
+ }
+ } else if(IMavenConstants.EDITOR_HINT_MISSING_CONFIGURATOR.equals(type)) {
+ String configuratorId = getConfiguratorId(marker);
+ if(configuratorId != null) {
+ requirement = new ProjectConfiguratorMappingRequirement(null, configuratorId);
+ }
+ }
+ return requirement;
+ }
+
+ private static IMarker[] getLifecycleMappingMarkers(IProject p) throws CoreException {
+ IMarker[] markers = p.findMarkers(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, true, IResource.DEPTH_ONE);
+ return markers;
+ }
+
+ /**
+ * Discovers lifecycle mapping proposals matching a {@link LifecycleMappingDiscoveryRequest} requirements. Actual
+ * discovery is delegated to the registered instance of {@link IMavenDiscovery}, if available.
+ */
+ public static void discoverProposals(LifecycleMappingDiscoveryRequest discoveryRequest, IProgressMonitor monitor)
+ throws CoreException {
+ if(discoveryRequest == null || discoveryRequest.getRequirements() == null
+ || discoveryRequest.getRequirements().isEmpty()) {
+ return;
+ }
+ IMavenDiscovery discoveryService = M2EUIPluginActivator.getDefault().getMavenDiscovery();
+ if(discoveryService == null) {
+ return;
+ }
+ Collection<ILifecycleMappingRequirement> requirements = discoveryRequest.getRequirements();
+ if(monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ monitor.beginTask(Messages.MavenImportWizard_searchingTaskTitle, requirements.size());
+ Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> allProposals = discoveryService.discover(
+ requirements, discoveryRequest.getSelectedProposals(), monitor);
+ discoveryRequest.setProposals(allProposals);
+ monitor.worked(1);
+ }
+
+ private static IMavenProjectFacade getFacade(IProject project, IProgressMonitor monitor) {
+ return MavenPlugin.getMavenProjectRegistry().create(project.getFile(IMavenConstants.POM_FILE_NAME), true, monitor);
+ }
+
+ private static String getLifecycleId(IMarker marker) {
+ return marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, null);
+ }
+
+ private static String getConfiguratorId(IMarker marker) {
+ return marker.getAttribute(IMavenConstants.MARKER_ATTR_CONFIGURATOR_ID, null);
+ }
+}
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 49879743..7459abc7 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
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2011 Sonatype, Inc.
+ * Copyright (c) 2011-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - refactored proposals discovery
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.wizards;
@@ -16,13 +20,22 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.TreeColumnLayout;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ILabelProviderListener;
@@ -57,23 +70,19 @@ import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
+import org.apache.maven.project.MavenProject;
+
+import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ProjectLifecycleMappingConfiguration;
-import org.eclipse.m2e.core.project.MavenProjectInfo;
-import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.MavenImages;
import org.eclipse.m2e.core.ui.internal.Messages;
import org.eclipse.m2e.core.ui.internal.lifecyclemapping.AggregateMappingLabelProvider;
import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
-import org.eclipse.m2e.core.ui.internal.lifecyclemapping.MojoExecutionMappingLabelProvider;
-import org.eclipse.m2e.core.ui.internal.lifecyclemapping.PackagingTypeMappingLabelProvider;
/**
@@ -84,6 +93,8 @@ import org.eclipse.m2e.core.ui.internal.lifecyclemapping.PackagingTypeMappingLab
@SuppressWarnings("restriction")
public class LifecycleMappingPage extends WizardPage {
+ private static final Logger LOG = LoggerFactory.getLogger(LifecycleMappingPage.class);
+
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final int MAVEN_INFO_IDX = 0;
@@ -96,7 +107,7 @@ public class LifecycleMappingPage extends WizardPage {
private static final int IGNORE_PARENT_IDX = 2;
- private LifecycleMappingConfiguration mappingConfiguration;
+ private LifecycleMappingDiscoveryRequest mappingConfiguration;
private TreeViewer treeViewer;
@@ -135,7 +146,12 @@ public class LifecycleMappingPage extends WizardPage {
setControl(container);
container.setLayout(new GridLayout(1, false));
- treeViewer = new TreeViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
+ Composite treeViewerContainer = new Composite(container, SWT.NULL);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(treeViewerContainer);
+ TreeColumnLayout treeColumnLayout = new TreeColumnLayout();
+ treeViewerContainer.setLayout(treeColumnLayout);
+
+ treeViewer = new TreeViewer(treeViewerContainer, SWT.BORDER | SWT.FULL_SELECTION);
Tree tree = treeViewer.getTree();
tree.setLinesVisible(true);
@@ -145,12 +161,15 @@ public class LifecycleMappingPage extends WizardPage {
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
trclmnNewColumn.setText(Messages.LifecycleMappingPage_mavenBuildColumnTitle);
+ treeColumnLayout.setColumnData(trclmnNewColumn, new ColumnWeightData(65, 150, true));
TreeViewerColumn columnViewerAction = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn columnAction = columnViewerAction.getColumn();
+ treeColumnLayout.setColumnData(columnAction, new ColumnWeightData(35, true));
columnAction.setText(Messages.LifecycleMappingPage_actionColumnTitle);
columnViewerAction.setEditingSupport(new EditingSupport(treeViewer) {
+ @SuppressWarnings("synthetic-access")
@Override
protected void setValue(Object element, Object value) {
if(element instanceof ILifecycleMappingLabelProvider) {
@@ -184,9 +203,11 @@ public class LifecycleMappingPage extends WizardPage {
}
getViewer().refresh(true);
updateErrorCount();
+ getContainer().updateButtons();
}
}
+ @SuppressWarnings("synthetic-access")
@Override
protected Object getValue(Object element) {
if(element instanceof ILifecycleMappingLabelProvider) {
@@ -205,6 +226,7 @@ public class LifecycleMappingPage extends WizardPage {
return Integer.valueOf(0);
}
+ @SuppressWarnings("synthetic-access")
@Override
protected CellEditor getCellEditor(Object element) {
if(element instanceof ILifecycleMappingLabelProvider) {
@@ -233,6 +255,7 @@ public class LifecycleMappingPage extends WizardPage {
throw new IllegalStateException();
}
+ @SuppressWarnings("synthetic-access")
@Override
protected boolean canEdit(Object element) {
if(element instanceof AggregateMappingLabelProvider) {
@@ -253,40 +276,57 @@ public class LifecycleMappingPage extends WizardPage {
}
public Object[] getElements(Object inputElement) {
- if(inputElement instanceof LifecycleMappingConfiguration) {
+ if(inputElement instanceof LifecycleMappingDiscoveryRequest) {
Map<ILifecycleMappingRequirement, List<ILifecycleMappingLabelProvider>> packagings = new HashMap<ILifecycleMappingRequirement, List<ILifecycleMappingLabelProvider>>();
Map<ILifecycleMappingRequirement, List<ILifecycleMappingLabelProvider>> mojos = new HashMap<ILifecycleMappingRequirement, List<ILifecycleMappingLabelProvider>>();
- Collection<ProjectLifecycleMappingConfiguration> projects = ((LifecycleMappingConfiguration) inputElement)
+ Map<IMavenProjectFacade, List<ILifecycleMappingRequirement>> projects = ((LifecycleMappingDiscoveryRequest) inputElement)
.getProjects();
- for(ProjectLifecycleMappingConfiguration prjconf : projects) {
- PackagingTypeMappingConfiguration pack = prjconf.getPackagingTypeMappingConfiguration();
- if(pack != null) {
- ILifecycleMappingRequirement packReq = pack.getLifecycleMappingRequirement();
- if(packReq != null && !mappingConfiguration.getProposals(packReq).isEmpty()) {
- List<ILifecycleMappingLabelProvider> val = packagings.get(packReq);
+ for(final Entry<IMavenProjectFacade, List<ILifecycleMappingRequirement>> entry : projects.entrySet()) {
+ final String relPath = entry.getKey().getProject().getFile(IMavenConstants.POM_FILE_NAME).getFullPath()
+ .toPortableString();
+ for(final ILifecycleMappingRequirement requirement : entry.getValue()) {
+ // include mojo execution if it has available proposals or interesting phase not mapped locally
+ if(requirement != null) {
+ List<ILifecycleMappingLabelProvider> val = mojos.get(requirement);
if(val == null) {
val = new ArrayList<ILifecycleMappingLabelProvider>();
- packagings.put(packReq, val);
+ mojos.put(requirement, val);
}
- val.add(new PackagingTypeMappingLabelProvider(prjconf, pack));
- }
- }
- List<MojoExecutionMappingConfiguration> mojoExecs = prjconf.getMojoExecutionConfigurations();
- if(mojoExecs != null) {
- for(MojoExecutionMappingConfiguration mojoMap : mojoExecs) {
- ILifecycleMappingRequirement mojoReq = mojoMap.getLifecycleMappingRequirement();
- // include mojo execution if it has available proposals or interesting phase not mapped locally
- if(mojoReq != null
- && !mappingConfiguration.getProposals(mojoReq).isEmpty()
- || (LifecycleMappingFactory.isInterestingPhase(mojoMap.getExecution().getLifecyclePhase()) && !mappingConfiguration
- .isRequirementSatisfied(mojoReq, true))) {
- List<ILifecycleMappingLabelProvider> val = mojos.get(mojoReq);
- if(val == null) {
- val = new ArrayList<ILifecycleMappingLabelProvider>();
- mojos.put(mojoReq, val);
+ val.add(new ILifecycleMappingLabelProvider() {
+
+ public String getMavenText() {
+ if(requirement instanceof MojoExecutionMappingRequirement) {
+ String executionId = ((MojoExecutionMappingRequirement) requirement).getExecutionId();
+ if("default".equals(executionId)) {
+ return NLS.bind("{0}", relPath);
+ }
+ return NLS.bind("Execution {0}, in {1}", executionId, relPath);
+ }
+
+ return null;
}
- val.add(new MojoExecutionMappingLabelProvider(prjconf, mojoMap));
- }
+
+ public boolean isError(LifecycleMappingDiscoveryRequest mappingConfiguration) {
+ return !mappingConfiguration.isRequirementSatisfied(getKey());
+ }
+
+ public ILifecycleMappingRequirement getKey() {
+ return requirement;
+ }
+
+ @SuppressWarnings("synthetic-access")
+ public Collection<MavenProject> getProjects() {
+ MavenProject mavenProject;
+ try {
+ mavenProject = entry.getKey().getMavenProject(new NullProgressMonitor());
+ return Collections.singleton(mavenProject);
+ } catch(CoreException e) {
+ LOG.error(e.getMessage(), e);
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ });
}
}
}
@@ -334,6 +374,7 @@ public class LifecycleMappingPage extends WizardPage {
public void addListener(ILabelProviderListener listener) {
}
+ @SuppressWarnings("synthetic-access")
public String getColumnText(Object element, int columnIndex) {
if(element instanceof ILifecycleMappingLabelProvider) {
ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element;
@@ -362,6 +403,7 @@ public class LifecycleMappingPage extends WizardPage {
return null;
}
+ @SuppressWarnings("synthetic-access")
public Image getColumnImage(Object element, int columnIndex) {
if(columnIndex != 0) {
return null;
@@ -381,6 +423,7 @@ public class LifecycleMappingPage extends WizardPage {
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @SuppressWarnings("synthetic-access")
public void selectionChanged(SelectionChangedEvent event) {
if(event.getSelection() instanceof IStructuredSelection
&& ((IStructuredSelection) event.getSelection()).size() == 1) {
@@ -400,8 +443,7 @@ public class LifecycleMappingPage extends WizardPage {
license.setText(proposal == null ? EMPTY_STRING : proposal.getLicense());
}
} else {
- details.setText(EMPTY_STRING);
- license.setText(EMPTY_STRING);
+ resetDetails();
}
}
});
@@ -432,6 +474,7 @@ public class LifecycleMappingPage extends WizardPage {
Button btnNewButton_1 = new Button(composite, SWT.NONE);
btnNewButton_1.addSelectionListener(new SelectionAdapter() {
@Override
+ @SuppressWarnings("synthetic-access")
public void widgetSelected(SelectionEvent e) {
mappingConfiguration.clearSelectedProposals();
ignore.clear();
@@ -446,7 +489,9 @@ public class LifecycleMappingPage extends WizardPage {
autoSelectButton = new Button(composite, SWT.NONE);
autoSelectButton.addSelectionListener(new SelectionAdapter() {
@Override
+ @SuppressWarnings("synthetic-access")
public void widgetSelected(SelectionEvent e) {
+ resetDetails();
ignore.clear();
ignoreAtDefinition.clear();
discoverProposals();
@@ -508,9 +553,14 @@ public class LifecycleMappingPage extends WizardPage {
treeViewer.refresh();
try {
getContainer().run(true, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ @SuppressWarnings("synthetic-access")
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
mappingConfiguration.clearSelectedProposals();
- ((MavenImportWizard) getWizard()).discoverProposals(mappingConfiguration, monitor);
+ try {
+ LifecycleMappingDiscoveryHelper.discoverProposals(mappingConfiguration, monitor);
+ } catch(CoreException ex) {
+ throw new InvocationTargetException(ex);
+ }
mappingConfiguration.autoCompleteMapping();
}
});
@@ -531,33 +581,18 @@ public class LifecycleMappingPage extends WizardPage {
if(visible) {
PlatformUI.getWorkbench().getHelpSystem()
.setHelp(getWizard().getContainer().getShell(), M2EUIPluginActivator.PLUGIN_ID + ".LifecycleMappingPage"); //$NON-NLS-1$
- mappingConfiguration = ((MavenImportWizard) getWizard()).getMappingConfiguration();
+ mappingConfiguration = ((MavenDiscoveryProposalWizard) getWizard()).getLifecycleMappingDiscoveryRequest();
if(!mappingConfiguration.isMappingComplete()) {
// try to solve problems only if there are any
mappingConfiguration.autoCompleteMapping();
}
treeViewer.setInput(mappingConfiguration);
updateErrorCount();
-
- //set initial column sizes
- TreeColumn[] columns = treeViewer.getTree().getColumns();
- for(int i = 0; i < columns.length; i++ ) {
- int ratio = i == 0 ? 6 : 4;
- columns[i].setWidth(treeViewer.getTree().getClientArea().width / 10 * ratio);
- }
}
}
public boolean canFlipToNextPage() {
- return getNextPage() != null;
- }
-
- protected Collection<MavenProjectInfo> getProjects() {
- return ((MavenImportWizard) getWizard()).getProjects();
- }
-
- protected ProjectImportConfiguration getProjectImportConfiguration() {
- return ((MavenImportWizard) getWizard()).getProjectImportConfiguration();
+ return true;//getNextPage() != null;
}
public List<IMavenDiscoveryProposal> getSelectedDiscoveryProposals() {
@@ -628,4 +663,14 @@ public class LifecycleMappingPage extends WizardPage {
return ignore.contains(prov) || ignoreAtDefinition.contains(prov)
|| mappingConfiguration.getSelectedProposal(prov.getKey()) != null || !prov.isError(mappingConfiguration);
}
+
+ private void resetDetails() {
+ if(details != null) {
+ details.setText(EMPTY_STRING);
+ }
+ if(license != null) {
+ license.setText(EMPTY_STRING);
+ }
+ }
+
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java
new file mode 100644
index 00000000..ecaa0503
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation (in o.e.m.c.u.i.w.MavenImportWizard)
+ * Red Hat, Inc. - refactored lifecycle mapping discovery
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.wizards;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.WorkspaceJob;
+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.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+import org.apache.maven.project.MavenProject;
+
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.M2EUtils;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingDiscoveryRequest;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
+import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants;
+import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
+import org.eclipse.m2e.core.ui.internal.Messages;
+import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
+import org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation;
+import org.eclipse.m2e.core.ui.internal.editing.PomEdits;
+import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
+import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
+
+
+/**
+ * Lifecycle Mapping remediation proposal Wizard
+ *
+ * @author Eugene Kuleshov
+ * @author Fred Bricon
+ */
+@SuppressWarnings("restriction")
+public class MavenDiscoveryProposalWizard extends Wizard implements IImportWizard {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MavenDiscoveryProposalWizard.class);
+
+ private LifecycleMappingPage lifecycleMappingPage;
+
+ private boolean initialized = false;
+
+ private LifecycleMappingDiscoveryRequest mappingDiscoveryRequest;
+
+ private Collection<IProject> projects;
+
+ private IMavenDiscoveryUI pageFactory;
+
+ public MavenDiscoveryProposalWizard(Collection<IProject> projects,
+ LifecycleMappingDiscoveryRequest mappingDiscoveryRequest) {
+ this.projects = projects;
+ this.mappingDiscoveryRequest = mappingDiscoveryRequest;
+ setNeedsProgressMonitor(true);
+ setWindowTitle(Messages.MavenImportWizard_title);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.pageFactory = M2EUIPluginActivator.getDefault().getImportWizardPageFactory();
+ initialized = true;
+ }
+
+ public void addPages() {
+ if(!initialized) {
+ init(null, null);
+ }
+ lifecycleMappingPage = new LifecycleMappingPage();
+ addPage(lifecycleMappingPage);
+ }
+
+ public boolean performFinish() {
+ if(lifecycleMappingPage != null && !lifecycleMappingPage.isMappingComplete() && !warnIncompleteMapping()) {
+ return false;
+ }
+
+ final List<IMavenDiscoveryProposal> proposals = getMavenDiscoveryProposals();
+
+ boolean doIgnore = !lifecycleMappingPage.getIgnore().isEmpty() || !lifecycleMappingPage.getIgnoreParent().isEmpty();
+ IMavenDiscoveryUI discovery = getPageFactory();
+ if(discovery != null && !proposals.isEmpty()) {
+ Set<String> projectsToConfigure = new HashSet<String>();
+ for(IProject project : projects) {
+ projectsToConfigure.add(project.getName());
+ }
+ doIgnore = discovery.implement(proposals, null, getContainer(), projectsToConfigure);
+ }
+
+ if(doIgnore) {
+ final IRunnableWithProgress ignoreJob = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ List<IProject> changed = new LinkedList<IProject>();
+ for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnore()) {
+ ILifecycleMappingRequirement req = prov.getKey();
+ if(req instanceof MojoExecutionMappingRequirement) {
+ changed.addAll(getProject(prov.getProjects()));
+ ignore(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
+ }
+ }
+
+ for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreParent()) {
+ ILifecycleMappingRequirement req = prov.getKey();
+ if(req instanceof MojoExecutionMappingRequirement) {
+ changed.addAll(getProject(prov.getProjects()));
+ ignoreAtDefinition(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
+ }
+ }
+
+ new UpdateMavenProjectJob(changed.toArray(new IProject[changed.size()])).schedule();
+ }
+
+ private Collection<IProject> getProject(Collection<MavenProject> projects) {
+ List<IProject> workspaceProjects = new LinkedList<IProject>();
+ for(MavenProject project : projects) {
+ IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(),
+ project.getArtifactId(), project.getVersion());
+ if(facade != null) {
+ workspaceProjects.add(facade.getProject());
+ }
+ }
+ return workspaceProjects;
+ }
+
+ private void ignore(MojoExecutionKey key, Collection<MavenProject> projects) {
+ String pluginGroupId = key.getGroupId();
+ String pluginArtifactId = key.getArtifactId();
+ String pluginVersion = key.getVersion();
+ String[] goals = new String[] {key.getGoal()};
+ for(MavenProject project : projects) {
+ IFile pomFile = M2EUtils.getPomFile(project);
+ try {
+ PomEdits.performOnDOMDocument(new OperationTuple(pomFile, new LifecycleMappingOperation(pluginGroupId,
+ pluginArtifactId, pluginVersion, PluginExecutionAction.ignore, goals)));
+ } catch(IOException ex) {
+ LOG.error(ex.getMessage(), ex);
+ } catch(CoreException ex) {
+ LOG.error(ex.getMessage(), ex);
+ }
+ }
+ }
+
+ private void ignoreAtDefinition(MojoExecutionKey key, Collection<MavenProject> projects) {
+ ignore(key, M2EUtils.getDefiningProjects(key, projects));
+ }
+ };
+
+ Job job = new WorkspaceJob("Apply Lifecycle Mapping Changes") {
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ try {
+ ignoreJob.run(monitor);
+ } catch(InvocationTargetException e) {
+ return AbstractCreateMavenProjectsOperation.toStatus(e);
+ } catch(InterruptedException e) {
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
+ job.schedule();
+ }
+
+ return true;
+ }
+
+ private IMavenDiscoveryUI getPageFactory() {
+ return pageFactory;
+ }
+
+ @Override
+ public boolean canFinish() {
+ return true;
+ }
+
+ private List<IMavenDiscoveryProposal> getMavenDiscoveryProposals() {
+ if(lifecycleMappingPage == null) {
+ return Collections.emptyList();
+ }
+ return lifecycleMappingPage.getSelectedDiscoveryProposals();
+ }
+
+ /**
+ * @return mapping configuration or null
+ */
+ public LifecycleMappingDiscoveryRequest getLifecycleMappingDiscoveryRequest() {
+ return mappingDiscoveryRequest;
+ }
+
+ private boolean skipIncompleteWarning() {
+ return M2EUIPluginActivator.getDefault().getPreferenceStore()
+ .getBoolean(MavenPreferenceConstants.P_WARN_INCOMPLETE_MAPPING);
+ }
+
+ private boolean warnIncompleteMapping() {
+ if(!skipIncompleteWarning()) {
+ MessageDialogWithToggle dialog = MessageDialogWithToggle.open(MessageDialog.CONFIRM, getShell(),
+ Messages.MavenImportWizard_titleIncompleteMapping, Messages.MavenImportWizard_messageIncompleteMapping,
+ Messages.MavenImportWizard_hideWarningMessage, false, null, null, SWT.SHEET);
+ if(dialog.getReturnCode() == Window.OK) {
+ M2EUIPluginActivator.getDefault().getPreferenceStore()
+ .setValue(MavenPreferenceConstants.P_WARN_INCOMPLETE_MAPPING, dialog.getToggleState());
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+}
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 fd755132..e3d9399b 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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
@@ -7,76 +7,29 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - refactored lifecycle mapping discovery out
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.wizards;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
-import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.project.MavenProject;
-
import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.internal.M2EUtils;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-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.LifecycleMappingConfiguration;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ProjectLifecycleMappingConfiguration;
-import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants;
-import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
-import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
-import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.Messages;
-import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
-import org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
-import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
/**
@@ -87,11 +40,9 @@ import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelP
@SuppressWarnings("restriction")
public class MavenImportWizard extends AbstractMavenProjectWizard implements IImportWizard {
- private static final Logger LOG = LoggerFactory.getLogger(MavenImportWizard.class);
-
- MavenImportWizardPage page;
+ //private static final Logger LOG = LoggerFactory.getLogger(MavenImportWizard.class);
- private LifecycleMappingPage lifecycleMappingPage;
+ private MavenImportWizardPage page;
private List<String> locations;
@@ -101,8 +52,6 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
private boolean initialized = false;
- private LifecycleMappingConfiguration mappingConfiguration;
-
public MavenImportWizard() {
setNeedsProgressMonitor(true);
setWindowTitle(Messages.MavenImportWizard_title);
@@ -114,12 +63,6 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
this.showLocation = false;
}
- public MavenImportWizard(ProjectImportConfiguration importConfiguration, List<String> locations,
- LifecycleMappingConfiguration mappingConfiguration) {
- this(importConfiguration, locations);
- this.mappingConfiguration = mappingConfiguration;
- }
-
public void setBasedirRemameRequired(boolean basedirRemameRequired) {
this.basedirRemameRequired = basedirRemameRequired;
}
@@ -150,147 +93,6 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
page.setBasedirRemameRequired(basedirRemameRequired);
addPage(page);
- if(getDiscovery() != null) {
- lifecycleMappingPage = new LifecycleMappingPage();
- addPage(lifecycleMappingPage);
- }
- }
-
- public boolean performFinish() {
- //mkleint: this sounds wrong.
- if(!page.isPageComplete()) {
- return false;
- }
- if(lifecycleMappingPage != null && !lifecycleMappingPage.isMappingComplete() && !warnIncompleteMapping()) {
- return false;
- }
-
- final List<IMavenDiscoveryProposal> proposals = getMavenDiscoveryProposals();
- final Collection<MavenProjectInfo> projects = getProjects();
-
- final IRunnableWithProgress importOperation = new AbstractCreateMavenProjectsOperation(workingSets) {
- @Override
- protected List<IProject> doCreateMavenProjects(IProgressMonitor progressMonitor) throws CoreException {
- SubMonitor monitor = SubMonitor.convert(progressMonitor, 101);
- try {
- List<IMavenProjectImportResult> results = MavenPlugin.getProjectConfigurationManager().importProjects(
- projects, importConfiguration, monitor.newChild(proposals.isEmpty() ? 100 : 50));
- return toProjects(results);
- } finally {
- monitor.done();
- }
- }
- };
-
- boolean doImport = true;
-
- IMavenDiscoveryUI discovery = getPageFactory();
- if(discovery != null && !proposals.isEmpty()) {
- Set<String> projectsToConfigure = new HashSet<String>();
- for(MavenProjectInfo projectInfo : projects) {
- if(projectInfo.getModel() != null) {
- projectsToConfigure.add(importConfiguration.getProjectName(projectInfo.getModel()));
- }
- }
- doImport = discovery.implement(proposals, importOperation, getContainer(), projectsToConfigure);
- }
-
- if(doImport) {
-
- String workingSetName = getRootProjectName();
- if(page.shouldCreateWorkingSetForRoot() && projects.size() > 0 && workingSetName != null) {
- IWorkingSetManager wsm = PlatformUI.getWorkbench().getWorkingSetManager();
- IWorkingSet workingSet = wsm.getWorkingSet(workingSetName);
- if(workingSet == null) {
- workingSet = wsm.createWorkingSet(workingSetName, new IAdaptable[0]);
- // TODO is there a constant we should be setting here?
- workingSet.setId("org.eclipse.ui.resourceWorkingSetPage");
- wsm.addWorkingSet(workingSet);
- }
- if(!workingSets.contains(workingSet)) {
- workingSets.add(workingSet);
- }
- }
-
- final IRunnableWithProgress ignoreJob = new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- List<IProject> changed = new LinkedList<IProject>();
- for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnore()) {
- ILifecycleMappingRequirement req = prov.getKey();
- if(req instanceof MojoExecutionMappingRequirement) {
- changed.addAll(getProject(prov.getProjects()));
- ignore(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
- }
- }
-
- for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreParent()) {
- ILifecycleMappingRequirement req = prov.getKey();
- if(req instanceof MojoExecutionMappingRequirement) {
- changed.addAll(getProject(prov.getProjects()));
- ignoreAtDefinition(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
- }
- }
-
- new UpdateMavenProjectJob(changed.toArray(new IProject[changed.size()])).schedule();
- }
-
- private Collection<IProject> getProject(Collection<MavenProject> projects) {
- List<IProject> workspaceProjects = new LinkedList<IProject>();
- for(MavenProject project : projects) {
- IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(),
- project.getArtifactId(), project.getVersion());
- if(facade != null) {
- workspaceProjects.add(facade.getProject());
- }
- }
- return workspaceProjects;
- }
-
- private void ignore(MojoExecutionKey key, Collection<MavenProject> projects) {
- String pluginGroupId = key.getGroupId();
- String pluginArtifactId = key.getArtifactId();
- String pluginVersion = key.getVersion();
- String[] goals = new String[] {key.getGoal()};
- for(MavenProject project : projects) {
- IFile pomFile = M2EUtils.getPomFile(project);
- try {
- PomEdits.performOnDOMDocument(new OperationTuple(pomFile, new LifecycleMappingOperation(pluginGroupId,
- pluginArtifactId, pluginVersion, PluginExecutionAction.ignore, goals)));
- } catch(IOException ex) {
- LOG.error(ex.getMessage(), ex);
- } catch(CoreException ex) {
- LOG.error(ex.getMessage(), ex);
- }
- }
- }
-
- private void ignoreAtDefinition(MojoExecutionKey key, Collection<MavenProject> projects) {
- ignore(key, M2EUtils.getDefiningProjects(key, projects));
- }
- };
-
- Job job = new WorkspaceJob(Messages.MavenImportWizard_job) {
- @Override
- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- try {
- importOperation.run(monitor);
- if(lifecycleMappingPage != null) {
- ignoreJob.run(monitor);
- }
- } catch(InvocationTargetException e) {
- return AbstractCreateMavenProjectsOperation.toStatus(e);
- } catch(InterruptedException e) {
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
- }
- };
- job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
- job.schedule();
- }
-
- return doImport;
}
private String getRootProjectName() {
@@ -298,109 +100,38 @@ public class MavenImportWizard extends AbstractMavenProjectWizard implements IIm
return rootProject != null ? importConfiguration.getProjectName(rootProject.getModel()) : null;
}
- @Override
- public boolean canFinish() {
- IWizardPage currentPage = getContainer().getCurrentPage();
-
- if(!currentPage.isPageComplete()) {
+ public boolean performFinish() {
+ //mkleint: this sounds wrong.
+ if(!page.isPageComplete()) {
return false;
}
- if(getDiscovery() == null) {
- return true;
- }
-
- if(currentPage == page) {
- // allow finish if there are no mapping problems and no selected proposals.
- // the latter is important to force the user to go through p2 license page
- return getMappingConfiguration().isMappingComplete(true)
- && getMappingConfiguration().getSelectedProposals().isEmpty();
- }
-
- return super.canFinish();
- }
-
- private List<IMavenDiscoveryProposal> getMavenDiscoveryProposals() {
- if(lifecycleMappingPage == null) {
- return Collections.emptyList();
- }
- return lifecycleMappingPage.getSelectedDiscoveryProposals();
- }
-
- public Collection<MavenProjectInfo> getProjects() {
- return page.getProjects();
- }
-
- /**
- * @return mapping configuration or null
- */
- public LifecycleMappingConfiguration getMappingConfiguration() {
- return mappingConfiguration;
- }
-
- void scanProjects(final List<MavenProjectInfo> list, IProgressMonitor monitor) {
- LOG.debug("About to calculate lifecycle mapping configuration"); //$NON-NLS-1$
- ProjectImportConfiguration importConfiguration = getProjectImportConfiguration();
- mappingConfiguration = LifecycleMappingConfiguration.calculate(list, importConfiguration, monitor);
- discoverProposals(mappingConfiguration, monitor);
- }
-
- void discoverProposals(LifecycleMappingConfiguration mappingConfiguration, IProgressMonitor monitor) {
- final IMavenDiscovery discovery = getDiscovery();
-
- if(discovery == null) {
- return;
- }
-
- Collection<ProjectLifecycleMappingConfiguration> projects = mappingConfiguration.getProjects();
- monitor.beginTask(Messages.MavenImportWizard_searchingTaskTitle, projects.size());
-
- Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> proposals = new LinkedHashMap<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>>();
-
- for(ProjectLifecycleMappingConfiguration project : projects) {
- if(monitor.isCanceled()) {
- throw new OperationCanceledException();
+ String workingSetName = getRootProjectName();
+
+ Collection<MavenProjectInfo> projects = getProjects();
+ if(page.shouldCreateWorkingSetForRoot() && !projects.isEmpty() && workingSetName != null) {
+ IWorkingSetManager wsm = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet = wsm.getWorkingSet(workingSetName);
+ if(workingSet == null) {
+ workingSet = wsm.createWorkingSet(workingSetName, new IAdaptable[0]);
+ // TODO is there a constant we should be setting here?
+ workingSet.setId("org.eclipse.ui.resourceWorkingSetPage");
+ wsm.addWorkingSet(workingSet);
}
- MavenProject mavenProject = project.getMavenProject();
- List<MojoExecution> mojoExecutions = project.getMojoExecutions();
- try {
- proposals
- .putAll(discovery.discover(mavenProject, mojoExecutions, mappingConfiguration.getSelectedProposals(),
- SubMonitor.convert(monitor,
- NLS.bind(Messages.MavenImportWizard_analyzingProject, project.getRelpath()), 1)));
- } catch(CoreException e) {
- //XXX we shall not swallow this exception but associate with the project/execution
- LOG.error(e.getMessage(), e);
+ if(!workingSets.contains(workingSet)) {
+ workingSets.add(workingSet);
}
- monitor.worked(1);
}
- mappingConfiguration.setProposals(proposals);
- }
+ ImportMavenProjectsJob job = new ImportMavenProjectsJob(projects, workingSets, importConfiguration);
+ job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
+ job.schedule();
- private boolean skipIncompleteWarning() {
- return M2EUIPluginActivator.getDefault().getPreferenceStore()
- .getBoolean(MavenPreferenceConstants.P_WARN_INCOMPLETE_MAPPING);
- }
-
- private boolean warnIncompleteMapping() {
- if(!skipIncompleteWarning()) {
- MessageDialogWithToggle dialog = MessageDialogWithToggle.open(MessageDialog.CONFIRM, getShell(),
- Messages.MavenImportWizard_titleIncompleteMapping, Messages.MavenImportWizard_messageIncompleteMapping,
- Messages.MavenImportWizard_hideWarningMessage, false, null, null, SWT.SHEET);
- if(dialog.getReturnCode() == Window.OK) {
- M2EUIPluginActivator.getDefault().getPreferenceStore()
- .setValue(MavenPreferenceConstants.P_WARN_INCOMPLETE_MAPPING, dialog.getToggleState());
- return true;
- }
- return false;
- }
return true;
}
- @Override
- public void dispose() {
- mappingConfiguration = null;
- super.dispose();
+ public Collection<MavenProjectInfo> getProjects() {
+ return page.getProjects();
}
+
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
index cb255ccb..2c6c46d3 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - refactored lifecycle mapping discovery
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.wizards;
@@ -43,7 +44,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
@@ -71,7 +71,6 @@ import org.apache.maven.model.Parent;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.MavenModelManager;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
import org.eclipse.m2e.core.project.AbstractProjectScanner;
import org.eclipse.m2e.core.project.LocalProjectScanner;
import org.eclipse.m2e.core.project.MavenProjectInfo;
@@ -221,7 +220,6 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
projectTreeViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
updateCheckedState();
- getMappingConfiguration().setSelectedProjects(getProjects());
setPageComplete();
}
});
@@ -419,7 +417,6 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
getWizard().getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
projectScanner.run(monitor);
- ((MavenImportWizard) getWizard()).scanProjects(getProjects(projectScanner.getProjects()), monitor);
}
//this collects all projects for analyzing..
@@ -442,7 +439,6 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
setErrorMessage(null);
setMessage(null);
loadingErrorMessage = null;
- LifecycleMappingConfiguration config = ((MavenImportWizard) getWizard()).getMappingConfiguration();
// update name of working set
MavenProjectInfo rootProject = getRootProject();
@@ -457,11 +453,8 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
//mkleint: XXX this sort of error handling is rather unfortunate
List<Throwable> errors = new ArrayList<Throwable>(projectScanner.getErrors());
- if(config != null) {
- errors.addAll(config.getErrors().values());
- }
if(!errors.isEmpty()) {
- StringBuffer sb = new StringBuffer(NLS.bind(Messages.wizardImportPageScanningErrors, errors.size()));
+ StringBuilder sb = new StringBuilder(NLS.bind(Messages.wizardImportPageScanningErrors, errors.size()));
int n = 1;
for(Throwable ex : errors) {
if(ex instanceof CoreException) {
@@ -661,30 +654,15 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
projectTreeViewer.refresh();
}
- @Override
- public IWizardPage getNextPage() {
- IWizardPage next = super.getNextPage();
- LifecycleMappingConfiguration config = getMappingConfiguration();
- if(config == null || (config.isMappingComplete(true) && config.getAllProposals().isEmpty())) {
- next = null;
- }
- return next;
- }
-
void setPageComplete() {
Object[] checkedElements = projectTreeViewer.getCheckedElements();
setPageComplete(checkedElements != null && checkedElements.length > 0);
}
- LifecycleMappingConfiguration getMappingConfiguration() {
- return ((MavenImportWizard) getWizard()).getMappingConfiguration();
- }
-
void setProjectSubtreeChecked(boolean checked) {
ITreeSelection selection = (ITreeSelection) projectTreeViewer.getSelection();
projectTreeViewer.setSubtreeChecked(selection.getFirstElement(), checked);
updateCheckedState();
- getMappingConfiguration().setSelectedProjects(getProjects());
setPageComplete();
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
index ca05305f..1d9ce5ad 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
@@ -325,12 +325,12 @@ public class LifecycleMappingFactory {
private static List<LifecycleMappingMetadataSource> getMavenPluginEmbeddedMetadataSources(
List<MojoExecution> mojoExecutions, List<ArtifactRepository> remoteRepositories, IProgressMonitor monitor) {
- Map<File, LifecycleMappingMetadataSource> result = new LinkedHashMap<File, LifecycleMappingMetadataSource>();
if(mojoExecutions == null || mojoExecutions.isEmpty()) {
// TODO need to understand under what conditions execution plan is null here
return Collections.emptyList();
}
+ Map<File, LifecycleMappingMetadataSource> result = new LinkedHashMap<File, LifecycleMappingMetadataSource>();
MavenImpl maven = (MavenImpl) MavenPlugin.getMaven();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java
index 6696a2c2..71c0954a 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/IMavenDiscovery.java
@@ -1,13 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - discover proposals for ILifecycleMappingRequirements
*******************************************************************************/
package org.eclipse.m2e.core.internal.lifecyclemapping.discovery;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -36,4 +41,22 @@ public interface IMavenDiscovery {
List<MojoExecution> mojoExecutions, List<IMavenDiscoveryProposal> preselected, IProgressMonitor monitor)
throws CoreException;
+ /**
+ * <p>
+ * Calculates discovery proposals for a given collection of {@link ILifecycleMappingRequirement}s. Multiple proposals
+ * per requirement element can be found.
+ * </p>
+ * <p>
+ * To support incremental collection of user choices in the GUI, optional <code>preselected</code>
+ * requirements/proposals map is used to eliminate new proposals that conflict with already selected choices. Result
+ * is expected to include preselected proposals as-is. Implementation is expected to eliminate proposals that conflict
+ * with already installed Eclipse bundles and preselected proposals.
+ * </p>
+ *
+ * @since 1.5.0
+ */
+ public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> discover(
+ Collection<ILifecycleMappingRequirement> requirements, List<IMavenDiscoveryProposal> preselected,
+ IProgressMonitor monitor) throws CoreException;
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingConfiguration.java
deleted file mode 100644
index 9419056a..00000000
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingConfiguration.java
+++ /dev/null
@@ -1,472 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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.internal.lifecyclemapping.discovery;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.osgi.util.NLS;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.execution.MavenExecutionRequest;
-import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.lifecycle.MavenExecutionPlan;
-import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.project.MavenProject;
-
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.ICallable;
-import org.eclipse.m2e.core.embedder.IMaven;
-import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
-import org.eclipse.m2e.core.internal.embedder.MavenImpl;
-import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingConfigurationException;
-import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
-import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult;
-import org.eclipse.m2e.core.internal.lifecyclemapping.MappingMetadataSource;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration.PackagingTypeMappingRequirement;
-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.internal.project.registry.ProjectRegistryManager;
-import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
-import org.eclipse.m2e.core.project.MavenProjectInfo;
-import org.eclipse.m2e.core.project.ProjectImportConfiguration;
-import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
-import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
-
-
-public class LifecycleMappingConfiguration {
- private static final Logger log = LoggerFactory.getLogger(LifecycleMappingConfiguration.class);
-
- private final Map<MavenProjectInfo, ProjectLifecycleMappingConfiguration> allprojects = new HashMap<MavenProjectInfo, ProjectLifecycleMappingConfiguration>();
-
- /**
- * All proposals to satisfy mapping requirements
- */
- private Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> allproposals;
-
- /**
- * Mapping proposals selected for implementation, i.e. bundles to be installed and mojo executions to be ignored.
- */
- private final Set<IMavenDiscoveryProposal> selectedProposals = new LinkedHashSet<IMavenDiscoveryProposal>();
-
- /**
- * Mapping requirements satisfied by installed eclipse bundles and m2e default lifecycle mapping metadata.
- */
- private final Set<ILifecycleMappingRequirement> installedProviders = new HashSet<ILifecycleMappingRequirement>();
-
- /**
- * Selected projects. null means "nothing is selected".
- */
- private Set<MavenProjectInfo> selectedProjects;
-
- private Map<MavenProjectInfo, Throwable> errors = new HashMap<MavenProjectInfo, Throwable>();
-
- private LifecycleMappingConfiguration() {
- }
-
- public List<ProjectLifecycleMappingConfiguration> getProjects() {
- ArrayList<ProjectLifecycleMappingConfiguration> projects = new ArrayList<ProjectLifecycleMappingConfiguration>();
- for(Map.Entry<MavenProjectInfo, ProjectLifecycleMappingConfiguration> project : allprojects.entrySet()) {
- if(selectedProjects.contains(project.getKey())) {
- projects.add(project.getValue());
- }
- }
- return projects;
- }
-
- private void addProject(MavenProjectInfo info, ProjectLifecycleMappingConfiguration project) {
- this.allprojects.put(info, project);
- }
-
- public void setProposals(Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> proposals) {
- this.allproposals = proposals;
- }
-
- /**
- * Returns all proposals available for provided requirement or empty List.
- */
- public List<IMavenDiscoveryProposal> getProposals(ILifecycleMappingRequirement requirement) {
- if(allproposals == null || requirement == null) {
- return Collections.emptyList();
- }
- List<IMavenDiscoveryProposal> result = allproposals.get(requirement);
- if(result == null) {
- return Collections.emptyList();
- }
- return result;
- }
-
- public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> getAllProposals() {
- if(allproposals == null) {
- return Collections.emptyMap();
- }
- return allproposals;
- }
-
- public void addSelectedProposal(IMavenDiscoveryProposal proposal) {
- selectedProposals.add(proposal);
- }
-
- public void removeSelectedProposal(IMavenDiscoveryProposal proposal) {
- selectedProposals.remove(proposal);
- }
-
- public boolean isRequirementSatisfied(ILifecycleMappingRequirement requirement) {
- return isRequirementSatisfied(requirement, false);
- }
-
- public boolean isRequirementSatisfied(ILifecycleMappingRequirement requirement, boolean installedOnly) {
- if(requirement == null) {
- return true;
- }
-
- if(installedProviders.contains(requirement)) {
- return true;
- }
-
- if(installedOnly || allproposals == null) {
- return false;
- }
-
- List<IMavenDiscoveryProposal> proposals = allproposals.get(requirement);
- if(proposals != null) {
- for(IMavenDiscoveryProposal proposal : proposals) {
- if(selectedProposals.contains(proposal)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Returns true if mapping configuration is complete after applying selected proposals.
- */
- public boolean isMappingComplete() {
- return isMappingComplete(false);
- }
-
- public boolean isMappingComplete(boolean installedOnly) {
- for(ProjectLifecycleMappingConfiguration project : getProjects()) {
- ILifecycleMappingRequirement packagingRequirement = project.getPackagingTypeMappingConfiguration()
- .getLifecycleMappingRequirement();
-
- if(!(packagingRequirement instanceof PackagingTypeMappingRequirement)
- && !isRequirementSatisfied(packagingRequirement, installedOnly)) {
- return false;
- }
-
- for(MojoExecutionMappingConfiguration mojoExecutionConfiguration : project.getMojoExecutionConfigurations()) {
- ILifecycleMappingRequirement executionRequirement = mojoExecutionConfiguration.getLifecycleMappingRequirement();
- if(!isRequirementSatisfied(executionRequirement, installedOnly)
- && LifecycleMappingFactory.isInterestingPhase(mojoExecutionConfiguration.getMojoExecutionKey()
- .getLifecyclePhase())) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- /**
- * Automatically selects proposals when where is only one possible solution to a problem. Returns true if mapping
- * configuration is complete after applying automatically selected proposals.
- */
- public void autoCompleteMapping() {
- LinkedHashSet<ILifecycleMappingRequirement> requirements = new LinkedHashSet<ILifecycleMappingRequirement>();
-
- for(ProjectLifecycleMappingConfiguration project : getProjects()) {
- ILifecycleMappingRequirement packagingRequirement = project.getPackagingTypeMappingConfiguration()
- .getLifecycleMappingRequirement();
-
- if(packagingRequirement != null) {
- requirements.add(packagingRequirement);
- }
-
- for(MojoExecutionMappingConfiguration mojoExecutionConfiguration : project.getMojoExecutionConfigurations()) {
- ILifecycleMappingRequirement executionRequirement = mojoExecutionConfiguration.getLifecycleMappingRequirement();
- if(executionRequirement != null) {
- requirements.add(executionRequirement);
- }
- }
- }
-
- for(ILifecycleMappingRequirement requirement : requirements) {
- if(!installedProviders.contains(requirement)) {
- List<IMavenDiscoveryProposal> proposals = getProposals(requirement);
- if(proposals.size() == 1) {
- addSelectedProposal(proposals.get(0));
- }
- }
- }
- }
-
- public IMavenDiscoveryProposal getSelectedProposal(ILifecycleMappingRequirement mojoExecutionKey) {
- if(allproposals == null) {
- return null;
- }
- List<IMavenDiscoveryProposal> proposals = allproposals.get(mojoExecutionKey);
- if(proposals == null) {
- return null;
- }
- for(IMavenDiscoveryProposal proposal : proposals) {
- if(getSelectedProposals().contains(proposal)) {
- return proposal;
- }
- }
- return null;
- }
-
- public List<IMavenDiscoveryProposal> getSelectedProposals() {
- return new ArrayList<IMavenDiscoveryProposal>(selectedProposals);
- }
-
- public void clearSelectedProposals() {
- selectedProposals.clear();
- }
-
- /**
- * Calculates lifecycle mapping configuration of the specified projects. Only considers mapping metadata specified in
- * projects' pom.xml files and their parent pom.xml files. Does NOT consider mapping metadata available from installed
- * Eclipse plugins and m2e default lifecycle mapping metadata.
- */
- public static LifecycleMappingConfiguration calculate(final Collection<MavenProjectInfo> projects,
- final ProjectImportConfiguration importConfiguration, final IProgressMonitor monitor) {
- try {
- final IMavenExecutionContext context = MavenPlugin.getMaven().createExecutionContext();
- final MavenExecutionRequest request = context.getExecutionRequest();
- request.addActiveProfiles(importConfiguration.getResolverConfiguration().getActiveProfileList());
- request.addInactiveProfiles(importConfiguration.getResolverConfiguration().getInactiveProfileList());
- return context.execute(new ICallable<LifecycleMappingConfiguration>() {
- public LifecycleMappingConfiguration call(IMavenExecutionContext context, IProgressMonitor monitor) {
- return calculate(projects, monitor);
- }
- }, monitor);
- } catch(CoreException ex) {
- LifecycleMappingConfiguration result = new LifecycleMappingConfiguration();
- for(MavenProjectInfo project : projects) {
- result.addError(project, ex);
- }
- return result;
- }
- }
-
- /*package*/static LifecycleMappingConfiguration calculate(Collection<MavenProjectInfo> projects,
- IProgressMonitor monitor) {
- monitor.beginTask("Analysing project execution plan", projects.size());
-
- LifecycleMappingConfiguration result = new LifecycleMappingConfiguration();
-
- List<MavenProjectInfo> nonErrorProjects = new ArrayList<MavenProjectInfo>();
- final IMaven maven = MavenPlugin.getMaven();
-
- for(final MavenProjectInfo projectInfo : projects) {
- if(monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- MavenProject mavenProject = null;
- try {
- SubMonitor subMmonitor = SubMonitor.convert(monitor, NLS.bind("Analysing {0}", projectInfo.getLabel()), 1);
-
- MavenExecutionResult executionResult = maven.execute(new ICallable<MavenExecutionResult>() {
- public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor monitor)
- throws CoreException {
- return maven.readMavenProject(projectInfo.getPomFile(), context.newProjectBuildingRequest());
- }
- }, subMmonitor);
-
- mavenProject = executionResult.getProject();
-
- if(monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- if(mavenProject != null) {
- if("pom".equals(projectInfo.getModel().getPackaging())) {
- // m2e uses a noop lifecycle mapping for packaging=pom
- List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
- PackagingTypeMappingConfiguration pkgConfiguration = new PackagingTypeMappingConfiguration(
- mavenProject.getPackaging(), null /*lifecycleMappingId*/);
- ProjectLifecycleMappingConfiguration configuration = new ProjectLifecycleMappingConfiguration(
- projectInfo.getLabel(), mavenProject, mojoExecutions, pkgConfiguration);
- result.addProject(projectInfo, configuration);
- nonErrorProjects.add(projectInfo);
- continue;
- }
-
- List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
- MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(mavenProject,
- Arrays.asList(ProjectRegistryManager.LIFECYCLE_CLEAN), false, subMmonitor);
- mojoExecutions.addAll(executionPlan.getMojoExecutions());
- executionPlan = maven.calculateExecutionPlan(mavenProject,
- Arrays.asList(ProjectRegistryManager.LIFECYCLE_DEFAULT), false, subMmonitor);
- mojoExecutions.addAll(executionPlan.getMojoExecutions());
- executionPlan = maven.calculateExecutionPlan(mavenProject,
- Arrays.asList(ProjectRegistryManager.LIFECYCLE_SITE), false, subMmonitor);
- mojoExecutions.addAll(executionPlan.getMojoExecutions());
-
- LifecycleMappingResult lifecycleResult = new LifecycleMappingResult();
-
- List<MappingMetadataSource> metadataSources;
- try {
- metadataSources = LifecycleMappingFactory.getProjectMetadataSources(mavenProject,
- LifecycleMappingFactory.getBundleMetadataSources(), mojoExecutions, true, monitor);
- } catch(LifecycleMappingConfigurationException e) {
- // could not read/parse/interpret mapping metadata configured in the pom or inherited from parent pom.
- // record the problem and continue
- log.error(e.getMessage(), e);
- continue;
- }
-
- LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(lifecycleResult, metadataSources,
- mavenProject, mojoExecutions, false, monitor);
- LifecycleMappingFactory.instantiateLifecycleMapping(lifecycleResult, mavenProject,
- lifecycleResult.getLifecycleMappingId());
- LifecycleMappingFactory.instantiateProjectConfigurators(mavenProject, lifecycleResult,
- lifecycleResult.getMojoExecutionMapping());
-
- PackagingTypeMappingConfiguration pkgConfiguration = new PackagingTypeMappingConfiguration(
- mavenProject.getPackaging(),
- isProjectSource(lifecycleResult.getLifecycleMappingMetadata()) ? lifecycleResult.getLifecycleMappingId()
- : null);
- ProjectLifecycleMappingConfiguration configuration = new ProjectLifecycleMappingConfiguration(
- projectInfo.getLabel(), mavenProject, mojoExecutions, pkgConfiguration);
-
- if(lifecycleResult.getLifecycleMapping() != null) {
- result.addInstalledProvider(configuration.getPackagingTypeMappingConfiguration()
- .getLifecycleMappingRequirement());
- }
-
- for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : lifecycleResult
- .getMojoExecutionMapping().entrySet()) {
- MojoExecutionKey key = entry.getKey();
- List<IPluginExecutionMetadata> mapppings = entry.getValue();
- IPluginExecutionMetadata primaryMapping = null;
- if(mapppings != null && !mapppings.isEmpty()) {
- primaryMapping = mapppings.get(0);
- }
- MojoExecutionMappingConfiguration executionConfiguration = new MojoExecutionMappingConfiguration(key,
- isProjectSource(primaryMapping) ? primaryMapping : null);
- configuration.addMojoExecution(executionConfiguration);
- if(primaryMapping != null) {
- switch(primaryMapping.getAction()) {
- case configurator:
- AbstractProjectConfigurator projectConfigurator = lifecycleResult.getProjectConfigurators().get(
- LifecycleMappingFactory.getProjectConfiguratorId(primaryMapping));
- if(projectConfigurator != null) {
- result.addInstalledProvider(executionConfiguration.getLifecycleMappingRequirement());
- }
- break;
- case error:
- case execute:
- case ignore:
- result.addInstalledProvider(executionConfiguration.getLifecycleMappingRequirement());
- break;
- default:
- throw new IllegalArgumentException("Missing handling for action=" + primaryMapping.getAction());
- }
- }
- }
- result.addProject(projectInfo, configuration);
- nonErrorProjects.add(projectInfo);
- } else {
- //XXX mkleint: what shall happen now? we don't have a valid MavenProject instance to play with,
- // currently we skip such project silently, is that ok?
- }
-
- } catch(OperationCanceledException ex) {
- throw ex;
- } catch(Throwable th) {
- result.addError(projectInfo, th);
- } finally {
- if(mavenProject != null) {
- ((MavenImpl) maven).releaseExtensionsRealm(mavenProject);
- }
- }
- }
-
- result.setSelectedProjects(nonErrorProjects);
-
- return result;
- }
-
- private static boolean isProjectSource(IPluginExecutionMetadata primaryMapping) {
- if(primaryMapping == null) {
- return false;
- }
- return isProjectSource(((PluginExecutionMetadata) primaryMapping).getSource());
- }
-
- private static boolean isProjectSource(LifecycleMappingMetadata mappingMetadata) {
- if(mappingMetadata == null) {
- return false;
- }
- return isProjectSource(mappingMetadata.getSource());
- }
-
- private static boolean isProjectSource(LifecycleMappingMetadataSource metadataSource) {
- if(metadataSource == null) {
- return false;
- }
- Object source = metadataSource.getSource();
- if(source instanceof MavenProject) {
- return true;
- }
- if(source instanceof Artifact) {
- return true;
- }
- return false;
- }
-
- private void addInstalledProvider(ILifecycleMappingRequirement requirement) {
- installedProviders.add(requirement);
- }
-
- public List<ProjectLifecycleMappingConfiguration> getProjects(ILifecycleMappingElement configurationElement) {
- List<ProjectLifecycleMappingConfiguration> result = new ArrayList<ProjectLifecycleMappingConfiguration>();
- for(ProjectLifecycleMappingConfiguration project : getProjects()) {
- if(project.getMojoExecutionConfigurations().equals(configurationElement)
- || project.getMojoExecutionConfigurations().contains(configurationElement)) {
- result.add(project);
- }
- }
- return result;
- }
-
- public void setSelectedProjects(Collection<MavenProjectInfo> projects) {
- this.selectedProjects = new HashSet<MavenProjectInfo>(projects);
- }
-
- public void addError(MavenProjectInfo info, Throwable th) {
- errors.put(info, th);
- }
-
- public Map<MavenProjectInfo, Throwable> getErrors() {
- return errors;
- }
-
-}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingDiscoveryRequest.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingDiscoveryRequest.java
new file mode 100644
index 00000000..de804807
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/LifecycleMappingDiscoveryRequest.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation as o.e.m.c.i.l.d.LifecycleMappingMapping
+ * Red Hat, Inc. - refactored as LifecycleMappingDiscoveryRequest
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.lifecyclemapping.discovery;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+
+/**
+ * Holder object, used to discover proposals satisfying lifecycle mapping requirements
+ *
+ * @since 1.5
+ * @author Igor Fedorenko
+ * @author Fred Bricon
+ */
+public class LifecycleMappingDiscoveryRequest {
+
+ /**
+ * All proposals to satisfy mapping requirements
+ */
+ private Map<IMavenProjectFacade, List<ILifecycleMappingRequirement>> allProjects = new LinkedHashMap<IMavenProjectFacade, List<ILifecycleMappingRequirement>>();
+
+ public Map<IMavenProjectFacade, List<ILifecycleMappingRequirement>> getProjects() {
+ return this.allProjects;
+ }
+
+ /**
+ * All proposals to satisfy mapping requirements
+ */
+ private Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> allproposals;
+
+ /**
+ * Mapping proposals selected for implementation, i.e. bundles to be installed and mojo executions to be ignored.
+ */
+ private final Set<IMavenDiscoveryProposal> selectedProposals = new LinkedHashSet<IMavenDiscoveryProposal>();
+
+ private Map<IMavenProjectFacade, Throwable> errors = new LinkedHashMap<IMavenProjectFacade, Throwable>();
+
+ public LifecycleMappingDiscoveryRequest() {
+ }
+
+ public void setProposals(Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> proposals) {
+ this.allproposals = proposals;
+ }
+
+ /**
+ * Returns all proposals available for provided requirement or empty List.
+ */
+ public List<IMavenDiscoveryProposal> getProposals(ILifecycleMappingRequirement requirement) {
+ if(allproposals == null || requirement == null) {
+ return Collections.emptyList();
+ }
+ List<IMavenDiscoveryProposal> result = allproposals.get(requirement);
+ if(result == null) {
+ return Collections.emptyList();
+ }
+ return result;
+ }
+
+ public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> getAllProposals() {
+ if(allproposals == null) {
+ return Collections.emptyMap();
+ }
+ return allproposals;
+ }
+
+ public void addSelectedProposal(IMavenDiscoveryProposal proposal) {
+ selectedProposals.add(proposal);
+ }
+
+ public void removeSelectedProposal(IMavenDiscoveryProposal proposal) {
+ selectedProposals.remove(proposal);
+ }
+
+ public boolean isRequirementSatisfied(ILifecycleMappingRequirement requirement) {
+ if(requirement == null) {
+ return true;
+ }
+
+ if(allproposals == null || allproposals.isEmpty()) {
+ return false;
+ }
+
+ List<IMavenDiscoveryProposal> proposals = allproposals.get(requirement);
+ if(proposals != null) {
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(selectedProposals.contains(proposal)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if mapping configuration is complete after applying selected proposals.
+ */
+ public boolean isMappingComplete() {
+ for(ILifecycleMappingRequirement packagingRequirement : getRequirements()) {
+ if(!isRequirementSatisfied(packagingRequirement)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Automatically selects proposals when there is only one possible solution to a problem.
+ */
+
+ public void autoCompleteMapping() {
+
+ for(Entry<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> entry : getAllProposals().entrySet()) {
+
+ List<IMavenDiscoveryProposal> proposals = entry.getValue();
+ if(proposals != null && proposals.size() == 1) {
+ addSelectedProposal(proposals.get(0));
+ }
+ }
+ }
+
+ public IMavenDiscoveryProposal getSelectedProposal(ILifecycleMappingRequirement requirement) {
+ if(allproposals == null) {
+ return null;
+ }
+ List<IMavenDiscoveryProposal> proposals = allproposals.get(requirement);
+ if(proposals == null) {
+ return null;
+ }
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(selectedProposals.contains(proposal)) {
+ return proposal;
+ }
+ }
+ return null;
+ }
+
+ public List<IMavenDiscoveryProposal> getSelectedProposals() {
+ return new ArrayList<IMavenDiscoveryProposal>(selectedProposals);
+ }
+
+ public void clearSelectedProposals() {
+ selectedProposals.clear();
+ }
+
+ public void addProject(IMavenProjectFacade facade, ILifecycleMappingRequirement requirement) {
+ if(facade != null && requirement != null) {
+ List<ILifecycleMappingRequirement> requirements = allProjects.get(facade);
+ if(requirements == null) {
+ requirements = new ArrayList<ILifecycleMappingRequirement>();
+ }
+ requirements.add(requirement);
+ allProjects.put(facade, requirements);
+ }
+ }
+
+ public void addError(IMavenProjectFacade facade, Throwable th) {
+ errors.put(facade, th);
+ }
+
+ public Map<IMavenProjectFacade, Throwable> getErrors() {
+ return errors;
+ }
+
+ public Collection<ILifecycleMappingRequirement> getRequirements() {
+ if(allProjects == null || allProjects.isEmpty()) {
+ return Collections.emptyList();
+ }
+ Set<ILifecycleMappingRequirement> requirements = new LinkedHashSet<ILifecycleMappingRequirement>();
+ for(Entry<IMavenProjectFacade, List<ILifecycleMappingRequirement>> entry : allProjects.entrySet()) {
+ requirements.addAll(entry.getValue());
+ }
+ return requirements;
+ }
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java
index 55c9cff9..861d5525 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java
@@ -1,13 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - packaging and executionId attributes to MojoExecutionMappingRequirement
*******************************************************************************/
package org.eclipse.m2e.core.internal.lifecyclemapping.discovery;
+import org.eclipse.core.runtime.Assert;
+
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
@@ -24,13 +30,32 @@ public class MojoExecutionMappingConfiguration implements ILifecycleMappingEleme
public static class MojoExecutionMappingRequirement implements ILifecycleMappingRequirement {
private final MojoExecutionKey execution;
+ private String executionId;
+
+ private String packaging;
+
public MojoExecutionMappingRequirement(MojoExecutionKey execution) {
+ Assert.isNotNull(execution);
this.execution = new MojoExecutionKey(execution.getGroupId(), execution.getArtifactId(), execution.getVersion(),
execution.getGoal(), null, null);
+
+ executionId = execution.getExecutionId();
+ }
+
+ /**
+ * @since 1.5.0
+ */
+ public MojoExecutionMappingRequirement(MojoExecutionKey execution, String packaging) {
+ this(execution);
+ this.packaging = packaging;
}
public int hashCode() {
- return execution.hashCode();
+ int hash = execution.hashCode();
+ if(executionId != null) {
+ //hash = 17 * hash + executionId.hashCode();
+ }
+ return hash;
}
public boolean equals(Object obj) {
@@ -45,11 +70,27 @@ public class MojoExecutionMappingConfiguration implements ILifecycleMappingEleme
MojoExecutionMappingRequirement other = (MojoExecutionMappingRequirement) obj;
return execution.equals(other.execution);
+
+ }
+
+ /**
+ * @since 1.5.0
+ */
+ public String getExecutionId() {
+ return executionId;
}
public MojoExecutionKey getExecution() {
return execution;
}
+
+ /**
+ * @since 1.5.0
+ */
+ public String getPackaging() {
+ return packaging;
+ }
+
}
public static class ProjectConfiguratorMappingRequirement implements ILifecycleMappingRequirement {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MarkerUtils.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MarkerUtils.java
index 967597a7..d11f97b6 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MarkerUtils.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MarkerUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Sonatype, Inc.
+ * Copyright (c) 2010-2013 Sonatype, Inc. 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - added getMojoExecution(IMarker)
*******************************************************************************/
package org.eclipse.m2e.core.internal.markers;
@@ -21,7 +22,9 @@ import org.eclipse.core.resources.IMarker;
import org.apache.maven.project.MavenProject;
+import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
/**
@@ -66,4 +69,28 @@ public class MarkerUtils {
}
}
}
+
+ /**
+ * Returns the {@link MojoExecutionKey} bound to an {@link IMarker}, or null if one of the groupId, artifactId,
+ * executionId or goal attribute is missing.
+ *
+ * @since 1.5.0
+ */
+ public static MojoExecutionKey getMojoExecution(IMarker marker) {
+ if(marker == null) {
+ return null;
+ }
+ // TODO Which of these are actually required?
+ String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, null);
+ String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, null);
+ String executionId = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, null);
+ String version = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, null);
+ String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, null);
+ String lifecyclePhase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, null);
+ if(goal != null && executionId != null && artifactId != null && groupId != null) {
+ return new MojoExecutionKey(groupId, artifactId, version, goal, lifecyclePhase, executionId);
+ }
+ return null;
+ }
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
index 0baf822e..d730d042 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 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
@@ -139,8 +139,11 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
ArrayList<IMavenProjectImportResult> result = new ArrayList<IMavenProjectImportResult>();
ArrayList<IProject> projects = new ArrayList<IProject>();
+ int total = projectInfos.size();
+ int i = 0;
// first, create all projects with basic configuration
for(MavenProjectInfo projectInfo : projectInfos) {
+ long t11 = System.currentTimeMillis();
if(monitor.isCanceled()) {
throw new OperationCanceledException();
}
@@ -152,6 +155,8 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
if(project != null) {
projects.add(project);
+ long importTime = System.currentTimeMillis() - t11;
+ log.debug("Imported project {} ({}/{}) in {} ms", project.getName(), ++i, total, importTime);
}
}
@@ -160,7 +165,7 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
configureNewMavenProjects(projects, progress.newChild(90));
long t2 = System.currentTimeMillis();
- log.info("Project import completed " + ((t2 - t1) / 1000) + " sec");
+ log.info("Imported and configured {} project(s) in {} sec", total, ((t2 - t1) / 1000));
return result;
}
@@ -214,6 +219,7 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
pomFiles.add(project.getFile(IMavenConstants.POM_FILE_NAME));
}
progress.subTask(Messages.ProjectConfigurationManager_task_refreshing);
+
projectManager.refresh(pomFiles, progress.newChild(75));
// TODO this emits project change events, which may be premature at this point
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java
deleted file mode 100644
index 93b19ead..00000000
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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.internal.discovery;
-
-import org.eclipse.core.runtime.IAdapterFactory;
-
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
-import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
-
-
-//TODO : can probably be removed..
-@SuppressWarnings({"restriction", "unchecked", "rawtypes"})
-public class InstallCatalogItemMappingLabelProvider implements IAdapterFactory {
-
- private final InstallCatalogItemMavenDiscoveryProposal proposal;
-
- /**
- * Factory instance constructor
- */
- public InstallCatalogItemMappingLabelProvider() {
- this(null);
- }
-
- public InstallCatalogItemMappingLabelProvider(InstallCatalogItemMavenDiscoveryProposal proposal) {
- this.proposal = proposal;
- }
-
- public String getMavenText() {
- return ""; //$NON-NLS-1$
- }
-
- public String getEclipseMappingText(LifecycleMappingConfiguration configuration) {
- return "INSTALL " + proposal.getCatalogItem().getName();
- }
-
- public Object getAdapter(Object adaptableObject, Class adapterType) {
- if(adapterType.isAssignableFrom(ILifecycleMappingLabelProvider.class)
- && adaptableObject instanceof InstallCatalogItemMavenDiscoveryProposal) {
- return new InstallCatalogItemMappingLabelProvider((InstallCatalogItemMavenDiscoveryProposal) adaptableObject);
- }
- return null;
- }
-
- public Class[] getAdapterList() {
- return new Class[] {ILifecycleMappingLabelProvider.class};
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#isError()
- */
- public boolean isError() {
- // TODO Auto-generated method isError
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#getKey()
- */
- public ILifecycleMappingRequirement getKey() {
- // TODO Auto-generated method getKey
- return null;
- }
-
-}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java
index fea74465..71019095 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.internal.discovery;
@@ -63,7 +66,7 @@ public class InstallCatalogItemMavenDiscoveryProposal implements IMavenDiscovery
* @see org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal#getDescription()
*/
public String getDescription() {
- return item.getOverview().getSummary();
+ return item.getOverview() == null ? "" : item.getOverview().getSummary();
}
/* (non-Javadoc)
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 3c59869c..4f47758d 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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
@@ -147,8 +147,9 @@ public class MavenDiscovery {
}
public static LifecycleMappingMetadataSource getLifecycleMappingMetadataSource(CatalogItem ci) {
+ URL url = null;
try {
- URL url = getLifecycleMappingMetadataSourceURL(ci);
+ url = getLifecycleMappingMetadataSourceURL(ci);
if(url == null) {
return null;
}
@@ -164,7 +165,8 @@ public class MavenDiscovery {
IOUtil.close(is);
}
} catch(FileNotFoundException e) {
- // CatalogItem does not contain lifecycle mapping
+ // CatalogItem does not contain lifecycle mapping
+ log.info("No lifecyle mapping found at " + url);
} catch(Exception e) {
log.warn(NLS.bind(Messages.MavenCatalogViewer_Error_loading_lifecycle, ci.getId()), e);
}
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 dad800c6..4d1a9403 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Sonatype, Inc.
+ * Copyright (c) 2011-2013 Sonatype, Inc. 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - discover proposals for ILifecycleMappingRequirements
*******************************************************************************/
package org.eclipse.m2e.internal.discovery;
@@ -62,7 +63,11 @@ import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappin
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.MojoExecutionMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.ProjectConfiguratorMappingRequirement;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration.LifecycleStrategyMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration.PackagingTypeMappingRequirement;
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;
@@ -114,6 +119,11 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
private List<CatalogItemCacheEntry> items;
+ /**
+ * Lock guarding lazy instantiation of item instance
+ */
+ private final Object itemsLock = new Object();
+
public MavenDiscoveryService() {
this(true);
}
@@ -125,42 +135,51 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
final List<MojoExecution> mojoExecutions, final List<IMavenDiscoveryProposal> preselected,
final IProgressMonitor monitor) throws CoreException {
+ initializeCatalog(monitor);
if(items == null) {
- items = new ArrayList<MavenDiscoveryService.CatalogItemCacheEntry>();
-
- Catalog catalog = MavenDiscovery.getCatalog();
- IStatus status = catalog.performDiscovery(monitor);
-
- if(!status.isOK()) {
- log.error(status.toString());
- return Collections.emptyMap();
- }
-
- IProvisioningAgent p2agent = ProvisioningUI.getDefaultUI().getSession().getProvisioningAgent();
- IProfileRegistry profRegistry = (IProfileRegistry) p2agent.getService(IProfileRegistry.SERVICE_NAME);
- IProfile profile = profRegistry.getProfile(IProfileRegistry.SELF);
-
- for(CatalogItem item : catalog.getItems()) {
- LifecycleMappingMetadataSource metadataSource = MavenDiscovery.getLifecycleMappingMetadataSource(item);
- List<String> projectConfigurators = new ArrayList<String>();
- List<String> mappingStrategies = new ArrayList<String>();
- MavenDiscovery.getProvidedProjectConfigurators(item, projectConfigurators, mappingStrategies);
- if(metadataSource != null && !itemInstalled(profile, item, monitor)) {
- addCatalogItem(item, metadataSource, projectConfigurators, mappingStrategies);
- }
- }
- catalog.dispose();
+ return Collections.emptyMap();
}
return MavenPlugin.getMaven().execute(
new ICallable<Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>>>() {
- public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> call(IMavenExecutionContext context, IProgressMonitor monitor)
- throws CoreException {
+ public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> call(IMavenExecutionContext context,
+ IProgressMonitor monitor) throws CoreException {
return discover0(mavenProject, mojoExecutions, preselected, monitor);
}
}, monitor);
}
+ private void initializeCatalog(final IProgressMonitor monitor) {
+ synchronized(itemsLock) {
+ if(items == null) {
+ items = new ArrayList<MavenDiscoveryService.CatalogItemCacheEntry>();
+
+ Catalog catalog = MavenDiscovery.getCatalog();
+ IStatus status = catalog.performDiscovery(monitor);
+
+ if(!status.isOK()) {
+ log.error(status.toString());
+ return;
+ }
+
+ IProvisioningAgent p2agent = ProvisioningUI.getDefaultUI().getSession().getProvisioningAgent();
+ IProfileRegistry profRegistry = (IProfileRegistry) p2agent.getService(IProfileRegistry.SERVICE_NAME);
+ IProfile profile = profRegistry.getProfile(IProfileRegistry.SELF);
+
+ for(CatalogItem item : catalog.getItems()) {
+ LifecycleMappingMetadataSource metadataSource = MavenDiscovery.getLifecycleMappingMetadataSource(item);
+ List<String> projectConfigurators = new ArrayList<String>();
+ List<String> mappingStrategies = new ArrayList<String>();
+ MavenDiscovery.getProvidedProjectConfigurators(item, projectConfigurators, mappingStrategies);
+ if(metadataSource != null && !itemInstalled(profile, item, monitor)) {
+ addCatalogItem(item, metadataSource, projectConfigurators, mappingStrategies);
+ }
+ }
+ catalog.dispose();
+ }
+ }
+ }
+
/*package*/Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> discover0(MavenProject mavenProject,
List<MojoExecution> mojoExecutions, List<IMavenDiscoveryProposal> preselected, IProgressMonitor monitor)
throws CoreException {
@@ -341,7 +360,10 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
}
private Collection<CatalogItem> toCatalogItems(List<IMavenDiscoveryProposal> proposals) {
- Set<CatalogItem> items = new HashSet<CatalogItem>();
+ if(proposals == null) {
+ return Collections.emptyList();
+ }
+ Set<CatalogItem> items = new HashSet<CatalogItem>(proposals.size());
for(IMavenDiscoveryProposal proposal : proposals) {
if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
items.add(((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem());
@@ -356,4 +378,100 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery#discover(java.util.Collection, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> discover(
+ Collection<ILifecycleMappingRequirement> requirements, List<IMavenDiscoveryProposal> preselected,
+ IProgressMonitor monitor) throws CoreException {
+
+ if(requirements == null || requirements.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ initializeCatalog(monitor);
+ if(items == null) {
+ return Collections.emptyMap();
+ }
+
+ Collection<CatalogItem> selectedItems = toCatalogItems(preselected);
+
+ Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> allproposals = new LinkedHashMap<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>>(
+ requirements.size());
+
+ for(CatalogItemCacheEntry itemEntry : items) {
+ if(monitor.isCanceled()) {
+ break;
+ }
+ CatalogItem item = itemEntry.getItem();
+ if(selectedItems.contains(item)) {
+ continue;
+ }
+ LifecycleMappingMetadataSource src = itemEntry.getMetadataSource();
+ log.debug("Considering catalog item '{}'", item.getName()); //$NON-NLS-1$
+ for(ILifecycleMappingRequirement requirement : requirements) {
+ boolean matchFound = false;
+ if(requirement instanceof MojoExecutionMappingRequirement) {
+ MojoExecutionMappingRequirement meReq = ((MojoExecutionMappingRequirement) requirement);
+ MojoExecutionKey mek = meReq.getExecution();
+ if(matchesFilter(src, mek, meReq.getPackaging())) {
+ matchFound = true;
+ }
+ } else if(requirement instanceof PackagingTypeMappingRequirement) {
+ String packaging = ((PackagingTypeMappingRequirement) requirement).getPackaging();
+ if(hasPackaging(src, packaging)) {
+ matchFound = true;
+ }
+ } else if(requirement instanceof LifecycleStrategyMappingRequirement) {
+ String mappingId = ((LifecycleStrategyMappingRequirement) requirement).getLifecycleMappingId();
+ if(itemEntry.getMappingStrategies().contains(mappingId)) {
+ matchFound = true;
+ }
+
+ } else if(requirement instanceof ProjectConfiguratorMappingRequirement) {
+ String configuratorId = ((ProjectConfiguratorMappingRequirement) requirement).getProjectConfiguratorId();
+ if(itemEntry.getProjectConfigurators().contains(configuratorId)) {
+ matchFound = true;
+ }
+
+ }
+ if(matchFound) {
+ IMavenDiscoveryProposal proposal = new InstallCatalogItemMavenDiscoveryProposal(item);
+ put(allproposals, requirement, proposal);
+ }
+ }
+ }
+
+ return allproposals;
+ }
+
+ private static boolean matchesFilter(LifecycleMappingMetadataSource src, MojoExecutionKey mojoExecution, String type) {
+ for(PluginExecutionMetadata p : src.getPluginExecutions()) {
+ if(p.getFilter().match(mojoExecution)) {
+ return true;
+ }
+ }
+ for(LifecycleMappingMetadata lm : src.getLifecycleMappings()) {
+ if((type == null && lm.getPackagingType() == null) || (type != null && type.equals(lm.getPackagingType()))) {
+ for(PluginExecutionMetadata p : lm.getPluginExecutions()) {
+ if(p.getFilter().match(mojoExecution)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean hasPackaging(LifecycleMappingMetadataSource lifecycleMappingMetadataSource,
+ String packagingType) {
+ for(LifecycleMappingMetadata lifecycleMappingMetadata : lifecycleMappingMetadataSource.getLifecycleMappings()) {
+ if(packagingType.equals(lifecycleMappingMetadata.getPackagingType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
index 3e5972d3..99d04dbd 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Sonatype, Inc.
+ * Copyright (c) 2011-2013 Sonatype, Inc. 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
@@ -7,10 +7,13 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - refactored getMojoExecution(IMarker) out to MarkerUtils
*******************************************************************************/
package org.eclipse.m2e.internal.discovery.markers;
+import static org.eclipse.m2e.core.internal.markers.MarkerUtils.getMojoExecution;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -90,20 +93,6 @@ public class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
MavenDiscovery.launchWizard(packagingTypes, mojos, lifecycleIds, configuratorIds);
}
- private MojoExecutionKey getMojoExecution(IMarker marker) {
- // TODO Which of these are actually required?
- String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, null);
- String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, null);
- String executionId = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, null);
- String version = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, null);
- String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, null);
- String lifecyclePhase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, null);
- if(goal != null && executionId != null && artifactId != null && groupId != null) {
- return new MojoExecutionKey(groupId, artifactId, version, goal, lifecyclePhase, executionId);
- }
- return null;
- }
-
private String getLifecycleId(IMarker marker) {
return marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, null);
}
diff --git a/org.eclipse.m2e.scm/src/org/eclipse/m2e/scm/internal/wizards/MavenProjectCheckoutJob.java b/org.eclipse.m2e.scm/src/org/eclipse/m2e/scm/internal/wizards/MavenProjectCheckoutJob.java
index 51310086..fcee8472 100644
--- a/org.eclipse.m2e.scm/src/org/eclipse/m2e/scm/internal/wizards/MavenProjectCheckoutJob.java
+++ b/org.eclipse.m2e.scm/src/org/eclipse/m2e/scm/internal/wizards/MavenProjectCheckoutJob.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - Refactored project import
*******************************************************************************/
package org.eclipse.m2e.scm.internal.wizards;
@@ -16,7 +17,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,7 +28,6 @@ import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
@@ -53,14 +52,11 @@ import org.apache.maven.model.Model;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.MavenModelManager;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
-import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.LocalProjectScanner;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
-import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
-import org.eclipse.m2e.core.ui.internal.wizards.AbstactCreateMavenProjectJob;
+import org.eclipse.m2e.core.ui.internal.wizards.ImportMavenProjectsJob;
import org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizard;
import org.eclipse.m2e.scm.MavenCheckoutOperation;
import org.eclipse.m2e.scm.MavenProjectScmInfo;
@@ -216,37 +212,8 @@ public abstract class MavenProjectCheckoutJob extends WorkspaceJob {
}
if(checkoutAllProjects) {
- if(M2EUIPluginActivator.getDefault().getMavenDiscovery() != null) {
- final LifecycleMappingConfiguration mappingConfiguration = LifecycleMappingConfiguration.calculate(projects,
- configuration, new NullProgressMonitor());
- if(!mappingConfiguration.isMappingComplete(true)) {
+ WorkspaceJob job = new ImportMavenProjectsJob(projects, workingSets, configuration);
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- MavenImportWizard wizard = new MavenImportWizard(configuration, collectedLocations,
- mappingConfiguration);
- wizard.setBasedirRemameRequired(true);
- WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
- int res = dialog.open();
- if(res == Window.CANCEL) {
- cleanup(collectedLocations);
- }
- }
- });
- return;
- }
- }
- WorkspaceJob job = new AbstactCreateMavenProjectJob(Messages.MavenProjectCheckoutJob_job, workingSets) {
- @Override
- protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
- Set<MavenProjectInfo> projectSet = MavenPlugin.getProjectConfigurationManager().collectProjects(projects);
-
- List<IMavenProjectImportResult> results = MavenPlugin.getProjectConfigurationManager().importProjects(
- projectSet, configuration, monitor);
-
- return toProjects(results);
- }
- };
ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory()
.modifyRule(ResourcesPlugin.getWorkspace().getRoot());
job.setRule(rule);

Back to the top