mirror of https://github.com/apache/maven.git
o Added convenience option to ease validation of class path in test controllers
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@721701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d9f1ef0b6d
commit
4d2c23b8f7
|
@ -51,6 +51,17 @@ public abstract class AbstractDependencyMojo
|
|||
*/
|
||||
protected MavenProject project;
|
||||
|
||||
/**
|
||||
* The number of trailing path levels that should be used to denote a class path element. If positive, each class
|
||||
* path element is trimmed down to the specified number of path levels by discarding leading directories, e.g. set
|
||||
* this parameter to 1 to keep only the simple file name. The trimmed down paths will always use the forward slash
|
||||
* as directory separator. For non-positive values, the full/absolute path is returned, using the platform-specific
|
||||
* separator.
|
||||
*
|
||||
* @parameter expression="${depres.significantPathLevels}"
|
||||
*/
|
||||
private int significantPathLevels;
|
||||
|
||||
/**
|
||||
* Writes the specified artifacts to the given output file.
|
||||
*
|
||||
|
@ -150,8 +161,8 @@ public abstract class AbstractDependencyMojo
|
|||
{
|
||||
for ( Iterator it = classPath.iterator(); it.hasNext(); )
|
||||
{
|
||||
Object element = it.next();
|
||||
writer.write( element.toString() );
|
||||
String element = it.next().toString();
|
||||
writer.write( stripLeadingDirs( element, significantPathLevels ) );
|
||||
writer.newLine();
|
||||
getLog().info( "[MAVEN-CORE-IT-LOG] " + element );
|
||||
}
|
||||
|
@ -177,4 +188,29 @@ public abstract class AbstractDependencyMojo
|
|||
}
|
||||
}
|
||||
|
||||
private String stripLeadingDirs( String path, int significantPathLevels )
|
||||
{
|
||||
String result;
|
||||
if ( significantPathLevels > 0 )
|
||||
{
|
||||
result = "";
|
||||
File file = new File( path );
|
||||
for ( int i = 0; i < significantPathLevels && file != null; i++ )
|
||||
{
|
||||
if ( result.length() > 0 )
|
||||
{
|
||||
// NOTE: Always use forward slash here to ease platform-independent testing
|
||||
result = '/' + result;
|
||||
}
|
||||
result = file.getName() + result;
|
||||
file = file.getParentFile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = path;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue