diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 530f229d1c..1453d6d12c 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -96,7 +96,7 @@ public class DefaultMaven try { - projects = collectProjects( request.getFiles(), request.getLocalRepository() ); + projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive() ); projects = projectBuilder.getSortedProjects( projects ); @@ -155,7 +155,7 @@ public class DefaultMaven } } - private List collectProjects( List files, ArtifactRepository localRepository ) + private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive ) throws ProjectBuildingException, ReactorException, IOException { List projects = new ArrayList( files.size() ); @@ -166,7 +166,7 @@ public class DefaultMaven MavenProject project = getProject( file, localRepository ); - if ( project.getModules() != null && !project.getModules().isEmpty() ) + if ( project.getModules() != null && !project.getModules().isEmpty() && recursive ) { project.setPackaging( "pom" ); @@ -178,7 +178,7 @@ public class DefaultMaven } List moduleFiles = FileUtils.getFiles( project.getFile().getParentFile(), includes, null ); - List collectedProjects = collectProjects( moduleFiles, localRepository ); + List collectedProjects = collectProjects( moduleFiles, localRepository, recursive ); projects.addAll( collectedProjects ); project.setCollectedProjects( collectedProjects ); } diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index f008e8eda1..d8f5fc49b0 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -133,11 +133,11 @@ public class MavenCli embedder.start( classWorld ); UserModelBuilder userModelBuilder = (UserModelBuilder) embedder.lookup( UserModelBuilder.ROLE ); - + UserModel userModel = userModelBuilder.buildUserModel(); - - ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder - .lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( + ArtifactRepositoryFactory.ROLE ); ArtifactRepository localRepository = getLocalRepository( userModel, artifactRepositoryFactory ); @@ -162,6 +162,11 @@ public class MavenCli } request = new DefaultMavenExecutionRequest( localRepository, userModel, eventDispatcher, commandLine.getArgList(), files, userDir.getPath() ); + + if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) ) + { + request.setRecursive( false ); + } } LoggerManager manager = (LoggerManager) embedder.lookup( LoggerManager.ROLE ); @@ -271,6 +276,8 @@ public class MavenCli private Options options = null; + public static final char NON_RECURSIVE = 'N'; + public CLIManager() { options = new Options(); @@ -292,6 +299,8 @@ public class MavenCli DEBUG ) ); options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription( "Execute goals for project found in the reactor" ).create( REACTOR ) ); + options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription( + "Do not recurse into sub-projects" ).create( NON_RECURSIVE ) ); } public CommandLine parse( String[] args ) @@ -360,7 +369,7 @@ public class MavenCli // TODO [BP]: this should not be necessary - grep for and remove System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository ); - + Repository repo = new Repository(); repo.setId( "local" ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index b88ae4db9e..a6c9b1f701 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -51,6 +51,8 @@ public class DefaultMavenExecutionRequest private final String baseDirectory; + private boolean recursive = true; + public DefaultMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, List goals, List files, String baseDirectory ) { @@ -77,6 +79,16 @@ public class DefaultMavenExecutionRequest return baseDirectory; } + public boolean isRecursive() + { + return recursive; + } + + public void setRecursive( boolean recursive ) + { + this.recursive = false; + } + public ArtifactRepository getLocalRepository() { return localRepository; diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 31bfe596de..bc038eca1b 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -52,4 +52,8 @@ public interface MavenExecutionRequest UserModel getUserModel(); String getBaseDirectory(); + + void setRecursive( boolean recursive ); + + boolean isRecursive(); }