[MNG-7667] Fix Bootstrap IT (#230)
This change extends Bootstrap IT (1st IT that fills in local repo) to hunt down some plugins that are bound in lifecycles provided by Maven under test.
Changes:
* the Bootstrap IT invokes only the phase where DownloadMojo is bound
* DownloadMojo (the "bootstrap") changed to do "this or that": it either resolves all artifacts from provided file OR collects plugins for given project packaging plugin versions provided by tested Maven default lifecycle.
* Split more Bootstrap project POMs, now we have 4 modules, we can add more (even extension if needed)
---
https://issues.apache.org/jira/browse/MNG-7667
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITBootstrapTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITBootstrapTest.java
index a575bf3..88cbb82 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITBootstrapTest.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITBootstrapTest.java
@@ -57,7 +57,10 @@
verifier.addCliOption( "--settings" );
verifier.addCliOption( "settings.xml" );
verifier.addCliOption( "-Dbootstrap=" + getClass().getResource( "/bootstrap.txt" ).toURI().getPath() );
- verifier.addCliArgument( "install" );
+
+ // bootstrap plugin is bound to this phase, do not go further
+ // important: maven-plugin packaging will fail at package phase, as there is no Mojo present!
+ verifier.addCliArgument( "process-resources" );
verifier.execute();
verifier.verifyErrorFreeLog();
}
diff --git a/core-it-suite/src/test/resources/bootstrap/bootstrap/pom.xml b/core-it-suite/src/test/resources/bootstrap/bootstrap/pom.xml
new file mode 100644
index 0000000..ae8cd7c
--- /dev/null
+++ b/core-it-suite/src/test/resources/bootstrap/bootstrap/pom.xml
@@ -0,0 +1,40 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.bootstrap</groupId>
+ <artifactId>maven-it-boostrap</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <artifactId>bootstrap</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Maven Integration Test :: Boostrap :: boostrap</name>
+
+ <!-- We do want the file here -->
+ <properties>
+ <file>${bootstrap}</file>
+ </properties>
+</project>
diff --git a/core-it-suite/src/test/resources/bootstrap/packaging-jar/pom.xml b/core-it-suite/src/test/resources/bootstrap/packaging-jar/pom.xml
new file mode 100644
index 0000000..e3d45f5
--- /dev/null
+++ b/core-it-suite/src/test/resources/bootstrap/packaging-jar/pom.xml
@@ -0,0 +1,35 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.bootstrap</groupId>
+ <artifactId>maven-it-boostrap</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <artifactId>packaging-jar</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Maven Integration Test :: Boostrap :: packaging-jar</name>
+</project>
diff --git a/core-it-suite/src/test/resources/bootstrap/packaging-maven-plugin/pom.xml b/core-it-suite/src/test/resources/bootstrap/packaging-maven-plugin/pom.xml
new file mode 100644
index 0000000..b9ba813
--- /dev/null
+++ b/core-it-suite/src/test/resources/bootstrap/packaging-maven-plugin/pom.xml
@@ -0,0 +1,35 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.bootstrap</groupId>
+ <artifactId>maven-it-boostrap</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <artifactId>packaging-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+
+ <name>Maven Integration Test :: Boostrap :: packaging-maven-plugin</name>
+</project>
diff --git a/core-it-suite/src/test/resources/bootstrap/packaging-war/pom.xml b/core-it-suite/src/test/resources/bootstrap/packaging-war/pom.xml
new file mode 100644
index 0000000..c5857a1
--- /dev/null
+++ b/core-it-suite/src/test/resources/bootstrap/packaging-war/pom.xml
@@ -0,0 +1,35 @@
+<?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>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.bootstrap</groupId>
+ <artifactId>maven-it-boostrap</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <artifactId>packaging-war</artifactId>
+ <packaging>war</packaging>
+
+ <name>Maven Integration Test :: Boostrap :: packaging-war</name>
+</project>
diff --git a/core-it-suite/src/test/resources/bootstrap/pom.xml b/core-it-suite/src/test/resources/bootstrap/pom.xml
index ab28b83..fedee76 100644
--- a/core-it-suite/src/test/resources/bootstrap/pom.xml
+++ b/core-it-suite/src/test/resources/bootstrap/pom.xml
@@ -33,15 +33,22 @@
plugins cannot be downloaded by Maven from non-default repositories configured in the POM if the plugin is invoked
directly from the command line. Also, having this in a central place spares us from copying the snapshot repo
config all around in the IT POMs.
+
+ Each module does:
+ - boostrap - resolves all artifacts provided in bootstrap file
+ - packaging-* - resolves build plugins provided by tested Maven default lifecycle(s)
</description>
- <properties>
- <maven.test.skip>true</maven.test.skip>
- </properties>
+ <modules>
+ <module>bootstrap</module>
+ <module>packaging-jar</module>
+ <module>packaging-maven-plugin</module>
+ <module>packaging-war</module>
+ </modules>
<build>
- <!-- This merely locks the plugin versions to disable auto-update -->
<plugins>
+ <!-- This merely locks the plugin versions to disable auto-update -->
<plugin>
<groupId>org.apache.maven.its</groupId>
<artifactId>maven-it-plugin-bootstrap</artifactId>
@@ -53,7 +60,7 @@
<goal>download</goal>
</goals>
<configuration>
- <file>${bootstrap}</file>
+ <file>${file}</file>
</configuration>
</execution>
</executions>
diff --git a/core-it-support/maven-it-plugin-bootstrap/src/main/java/org/apache/maven/its/bootstrap/DownloadMojo.java b/core-it-support/maven-it-plugin-bootstrap/src/main/java/org/apache/maven/its/bootstrap/DownloadMojo.java
index 64e258d..018c973 100644
--- a/core-it-support/maven-it-plugin-bootstrap/src/main/java/org/apache/maven/its/bootstrap/DownloadMojo.java
+++ b/core-it-support/maven-it-plugin-bootstrap/src/main/java/org/apache/maven/its/bootstrap/DownloadMojo.java
@@ -23,19 +23,22 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
@@ -45,7 +48,8 @@
import org.eclipse.aether.resolution.DependencyRequest;
/**
- * Boostrap plugin to download all required dependencies
+ * Boostrap plugin to download all required dependencies (provided in file) or to collect lifecycle bound build plugin
+ * versions.
*/
@Mojo( name = "download" )
public class DownloadMojo
@@ -56,13 +60,13 @@
* A list of artifacts coordinates.
*/
@Parameter
- private List<Dependency> dependencies = new ArrayList<>();
+ private Set<Dependency> dependencies = new HashSet<>();
/**
* A list of string of the form groupId:artifactId:version[:packaging[:classifier]].
*/
@Parameter
- private List<String> artifacts = new ArrayList<>();
+ private Set<String> artifacts = new HashSet<>();
/**
* A file containing lines of the form groupId:artifactId:version[:packaging[:classifier]].
@@ -82,8 +86,10 @@
@Override
public void execute() throws MojoFailureException
{
+ // this or that: either resolver file listed artifacts or collect lifecycle packaging plugins
if ( file != null && file.exists() )
{
+ System.out.println( "Collecting artifacts from file: " + file );
try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
{
reader.lines()
@@ -96,6 +102,16 @@
throw new MojoFailureException( "Unable to read dependencies: " + file, e );
}
}
+ else
+ {
+ MavenProject project = session.getCurrentProject();
+ System.out.println( "Collecting build plugins from packaging: " + project.getPackaging() );
+ for ( Plugin plugin : project.getBuildPlugins() )
+ {
+ artifacts.add( plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() );
+ }
+ }
+
for ( String artifact : artifacts )
{
if ( artifact != null )