mirror of https://github.com/apache/maven.git
[MNG-4331] Add new mojo annotation @requiresDependencyCollection to grab dependency tree without files
o Added IT git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@809429 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
785f9c5e8c
commit
2e768dadce
|
@ -86,6 +86,7 @@ public class IntegrationTestSuite
|
|||
// suite.addTestSuite( MavenIT0109ReleaseUpdateTest.class );
|
||||
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
|
||||
|
||||
suite.addTestSuite( MavenITmng4331DependencyCollectionTest.class );
|
||||
suite.addTestSuite( MavenITmng4328PrimitiveMojoParameterConfigurationTest.class );
|
||||
suite.addTestSuite( MavenITmng4327ExcludeForkingMojoFromForkedLifecycleTest.class );
|
||||
suite.addTestSuite( MavenITmng4321CliUsesPluginMgmtConfigTest.class );
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package org.apache.maven.it;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.it.Verifier;
|
||||
import org.apache.maven.it.util.ResourceExtractor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4331">MNG-4331</a>.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public class MavenITmng4331DependencyCollectionTest
|
||||
extends AbstractMavenIntegrationTestCase
|
||||
{
|
||||
|
||||
public MavenITmng4331DependencyCollectionTest()
|
||||
{
|
||||
super( "[3.0-alpha-3,)" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that @requiresDependencyCollection works for a goal that is bound into a very early lifecycle phase
|
||||
* like "validate" where none of the reactor projects have an artifact file. The Enforcer Plugin is the
|
||||
* real world example for this use case.
|
||||
*/
|
||||
public void testitEarlyLifecyclePhase()
|
||||
throws Exception
|
||||
{
|
||||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4331" );
|
||||
|
||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||
verifier.setAutoclean( false );
|
||||
verifier.deleteArtifacts( "org.apache.maven.its.mng4331" );
|
||||
verifier.deleteDirectory( "sub-2/target" );
|
||||
verifier.setLogFileName( "log-lifecycle.txt" );
|
||||
verifier.executeGoal( "validate" );
|
||||
verifier.verifyErrorFreeLog();
|
||||
verifier.resetStreams();
|
||||
|
||||
List artifacts = verifier.loadLines( "sub-2/target/compile.txt", "UTF-8" );
|
||||
assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven.its.mng4331:sub-1:jar:0.1" ) );
|
||||
assertEquals( 1, artifacts.size() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that @requiresDependencyCollection works for an aggregator goal that is invoked from the command line.
|
||||
* The Release Plugin is the real world example for this use case.
|
||||
*/
|
||||
public void testitCliAggregator()
|
||||
throws Exception
|
||||
{
|
||||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4331" );
|
||||
|
||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||
verifier.setAutoclean( false );
|
||||
verifier.deleteDirectory( "target" );
|
||||
verifier.deleteArtifacts( "org.apache.maven.its.mng4331" );
|
||||
verifier.getCliOptions().add( "-Ddepres.projectArtifacts=target/@artifactId@.txt" );
|
||||
verifier.setLogFileName( "log-aggregator.txt" );
|
||||
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-collection:2.1-SNAPSHOT:aggregate-test" );
|
||||
verifier.verifyErrorFreeLog();
|
||||
verifier.resetStreams();
|
||||
|
||||
List artifacts = verifier.loadLines( "target/sub-2.txt", "UTF-8" );
|
||||
assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven.its.mng4331:sub-1:jar:0.1" ) );
|
||||
assertEquals( 1, artifacts.size() );
|
||||
|
||||
artifacts = verifier.loadLines( "target/sub-1.txt", "UTF-8" );
|
||||
assertEquals( 0, artifacts.size() );
|
||||
|
||||
artifacts = verifier.loadLines( "target/test.txt", "UTF-8" );
|
||||
assertEquals( 0, artifacts.size() );
|
||||
}
|
||||
|
||||
}
|
|
@ -91,6 +91,12 @@ under the License.
|
|||
<version>${itPluginVersion}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-dependency-collection</artifactId>
|
||||
<version>${itPluginVersion}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?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>
|
||||
|
||||
<groupId>org.apache.maven.its.mng4331</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>0.1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Maven Integration Test :: MNG-4331</name>
|
||||
<description>
|
||||
Verify that the mojo annotation @requiresDependencyCollection allows to grab the transitive dependencies
|
||||
without resolving their artifact files.
|
||||
</description>
|
||||
|
||||
<modules>
|
||||
<module>sub-1</module>
|
||||
<module>sub-2</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,36 @@
|
|||
<?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>
|
||||
|
||||
<groupId>org.apache.maven.its.mng4331</groupId>
|
||||
<artifactId>sub-1</artifactId>
|
||||
<version>0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Maven Integration Test :: MNG-4331 :: Sub-1</name>
|
||||
<description>
|
||||
Verify that the mojo annotation @requiresDependencyCollection allows to grab the transitive dependencies
|
||||
without resolving their artifact files.
|
||||
</description>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,66 @@
|
|||
<?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>
|
||||
|
||||
<groupId>org.apache.maven.its.mng4331</groupId>
|
||||
<artifactId>sub-2</artifactId>
|
||||
<version>0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Maven Integration Test :: MNG-4331 :: Sub-2</name>
|
||||
<description>
|
||||
Verify that the mojo annotation @requiresDependencyCollection allows to grab the transitive dependencies
|
||||
without resolving their artifact files.
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- This dependency or more precisly its POM is part of the reactor but the actual artifact file is not (yet build) -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.mng4331</groupId>
|
||||
<artifactId>sub-1</artifactId>
|
||||
<version>0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-dependency-collection</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<compileArtifacts>target/compile.txt</compileArtifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,86 @@
|
|||
<?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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>maven-it-plugins</artifactId>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-it-plugin-dependency-collection</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Maven Integration Test Plugin :: Dependency Collection</name>
|
||||
<description>
|
||||
A test plugin that provides several goals which employ @requiresDependencyCollection with different scopes. If
|
||||
desired, the resulting artifact identifiers can be written to a text file.
|
||||
</description>
|
||||
<inceptionYear>2008</inceptionYear>
|
||||
|
||||
<properties>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>delete-incomplete-plugin-descriptor</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<!-- The maven-plugin-plugin does not handle the new anno so delete its bad output -->
|
||||
<delete file="${project.build.outputDirectory}/META-INF/maven/plugin.xml"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,130 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Provides common services for all mojos of this plugin.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractDependencyMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* The current Maven project.
|
||||
*
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected MavenProject project;
|
||||
|
||||
/**
|
||||
* Writes the specified artifacts to the given output file.
|
||||
*
|
||||
* @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or
|
||||
* empty if the output file should not be written.
|
||||
* @param artifacts The list of artifacts to write to the file, may be <code>null</code>.
|
||||
* @throws MojoExecutionException If the output file could not be written.
|
||||
*/
|
||||
protected void writeArtifacts( String pathname, Collection artifacts )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
if ( pathname == null || pathname.length() <= 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
File file = resolveFile( pathname );
|
||||
|
||||
getLog().info( "[MAVEN-CORE-IT-LOG] Dumping artifact list: " + file );
|
||||
|
||||
BufferedWriter writer = null;
|
||||
try
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) );
|
||||
|
||||
if ( artifacts != null )
|
||||
{
|
||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
writer.write( artifact.getId() );
|
||||
writer.newLine();
|
||||
getLog().info( "[MAVEN-CORE-IT-LOG] " + artifact.getId() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to write artifact list", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( writer != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// just ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: We don't want to test path translation here so resolve relative path manually for robustness
|
||||
private File resolveFile( String pathname )
|
||||
{
|
||||
File file = null;
|
||||
|
||||
if ( pathname != null )
|
||||
{
|
||||
file = new File( pathname );
|
||||
|
||||
if ( !file.isAbsolute() )
|
||||
{
|
||||
file = new File( project.getBasedir(), pathname );
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
/*
|
||||
* 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.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Combines dependency collection with aggregation. The path parameters of this mojo support the token
|
||||
* <code>@artifactId@</code> to dynamically adjust the output file for each project in the reactor whose
|
||||
* dependencies are dumped.
|
||||
*
|
||||
* @goal aggregate-test
|
||||
* @requiresDependencyResolution test
|
||||
* @aggregator true
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AggregateTestMojo
|
||||
extends AbstractDependencyMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
|
||||
* do not contribute to the class path.
|
||||
*
|
||||
* @parameter expression="${depres.projectArtifacts}"
|
||||
*/
|
||||
private String projectArtifacts;
|
||||
|
||||
/**
|
||||
* The Maven projects in the reactor.
|
||||
*
|
||||
* @parameter default-value="${reactorProjects}"
|
||||
* @readonly
|
||||
*/
|
||||
private List reactorProjects;
|
||||
|
||||
/**
|
||||
* Runs this mojo.
|
||||
*
|
||||
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() );
|
||||
|
||||
// NOTE: We can't make any assumptions about the class path but as a minimum it must not cause an exception
|
||||
project.getTestClasspathElements();
|
||||
}
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
private String filter( String filename, MavenProject project )
|
||||
{
|
||||
String result = filename;
|
||||
|
||||
if ( filename != null )
|
||||
{
|
||||
result = result.replaceAll( "@artifactId@", project.getArtifactId() );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
/**
|
||||
* Creates text files that list the dependencies with scope compile in the order returned from the Maven core.
|
||||
*
|
||||
* @goal compile
|
||||
* @requiresDependencyResolution compile
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CompileMojo
|
||||
extends AbstractDependencyMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk. Unlike the compile artifacts, the collection of project artifacts additionally contains those artifacts
|
||||
* that do not contribute to the class path.
|
||||
*
|
||||
* @parameter expression="${depres.projectArtifacts}"
|
||||
*/
|
||||
private String projectArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the compile artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk.
|
||||
*
|
||||
* @parameter expression="${depres.compileArtifacts}"
|
||||
*/
|
||||
private String compileArtifacts;
|
||||
|
||||
/**
|
||||
* Runs this mojo.
|
||||
*
|
||||
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
writeArtifacts( projectArtifacts, project.getArtifacts() );
|
||||
writeArtifacts( compileArtifacts, project.getCompileArtifacts() );
|
||||
|
||||
// NOTE: We can't make any assumptions about the class path but as a minimum it must not cause an exception
|
||||
project.getCompileClasspathElements();
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
/**
|
||||
* Creates text files that list the dependencies with scope runtime in the order returned from the Maven core.
|
||||
*
|
||||
* @goal runtime
|
||||
* @requiresDependencyResolution runtime
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RuntimeMojo
|
||||
extends AbstractDependencyMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk. Unlike the runtime artifacts, the collection of project artifacts additionally contains those artifacts
|
||||
* that do not contribute to the class path.
|
||||
*
|
||||
* @parameter expression="${depres.projectArtifacts}"
|
||||
*/
|
||||
private String projectArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the runtime artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk.
|
||||
*
|
||||
* @parameter expression="${depres.runtimeArtifacts}"
|
||||
*/
|
||||
private String runtimeArtifacts;
|
||||
|
||||
/**
|
||||
* Runs this mojo.
|
||||
*
|
||||
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
writeArtifacts( projectArtifacts, project.getArtifacts() );
|
||||
writeArtifacts( runtimeArtifacts, project.getRuntimeArtifacts() );
|
||||
|
||||
// NOTE: We can't make any assumptions about the class path but as a minimum it must not cause an exception
|
||||
project.getRuntimeClasspathElements();
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
/**
|
||||
* Creates text files that list the dependencies with scope test in the order returned from the Maven core.
|
||||
*
|
||||
* @goal test
|
||||
* @requiresDependencyResolution test
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestMojo
|
||||
extends AbstractDependencyMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
|
||||
* do not contribute to the class path.
|
||||
*
|
||||
* @parameter expression="${depres.projectArtifacts}"
|
||||
*/
|
||||
private String projectArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the test artifacts, relative to the project base directory. Each line of this
|
||||
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
* disk.
|
||||
*
|
||||
* @parameter expression="${depres.testArtifacts}"
|
||||
*/
|
||||
private String testArtifacts;
|
||||
|
||||
/**
|
||||
* Runs this mojo.
|
||||
*
|
||||
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
writeArtifacts( projectArtifacts, project.getArtifacts() );
|
||||
writeArtifacts( testArtifacts, project.getTestArtifacts() );
|
||||
|
||||
// NOTE: We can't make any assumptions about the class path but as a minimum it must not cause an exception
|
||||
project.getTestClasspathElements();
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin>
|
||||
<description>A test plugin that provides several goals which employ @requiresDependencyCollection with different scopes. If
|
||||
desired, the resulting artifact identifiers can be written to a text file.</description>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-dependency-collection</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<goalPrefix>itdependency-collection</goalPrefix>
|
||||
<isolatedRealm>false</isolatedRealm>
|
||||
<inheritedByDefault>true</inheritedByDefault>
|
||||
<mojos>
|
||||
<mojo>
|
||||
<goal>compile</goal>
|
||||
<description>Creates text files that list the dependencies with scope compile in the order returned from the Maven core.</description>
|
||||
<requiresDependencyCollection>compile</requiresDependencyCollection>
|
||||
<requiresDirectInvocation>false</requiresDirectInvocation>
|
||||
<requiresProject>true</requiresProject>
|
||||
<requiresReports>false</requiresReports>
|
||||
<aggregator>false</aggregator>
|
||||
<requiresOnline>false</requiresOnline>
|
||||
<inheritedByDefault>true</inheritedByDefault>
|
||||
<implementation>org.apache.maven.plugin.coreit.CompileMojo</implementation>
|
||||
<language>java</language>
|
||||
<instantiationStrategy>per-lookup</instantiationStrategy>
|
||||
<executionStrategy>once-per-session</executionStrategy>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>compileArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the compile artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>project</name>
|
||||
<type>org.apache.maven.project.MavenProject</type>
|
||||
<required>true</required>
|
||||
<editable>false</editable>
|
||||
<description>The current Maven project.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>projectArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk. Unlike the compile artifacts, the collection of project artifacts additionally contains those artifacts
|
||||
that do not contribute to the class path.</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<configuration>
|
||||
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
|
||||
<compileArtifacts implementation="java.lang.String">${depres.compileArtifacts}</compileArtifacts>
|
||||
<projectArtifacts implementation="java.lang.String">${depres.projectArtifacts}</projectArtifacts>
|
||||
</configuration>
|
||||
</mojo>
|
||||
<mojo>
|
||||
<goal>aggregate-test</goal>
|
||||
<description>Combines dependency collection with aggregation. The path parameters of this mojo support the token
|
||||
<code>&#64;artifactId&#64;</code> to dynamically adjust the output file for each project in the reactor whose
|
||||
dependencies are dumped.</description>
|
||||
<requiresDependencyCollection>test</requiresDependencyCollection>
|
||||
<requiresDirectInvocation>false</requiresDirectInvocation>
|
||||
<requiresProject>true</requiresProject>
|
||||
<requiresReports>false</requiresReports>
|
||||
<aggregator>true</aggregator>
|
||||
<requiresOnline>false</requiresOnline>
|
||||
<inheritedByDefault>true</inheritedByDefault>
|
||||
<implementation>org.apache.maven.plugin.coreit.AggregateTestMojo</implementation>
|
||||
<language>java</language>
|
||||
<instantiationStrategy>per-lookup</instantiationStrategy>
|
||||
<executionStrategy>once-per-session</executionStrategy>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>project</name>
|
||||
<type>org.apache.maven.project.MavenProject</type>
|
||||
<required>true</required>
|
||||
<editable>false</editable>
|
||||
<description>The current Maven project.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>projectArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
|
||||
do not contribute to the class path.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>reactorProjects</name>
|
||||
<type>java.util.List</type>
|
||||
<required>false</required>
|
||||
<editable>false</editable>
|
||||
<description>The Maven projects in the reactor.</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<configuration>
|
||||
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
|
||||
<projectArtifacts implementation="java.lang.String">${depres.projectArtifacts}</projectArtifacts>
|
||||
<reactorProjects implementation="java.util.List" default-value="${reactorProjects}"/>
|
||||
</configuration>
|
||||
</mojo>
|
||||
<mojo>
|
||||
<goal>test</goal>
|
||||
<description>Creates text files that list the dependencies with scope test in the order returned from the Maven core.</description>
|
||||
<requiresDependencyCollection>test</requiresDependencyCollection>
|
||||
<requiresDirectInvocation>false</requiresDirectInvocation>
|
||||
<requiresProject>true</requiresProject>
|
||||
<requiresReports>false</requiresReports>
|
||||
<aggregator>false</aggregator>
|
||||
<requiresOnline>false</requiresOnline>
|
||||
<inheritedByDefault>true</inheritedByDefault>
|
||||
<implementation>org.apache.maven.plugin.coreit.TestMojo</implementation>
|
||||
<language>java</language>
|
||||
<instantiationStrategy>per-lookup</instantiationStrategy>
|
||||
<executionStrategy>once-per-session</executionStrategy>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>project</name>
|
||||
<type>org.apache.maven.project.MavenProject</type>
|
||||
<required>true</required>
|
||||
<editable>false</editable>
|
||||
<description>The current Maven project.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>projectArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
|
||||
do not contribute to the class path.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>testArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the test artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk.</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<configuration>
|
||||
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
|
||||
<projectArtifacts implementation="java.lang.String">${depres.projectArtifacts}</projectArtifacts>
|
||||
<testArtifacts implementation="java.lang.String">${depres.testArtifacts}</testArtifacts>
|
||||
</configuration>
|
||||
</mojo>
|
||||
<mojo>
|
||||
<goal>runtime</goal>
|
||||
<description>Creates text files that list the dependencies with scope runtime in the order returned from the Maven core.</description>
|
||||
<requiresDependencyCollection>runtime</requiresDependencyCollection>
|
||||
<requiresDirectInvocation>false</requiresDirectInvocation>
|
||||
<requiresProject>true</requiresProject>
|
||||
<requiresReports>false</requiresReports>
|
||||
<aggregator>false</aggregator>
|
||||
<requiresOnline>false</requiresOnline>
|
||||
<inheritedByDefault>true</inheritedByDefault>
|
||||
<implementation>org.apache.maven.plugin.coreit.RuntimeMojo</implementation>
|
||||
<language>java</language>
|
||||
<instantiationStrategy>per-lookup</instantiationStrategy>
|
||||
<executionStrategy>once-per-session</executionStrategy>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>project</name>
|
||||
<type>org.apache.maven.project.MavenProject</type>
|
||||
<required>true</required>
|
||||
<editable>false</editable>
|
||||
<description>The current Maven project.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>projectArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the project artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk. Unlike the runtime artifacts, the collection of project artifacts additionally contains those artifacts
|
||||
that do not contribute to the class path.</description>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>runtimeArtifacts</name>
|
||||
<type>java.lang.String</type>
|
||||
<required>false</required>
|
||||
<editable>true</editable>
|
||||
<description>The path to the output file for the runtime artifacts, relative to the project base directory. Each line of this
|
||||
UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
|
||||
disk.</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<configuration>
|
||||
<project implementation="org.apache.maven.project.MavenProject" default-value="${project}"/>
|
||||
<projectArtifacts implementation="java.lang.String">${depres.projectArtifacts}</projectArtifacts>
|
||||
<runtimeArtifacts implementation="java.lang.String">${depres.runtimeArtifacts}</runtimeArtifacts>
|
||||
</configuration>
|
||||
</mojo>
|
||||
</mojos>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-profile</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0-alpha-8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<type>jar</type>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>classworlds</groupId>
|
||||
<artifactId>classworlds</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.1-alpha-2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact-manager</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-repository-metadata</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<type>jar</type>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-provider-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0-alpha-5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
|
@ -38,6 +38,7 @@ under the License.
|
|||
<module>maven-it-plugin-configuration</module>
|
||||
<module>maven-it-plugin-context-passing</module>
|
||||
<module>maven-it-plugin-core-stubs</module>
|
||||
<module>maven-it-plugin-dependency-collection</module>
|
||||
<module>maven-it-plugin-dependency-resolution</module>
|
||||
<module>maven-it-plugin-expression</module>
|
||||
<module>maven-it-plugin-error</module>
|
||||
|
|
Loading…
Reference in New Issue