maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/project MavenProject.java
Date Sun, 27 Feb 2005 21:51:52 GMT
brett       2005/02/27 13:51:52

  Modified:    maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin
                        CompilerMojo.java
               maven-core/src/main/java/org/apache/maven/project
                        MavenProject.java
  Log:
  compile based on source roots
  
  Revision  Changes    Path
  1.13      +30 -11    maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
  
  Index: CompilerMojo.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CompilerMojo.java	25 Feb 2005 03:14:49 -0000	1.12
  +++ CompilerMojo.java	27 Feb 2005 21:51:52 -0000	1.13
  @@ -6,6 +6,7 @@
   import org.codehaus.plexus.compiler.javac.JavacCompiler;
   
   import java.io.File;
  +import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.Iterator;
   import java.util.List;
  @@ -18,11 +19,11 @@
    * @description Compiles application sources
    *
    * @parameter
  - *  name="sourceDirectory"
  - *  type="String"
  + *  name="compileSourceRootsList"
  + *  type="java.util.List"
    *  required="true"
    *  validator=""
  - *  expression="#project.build.sourceDirectory"
  + *  expression="#project.compileSourceRootsList"
    *  description=""
    *
    * @parameter
  @@ -51,8 +52,6 @@
    *
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
    * @version $Id$
  - * @todo use compile source roots and not the pom.build.sourceDirectory so that any
  - *       sort of preprocessing and/or source generation can be taken into consideration.
    * @todo change debug parameter type to Boolean
    */
   
  @@ -70,7 +69,7 @@
           //
           // ----------------------------------------------------------------------
   
  -        String sourceDirectory = (String) request.getParameter( "sourceDirectory" );
  +        List compileSourceRootsList = (List) request.getParameter( "compileSourceRootsList"
);
   
           String outputDirectory = (String) request.getParameter( "outputDirectory" );
   
  @@ -79,17 +78,18 @@
           // ----------------------------------------------------------------------
           //
           // ----------------------------------------------------------------------
  -        
  -        if ( ! new File( sourceDirectory ).exists() )
  +
  +        compileSourceRootsList = removeEmptyCompileSourceRoots( compileSourceRootsList
);
  +        if ( compileSourceRootsList.isEmpty() )
           {
               return;
           }
  -        
  +
           CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
           
           compilerConfiguration.setOutputLocation(outputDirectory);
           compilerConfiguration.setClasspathEntries(Arrays.asList(classpathElements));
  -        compilerConfiguration.setSourceLocations(Arrays.asList(new String[] {sourceDirectory}));
  +        compilerConfiguration.setSourceLocations( compileSourceRootsList );
           
           /* Compile with debugging info */
           String debugAsString = (String) request.getParameter( "debug" );
  @@ -140,4 +140,23 @@
               response.setExecutionFailure( new CompilationFailureResponse( messages ) );
           }
       }
  +
  +    /** @todo also in ant plugin. This should be resolved at some point so that it does
not need to be calculated continuously - or should the plugins accept empty source roots as
is? */
  +    private static List removeEmptyCompileSourceRoots( List compileSourceRootsList )
  +    {
  +        List newCompileSourceRootsList = new ArrayList();
  +        if ( compileSourceRootsList != null )
  +        {
  +            // copy as I may be modifying it
  +            for ( Iterator i = compileSourceRootsList.iterator(); i.hasNext(); )
  +            {
  +                String srcDir = (String) i.next();
  +                if ( !newCompileSourceRootsList.contains( srcDir ) && new File(
srcDir ).exists() )
  +                {
  +                    newCompileSourceRootsList.add( srcDir );
  +                }
  +            }
  +        }
  +        return newCompileSourceRootsList;
  +    }
   }
  
  
  
  1.19      +16 -10    maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
  
  Index: MavenProject.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- MavenProject.java	23 Feb 2005 02:37:39 -0000	1.18
  +++ MavenProject.java	27 Feb 2005 21:51:52 -0000	1.19
  @@ -129,8 +129,6 @@
       //!!! Refactor, collect the list of compile source roots and create a path1:path2
       // type construct from the list instead of the other way around. jvz.
   
  -    private static String PS = System.getProperty( "path.separator" );
  -
       private String compileSourceRoots = "";
   
       private String testCompileSourceRoots = "";
  @@ -139,25 +137,29 @@
       {
           if ( path != null || path.trim().length() != 0 )
           {
  -            compileSourceRoots += path + PS;
  +            if ( compileSourceRoots.length() > 0 )
  +            {
  +                compileSourceRoots += File.pathSeparator;
  +            }
  +            compileSourceRoots += path;
           }
       }
   
       public String getCompileSourceRoots()
       {
           // Get rid of any trailing path separators.
  -        if ( compileSourceRoots.endsWith( PS ) )
  +        if ( compileSourceRoots.endsWith( File.pathSeparator ) )
           {
               compileSourceRoots = compileSourceRoots.substring( 0, compileSourceRoots.length()
- 1 );
           }
   
           // Always add the build.sourceDirectory
  -        return getBuild().getSourceDirectory() + PS + compileSourceRoots;
  +        return getBuild().getSourceDirectory() + File.pathSeparator + compileSourceRoots;
       }
   
       public List getCompileSourceRootsList()
       {
  -        String[] s = StringUtils.split( getCompileSourceRoots(), PS );
  +        String[] s = StringUtils.split( getCompileSourceRoots(), File.pathSeparator );
   
           List list = new ArrayList();
   
  @@ -173,25 +175,29 @@
       {
           if ( path != null || path.trim().length() != 0 )
           {
  -            testCompileSourceRoots += path + PS;
  +            if ( testCompileSourceRoots.length() > 0 )
  +            {
  +                testCompileSourceRoots += File.pathSeparator;
  +            }
  +            testCompileSourceRoots += path;
           }
       }
   
       public String getTestCompileSourceRoots()
       {
           // Get rid of any trailing path separators.
  -        if ( testCompileSourceRoots.endsWith( PS ) )
  +        if ( testCompileSourceRoots.endsWith( File.pathSeparator ) )
           {
               testCompileSourceRoots = testCompileSourceRoots.substring( 0, testCompileSourceRoots.length()
- 1 );
           }
   
           // Always add the build.unitTestSourceDirectory
  -        return getBuild().getUnitTestSourceDirectory() + PS + testCompileSourceRoots;
  +        return getBuild().getUnitTestSourceDirectory() + File.pathSeparator + testCompileSourceRoots;
       }
   
       public List getTestCompileSourceRootsList()
       {
  -        String[] s = StringUtils.split( getTestCompileSourceRoots(), PS );
  +        String[] s = StringUtils.split( getTestCompileSourceRoots(), File.pathSeparator
);
   
           List list = new ArrayList();
   
  
  
  

Mime
View raw message