mirror of https://github.com/apache/maven.git
compile based on source roots
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163423 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
236dc52410
commit
21f1cffa59
|
@ -129,8 +129,6 @@ public class MavenProject
|
||||||
//!!! Refactor, collect the list of compile source roots and create a path1:path2
|
//!!! 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.
|
// 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 compileSourceRoots = "";
|
||||||
|
|
||||||
private String testCompileSourceRoots = "";
|
private String testCompileSourceRoots = "";
|
||||||
|
@ -139,25 +137,29 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
if ( path != null || path.trim().length() != 0 )
|
if ( path != null || path.trim().length() != 0 )
|
||||||
{
|
{
|
||||||
compileSourceRoots += path + PS;
|
if ( compileSourceRoots.length() > 0 )
|
||||||
|
{
|
||||||
|
compileSourceRoots += File.pathSeparator;
|
||||||
|
}
|
||||||
|
compileSourceRoots += path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCompileSourceRoots()
|
public String getCompileSourceRoots()
|
||||||
{
|
{
|
||||||
// Get rid of any trailing path separators.
|
// Get rid of any trailing path separators.
|
||||||
if ( compileSourceRoots.endsWith( PS ) )
|
if ( compileSourceRoots.endsWith( File.pathSeparator ) )
|
||||||
{
|
{
|
||||||
compileSourceRoots = compileSourceRoots.substring( 0, compileSourceRoots.length() - 1 );
|
compileSourceRoots = compileSourceRoots.substring( 0, compileSourceRoots.length() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always add the build.sourceDirectory
|
// Always add the build.sourceDirectory
|
||||||
return getBuild().getSourceDirectory() + PS + compileSourceRoots;
|
return getBuild().getSourceDirectory() + File.pathSeparator + compileSourceRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getCompileSourceRootsList()
|
public List getCompileSourceRootsList()
|
||||||
{
|
{
|
||||||
String[] s = StringUtils.split( getCompileSourceRoots(), PS );
|
String[] s = StringUtils.split( getCompileSourceRoots(), File.pathSeparator );
|
||||||
|
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
|
|
||||||
|
@ -173,25 +175,29 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
if ( path != null || path.trim().length() != 0 )
|
if ( path != null || path.trim().length() != 0 )
|
||||||
{
|
{
|
||||||
testCompileSourceRoots += path + PS;
|
if ( testCompileSourceRoots.length() > 0 )
|
||||||
|
{
|
||||||
|
testCompileSourceRoots += File.pathSeparator;
|
||||||
|
}
|
||||||
|
testCompileSourceRoots += path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTestCompileSourceRoots()
|
public String getTestCompileSourceRoots()
|
||||||
{
|
{
|
||||||
// Get rid of any trailing path separators.
|
// Get rid of any trailing path separators.
|
||||||
if ( testCompileSourceRoots.endsWith( PS ) )
|
if ( testCompileSourceRoots.endsWith( File.pathSeparator ) )
|
||||||
{
|
{
|
||||||
testCompileSourceRoots = testCompileSourceRoots.substring( 0, testCompileSourceRoots.length() - 1 );
|
testCompileSourceRoots = testCompileSourceRoots.substring( 0, testCompileSourceRoots.length() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always add the build.unitTestSourceDirectory
|
// Always add the build.unitTestSourceDirectory
|
||||||
return getBuild().getUnitTestSourceDirectory() + PS + testCompileSourceRoots;
|
return getBuild().getUnitTestSourceDirectory() + File.pathSeparator + testCompileSourceRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getTestCompileSourceRootsList()
|
public List getTestCompileSourceRootsList()
|
||||||
{
|
{
|
||||||
String[] s = StringUtils.split( getTestCompileSourceRoots(), PS );
|
String[] s = StringUtils.split( getTestCompileSourceRoots(), File.pathSeparator );
|
||||||
|
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.codehaus.plexus.compiler.CompilerError;
|
||||||
import org.codehaus.plexus.compiler.javac.JavacCompiler;
|
import org.codehaus.plexus.compiler.javac.JavacCompiler;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -18,11 +19,11 @@ import java.util.List;
|
||||||
* @description Compiles application sources
|
* @description Compiles application sources
|
||||||
*
|
*
|
||||||
* @parameter
|
* @parameter
|
||||||
* name="sourceDirectory"
|
* name="compileSourceRootsList"
|
||||||
* type="String"
|
* type="java.util.List"
|
||||||
* required="true"
|
* required="true"
|
||||||
* validator=""
|
* validator=""
|
||||||
* expression="#project.build.sourceDirectory"
|
* expression="#project.compileSourceRootsList"
|
||||||
* description=""
|
* description=""
|
||||||
*
|
*
|
||||||
* @parameter
|
* @parameter
|
||||||
|
@ -51,8 +52,6 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
* @version $Id$
|
* @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
|
* @todo change debug parameter type to Boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ public class CompilerMojo
|
||||||
//
|
//
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
String sourceDirectory = (String) request.getParameter( "sourceDirectory" );
|
List compileSourceRootsList = (List) request.getParameter( "compileSourceRootsList" );
|
||||||
|
|
||||||
String outputDirectory = (String) request.getParameter( "outputDirectory" );
|
String outputDirectory = (String) request.getParameter( "outputDirectory" );
|
||||||
|
|
||||||
|
@ -80,7 +79,8 @@ public class CompilerMojo
|
||||||
//
|
//
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
if ( ! new File( sourceDirectory ).exists() )
|
compileSourceRootsList = removeEmptyCompileSourceRoots( compileSourceRootsList );
|
||||||
|
if ( compileSourceRootsList.isEmpty() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class CompilerMojo
|
||||||
|
|
||||||
compilerConfiguration.setOutputLocation(outputDirectory);
|
compilerConfiguration.setOutputLocation(outputDirectory);
|
||||||
compilerConfiguration.setClasspathEntries(Arrays.asList(classpathElements));
|
compilerConfiguration.setClasspathEntries(Arrays.asList(classpathElements));
|
||||||
compilerConfiguration.setSourceLocations(Arrays.asList(new String[] {sourceDirectory}));
|
compilerConfiguration.setSourceLocations( compileSourceRootsList );
|
||||||
|
|
||||||
/* Compile with debugging info */
|
/* Compile with debugging info */
|
||||||
String debugAsString = (String) request.getParameter( "debug" );
|
String debugAsString = (String) request.getParameter( "debug" );
|
||||||
|
@ -140,4 +140,23 @@ public class CompilerMojo
|
||||||
response.setExecutionFailure( new CompilationFailureResponse( messages ) );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue