[MDEP-301] Allow build-classpath to output to property
Submitted by Ryan Heinen.
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1442131 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java b/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java
index fbccf9f..5a4f6b8 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java
@@ -85,6 +85,12 @@
private File cpFile;
/**
+ * A property to set to the contents of the classpath string.
+ */
+ @Parameter( property = "mdep.outputProperty")
+ private String outputProperty;
+
+ /**
* The file to write the classpath string. If undefined, it just prints the classpath as [INFO].
*/
@Parameter( property = "mdep.outputFile" )
@@ -228,7 +234,15 @@
cpString = "classpath=" + cpString;
}
- if ( outputFile == null )
+ if ( outputProperty != null )
+ {
+ project.getProperties().setProperty( outputProperty, cpString );
+ if (getLog().isDebugEnabled())
+ {
+ getLog().debug( outputProperty + " = " + cpString );
+ }
+ }
+ else if ( outputFile == null )
{
getLog().info( "Dependencies classpath:\n" + cpString );
}
@@ -430,6 +444,22 @@
}
/**
+ * @return the outputProperty
+ */
+ public String getOutputProperty()
+ {
+ return this.outputProperty;
+ }
+
+ /**
+ * @param theOutputProperty the outputProperty to set
+ */
+ public void setOutputProperty( String theOutputProperty )
+ {
+ this.outputProperty = theOutputProperty;
+ }
+
+ /**
* @return the fileSeparator
*/
public String getFileSeparator()
diff --git a/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java b/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java
index 56cdf93..8a93ca3 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java
@@ -100,6 +100,14 @@
assertFalse( file.indexOf( File.separator ) >= 0 );
assertTrue( file.indexOf( fileSep ) >= 0 );
assertTrue( file.indexOf( pathSep ) >= 0 );
+
+ String propertyValue = project.getProperties().getProperty( "outputProperty" );
+ assertNull( propertyValue );
+ mojo.setOutputProperty( "outputProperty" );
+ mojo.execute();
+ propertyValue = project.getProperties().getProperty( "outputProperty" );
+ assertNotNull( propertyValue );
+
}
public void testPath() throws Exception
diff --git a/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
index 4b32e802..754d066 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
@@ -157,6 +157,8 @@
private String defaultGoal;
private Set artifacts;
+
+ private Properties properties;
public DependencyProjectStub()
{
@@ -1010,7 +1012,10 @@
public Properties getProperties()
{
- return new Properties();
+ if (properties == null) {
+ properties = new Properties();
+ }
+ return properties;
}
public List getFilters()