Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-07-27 14:51:03 +0000
committerFred Bricon2016-09-13 16:05:39 +0000
commiteafaf78f436b8475cf9ec62e8f2b35d1210d84c1 (patch)
tree30ff31bf59cb90f57e8cec752d59e64b21673815
parent83e9a934110cb0932a9b1a3ac3de6a1bcf86514d (diff)
downloadm2e-core-eafaf78f436b8475cf9ec62e8f2b35d1210d84c1.tar.gz
m2e-core-eafaf78f436b8475cf9ec62e8f2b35d1210d84c1.tar.xz
m2e-core-eafaf78f436b8475cf9ec62e8f2b35d1210d84c1.zip
Bug 498582 - Enable m2e detection whenever a folder contains a pom.xml
Change-Id: Ief78c0dce15cb0c9d97c372f7a8ef3ff2b683c56 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java78
-rw-r--r--org.eclipse.m2e.importer/plugin.xml4
3 files changed, 70 insertions, 15 deletions
diff --git a/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF b/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF
index a010f859..5999cd40 100644
--- a/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF
@@ -15,4 +15,5 @@ Require-Bundle: org.eclipse.m2e.importer;bundle-version="[1.8.0,1.9.0)",
org.eclipse.ui.workbench,
org.apache.ant,
org.eclipse.jdt.core,
- org.eclipse.m2e.tests.common;bundle-version="[1.8.0,1.9.0)"
+ org.eclipse.m2e.tests.common;bundle-version="[1.8.0,1.9.0)",
+ org.apache.commons.io;bundle-version="2.2.0"
diff --git a/org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java b/org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java
index 5a900390..e268cfdd 100644
--- a/org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java
+++ b/org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java
@@ -9,6 +9,7 @@
package org.eclipse.m2e.importer.tests;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
@@ -17,9 +18,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.apache.commons.io.FileUtils;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -37,19 +42,30 @@ import org.eclipse.m2e.tests.common.JobHelpers.IJobMatcher;
public class MavenImporterTest extends AbstractMavenProjectTestCase {
- @Test
- public void test() throws Exception {
- File outputDirectory = Files.createTempDirectory("example1").toFile(); //$NON-NLS-1$
- copyDir(new File("resources/examples/example1"), outputDirectory);
+ private File projectDirectory;
+
+ @Before
+ public void setUp() throws IOException {
+ projectDirectory = new File(Files.createTempDirectory("m2e-tests").toFile(), "example1");
+ projectDirectory.mkdirs(); //$NON-NLS-1$ //$NON-NLS-2$
+ copyDir(new File("resources/examples/example1"), projectDirectory);
// Make sure projects don't have Eclipse metadata set
- new File(outputDirectory, ".project").delete();
- new File(outputDirectory, ".classpath").delete();
- new File(outputDirectory, "module1/.project").delete();
- new File(outputDirectory, "module1/.classpath").delete();
+ new File(projectDirectory, ".project").delete();
+ new File(projectDirectory, ".classpath").delete();
+ new File(projectDirectory, "module1/.project").delete();
+ new File(projectDirectory, "module1/.classpath").delete();
+ }
+ @After
+ public void tearDown() throws IOException {
+ FileUtils.deleteDirectory(this.projectDirectory.getParentFile());
+ }
+
+ @Test
+ public void test() throws Exception {
Set<IProject> newProjects = null;
- SmartImportJob job = new SmartImportJob(outputDirectory, Collections.EMPTY_SET, true, true);
+ SmartImportJob job = new SmartImportJob(projectDirectory, Collections.EMPTY_SET, true, true);
Map<File, List<ProjectConfigurator>> proposals = job.getImportProposals(monitor);
Assert.assertEquals("Expected 2 projects to import", 2, proposals.size()); //$NON-NLS-1$
@@ -79,11 +95,51 @@ public class MavenImporterTest extends AbstractMavenProjectTestCase {
}, 30_000);
for(IProject project : newProjects) {
- Assert
- .assertTrue(project.getLocation().toFile().getCanonicalPath().startsWith(outputDirectory.getCanonicalPath()));
+ Assert.assertTrue(
+ project.getLocation().toFile().getCanonicalPath().startsWith(projectDirectory.getCanonicalPath()));
IMavenProjectFacade mavenProject = MavenPlugin.getMavenProjectRegistry().getProject(project);
Assert.assertNotNull("Project not configured as Maven", mavenProject); //$NON-NLS-1$
}
+ }
+
+ @Test
+ public void testRootWithoutPom() throws Exception {
+ Set<IProject> newProjects = null;
+ // important part here is the "getParentFile()"
+ SmartImportJob job = new SmartImportJob(projectDirectory.getParentFile(), Collections.EMPTY_SET, true, true);
+
+ Map<File, List<ProjectConfigurator>> proposals = job.getImportProposals(monitor);
+ Assert.assertEquals("Expected 2 projects to import", 2, proposals.size()); //$NON-NLS-1$
+ boolean thymConfiguratorFound = false;
+ for(ProjectConfigurator configurator : proposals.values().iterator().next()) {
+ if(configurator instanceof MavenProjectConfigurator) {
+ thymConfiguratorFound = true;
+ }
+ }
+ Assert.assertTrue("Maven configurator not found while checking directory", thymConfiguratorFound); //$NON-NLS-1$
+
+ // accept proposals
+ job.setDirectoriesToImport(proposals.keySet());
+
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ Set<IProject> beforeImport = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
+ job.run(monitor);
+ job.join();
+ newProjects = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
+ newProjects.removeAll(beforeImport);
+ Assert.assertEquals("Expected only 2 new projects", 2, newProjects.size()); //$NON-NLS-1$
+ JobHelpers.waitForJobs(new IJobMatcher() {
+ public boolean matches(Job job) {
+ return MavenProjectConfigurator.UPDATE_MAVEN_CONFIGURATION_JOB_NAME.equals(job.getName());
+ }
+ }, 30_000);
+
+ for(IProject project : newProjects) {
+ Assert.assertTrue(
+ project.getLocation().toFile().getCanonicalPath().startsWith(projectDirectory.getCanonicalPath()));
+ IMavenProjectFacade mavenProject = MavenPlugin.getMavenProjectRegistry().getProject(project);
+ Assert.assertNotNull("Project not configured as Maven", mavenProject); //$NON-NLS-1$
+ }
}
}
diff --git a/org.eclipse.m2e.importer/plugin.xml b/org.eclipse.m2e.importer/plugin.xml
index d264277e..20ce2666 100644
--- a/org.eclipse.m2e.importer/plugin.xml
+++ b/org.eclipse.m2e.importer/plugin.xml
@@ -7,9 +7,7 @@
class="org.eclipse.m2e.importer.internal.MavenProjectConfigurator"
label="Maven">
<activeWhen>
- <hasFile
- path="pom.xml">
- </hasFile>
+ <hasFileRecursively filename="pom.xml"/>
</activeWhen>
</projectConfigurator>
</extension>

Back to the top