Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/WorkingSets.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectJob.java15
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java17
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/ImportMavenProjectsJob.java4
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizard.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizard.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWorkspaceAssigner.java44
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java52
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectConfigurationManager.java25
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectCreationListener.java26
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java44
11 files changed, 223 insertions, 37 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/WorkingSets.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/WorkingSets.java
index 4900c898..26df0480 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/WorkingSets.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/WorkingSets.java
@@ -13,7 +13,9 @@ package org.eclipse.m2e.core.ui.internal;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -91,10 +93,11 @@ public class WorkingSets {
if(workingSet != null) {
IAdaptable[] adaptedProjects = workingSet.adaptElements(projects);
IAdaptable[] oldElements = workingSet.getElements();
- IAdaptable[] newElements = new IAdaptable[oldElements.length + adaptedProjects.length];
- System.arraycopy(oldElements, 0, newElements, 0, oldElements.length);
- System.arraycopy(adaptedProjects, 0, newElements, oldElements.length, adaptedProjects.length);
- workingSet.setElements(newElements);
+
+ Set<IAdaptable> newElements = new LinkedHashSet<>();
+ Collections.addAll(newElements, oldElements);
+ Collections.addAll(newElements, adaptedProjects);
+ workingSet.setElements(newElements.toArray(new IProject[newElements.size()]));
}
}
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectJob.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectJob.java
index 7fa1afc2..2b4c048f 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectJob.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectJob.java
@@ -31,10 +31,23 @@ import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
public abstract class AbstractCreateMavenProjectJob extends WorkspaceJob {
- private final List<IWorkingSet> workingSets;
+ @Deprecated
+ private List<IWorkingSet> workingSets;
private List<IProject> createdProjects;
+ /**
+ * @since 1.8
+ */
+ public AbstractCreateMavenProjectJob(String name) {
+ super(name);
+ }
+
+ /**
+ * A {@link #AbstractCreateMavenProjectJob(String)} constructor should be used along with a
+ * {@link MavenProjectWorkspaceAssigner} instead.
+ */
+ @Deprecated
public AbstractCreateMavenProjectJob(String name, List<IWorkingSet> workingSets) {
super(name);
this.workingSets = workingSets;
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 81d3cfcd..7c0271c3 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
@@ -34,8 +34,19 @@ import org.eclipse.m2e.core.ui.internal.WorkingSets;
public abstract class AbstractCreateMavenProjectsOperation implements IRunnableWithProgress {
- private final List<IWorkingSet> workingSets;
+ @Deprecated
+ private List<IWorkingSet> workingSets;
+ /**
+ * @since 1.8
+ */
+ public AbstractCreateMavenProjectsOperation() {
+ }
+
+ /**
+ * A no-arg constructor should be used along with a {@link MavenProjectWorkspaceAssigner} instead.
+ */
+ @Deprecated
public AbstractCreateMavenProjectsOperation(List<IWorkingSet> workingSets) {
this.workingSets = workingSets;
}
@@ -60,7 +71,9 @@ public abstract class AbstractCreateMavenProjectsOperation implements IRunnableW
try {
try {
this.createdProjects = doCreateMavenProjects(monitor);
- WorkingSets.addToWorkingSets(createdProjects, workingSets);
+ if(workingSets != null) {
+ WorkingSets.addToWorkingSets(createdProjects, workingSets);
+ }
} catch(CoreException e) {
throw new InvocationTargetException(e);
}
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
index aa2852e3..ca365a37 100644
--- 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
@@ -59,14 +59,14 @@ public class ImportMavenProjectsJob extends WorkspaceJob {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
- final AbstractCreateMavenProjectsOperation importOperation = new AbstractCreateMavenProjectsOperation(workingSets) {
+ final AbstractCreateMavenProjectsOperation importOperation = new AbstractCreateMavenProjectsOperation() {
@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));
+ projects, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor.newChild(100));
return toProjects(results);
} finally {
monitor.done();
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizard.java
index 32cb658b..00bf9122 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizard.java
@@ -222,8 +222,7 @@ public class MavenModuleWizard extends AbstractMavenProjectWizard implements INe
final String[] folders = artifactPage.getFolders();
- job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, moduleName),
- workingSets) {
+ job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, moduleName)) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction());
@@ -234,7 +233,7 @@ public class MavenModuleWizard extends AbstractMavenProjectWizard implements INe
// XXX should run update sources on parent instead of creating new module project
MavenPlugin.getProjectConfigurationManager().createSimpleProject(project, location.append(moduleName), model,
- folders, importConfiguration, monitor);
+ folders, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
setModule(projectName);
@@ -253,13 +252,13 @@ public class MavenModuleWizard extends AbstractMavenProjectWizard implements INe
final String javaPackage = parametersPage.getJavaPackage();
final Properties properties = parametersPage.getProperties();
- job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId()),
- workingSets) {
+ job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId())) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
List<IProject> projects = MavenPlugin.getProjectConfigurationManager().createArchetypeProjects(location,
archetype, //
- groupId, artifactId, version, javaPackage, properties, importConfiguration, monitor);
+ groupId, artifactId, version, javaPackage, //
+ properties, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
setModule(moduleName);
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizard.java
index b04e75de..152fa268 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizard.java
@@ -217,12 +217,11 @@ public class MavenProjectWizard extends AbstractMavenProjectWizard implements IN
if(simpleProject.getSelection()) {
final String[] folders = artifactPage.getFolders();
- job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, projectName),
- workingSets) {
+ job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, projectName)) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
MavenPlugin.getProjectConfigurationManager().createSimpleProject(project, location, model, folders, //
- importConfiguration, monitor);
+ importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
return Arrays.asList(project);
}
};
@@ -236,13 +235,13 @@ public class MavenProjectWizard extends AbstractMavenProjectWizard implements IN
final String javaPackage = parametersPage.getJavaPackage();
final Properties properties = parametersPage.getProperties();
- job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId()),
- workingSets) {
+ job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreating, archetype.getArtifactId())) {
@Override
protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
List<IProject> projects = MavenPlugin.getProjectConfigurationManager().createArchetypeProjects(location,
archetype, //
- groupId, artifactId, version, javaPackage, properties, importConfiguration, monitor);
+ groupId, artifactId, version, javaPackage, //
+ properties, importConfiguration, new MavenProjectWorkspaceAssigner(workingSets), monitor);
return projects;
}
};
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWorkspaceAssigner.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWorkspaceAssigner.java
new file mode 100644
index 00000000..5f934c76
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWorkspaceAssigner.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Anton Tanasenko
+ * 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:
+ * Anton Tanasenko - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.wizards;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.ui.IWorkingSet;
+
+import org.eclipse.m2e.core.project.IProjectConfigurationManager;
+import org.eclipse.m2e.core.project.IProjectCreationListener;
+import org.eclipse.m2e.core.ui.internal.WorkingSets;
+
+
+/**
+ * {@linkplain IProjectCreationListener} which adds new projects to specified working sets. Should be used in
+ * {@link IProjectConfigurationManager} methods instead of {@code IWorkingSet[]} argument to
+ * {@link AbstractCreateMavenProjectJob} or {@link AbstractCreateMavenProjectsOperation}
+ *
+ * @since 1.8
+ */
+public class MavenProjectWorkspaceAssigner implements IProjectCreationListener {
+
+ private List<IWorkingSet> workingSets;
+
+ public MavenProjectWorkspaceAssigner(List<IWorkingSet> workingSets) {
+ this.workingSets = workingSets;
+ }
+
+ @Override
+ public void projectCreated(IProject project) {
+ WorkingSets.addToWorkingSets(new IProject[] {project}, workingSets);
+ }
+
+}
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 58d5f656..05c5d4b9 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
@@ -87,6 +87,7 @@ import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
+import org.eclipse.m2e.core.project.IProjectCreationListener;
import org.eclipse.m2e.core.project.LocalProjectScanner;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
import org.eclipse.m2e.core.project.MavenProjectInfo;
@@ -127,8 +128,14 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
this.mavenConfiguration = mavenConfiguration;
}
+ public List<IMavenProjectImportResult> importProjects(Collection<MavenProjectInfo> projectInfos,
+ ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
+ return importProjects(projectInfos, configuration, null, monitor);
+ }
+
public List<IMavenProjectImportResult> importProjects(final Collection<MavenProjectInfo> projectInfos,
- final ProjectImportConfiguration configuration, final IProgressMonitor monitor) throws CoreException {
+ final ProjectImportConfiguration configuration, final IProjectCreationListener listener,
+ final IProgressMonitor monitor) throws CoreException {
final SubMonitor progress = SubMonitor.convert(monitor, Messages.ProjectConfigurationManager_task_importing, 100);
@@ -152,7 +159,7 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
}
SubMonitor subProgress = SubMonitor.convert(progress.newChild(10), projectInfos.size() * 100);
- IProject project = create(projectInfo, configuration, subProgress.newChild(100));
+ IProject project = create(projectInfo, configuration, listener, subProgress.newChild(100));
result.add(new MavenProjectImportResult(projectInfo, project));
@@ -650,6 +657,11 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
// project creation
+ public void createSimpleProject(IProject project, IPath location, Model model, String[] directories,
+ ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
+ createSimpleProject(project, location, model, directories, configuration, null, monitor);
+ }
+
/**
* Creates simple Maven project
* <p>
@@ -665,7 +677,8 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
*/
// XXX should use Maven plugin configurations instead of manually specifying folders
public void createSimpleProject(IProject project, IPath location, Model model, String[] directories,
- ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
+ ProjectImportConfiguration configuration, IProjectCreationListener listener, IProgressMonitor monitor)
+ throws CoreException {
String projectName = project.getName();
monitor.beginTask(NLS.bind(Messages.ProjectConfigurationManager_task_creating, projectName), 5);
@@ -687,6 +700,10 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
}
monitor.worked(1);
+ if(listener != null) {
+ listener.projectCreated(project);
+ }
+
monitor.subTask(Messages.ProjectConfigurationManager_task_creating_project);
enableMavenNature(project, configuration.getResolverConfiguration(), monitor);
monitor.worked(1);
@@ -752,20 +769,35 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
* @return an unmodifiable list of created projects.
* @since 1.1
*/
+ public List<IProject> createArchetypeProjects(IPath location, Archetype archetype, final String groupId,
+ String artifactId, String version, String javaPackage, Properties properties,
+ ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
+ return createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties,
+ configuration, null, monitor);
+ }
+
+ /**
+ * Creates project structure using Archetype and then imports created project(s)
+ *
+ * @return an unmodifiable list of created projects.
+ * @since 1.8
+ */
public List<IProject> createArchetypeProjects(final IPath location, final Archetype archetype, final String groupId,
final String artifactId, final String version, final String javaPackage, final Properties properties,
- final ProjectImportConfiguration configuration, final IProgressMonitor monitor) throws CoreException {
+ final ProjectImportConfiguration configuration, final IProjectCreationListener listener,
+ final IProgressMonitor monitor) throws CoreException {
return maven.execute(new ICallable<List<IProject>>() {
public List<IProject> call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
return createArchetypeProjects0(location, archetype, groupId, artifactId, version, javaPackage, properties,
- configuration, monitor);
+ configuration, listener, monitor);
}
}, monitor);
}
/*package*/List<IProject> createArchetypeProjects0(IPath location, Archetype archetype, String groupId,
String artifactId, String version, String javaPackage, Properties properties,
- ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
+ ProjectImportConfiguration configuration, IProjectCreationListener listener, IProgressMonitor monitor)
+ throws CoreException {
monitor.beginTask(NLS.bind(Messages.ProjectConfigurationManager_task_creating_project1, artifactId), 2);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
@@ -827,7 +859,7 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
Set<MavenProjectInfo> projectSet = collectProjects(scanner.getProjects());
- List<IMavenProjectImportResult> importResults = importProjects(projectSet, configuration, monitor);
+ List<IMavenProjectImportResult> importResults = importProjects(projectSet, configuration, listener, monitor);
for(IMavenProjectImportResult r : importResults) {
IProject p = r.getProject();
if(p != null && p.exists()) {
@@ -903,7 +935,7 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
}
/*package*/IProject create(MavenProjectInfo projectInfo, ProjectImportConfiguration configuration,
- IProgressMonitor monitor) throws CoreException {
+ IProjectCreationListener listener, IProgressMonitor monitor) throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
@@ -967,6 +999,10 @@ public class ProjectConfigurationManager implements IProjectConfigurationManager
project.open(monitor);
}
+ if(listener != null) {
+ listener.projectCreated(project);
+ }
+
ResolverConfiguration resolverConfiguration = configuration.getResolverConfiguration();
enableBasicMavenNature(project, resolverConfiguration, monitor);
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectConfigurationManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectConfigurationManager.java
index 420e0da7..6a7a77c2 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectConfigurationManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectConfigurationManager.java
@@ -36,10 +36,24 @@ public interface IProjectConfigurationManager {
List<IMavenProjectImportResult> importProjects(Collection<MavenProjectInfo> projects, //
ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException;
+ /**
+ * @since 1.8
+ */
+ List<IMavenProjectImportResult> importProjects(Collection<MavenProjectInfo> projects, //
+ ProjectImportConfiguration configuration, IProjectCreationListener importListener, IProgressMonitor monitor)
+ throws CoreException;
+
void createSimpleProject(IProject project, IPath location, Model model, String[] folders,
ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException;
/**
+ * @since 1.8
+ */
+ void createSimpleProject(IProject project, IPath location, Model model, String[] folders,
+ ProjectImportConfiguration configuration, IProjectCreationListener importListener, IProgressMonitor monitor)
+ throws CoreException;
+
+ /**
* @deprecated use
* {@link #createArchetypeProjects(IPath, Archetype, String, String, String, String, Properties, ProjectImportConfiguration, IProgressMonitor)}
*/
@@ -58,6 +72,17 @@ public interface IProjectConfigurationManager {
String groupId, String artifactId, String version, String javaPackage, Properties properties, //
ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException;
+ /**
+ * Creates project structure using Archetype and then imports the created project(s)
+ *
+ * @return an unmodifiable list of created projects.
+ * @since 1.8
+ */
+ List<IProject> createArchetypeProjects(IPath location, Archetype archetype, //
+ String groupId, String artifactId, String version, String javaPackage, Properties properties, //
+ ProjectImportConfiguration configuration, IProjectCreationListener importListener, IProgressMonitor monitor)
+ throws CoreException;
+
Set<MavenProjectInfo> collectProjects(Collection<MavenProjectInfo> projects);
void enableMavenNature(IProject project, ResolverConfiguration configuration, IProgressMonitor monitor)
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectCreationListener.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectCreationListener.java
new file mode 100644
index 00000000..22312392
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IProjectCreationListener.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Anton Tanasenko
+ * 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:
+ * Anton Tanasenko - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.core.project;
+
+import org.eclipse.core.resources.IProject;
+
+
+/**
+ * @since 1.8
+ */
+public interface IProjectCreationListener {
+
+ /**
+ * Called when a new maven project gets imported/created in the workspace but before it is actually configured.
+ */
+ void projectCreated(IProject project);
+
+}
diff --git a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
index 52a5b9db..6454b4ba 100644
--- a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
+++ b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractMavenProjectTestCase.java
@@ -76,6 +76,7 @@ import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.IProjectCreationListener;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.MavenUpdateRequest;
@@ -325,10 +326,24 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
* @param configuration - a resolver configuration to be used to configure imported project
* @return created project
*/
- protected IProject importProject(String pomLocation, ResolverConfiguration configuration) throws IOException,
- CoreException {
+ protected IProject importProject(String pomLocation, ResolverConfiguration configuration)
+ throws IOException, CoreException {
+ return importProject(pomLocation, configuration, null);
+ }
+
+ /**
+ * Import a test project into the Eclipse workspace
+ *
+ * @param pomLocation - a relative location of the pom file for the project to import
+ * @param configuration - a resolver configuration to be used to configure imported project
+ * @param listener - listener which will get notified of the raw project creation
+ * @return created project
+ */
+ protected IProject importProject(String pomLocation, ResolverConfiguration configuration,
+ IProjectCreationListener listener) throws IOException, CoreException {
File pomFile = new File(pomLocation);
- return importProjects(pomFile.getParentFile().getCanonicalPath(), new String[] {pomFile.getName()}, configuration)[0];
+ return importProjects(pomFile.getParentFile().getCanonicalPath(), new String[] {pomFile.getName()}, configuration,
+ false, listener)[0];
}
/**
@@ -344,8 +359,21 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
return importProjects(basedir, pomNames, configuration, false);
}
+ /**
+ * Import test projects into the Eclipse workspace
+ *
+ * @param basedir - a base directory for all projects to import
+ * @param pomNames - a relative locations of the pom files for the projects to import
+ * @param configuration - a resolver configuration to be used to configure imported projects
+ * @return created projects
+ */
protected IProject[] importProjects(String basedir, String[] pomNames, ResolverConfiguration configuration,
boolean skipSanityCheck) throws IOException, CoreException {
+ return importProjects(basedir, pomNames, configuration, skipSanityCheck, null);
+ }
+
+ protected IProject[] importProjects(String basedir, String[] pomNames, ResolverConfiguration configuration,
+ boolean skipSanityCheck, IProjectCreationListener listener) throws IOException, CoreException {
MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();
IWorkspaceRoot root = workspace.getRoot();
@@ -369,7 +397,7 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
workspace.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
importResults.addAll(MavenPlugin.getProjectConfigurationManager().importProjects(projectInfos,
- importConfiguration, monitor));
+ importConfiguration, listener, monitor));
}
}, MavenPlugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor);
@@ -401,8 +429,8 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
File workspaceRoot = workspace.getRoot().getLocation().toFile();
File basedir = projectInfo.getPomFile().getParentFile().getCanonicalFile();
- projectInfo.setBasedirRename(basedir.getParentFile().equals(workspaceRoot) ? MavenProjectInfo.RENAME_REQUIRED
- : MavenProjectInfo.RENAME_NO);
+ projectInfo.setBasedirRename(
+ basedir.getParentFile().equals(workspaceRoot) ? MavenProjectInfo.RENAME_REQUIRED : MavenProjectInfo.RENAME_NO);
}
protected IProject importProject(String projectName, String projectLocation, ResolverConfiguration configuration)
@@ -566,8 +594,8 @@ public abstract class AbstractMavenProjectTestCase extends TestCase {
field.set(projectFacade, null);
}
}
- MavenPluginActivator.getDefault().getMavenProjectManagerImpl()
- .putMavenProject((MavenProjectFacade) projectFacade, null);
+ MavenPluginActivator.getDefault().getMavenProjectManagerImpl().putMavenProject((MavenProjectFacade) projectFacade,
+ null);
}
@Override

Back to the top