refactor source roots to be lists

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163470 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-07 20:56:23 +00:00
parent 72a993eea1
commit 47da41f68e
9 changed files with 47 additions and 79 deletions

View File

@ -20,6 +20,11 @@ import java.io.File;
public interface Artifact
{
// TODO: into scope handler
String SCOPE_COMPILE = "compile";
String SCOPE_TEST = "test";
String SCOPE_RUNTIME = "runtime";
String getGroupId();
String getArtifactId();

View File

@ -57,7 +57,7 @@ public class DefaultArtifact
/** @todo this should be replaced by type handler */
public DefaultArtifact( String groupId, String artifactId, String version, String type, String extension )
{
this( groupId, artifactId, version, null, type, extension );
this( groupId, artifactId, version, SCOPE_RUNTIME, type, extension );
}
public DefaultArtifact( String groupId, String artifactId, String version, String type )

View File

@ -164,6 +164,9 @@ public class DefaultMavenProjectBuilder
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
project.addCompileSourceRoot( project.getBuild().getSourceDirectory() );
project.addTestCompileSourceRoot( project.getBuild().getUnitTestSourceDirectory() );
return project;
}
catch ( Exception e )

View File

@ -30,7 +30,6 @@ import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Scm;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
@ -125,88 +124,48 @@ public class MavenProject
// Test and compile sourceroots.
// ----------------------------------------------------------------------
//!!! 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 List compileSourceRoots = new ArrayList();
private String compileSourceRoots = "";
private String testCompileSourceRoots = "";
private List testCompileSourceRoots = new ArrayList();
public void addCompileSourceRoot( String path )
{
if ( path != null || path.trim().length() != 0 )
if ( path != null )
{
if ( compileSourceRoots.length() > 0 )
path = path.trim();
if ( path.length() != 0 )
{
compileSourceRoots += File.pathSeparator;
if ( !compileSourceRoots.contains( path ) )
{
compileSourceRoots.add( path );
}
}
compileSourceRoots += path;
}
}
public String getCompileSourceRoots()
{
// Get rid of any trailing path separators.
if ( compileSourceRoots.endsWith( File.pathSeparator ) )
{
compileSourceRoots = compileSourceRoots.substring( 0, compileSourceRoots.length() - 1 );
}
// Always add the build.sourceDirectory
return getBuild().getSourceDirectory() + File.pathSeparator + compileSourceRoots;
}
public List getCompileSourceRootsList()
{
String[] s = StringUtils.split( getCompileSourceRoots(), File.pathSeparator );
List list = new ArrayList();
for ( int i = 0; i < s.length; i++ )
{
list.add( s[i] );
}
return list;
}
public void addTestCompileSourceRoot( String path )
{
if ( path != null || path.trim().length() != 0 )
if ( path != null )
{
if ( testCompileSourceRoots.length() > 0 )
path = path.trim();
if ( path.length() != 0 )
{
testCompileSourceRoots += File.pathSeparator;
if ( !testCompileSourceRoots.contains( path ) )
{
testCompileSourceRoots.add( path );
}
}
testCompileSourceRoots += path;
}
}
public String getTestCompileSourceRoots()
public List getCompileSourceRoots()
{
// Get rid of any trailing path separators.
if ( testCompileSourceRoots.endsWith( File.pathSeparator ) )
{
testCompileSourceRoots = testCompileSourceRoots.substring( 0, testCompileSourceRoots.length() - 1 );
}
// Always add the build.unitTestSourceDirectory
return getBuild().getUnitTestSourceDirectory() + File.pathSeparator + testCompileSourceRoots;
return compileSourceRoots;
}
public List getTestCompileSourceRootsList()
public List getTestCompileSourceRoots()
{
String[] s = StringUtils.split( getTestCompileSourceRoots(), File.pathSeparator );
List list = new ArrayList();
for ( int i = 0; i < s.length; i++ )
{
list.add( s[i] );
}
return list;
return testCompileSourceRoots;
}
public List getCompileClasspathElements()
@ -218,7 +177,7 @@ public class MavenProject
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
if ( a.getScope() == null || "compile".equals( a.getScope() ) )
if ( a.getScope() == null || Artifact.SCOPE_COMPILE.equals( a.getScope() ) )
{
list.add( a.getPath() );
}
@ -239,8 +198,8 @@ public class MavenProject
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
if ( a.getScope() == null || "test".equals( a.getScope() ) || "compile".equals( a.getScope() )
|| "runtime".equals( a.getScope() ) )
if ( a.getScope() == null || Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() )
|| Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
list.add( a.getPath() );
}

View File

@ -807,6 +807,7 @@
<version>4.0.0</version>
<description>The scope of the dependency - build, compile, test, runtime</description>
<type>String</type>
<defaultValue>runtime</defaultValue>
</field>
</fields>
<codeSegments>

View File

@ -18,11 +18,11 @@ import java.util.List;
* @description Compiles application sources
*
* @parameter
* name="compileSourceRootsList"
* name="compileSourceRoots"
* type="java.util.List"
* required="true"
* validator=""
* expression="#project.compileSourceRootsList"
* expression="#project.compileSourceRoots"
* description=""
*
* @parameter
@ -68,7 +68,7 @@ public class CompilerMojo
//
// ----------------------------------------------------------------------
List compileSourceRootsList = (List) request.getParameter( "compileSourceRootsList" );
List compileSourceRoots = (List) request.getParameter( "compileSourceRoots" );
String outputDirectory = (String) request.getParameter( "outputDirectory" );
@ -78,8 +78,8 @@ public class CompilerMojo
//
// ----------------------------------------------------------------------
compileSourceRootsList = removeEmptyCompileSourceRoots( compileSourceRootsList );
if ( compileSourceRootsList.isEmpty() )
compileSourceRoots = removeEmptyCompileSourceRoots( compileSourceRoots );
if ( compileSourceRoots.isEmpty() )
{
return;
}
@ -88,7 +88,7 @@ public class CompilerMojo
compilerConfiguration.setOutputLocation(outputDirectory);
compilerConfiguration.setClasspathEntries( classpathElements );
compilerConfiguration.setSourceLocations( compileSourceRootsList );
compilerConfiguration.setSourceLocations( compileSourceRoots );
/* Compile with debugging info */
String debugAsString = (String) request.getParameter( "debug" );

View File

@ -10,11 +10,11 @@ package org.apache.maven.plugin;
* @requiresDependencyResolution
*
* @parameter
* name="compileSourceRootsList"
* name="compileSourceRoots"
* type="java.util.List"
* required="true"
* validator=""
* expression="#project.testCompileSourceRootsList"
* expression="#project.testCompileSourceRoots"
* description=""
*
* @parameter

View File

@ -0,0 +1 @@
maven-reporting-api.iml

View File

@ -30,10 +30,9 @@
<version>3.8.1</version>
</dependency>
</dependencies>
<preGoals>
<preGoal>
<name>compiler:compile</name>
<attain>plexus:descriptor</attain>
</preGoal>
</preGoals>
<plugins>
<plugin>
<id>plexus</id>
</plugin>
</plugins>
</project>