From 4d2c23b8f75e90906d6aa60aa328290cd14507f0 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sat, 29 Nov 2008 18:34:46 +0000 Subject: [PATCH] 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 --- .../plugin/coreit/AbstractDependencyMojo.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java index dff636bb70..08657906ba 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java @@ -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 @@ protected void writeClassPath( String pathname, Collection classPath ) { 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 @@ protected void writeClassPath( String pathname, Collection classPath ) } } + 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; + } + }