You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/11/29 19:34:46 UTC

svn commit: r721701 - /maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java

Author: bentmann
Date: Sat Nov 29 10:34:46 2008
New Revision: 721701

URL: http://svn.apache.org/viewvc?rev=721701&view=rev
Log:
o Added convenience option to ease validation of class path in test controllers

Modified:
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java

Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java?rev=721701&r1=721700&r2=721701&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java Sat Nov 29 10:34:46 2008
@@ -52,6 +52,17 @@
     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.
      * 
      * @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or
@@ -150,8 +161,8 @@
             {
                 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 @@
         }
     }
 
+    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;
+    }
+
 }