From 4b1038de53193748ed9d300e0f718df11aea136b Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 26 Jul 2005 03:55:37 +0000 Subject: [PATCH] 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 --- .../java/org/apache/maven/it/Verifier.java | 48 +++++++---- maven-core-it/README.txt | 11 +++ maven-core-it/integration-tests.txt | 4 + maven-core-it/it0036/expected-results.txt | 1 + maven-core-it/it0036/goals.txt | 1 + maven-core-it/it0036/pom.xml | 16 ++++ maven-core-it/it0036/release-pom.xml | 16 ++++ .../java/org/apache/maven/it0000/Person.java | 16 ++++ .../org/apache/maven/it0000/PersonTest.java | 16 ++++ maven-core-it/it0037/cli-options.txt | 1 + maven-core-it/it0037/expected-results.txt | 1 + maven-core-it/it0037/goals.txt | 1 + maven-core-it/it0037/pom.xml | 16 ++++ maven-core-it/it0037/pom2.xml | 16 ++++ .../java/org/apache/maven/it0000/Person.java | 16 ++++ .../org/apache/maven/it0000/PersonTest.java | 16 ++++ maven-core-it/it0038/cli-options.txt | 1 + maven-core-it/it0038/expected-results.txt | 1 + maven-core-it/it0038/goals.txt | 1 + maven-core-it/it0038/pom.xml | 16 ++++ maven-core-it/it0038/project/pom2.xml | 16 ++++ .../java/org/apache/maven/it0000/Person.java | 16 ++++ .../org/apache/maven/it0000/PersonTest.java | 16 ++++ maven-core-it/it0039/cli-options.txt | 1 + maven-core-it/it0039/expected-results.txt | 2 + maven-core-it/it0039/goals.txt | 1 + maven-core-it/it0039/project/pom.xml | 16 ++++ maven-core-it/it0039/project/release-pom.xml | 16 ++++ .../java/org/apache/maven/it0000/Person.java | 16 ++++ .../org/apache/maven/it0000/PersonTest.java | 16 ++++ maven-core-it/it0039/project2/pom.xml | 16 ++++ maven-core-it/it0039/project2/release-pom.xml | 16 ++++ .../java/org/apache/maven/it0000/Person.java | 16 ++++ .../org/apache/maven/it0000/PersonTest.java | 16 ++++ .../java/org/apache/maven/DefaultMaven.java | 86 ++++++++++++++++++- .../src/main/java/org/apache/maven/Maven.java | 4 + .../java/org/apache/maven/cli/MavenCli.java | 55 ++++-------- .../DefaultMavenExecutionRequest.java | 34 +++++--- .../execution/MavenExecutionRequest.java | 10 ++- 39 files changed, 511 insertions(+), 73 deletions(-) create mode 100644 maven-core-it/it0036/expected-results.txt create mode 100644 maven-core-it/it0036/goals.txt create mode 100644 maven-core-it/it0036/pom.xml create mode 100644 maven-core-it/it0036/release-pom.xml create mode 100644 maven-core-it/it0036/src/main/java/org/apache/maven/it0000/Person.java create mode 100644 maven-core-it/it0036/src/test/java/org/apache/maven/it0000/PersonTest.java create mode 100644 maven-core-it/it0037/cli-options.txt create mode 100644 maven-core-it/it0037/expected-results.txt create mode 100644 maven-core-it/it0037/goals.txt create mode 100644 maven-core-it/it0037/pom.xml create mode 100644 maven-core-it/it0037/pom2.xml create mode 100644 maven-core-it/it0037/src/main/java/org/apache/maven/it0000/Person.java create mode 100644 maven-core-it/it0037/src/test/java/org/apache/maven/it0000/PersonTest.java create mode 100644 maven-core-it/it0038/cli-options.txt create mode 100644 maven-core-it/it0038/expected-results.txt create mode 100644 maven-core-it/it0038/goals.txt create mode 100644 maven-core-it/it0038/pom.xml create mode 100644 maven-core-it/it0038/project/pom2.xml create mode 100644 maven-core-it/it0038/project/src/main/java/org/apache/maven/it0000/Person.java create mode 100644 maven-core-it/it0038/project/src/test/java/org/apache/maven/it0000/PersonTest.java create mode 100644 maven-core-it/it0039/cli-options.txt create mode 100644 maven-core-it/it0039/expected-results.txt create mode 100644 maven-core-it/it0039/goals.txt create mode 100644 maven-core-it/it0039/project/pom.xml create mode 100644 maven-core-it/it0039/project/release-pom.xml create mode 100644 maven-core-it/it0039/project/src/main/java/org/apache/maven/it0000/Person.java create mode 100644 maven-core-it/it0039/project/src/test/java/org/apache/maven/it0000/PersonTest.java create mode 100644 maven-core-it/it0039/project2/pom.xml create mode 100644 maven-core-it/it0039/project2/release-pom.xml create mode 100644 maven-core-it/it0039/project2/src/main/java/org/apache/maven/it0000/Person.java create mode 100644 maven-core-it/it0039/project2/src/test/java/org/apache/maven/it0000/PersonTest.java diff --git a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java index 6b7ca63804..a5ce4a602b 100644 --- a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java +++ b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java @@ -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(); diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt index 95253c6474..a6e10f6500 100644 --- a/maven-core-it/README.txt +++ b/maven-core-it/README.txt @@ -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 diff --git a/maven-core-it/integration-tests.txt b/maven-core-it/integration-tests.txt index 57978a24c2..c2644f21ac 100644 --- a/maven-core-it/integration-tests.txt +++ b/maven-core-it/integration-tests.txt @@ -1,3 +1,7 @@ +it0039 +it0038 +it0037 +it0036 it0035 it0034 it0033 diff --git a/maven-core-it/it0036/expected-results.txt b/maven-core-it/it0036/expected-results.txt new file mode 100644 index 0000000000..ae5631bc44 --- /dev/null +++ b/maven-core-it/it0036/expected-results.txt @@ -0,0 +1 @@ +target/maven-core-it0036-1.0.jar diff --git a/maven-core-it/it0036/goals.txt b/maven-core-it/it0036/goals.txt new file mode 100644 index 0000000000..ba3bd78738 --- /dev/null +++ b/maven-core-it/it0036/goals.txt @@ -0,0 +1 @@ +package diff --git a/maven-core-it/it0036/pom.xml b/maven-core-it/it0036/pom.xml new file mode 100644 index 0000000000..cba03f74a6 --- /dev/null +++ b/maven-core-it/it0036/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0036 + jar + 1.0-SNAPSHOT + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0036/release-pom.xml b/maven-core-it/it0036/release-pom.xml new file mode 100644 index 0000000000..e2e142f395 --- /dev/null +++ b/maven-core-it/it0036/release-pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0036 + jar + 1.0 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0036/src/main/java/org/apache/maven/it0000/Person.java b/maven-core-it/it0036/src/main/java/org/apache/maven/it0000/Person.java new file mode 100644 index 0000000000..a9fb4bc9d2 --- /dev/null +++ b/maven-core-it/it0036/src/main/java/org/apache/maven/it0000/Person.java @@ -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; + } +} diff --git a/maven-core-it/it0036/src/test/java/org/apache/maven/it0000/PersonTest.java b/maven-core-it/it0036/src/test/java/org/apache/maven/it0000/PersonTest.java new file mode 100644 index 0000000000..354f917f46 --- /dev/null +++ b/maven-core-it/it0036/src/test/java/org/apache/maven/it0000/PersonTest.java @@ -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() ); + } +} diff --git a/maven-core-it/it0037/cli-options.txt b/maven-core-it/it0037/cli-options.txt new file mode 100644 index 0000000000..d6c294b135 --- /dev/null +++ b/maven-core-it/it0037/cli-options.txt @@ -0,0 +1 @@ +-f pom2.xml diff --git a/maven-core-it/it0037/expected-results.txt b/maven-core-it/it0037/expected-results.txt new file mode 100644 index 0000000000..8af7ba0c25 --- /dev/null +++ b/maven-core-it/it0037/expected-results.txt @@ -0,0 +1 @@ +target/maven-core-it0037-1.0-build2.jar diff --git a/maven-core-it/it0037/goals.txt b/maven-core-it/it0037/goals.txt new file mode 100644 index 0000000000..ba3bd78738 --- /dev/null +++ b/maven-core-it/it0037/goals.txt @@ -0,0 +1 @@ +package diff --git a/maven-core-it/it0037/pom.xml b/maven-core-it/it0037/pom.xml new file mode 100644 index 0000000000..6db33813fb --- /dev/null +++ b/maven-core-it/it0037/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0037 + jar + 1.0 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0037/pom2.xml b/maven-core-it/it0037/pom2.xml new file mode 100644 index 0000000000..24cfa25c1e --- /dev/null +++ b/maven-core-it/it0037/pom2.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0037 + jar + 1.0-build2 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0037/src/main/java/org/apache/maven/it0000/Person.java b/maven-core-it/it0037/src/main/java/org/apache/maven/it0000/Person.java new file mode 100644 index 0000000000..a9fb4bc9d2 --- /dev/null +++ b/maven-core-it/it0037/src/main/java/org/apache/maven/it0000/Person.java @@ -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; + } +} diff --git a/maven-core-it/it0037/src/test/java/org/apache/maven/it0000/PersonTest.java b/maven-core-it/it0037/src/test/java/org/apache/maven/it0000/PersonTest.java new file mode 100644 index 0000000000..354f917f46 --- /dev/null +++ b/maven-core-it/it0037/src/test/java/org/apache/maven/it0000/PersonTest.java @@ -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() ); + } +} diff --git a/maven-core-it/it0038/cli-options.txt b/maven-core-it/it0038/cli-options.txt new file mode 100644 index 0000000000..36b42ef61f --- /dev/null +++ b/maven-core-it/it0038/cli-options.txt @@ -0,0 +1 @@ +-f project/pom2.xml diff --git a/maven-core-it/it0038/expected-results.txt b/maven-core-it/it0038/expected-results.txt new file mode 100644 index 0000000000..76795e1160 --- /dev/null +++ b/maven-core-it/it0038/expected-results.txt @@ -0,0 +1 @@ +project/target/maven-core-it0037-1.0-build2.jar diff --git a/maven-core-it/it0038/goals.txt b/maven-core-it/it0038/goals.txt new file mode 100644 index 0000000000..ba3bd78738 --- /dev/null +++ b/maven-core-it/it0038/goals.txt @@ -0,0 +1 @@ +package diff --git a/maven-core-it/it0038/pom.xml b/maven-core-it/it0038/pom.xml new file mode 100644 index 0000000000..6db33813fb --- /dev/null +++ b/maven-core-it/it0038/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0037 + jar + 1.0 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0038/project/pom2.xml b/maven-core-it/it0038/project/pom2.xml new file mode 100644 index 0000000000..24cfa25c1e --- /dev/null +++ b/maven-core-it/it0038/project/pom2.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0037 + jar + 1.0-build2 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0038/project/src/main/java/org/apache/maven/it0000/Person.java b/maven-core-it/it0038/project/src/main/java/org/apache/maven/it0000/Person.java new file mode 100644 index 0000000000..a9fb4bc9d2 --- /dev/null +++ b/maven-core-it/it0038/project/src/main/java/org/apache/maven/it0000/Person.java @@ -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; + } +} diff --git a/maven-core-it/it0038/project/src/test/java/org/apache/maven/it0000/PersonTest.java b/maven-core-it/it0038/project/src/test/java/org/apache/maven/it0000/PersonTest.java new file mode 100644 index 0000000000..354f917f46 --- /dev/null +++ b/maven-core-it/it0038/project/src/test/java/org/apache/maven/it0000/PersonTest.java @@ -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() ); + } +} diff --git a/maven-core-it/it0039/cli-options.txt b/maven-core-it/it0039/cli-options.txt new file mode 100644 index 0000000000..6a14e7fded --- /dev/null +++ b/maven-core-it/it0039/cli-options.txt @@ -0,0 +1 @@ +-r diff --git a/maven-core-it/it0039/expected-results.txt b/maven-core-it/it0039/expected-results.txt new file mode 100644 index 0000000000..5dc096f3f8 --- /dev/null +++ b/maven-core-it/it0039/expected-results.txt @@ -0,0 +1,2 @@ +project/target/maven-core-it0039-p1-1.0.jar +project2/target/maven-core-it0039-p2-1.0.jar diff --git a/maven-core-it/it0039/goals.txt b/maven-core-it/it0039/goals.txt new file mode 100644 index 0000000000..ba3bd78738 --- /dev/null +++ b/maven-core-it/it0039/goals.txt @@ -0,0 +1 @@ +package diff --git a/maven-core-it/it0039/project/pom.xml b/maven-core-it/it0039/project/pom.xml new file mode 100644 index 0000000000..dadf187ae2 --- /dev/null +++ b/maven-core-it/it0039/project/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0039-p1 + jar + 1.0-SNAPSHOT + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0039/project/release-pom.xml b/maven-core-it/it0039/project/release-pom.xml new file mode 100644 index 0000000000..8dca614880 --- /dev/null +++ b/maven-core-it/it0039/project/release-pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0039-p1 + jar + 1.0 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0039/project/src/main/java/org/apache/maven/it0000/Person.java b/maven-core-it/it0039/project/src/main/java/org/apache/maven/it0000/Person.java new file mode 100644 index 0000000000..a9fb4bc9d2 --- /dev/null +++ b/maven-core-it/it0039/project/src/main/java/org/apache/maven/it0000/Person.java @@ -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; + } +} diff --git a/maven-core-it/it0039/project/src/test/java/org/apache/maven/it0000/PersonTest.java b/maven-core-it/it0039/project/src/test/java/org/apache/maven/it0000/PersonTest.java new file mode 100644 index 0000000000..354f917f46 --- /dev/null +++ b/maven-core-it/it0039/project/src/test/java/org/apache/maven/it0000/PersonTest.java @@ -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() ); + } +} diff --git a/maven-core-it/it0039/project2/pom.xml b/maven-core-it/it0039/project2/pom.xml new file mode 100644 index 0000000000..dffc9b1023 --- /dev/null +++ b/maven-core-it/it0039/project2/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0039-p2 + jar + 1.0-SNAPSHOT + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0039/project2/release-pom.xml b/maven-core-it/it0039/project2/release-pom.xml new file mode 100644 index 0000000000..3a6e6a42e1 --- /dev/null +++ b/maven-core-it/it0039/project2/release-pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven + maven-core-it0039-p2 + jar + 1.0 + + + junit + junit + 3.8.1 + jar + test + + + diff --git a/maven-core-it/it0039/project2/src/main/java/org/apache/maven/it0000/Person.java b/maven-core-it/it0039/project2/src/main/java/org/apache/maven/it0000/Person.java new file mode 100644 index 0000000000..a9fb4bc9d2 --- /dev/null +++ b/maven-core-it/it0039/project2/src/main/java/org/apache/maven/it0000/Person.java @@ -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; + } +} diff --git a/maven-core-it/it0039/project2/src/test/java/org/apache/maven/it0000/PersonTest.java b/maven-core-it/it0039/project2/src/test/java/org/apache/maven/it0000/PersonTest.java new file mode 100644 index 0000000000..354f917f46 --- /dev/null +++ b/maven-core-it/it0039/project2/src/test/java/org/apache/maven/it0000/PersonTest.java @@ -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() ); + } +} 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 18c28ec84f..ae3be10fd2 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -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(); + } + } + } } diff --git a/maven-core/src/main/java/org/apache/maven/Maven.java b/maven-core/src/main/java/org/apache/maven/Maven.java index 298d7391c1..6099020edb 100644 --- a/maven-core/src/main/java/org/apache/maven/Maven.java +++ b/maven-core/src/main/java/org/apache/maven/Maven.java @@ -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; } \ No newline at end of file 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 f7134f5c0c..48e40d346f 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 @@ -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 ) ); 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 1918b3aecd..2d549cea35 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 @@ -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; } } 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 f63980df07..82646165ab 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 @@ -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(); }