[ARCHETYPE-491] Allow to run integration test with another archetype as parent project
This closes #8
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/invoker.properties b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/invoker.properties
new file mode 100644
index 0000000..3802c4a
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = clean integration-test
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/pom.xml b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/pom.xml
new file mode 100644
index 0000000..4fff62d
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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.apache.maven.plugins.archetype.its</groupId>
+ <artifactId>build-archetype-and-run-its-with-existing-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-archetype</packaging>
+
+ <name>build-archetype-with-existing-parent</name>
+ <description>packages an archetype then runs IT (archetype:integration-test) within a Maven Project being created through another archetype</description>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>@project.version@</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <settingsFile>${basedir}/test-settings.xml</settingsFile>
+ <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ </configuration>
+
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <includeEmptyDirs>true</includeEmptyDirs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..28ff4bf
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+ name="build-archetype-IT">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..7ba4cfb
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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>
+## There should be no parent specified, as it should be set automatically
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+
+ <name>archetype build IT</name>
+</project>
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/src/main/java/App.java
new file mode 100644
index 0000000..0e020bd
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/main/resources/archetype-resources/src/main/java/App.java
@@ -0,0 +1,36 @@
+package ${package};
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ System.out.println( "groupId = ${groupId}" );
+ System.out.println( "artifactId = ${artifactId}" );
+ System.out.println( "package = ${package}" );
+ System.out.println( "packageInPathFormat = ${packageInPathFormat}" );
+ }
+}
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.pom.properties b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.pom.properties
new file mode 100644
index 0000000..0dfcb2b
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.pom.properties
@@ -0,0 +1,4 @@
+# https://github.com/mojohaus/pom-root, creates simple pom with packaging pom
+groupId=org.codehaus.mojo.archetypes
+artifactId=pom-root
+version=1.1
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.properties b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.properties
new file mode 100644
index 0000000..3fbeda5
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/archetype.properties
@@ -0,0 +1,4 @@
+groupId=com.company
+artifactId=project
+version=1.0-SNAPSHOT
+package=com.company.project
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..2607200
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,4 @@
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
+package=build.archetype
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/goal.txt b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..f8808ba
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/goal.txt
@@ -0,0 +1 @@
+compile
\ No newline at end of file
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/pom.xml b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/pom.xml
new file mode 100644
index 0000000..62a4b5b
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+--><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>
+ <artifactId>project</artifactId>
+ <groupId>com.company</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>archetype.it</groupId>
+ <artifactId>basic</artifactId>
+ <version>0.1-SNAPSHOT</version>
+
+ <name>archetype build IT</name>
+</project>
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/src/main/java/build/archetype/App.java b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/src/main/java/build/archetype/App.java
new file mode 100644
index 0000000..3119279
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/reference/src/main/java/build/archetype/App.java
@@ -0,0 +1,36 @@
+package build.archetype;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ System.out.println( "groupId = archetype.it" );
+ System.out.println( "artifactId = basic" );
+ System.out.println( "package = build.archetype" );
+ System.out.println( "packageInPathFormat = build/archetype" );
+ }
+}
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/verify.groovy b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/verify.groovy
new file mode 100644
index 0000000..b8e0729
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/src/test/resources/projects/basic/verify.groovy
@@ -0,0 +1 @@
+System.out.println("Yeah Baby, it rocks!")
\ No newline at end of file
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/test-settings.xml b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/test-settings.xml
new file mode 100644
index 0000000..ab9e16e
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/test-settings.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<settings>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
\ No newline at end of file
diff --git a/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/verify.bsh b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/verify.bsh
new file mode 100644
index 0000000..2d245ae
--- /dev/null
+++ b/maven-archetype-plugin/src/it/build-archetype-and-run-its-with-existing-parent/verify.bsh
@@ -0,0 +1,46 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import org.codehaus.plexus.util.*;
+
+basedir = new File( basedir, "target/test-classes/projects/basic/project/project/basic" );
+if ( !basedir.exists() ) {
+ throw new Exception( basedir + " is missing." );
+}
+
+File main = new File( basedir, "src/main" );
+
+// check <fileset packaged="true">
+File app = new File( main, "java/build/archetype/App.java" );
+if ( !app.isFile() )
+{
+ throw new Exception( app + " file is missing or not a file." );
+}
+
+File buildLog = new File( basedir, "build.log" );
+
+String content = FileUtils.fileRead( buildLog, "UTF-8" );
+
+int idx = content.indexOf( "Yeah Baby, it rocks!" );
+if ( idx < 0 )
+{
+ throw new Exception( "build.log missing System.out.println from verify.groovy" );
+}
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
index 66966d4..c7ecb8d 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
@@ -19,12 +19,37 @@
* under the License.
*/
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.maven.archetype.ArchetypeGenerationRequest;
import org.apache.maven.archetype.ArchetypeGenerationResult;
import org.apache.maven.archetype.common.Constants;
import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
import org.apache.maven.archetype.generator.ArchetypeGenerator;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -48,25 +73,6 @@
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
/**
* <p>
* Execute the archetype integration tests, consisting in generating projects from the current archetype and optionally
@@ -84,6 +90,43 @@
* the IT.</li>
* </ul>
* <p/>
+ * To let the IT create a Maven module below some other Maven project (being generated from another archetype)
+ * one can additionally specify an optional <code>archetype.pom.properties</code> file in the parent directory,
+ * specifying the archetype's <code>groupId</code>, <code>artifactId</code> and <code>version</code> along with its
+ * <code>archetype.properties</code> file, containing properties for project generation. Both files are leveraged
+ * to create the parent project for this IT. Parent projects can be nested.
+ * An example structure for such an integration test looks like this
+ * <table>
+ * <tr>
+ * <th>File/Directory</code></td>
+ * <th>Description</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1</code></td>
+ * <td>Directory for integration test 1</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1/archetype.pom.properties</code></td>
+ * <td>GAV for the archetype from which to generate the parent</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1/archetype.properties</code></td>
+ * <td>All required properties for the archetype being specified by <code>archetype.pom.properties</code> on this level</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1/child</code></td>
+ * <td>Directory for maven module within integration test 1 (this folder's name is not relevant)</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1/child/goal.txt</code></td>
+ * <td>The file containing the list of goals to be executed against the generated project</td>
+ * </tr>
+ * <tr>
+ * <td><code>src/test/resources/projects/it1/child/archetype.properties</code></td>
+ * <td>All required properties for this project's archetype</td>
+ * </tr>
+ * </table>
+ * <p/>
* Notice that it is expected to be run as part as of a build after the <code>package</code> phase and not directly as a
* goal from CLI.
*
@@ -100,6 +143,18 @@
@Component
private Invoker invoker;
+ @Component
+ private ArtifactFactory artifactFactory;
+
+ @Component
+ private ArtifactResolver artifactResolver;
+
+ @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
+ protected List remoteRepositories;
+
+ @Parameter( defaultValue = "${localRepository}", readonly = true, required = true )
+ protected ArtifactRepository localRepository;
+
/**
* The archetype project to execute the integration tests on.
*/
@@ -240,7 +295,7 @@
try
{
- List<File> projectsGoalFiles = FileUtils.getFiles( testProjectsDirectory, "*/goal.txt", "" );
+ List<File> projectsGoalFiles = FileUtils.getFiles( testProjectsDirectory, "**/goal.txt", "" );
if ( projectsGoalFiles.size() == 0 )
{
@@ -427,40 +482,15 @@
{
Properties properties = getProperties( goalFile );
- String basedir = goalFile.getParentFile().getPath() + "/project";
+ File basedir = new File( goalFile.getParentFile(), "project" );
FileUtils.deleteDirectory( basedir );
- FileUtils.mkdir( basedir );
+ FileUtils.mkdir( basedir.toString() );
+
+ basedir = setupParentProjects( goalFile.getParentFile().getParentFile(), basedir );
- //@formatter:off
- ArchetypeGenerationRequest request =
- new ArchetypeGenerationRequest().setArchetypeGroupId( project.getGroupId() ).setArchetypeArtifactId(
- project.getArtifactId() ).setArchetypeVersion( project.getVersion() ).setGroupId(
- properties.getProperty( Constants.GROUP_ID ) ).setArtifactId(
- properties.getProperty( Constants.ARTIFACT_ID ) ).setVersion(
- properties.getProperty( Constants.VERSION ) ).setPackage(
- properties.getProperty( Constants.PACKAGE ) ).setOutputDirectory( basedir ).setProperties(
- properties );
- //@formatter:on
-
- ArchetypeGenerationResult result = new ArchetypeGenerationResult();
-
- archetypeGenerator.generateArchetype( request, archetypeFile, result );
-
- if ( result.getCause() != null )
- {
- if ( result.getCause() instanceof ArchetypeNotConfigured )
- {
- ArchetypeNotConfigured anc = (ArchetypeNotConfigured) result.getCause();
-
- throw new IntegrationTestFailure(
- "Missing required properties in archetype.properties: " + StringUtils.join(
- anc.getMissingProperties().iterator(), ", " ), anc );
- }
-
- throw new IntegrationTestFailure( result.getCause().getMessage(), result.getCause() );
- }
+ ArchetypeGenerationRequest request = generate( project.getGroupId(), project.getArtifactId(), project.getVersion(), archetypeFile, properties, basedir.toString() );
File reference = new File( goalFile.getParentFile(), "reference" );
@@ -486,6 +516,97 @@
}
}
+ private ArchetypeGenerationRequest generate( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion, File archetypeFile, Properties properties, String basedir ) throws IntegrationTestFailure
+ {
+ //@formatter:off
+ ArchetypeGenerationRequest request =
+ new ArchetypeGenerationRequest().setArchetypeGroupId( archetypeGroupId ).setArchetypeArtifactId(
+ archetypeArtifactId ).setArchetypeVersion( archetypeVersion ).setGroupId(
+ properties.getProperty( Constants.GROUP_ID ) ).setArtifactId(
+ properties.getProperty( Constants.ARTIFACT_ID ) ).setVersion(
+ properties.getProperty( Constants.VERSION ) ).setPackage(
+ properties.getProperty( Constants.PACKAGE ) ).setOutputDirectory( basedir ).setProperties(
+ properties );
+ //@formatter:on
+
+ ArchetypeGenerationResult result = new ArchetypeGenerationResult();
+
+ archetypeGenerator.generateArchetype( request, archetypeFile, result );
+
+ if ( result.getCause() != null )
+ {
+ if ( result.getCause() instanceof ArchetypeNotConfigured )
+ {
+ ArchetypeNotConfigured anc = (ArchetypeNotConfigured) result.getCause();
+
+ throw new IntegrationTestFailure(
+ "Missing required properties in archetype.properties: " + StringUtils.join(
+ anc.getMissingProperties().iterator(), ", " ), anc );
+ }
+
+ throw new IntegrationTestFailure( result.getCause().getMessage(), result.getCause() );
+ }
+ return request;
+ }
+
+ private File setupParentProjects( File configFolder, File buildFolder )
+ throws IOException, MojoExecutionException, IntegrationTestFailure
+ {
+ // look for 'archetype.pom.properties'
+ File archetypePomPropertiesFile = new File( configFolder, "archetype.pom.properties" );
+ if ( !archetypePomPropertiesFile.exists() )
+ {
+ getLog().debug( "No 'archetype.pom.properties' file found in " + configFolder );
+ return buildFolder;
+ }
+
+ // go up to the parent configuration folder
+ buildFolder = setupParentProjects( configFolder.getParentFile(), buildFolder );
+
+ Properties archetypePomProperties = loadProperties( archetypePomPropertiesFile );
+ String groupId = archetypePomProperties.getProperty( Constants.GROUP_ID );
+ if ( StringUtils.isEmpty( groupId ) )
+ {
+ throw new MojoExecutionException( "Property " + Constants.GROUP_ID + " not set in " + archetypePomPropertiesFile );
+ }
+ String artifactId = archetypePomProperties.getProperty( Constants.ARTIFACT_ID );
+ if ( StringUtils.isEmpty( artifactId ) )
+ {
+ throw new MojoExecutionException( "Property " + Constants.ARTIFACT_ID + " not set in " + archetypePomPropertiesFile );
+ }
+ String version = archetypePomProperties.getProperty( Constants.VERSION );
+ if ( StringUtils.isEmpty( version ) )
+ {
+ throw new MojoExecutionException( "Property " + Constants.VERSION + " not set in " + archetypePomPropertiesFile );
+ }
+
+ File archetypeFile;
+ try
+ {
+ archetypeFile = getArchetypeFile( groupId, artifactId, version );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new MojoExecutionException( "Could not resolve archetype artifact " , e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( "Could not find archetype artifact " , e );
+ }
+ Properties archetypeProperties = getProperties( archetypePomPropertiesFile );
+ getLog().info( "Setting up parent project in " + buildFolder );
+ ArchetypeGenerationRequest request = generate( groupId, artifactId, version, archetypeFile, archetypeProperties, buildFolder.toString() );
+ return new File( buildFolder, request.getArtifactId() );
+ }
+
+ private File getArchetypeFile( String groupId, String artifactId, String version )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ Artifact archetypeArtifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "maven-archetype" );
+ artifactResolver.resolve( archetypeArtifact, remoteRepositories, localRepository );
+ return archetypeArtifact.getFile();
+ }
+
private Properties getProperties( File goalFile )
throws IOException
{