mirror of https://github.com/apache/maven.git
o Added new IT plugin to test things that involve dependency resolution
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@699315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
13ea233356
commit
66f606b5a9
|
@ -0,0 +1,62 @@
|
|||
<?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-resolution</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Maven Integration Test Plugin :: Dependency Resolution</name>
|
||||
<description>
|
||||
A test plugin that provides several goals which employ @requiresDependencyResolution with different scopes. If
|
||||
desired, the resulting class path or 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>
|
||||
</project>
|
|
@ -0,0 +1,178 @@
|
|||
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.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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, List artifacts )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
if ( pathname == null || pathname.length() <= 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: We don't want to test path translation here so resolve relative path manually for robustness
|
||||
File file = new File( pathname );
|
||||
if ( !file.isAbsolute() )
|
||||
{
|
||||
file = new File( project.getBasedir(), 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to write artifact list", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( writer != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// just ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the specified class path elements 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 classPath The list of class path elements to write to the file, may be <code>null</code>.
|
||||
* @throws MojoExecutionException If the output file could not be written.
|
||||
*/
|
||||
protected void writeClassPath( String pathname, List classPath )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
if ( pathname == null || pathname.length() <= 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: We don't want to test path translation here so resolve relative path manually for robustness
|
||||
File file = new File( pathname );
|
||||
if ( !file.isAbsolute() )
|
||||
{
|
||||
file = new File( project.getBasedir(), pathname );
|
||||
}
|
||||
|
||||
getLog().info( "[MAVEN-CORE-IT-LOG] Dumping class path: " + file );
|
||||
|
||||
BufferedWriter writer = null;
|
||||
try
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) );
|
||||
|
||||
if ( classPath != null )
|
||||
{
|
||||
for ( Iterator it = classPath.iterator(); it.hasNext(); )
|
||||
{
|
||||
Object element = it.next();
|
||||
writer.write( element.toString() );
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to write class path list", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( writer != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// just ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
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.AbstractMojo;
|
||||
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 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
|
||||
*/
|
||||
private String compileArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the compile class path, relative to the project base directory. Each line of
|
||||
* this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
|
||||
* will not be written to disk.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String compileClassPath;
|
||||
|
||||
/**
|
||||
* 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( compileArtifacts, project.getCompileArtifacts() );
|
||||
writeClassPath( compileClassPath, project.getCompileClasspathElements() );
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
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.AbstractMojo;
|
||||
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 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
|
||||
*/
|
||||
private String runtimeArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the runtime class path, relative to the project base directory. Each line of
|
||||
* this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
|
||||
* will not be written to disk.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String runtimeClassPath;
|
||||
|
||||
/**
|
||||
* 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( runtimeArtifacts, project.getRuntimeArtifacts() );
|
||||
writeClassPath( runtimeClassPath, project.getRuntimeClasspathElements() );
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
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.AbstractMojo;
|
||||
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 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
|
||||
*/
|
||||
private String testArtifacts;
|
||||
|
||||
/**
|
||||
* The path to the output file for the test class path, relative to the project base directory. Each line of
|
||||
* this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
|
||||
* will not be written to disk.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String testClassPath;
|
||||
|
||||
/**
|
||||
* 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( testArtifacts, project.getTestArtifacts() );
|
||||
writeClassPath( testClassPath, project.getTestClasspathElements() );
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Failed to resolve dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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-resolution</module>
|
||||
<module>maven-it-plugin-file</module>
|
||||
<module>maven-it-plugin-fork</module>
|
||||
<module>maven-it-plugin-generate-envar-properties</module>
|
||||
|
|
Loading…
Reference in New Issue