mirror of https://github.com/apache/maven.git
Working on: MNG-607
o Added '-f' CLI option, to allow use of non-standard pom files, or spawning of a build from outside of the project dir. o Added preferential processing of release-pom.xml over pom.xml if it exists (assumes that the current checkout is a release of the software) o Moved all file discovery from MavenCli to DefaultMaven, to allow embedders to have access to this logic. o Modified MavenExecutionRequest to add a flag for reactor-activation and the name of a non-standard pom to use, if appropriate. o Removed getFiles() and getProjectFiles() from MavenExecutionRequest, since file discovery is now done in the DefaultMaven. o Added integration tests to check preference of release-pom.xml in standalone and '-r' mode o Added integration tests to check usage of '-f' option within and outside of the project directory o Added processing for cli-options.txt to maven-core-it-verifier (Verifier.java) to allow specification of '-f' and '-r' in tests NOTE: the release plugin still doesn't correctly remove the release-pom.xml from HEAD/trunk, since I don't have access to the SCM remove command from maven-scm. I'm waiting for Emmanuel to finish some API changes before moving to the new maven-scm version, and implementing this final step. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3251b41d8e
commit
4b1038de53
|
@ -160,30 +160,34 @@ public class Verifier
|
|||
{
|
||||
List lines = new ArrayList();
|
||||
|
||||
try
|
||||
if ( file.exists() )
|
||||
{
|
||||
BufferedReader reader = new BufferedReader( new FileReader( file ) );
|
||||
|
||||
String line = "";
|
||||
|
||||
while ( ( line = reader.readLine() ) != null )
|
||||
try
|
||||
{
|
||||
line = line.trim();
|
||||
BufferedReader reader = new BufferedReader( new FileReader( file ) );
|
||||
|
||||
if ( line.startsWith( "#" ) || line.length() == 0 )
|
||||
String line = "";
|
||||
|
||||
while ( ( line = reader.readLine() ) != null )
|
||||
{
|
||||
continue;
|
||||
line = line.trim();
|
||||
|
||||
if ( line.startsWith( "#" ) || line.length() == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lines.addAll( replaceArtifacts( line ) );
|
||||
}
|
||||
|
||||
lines.addAll( replaceArtifacts( line ) );
|
||||
reader.close();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new VerificationException( e );
|
||||
}
|
||||
|
||||
reader.close();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new VerificationException( e );
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
@ -461,6 +465,8 @@ public class Verifier
|
|||
String mavenHome = System.getProperty( "maven.home" );
|
||||
|
||||
List goals = loadFile( basedir, filename );
|
||||
|
||||
List cliOptions = loadFile( basedir, "cli-options.txt" );
|
||||
|
||||
if ( goals.size() == 0 )
|
||||
{
|
||||
|
@ -493,6 +499,12 @@ public class Verifier
|
|||
|
||||
cli.setExecutable( executable );
|
||||
|
||||
for ( Iterator it = cliOptions.iterator(); it.hasNext(); )
|
||||
{
|
||||
String key = (String) it.next();
|
||||
cli.createArgument().setValue(key);
|
||||
}
|
||||
|
||||
cli.createArgument().setValue( "-e" );
|
||||
// cli.createArgument().setValue( "-X" );
|
||||
|
||||
|
@ -507,7 +519,7 @@ public class Verifier
|
|||
String key = (String) i.next();
|
||||
cli.createArgument().setLine( "-D" + key + "=" + properties.getProperty( key ) );
|
||||
}
|
||||
|
||||
|
||||
// Note: Make sure that the repo is surrounded by quotes as it can possibly have
|
||||
// spaces in its path.
|
||||
cli.createArgument().setLine( "-Dmaven.repo.local=" + "\"" + localRepo + "\"" );
|
||||
|
@ -607,7 +619,7 @@ public class Verifier
|
|||
verifier.executeHook( "prebuild-hook.txt" );
|
||||
|
||||
Properties properties = verifier.loadProperties( "system.properties" );
|
||||
|
||||
|
||||
Properties controlProperties = verifier.loadProperties( "verifier.properties" );
|
||||
|
||||
boolean chokeOnErrorOutput = Boolean.valueOf( controlProperties.getProperty( "failOnErrorOutput", "true" ) ).booleanValue();
|
||||
|
|
|
@ -105,6 +105,17 @@ it0034: Test version range junit [3.7,) resolves to 3.8.1
|
|||
|
||||
it0035: Test artifact relocation.
|
||||
|
||||
it0036: Test building from release-pom.xml when it's available
|
||||
|
||||
it0037: Test building with alternate pom file using '-f'
|
||||
|
||||
it0038: Test building project from outside the project directory using '-f'
|
||||
option
|
||||
|
||||
it0039: Test reactor for projects that have release-pom.xml in addition to
|
||||
pom.xml. The release-pom.xml file should be chosen above pom.xml for
|
||||
these projects in the build.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
- generated sources
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
it0039
|
||||
it0038
|
||||
it0037
|
||||
it0036
|
||||
it0035
|
||||
it0034
|
||||
it0033
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
target/maven-core-it0036-1.0.jar
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0036</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0036</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
-f pom2.xml
|
|
@ -0,0 +1 @@
|
|||
target/maven-core-it0037-1.0-build2.jar
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0037</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0037</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-build2</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
-f project/pom2.xml
|
|
@ -0,0 +1 @@
|
|||
project/target/maven-core-it0037-1.0-build2.jar
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0037</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0037</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-build2</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
-r
|
|
@ -0,0 +1,2 @@
|
|||
project/target/maven-core-it0039-p1-1.0.jar
|
||||
project2/target/maven-core-it0039-p2-1.0.jar
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0039-p1</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0039-p1</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0039-p2</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0039-p2</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</model>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0000;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
|
@ -53,12 +53,14 @@ import org.codehaus.plexus.context.Context;
|
|||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -73,6 +75,8 @@ public class DefaultMaven
|
|||
extends AbstractLogEnabled
|
||||
implements Maven, Contextualizable
|
||||
{
|
||||
public static File userDir = new File( System.getProperty( "user.dir" ) );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Components
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -129,7 +133,9 @@ public class DefaultMaven
|
|||
|
||||
try
|
||||
{
|
||||
projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive(),
|
||||
List files = getProjectFiles( request );
|
||||
|
||||
projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
|
||||
request.getSettings() );
|
||||
|
||||
projects = ProjectSorter.getSortedProjects( projects );
|
||||
|
@ -229,6 +235,11 @@ public class DefaultMaven
|
|||
{
|
||||
File file = (File) iterator.next();
|
||||
|
||||
if ( RELEASE_POMv4.equals( file.getName() ) )
|
||||
{
|
||||
getLogger().info( "NOTE: Using release-pom: " + file + " in reactor build." );
|
||||
}
|
||||
|
||||
MavenProject project = getProject( file, localRepository, settings );
|
||||
|
||||
if ( project.getPrerequesites() != null && project.getPrerequesites().getMaven() != null )
|
||||
|
@ -635,4 +646,77 @@ public class DefaultMaven
|
|||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private List getProjectFiles( MavenExecutionRequest request )
|
||||
throws IOException
|
||||
{
|
||||
List files = Collections.EMPTY_LIST;
|
||||
|
||||
if ( request.isReactorActive() )
|
||||
{
|
||||
// TODO: should we now include the pom.xml in the current directory?
|
||||
// String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
|
||||
// String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
|
||||
|
||||
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 + ",**/" + RELEASE_POMv4 );
|
||||
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 + "," + RELEASE_POMv4 );
|
||||
|
||||
files = FileUtils.getFiles( userDir, includes, excludes );
|
||||
|
||||
filterOneProjectFilePerDirectory( files );
|
||||
|
||||
// make sure there is consistent ordering on all platforms, rather than using the filesystem ordering
|
||||
Collections.sort( files );
|
||||
}
|
||||
else if ( request.getPomFile() != null )
|
||||
{
|
||||
File projectFile = new File( request.getPomFile() ).getAbsoluteFile();
|
||||
|
||||
if ( projectFile.exists() )
|
||||
{
|
||||
files = Collections.singletonList( projectFile );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
File projectFile = new File( userDir, RELEASE_POMv4 );
|
||||
|
||||
if ( !projectFile.exists() )
|
||||
{
|
||||
projectFile = new File( userDir, POMv4 );
|
||||
}
|
||||
|
||||
if ( projectFile.exists() )
|
||||
{
|
||||
files = Collections.singletonList( projectFile );
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
private void filterOneProjectFilePerDirectory( List files )
|
||||
{
|
||||
List releaseDirs = new ArrayList();
|
||||
|
||||
for ( Iterator it = files.iterator(); it.hasNext(); )
|
||||
{
|
||||
File projectFile = (File) it.next();
|
||||
|
||||
if ( RELEASE_POMv4.equals( projectFile.getName() ) )
|
||||
{
|
||||
releaseDirs.add( projectFile.getParentFile() );
|
||||
}
|
||||
}
|
||||
|
||||
for ( Iterator it = files.iterator(); it.hasNext(); )
|
||||
{
|
||||
File projectFile = (File) it.next();
|
||||
|
||||
// remove pom.xml files where there is a sibling release-pom.xml file...
|
||||
if ( !RELEASE_POMv4.equals( projectFile.getName() ) && releaseDirs.contains( projectFile.getParentFile() ) )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@ public interface Maven
|
|||
{
|
||||
static String ROLE = Maven.class.getName();
|
||||
|
||||
String POMv4 = "pom.xml";
|
||||
|
||||
String RELEASE_POMv4 = "release-pom.xml";
|
||||
|
||||
MavenExecutionResponse execute( MavenExecutionRequest request )
|
||||
throws ReactorException;
|
||||
}
|
|
@ -27,8 +27,8 @@ import org.apache.maven.Maven;
|
|||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
|
@ -48,14 +48,11 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
|||
import org.codehaus.plexus.embed.Embedder;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.logging.LoggerManager;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -64,8 +61,6 @@ import java.util.Properties;
|
|||
*/
|
||||
public class MavenCli
|
||||
{
|
||||
public static final String POMv4 = "pom.xml";
|
||||
|
||||
public static File userDir = new File( System.getProperty( "user.dir" ) );
|
||||
|
||||
public static int main( String[] args, ClassWorld classWorld )
|
||||
|
@ -218,17 +213,6 @@ public class MavenCli
|
|||
settings.setUsePluginRegistry( false );
|
||||
}
|
||||
|
||||
List projectFiles = null;
|
||||
try
|
||||
{
|
||||
projectFiles = getProjectFiles( commandLine );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
showFatalError( "Error locating project files for reactor execution", e, showErrors );
|
||||
return 1;
|
||||
}
|
||||
|
||||
Maven maven = null;
|
||||
MavenExecutionRequest request = null;
|
||||
LoggerManager manager = null;
|
||||
|
@ -241,7 +225,9 @@ public class MavenCli
|
|||
manager.setThreshold( Logger.LEVEL_DEBUG );
|
||||
}
|
||||
|
||||
request = createRequest( projectFiles, embedder, commandLine, settings, eventDispatcher, manager );
|
||||
request = createRequest( embedder, commandLine, settings, eventDispatcher, manager );
|
||||
|
||||
setProjectFileOptions( commandLine, request );
|
||||
|
||||
maven = createMavenInstance( embedder, settings.isInteractiveMode() );
|
||||
}
|
||||
|
@ -311,7 +297,7 @@ public class MavenCli
|
|||
}
|
||||
}
|
||||
|
||||
private static MavenExecutionRequest createRequest( List files, Embedder embedder, CommandLine commandLine,
|
||||
private static MavenExecutionRequest createRequest( Embedder embedder, CommandLine commandLine,
|
||||
Settings settings, EventDispatcher eventDispatcher,
|
||||
LoggerManager manager )
|
||||
throws ComponentLookupException
|
||||
|
@ -321,7 +307,7 @@ public class MavenCli
|
|||
ArtifactRepository localRepository = createLocalRepository( embedder, settings, commandLine );
|
||||
|
||||
request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
|
||||
commandLine.getArgList(), files, userDir.getPath() );
|
||||
commandLine.getArgList(), userDir.getPath() );
|
||||
|
||||
// TODO [BP]: do we set one per mojo? where to do it?
|
||||
Logger logger = manager.getLoggerForComponent( Mojo.ROLE );
|
||||
|
@ -337,32 +323,16 @@ public class MavenCli
|
|||
return request;
|
||||
}
|
||||
|
||||
private static List getProjectFiles( CommandLine commandLine )
|
||||
throws IOException
|
||||
private static void setProjectFileOptions( CommandLine commandLine, MavenExecutionRequest request )
|
||||
{
|
||||
List files = Collections.EMPTY_LIST;
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
{
|
||||
// TODO: should we now include the pom.xml in the current directory?
|
||||
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
|
||||
|
||||
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
|
||||
|
||||
files = FileUtils.getFiles( userDir, includes, excludes );
|
||||
|
||||
// make sure there is consistent ordering on all platforms, rather than using the filesystem ordering
|
||||
Collections.sort( files );
|
||||
request.setReactorActive( true );
|
||||
}
|
||||
else
|
||||
else if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
|
||||
{
|
||||
File projectFile = new File( userDir, POMv4 );
|
||||
|
||||
if ( projectFile.exists() )
|
||||
{
|
||||
files = Collections.singletonList( projectFile );
|
||||
}
|
||||
request.setPomFile( commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE ) );
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
private static Maven createMavenInstance( Embedder embedder, boolean interactive )
|
||||
|
@ -497,6 +467,8 @@ public class MavenCli
|
|||
|
||||
static class CLIManager
|
||||
{
|
||||
public static final char ALTERNATE_POM_FILE = 'f';
|
||||
|
||||
public static final char BATCH_MODE = 'B';
|
||||
|
||||
public static final char SET_SYSTEM_PROPERTY = 'D';
|
||||
|
@ -540,6 +512,9 @@ public class MavenCli
|
|||
public CLIManager()
|
||||
{
|
||||
options = new Options();
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "file").hasArg().withDescription( "Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
|
||||
SET_SYSTEM_PROPERTY ) );
|
||||
|
|
|
@ -37,8 +37,6 @@ public class DefaultMavenExecutionRequest
|
|||
|
||||
private final List goals;
|
||||
|
||||
private final List files;
|
||||
|
||||
protected MavenSession session;
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
@ -49,8 +47,12 @@ public class DefaultMavenExecutionRequest
|
|||
|
||||
private boolean recursive = true;
|
||||
|
||||
private boolean reactorActive;
|
||||
|
||||
private String pomFilename;
|
||||
|
||||
public DefaultMavenExecutionRequest( ArtifactRepository localRepository, Settings settings,
|
||||
EventDispatcher eventDispatcher, List goals, List files, String baseDirectory )
|
||||
EventDispatcher eventDispatcher, List goals, String baseDirectory )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
|
||||
|
@ -60,8 +62,6 @@ public class DefaultMavenExecutionRequest
|
|||
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
|
||||
this.files = files;
|
||||
|
||||
this.baseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
|
@ -104,11 +104,6 @@ public class DefaultMavenExecutionRequest
|
|||
return session;
|
||||
}
|
||||
|
||||
public List getProjectFiles()
|
||||
{
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setSession( MavenSession session )
|
||||
{
|
||||
this.session = session;
|
||||
|
@ -124,8 +119,23 @@ public class DefaultMavenExecutionRequest
|
|||
return eventDispatcher;
|
||||
}
|
||||
|
||||
public List getFiles()
|
||||
public void setReactorActive( boolean reactorActive )
|
||||
{
|
||||
return files;
|
||||
this.reactorActive = reactorActive;
|
||||
}
|
||||
|
||||
public boolean isReactorActive()
|
||||
{
|
||||
return reactorActive;
|
||||
}
|
||||
|
||||
public void setPomFile( String pomFilename )
|
||||
{
|
||||
this.pomFilename = pomFilename;
|
||||
}
|
||||
|
||||
public String getPomFile()
|
||||
{
|
||||
return pomFilename;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@ public interface MavenExecutionRequest
|
|||
|
||||
MavenSession getSession();
|
||||
|
||||
List getFiles();
|
||||
|
||||
void addEventMonitor( EventMonitor monitor );
|
||||
|
||||
EventDispatcher getEventDispatcher();
|
||||
|
@ -50,4 +48,12 @@ public interface MavenExecutionRequest
|
|||
void setRecursive( boolean recursive );
|
||||
|
||||
boolean isRecursive();
|
||||
|
||||
void setReactorActive( boolean reactorActive );
|
||||
|
||||
boolean isReactorActive();
|
||||
|
||||
void setPomFile( String pomFile );
|
||||
|
||||
String getPomFile();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue