diff options
author | Mickael Istria | 2016-01-14 08:37:55 +0000 |
---|---|---|
committer | Mickael Istria | 2016-01-28 16:54:29 +0000 |
commit | f20750a49c148b27e0499039037d15bc051afe3b (patch) | |
tree | eaad3e53763b16697d0c554f8a9d207f391020ec | |
parent | 31bface99786a03d3debdf59f1b00906898fcb97 (diff) | |
download | m2e-core-f20750a49c148b27e0499039037d15bc051afe3b.tar.gz m2e-core-f20750a49c148b27e0499039037d15bc051afe3b.tar.xz m2e-core-f20750a49c148b27e0499039037d15bc051afe3b.zip |
[464535] Test for importer
Change-Id: I3bc8685eea13abd5e588674d15921ae94f1852fd
Signed-off-by: Mickael Istria <mistria@redhat.com>
11 files changed, 257 insertions, 3 deletions
diff --git a/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF b/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..9d25c7fc --- /dev/null +++ b/org.eclipse.m2e.importer.tests/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.m2e.importer.tests +Bundle-Version: 1.7.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-Vendor: %Bundle-Vendor +Bundle-Localization: plugin +Require-Bundle: org.eclipse.m2e.importer;bundle-version="[1.7.0,1.8.0)", + org.junit;bundle-version="4.12.0", + org.eclipse.m2e.core;bundle-version="[1.7.0,1.8.0)", + org.eclipse.core.resources, + org.eclipse.e4.ui.importer;bundle-version="0.2.0", + org.eclipse.core.runtime, + org.eclipse.ui.workbench, + org.apache.ant, + org.eclipse.jdt.core, + org.eclipse.m2e.tests.common;bundle-version="[1.7.0,1.8.0)" diff --git a/org.eclipse.m2e.importer.tests/build.properties b/org.eclipse.m2e.importer.tests/build.properties new file mode 100644 index 00000000..7d75703d --- /dev/null +++ b/org.eclipse.m2e.importer.tests/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + plugin.properties,\ + resources/,\ + . diff --git a/org.eclipse.m2e.importer.tests/plugin.properties b/org.eclipse.m2e.importer.tests/plugin.properties new file mode 100644 index 00000000..150f33e5 --- /dev/null +++ b/org.eclipse.m2e.importer.tests/plugin.properties @@ -0,0 +1,2 @@ +Bundle-Vendor = Eclipse.org - m2e +Bundle-Name = Tests for m2e extension for import framework
\ No newline at end of file diff --git a/org.eclipse.m2e.importer.tests/pom.xml b/org.eclipse.m2e.importer.tests/pom.xml new file mode 100644 index 00000000..1a7a6b0c --- /dev/null +++ b/org.eclipse.m2e.importer.tests/pom.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright (c) 2016 Red Hat 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: + Mickael Istria (Red Hat Inc.) - Initial implementation +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.m2e</groupId> + <artifactId>m2e-core</artifactId> + <version>1.7.0-SNAPSHOT</version> + </parent> + + <artifactId>org.eclipse.m2e.importer.tests</artifactId> + <packaging>eclipse-test-plugin</packaging> + + <name>Tests for Maven Integration for Eclipse Importer framework</name> + + <properties> + <tycho.test.jvmArgs>-Xmx800m</tycho.test.jvmArgs> + <tycho.surefire.timeout>300</tycho.surefire.timeout> + </properties> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <version>${tycho-version}</version> + <configuration> + <useUIHarness>true</useUIHarness> + <useUIThread>true</useUIThread> + <!-- kill test JVM if tests take more than 10 minutes (600 seconds) to finish --> + <forkedProcessTimeoutInSeconds>${tycho.surefire.timeout}</forkedProcessTimeoutInSeconds> + <argLine>${tycho.test.jvmArgs}</argLine> + <includes> + <include>**/*Test.class</include> + </includes> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + <profiles> + <profile> + <id>osx</id> + <activation> + <os> + <family>mac</family> + </os> + </activation> + <properties> + <tycho.test.jvmArgs>-Xmx800m -Dosgi.ws=cocoa -XstartOnFirstThread</tycho.test.jvmArgs> + </properties> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <version>${tycho-version}</version> + <configuration> + <dependencies combine.children="append"> + <dependency> + <artifactId>org.eclipse.jdt.launching.macosx</artifactId> + <version>0.0.0</version> + <type>eclipse-plugin</type> + </dependency> + <dependency> + <type>eclipse-feature</type> + <artifactId>org.eclipse.e4.rcp</artifactId> + <version>0.0.0</version> + </dependency> + </dependencies> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + </profile> + + +</project> diff --git a/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/pom.xml b/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/pom.xml new file mode 100644 index 00000000..68f28d4b --- /dev/null +++ b/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/pom.xml @@ -0,0 +1,19 @@ +<!-- Copyright (c) 2016 Red Hat 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: + Mickael Istria (Red Hat Inc.) - Initial implementation +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse.m2e.tests.example1</groupId> + <artifactId>parent</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>module1</artifactId> +</project>
\ No newline at end of file diff --git a/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/src/main/java/module1/Dummy.java b/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/src/main/java/module1/Dummy.java new file mode 100644 index 00000000..8d8dacf5 --- /dev/null +++ b/org.eclipse.m2e.importer.tests/resources/examples/example1/module1/src/main/java/module1/Dummy.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat 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: + * Mickael Istria (Red Hat Inc.) - Initial implementation + *******************************************************************************/ +package module1; + +public class Dummy { + +} diff --git a/org.eclipse.m2e.importer.tests/resources/examples/example1/pom.xml b/org.eclipse.m2e.importer.tests/resources/examples/example1/pom.xml new file mode 100644 index 00000000..2457b14b --- /dev/null +++ b/org.eclipse.m2e.importer.tests/resources/examples/example1/pom.xml @@ -0,0 +1,20 @@ +<!-- Copyright (c) 2016 Red Hat 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: + Mickael Istria (Red Hat Inc.) - Initial implementation +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.eclipse.m2e.tests.example1</groupId> + <artifactId>parent</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>pom</packaging> + <modules> + <module>module1</module> + </modules> +</project>
\ No newline at end of file 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 new file mode 100644 index 00000000..b6e5c0f3 --- /dev/null +++ b/org.eclipse.m2e.importer.tests/src/org/eclipse/m2e/importer/tests/MavenImporterTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.m2e.importer.tests; + +import java.io.File; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Test; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.ui.internal.wizards.datatransfer.EasymportJob; +import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.importer.internal.MavenProjectConfigurator; +import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase; + + +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); + + // 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(); + + Set<IProject> newProjects = null; + EasymportJob job = new EasymportJob(outputDirectory, 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$ + + waitForJobsToComplete(monitor); + + for(IProject project : newProjects) { + Assert + .assertTrue(project.getLocation().toFile().getCanonicalPath().startsWith(outputDirectory.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/META-INF/MANIFEST.MF b/org.eclipse.m2e.importer/META-INF/MANIFEST.MF index 34c691c8..9e5bd696 100644 --- a/org.eclipse.m2e.importer/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.importer/META-INF/MANIFEST.MF @@ -16,3 +16,4 @@ Require-Bundle: org.eclipse.e4.ui.importer, Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.m2e.importer.internal.Activator +Export-Package: org.eclipse.m2e.importer.internal diff --git a/org.eclipse.m2e.importer/src/org/eclipse/m2e/importer/internal/Activator.java b/org.eclipse.m2e.importer/src/org/eclipse/m2e/importer/internal/Activator.java index b6b87a45..79041322 100644 --- a/org.eclipse.m2e.importer/src/org/eclipse/m2e/importer/internal/Activator.java +++ b/org.eclipse.m2e.importer/src/org/eclipse/m2e/importer/internal/Activator.java @@ -7,11 +7,8 @@ *******************************************************************************/ package org.eclipse.m2e.importer.internal; -import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * The activator class controls the plug-in life cycle @@ -327,6 +327,8 @@ <module>org.eclipse.m2e.importer</module> <module>org.eclipse.m2e.importer.feature</module> <module>org.eclipse.m2e.incubation.site</module> + <!-- Tests --> + <module>org.eclipse.m2e.importer.tests</module> </modules> <repositories> <repository> |