maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ifedore...@apache.org
Subject [1/2] maven git commit: moved maven.config processing to java, disallow goals
Date Tue, 27 Jan 2015 20:22:10 GMT
Repository: maven
Updated Branches:
  refs/heads/project-basedir 66ad0a4a5 -> fd6f47911


moved maven.config processing to java, disallow goals

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/0a76e91b
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/0a76e91b
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/0a76e91b

Branch: refs/heads/project-basedir
Commit: 0a76e91bd4c0498004c94211a62db266d838830f
Parents: 66ad0a4
Author: Igor Fedorenko <ifedorenko@apache.org>
Authored: Tue Jan 27 15:06:07 2015 -0500
Committer: Igor Fedorenko <ifedorenko@apache.org>
Committed: Tue Jan 27 15:06:07 2015 -0500

----------------------------------------------------------------------
 apache-maven/src/bin/mvn                        |  9 ++--
 apache-maven/src/bin/mvnDebug                   |  9 ++--
 apache-maven/src/bin/mvnyjp                     |  9 ++--
 .../java/org/apache/maven/cli/MavenCli.java     | 51 +++++++++++++++++-
 .../java/org/apache/maven/cli/MavenCliTest.java | 56 ++++++++++++++++++++
 .../projects/config-illegal/.mvn/maven.config   |  1 +
 .../src/test/projects/config/.mvn/maven.config  |  2 +
 7 files changed, 120 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/apache-maven/src/bin/mvn
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 70fa2f9..cec2baa 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -190,9 +190,8 @@ if $cygwin; then
 fi
 
 . "$M2_HOME/bin/mvn-common.sh"
-export MAVEN_BASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
-MAVEN_CONFIG=$(concat "$MAVEN_BASEDIR/.mvn/maven.config")
-MAVEN_OPTS="$(concat "$MAVEN_BASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS=$(concat "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS
 
 # Provide a "standardized" way to retrieve the CLI args that will 
 # work with both Windows and non-Windows executions.
@@ -203,5 +202,5 @@ exec "$JAVACMD" \
   $MAVEN_OPTS \
   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
-  "-Dmaven.home=${M2_HOME}"  \
-  ${CLASSWORLDS_LAUNCHER} $MAVEN_CONFIG "$@"
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
+  ${CLASSWORLDS_LAUNCHER} "$@"

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/apache-maven/src/bin/mvnDebug
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvnDebug b/apache-maven/src/bin/mvnDebug
index 14dc4b5..d3fa982 100755
--- a/apache-maven/src/bin/mvnDebug
+++ b/apache-maven/src/bin/mvnDebug
@@ -194,9 +194,8 @@ if $cygwin; then
 fi
 
 . "$M2_HOME/bin/mvn-common.sh"
-export MAVEN_BASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
-MAVEN_CONFIG=$(concat "$MAVEN_BASEDIR/.mvn/maven.config")
-MAVEN_OPTS="$(concat "$MAVEN_BASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS=$(concat "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS
 
 # Provide a "standardized" way to retrieve the CLI args that will 
 # work with both Windows and non-Windows executions.
@@ -208,5 +207,5 @@ exec "$JAVACMD" \
   $MAVEN_DEBUG_OPTS \
   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
-  "-Dmaven.home=${M2_HOME}"  \
-  ${CLASSWORLDS_LAUNCHER} $MAVEN_CONFIG "$@"
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
+  ${CLASSWORLDS_LAUNCHER} "$@"

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/apache-maven/src/bin/mvnyjp
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvnyjp b/apache-maven/src/bin/mvnyjp
index d64979a..b78eeab 100755
--- a/apache-maven/src/bin/mvnyjp
+++ b/apache-maven/src/bin/mvnyjp
@@ -197,9 +197,8 @@ fi
 MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS"
 
 . "$M2_HOME/bin/mvn-common.sh"
-export MAVEN_BASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
-MAVEN_CONFIG=$(concat "$MAVEN_BASEDIR/.mvn/maven.config")
-MAVEN_OPTS="$(concat "$MAVEN_BASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS=$(concat "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS
 
 # Provide a "standardized" way to retrieve the CLI args that will 
 # work with both Windows and non-Windows executions.
@@ -210,5 +209,5 @@ exec "$JAVACMD" \
   $MAVEN_OPTS \
   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
-  "-Dmaven.home=${M2_HOME}"  \
-  ${CLASSWORLDS_LAUNCHER} $MAVEN_CONFIG "$@"
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
+  ${CLASSWORLDS_LAUNCHER} "$@"

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 5b7bd7f..a07e08b 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -19,12 +19,16 @@ package org.apache.maven.cli;
  * under the License.
  */
 
+import java.io.BufferedReader;
 import java.io.Console;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -105,6 +109,8 @@ public class MavenCli
 
     public static final String THREADS_DEPRECATED = "maven.threads.experimental";
 
+    public static final String PROJECT_BASEDIR = "maven.projectBasedir";
+
     @SuppressWarnings( "checkstyle:constantname" )
     public static final String userHome = System.getProperty( "user.home" );
 
@@ -275,7 +281,7 @@ public class MavenCli
         }
     }
 
-    private void cli( CliRequest cliRequest )
+    void cli( CliRequest cliRequest )
         throws Exception
     {
         //
@@ -286,9 +292,50 @@ public class MavenCli
 
         CLIManager cliManager = new CLIManager();
 
+        List<String> args = new ArrayList<String>();
+
+        try
+        {
+            String basedir = System.getProperty( PROJECT_BASEDIR );
+            File configFile =
+                basedir != null ? new File( basedir, ".mvn/maven.config" ) : new File( ".mvn/maven.config"
);
+
+            if ( configFile.isFile() )
+            {
+                BufferedReader r =
+                    new BufferedReader( new InputStreamReader( new FileInputStream( configFile
), "UTF-8" ) );
+                try
+                {
+                    String str;
+                    while ( ( str = r.readLine() ) != null )
+                    {
+                        args.add( str );
+                    }
+                }
+                finally
+                {
+                    r.close();
+                }
+
+                CommandLine config = cliManager.parse( args.toArray( new String[args.size()]
) );
+                List<?> unrecongized = config.getArgList();
+                if ( !unrecongized.isEmpty() )
+                {
+                    throw new ParseException( "Unrecognized maven.config entries: " + unrecongized
);
+                }
+            }
+        }
+        catch ( ParseException e )
+        {
+            System.err.println( "Unable to parse maven.config: " + e.getMessage() );
+            cliManager.displayHelp( System.out );
+            throw e;
+        }
+
         try
         {
-            cliRequest.commandLine = cliManager.parse( cliRequest.args );
+            args.addAll( 0, Arrays.asList( cliRequest.args ) );
+            cliRequest.commandLine = cliManager.parse( args.toArray( new String[args.size()]
) );
         }
         catch ( ParseException e )
         {

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
index 6e06cc5..a0310c6 100644
--- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
+++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
@@ -19,16 +19,39 @@ package org.apache.maven.cli;
  * under the License.
  */
 
+import java.io.File;
+
 import junit.framework.TestCase;
 
+import org.apache.commons.cli.ParseException;
+import org.apache.maven.cli.MavenCli.CliRequest;
+
 public class MavenCliTest
     extends TestCase
 {
     private MavenCli cli;
 
+    private String origBasedir;
+
     protected void setUp()
     {
         cli = new MavenCli();
+        origBasedir = System.getProperty( MavenCli.PROJECT_BASEDIR );
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        if ( origBasedir != null )
+        {
+            System.setProperty( MavenCli.PROJECT_BASEDIR, origBasedir );
+        }
+        else
+        {
+            System.getProperties().remove( MavenCli.PROJECT_BASEDIR );
+        }
+        super.tearDown();
     }
 
     public void testCalculateDegreeOfConcurrencyWithCoreMultiplier()
@@ -49,4 +72,37 @@ public class MavenCliTest
             // carry on
         }
     }
+
+    public void testMavenConfig()
+        throws Exception
+    {
+        System.setProperty( MavenCli.PROJECT_BASEDIR, new File( "src/test/projects/config"
).getCanonicalPath() );
+        CliRequest request = new CliRequest( new String[0], null );
+
+        // read .mvn/maven.config
+        cli.cli( request );
+        assertEquals( "multithreaded", request.commandLine.getOptionValue( "builder" ) );
+
+        // override from command line
+        request = new CliRequest( new String[] { "--builder", "foobar" }, null );
+        cli.cli( request );
+        assertEquals( "foobar", request.commandLine.getOptionValue( "builder" ) );
+    }
+
+    public void testMavenConfigInvalid()
+        throws Exception
+    {
+        System.setProperty( MavenCli.PROJECT_BASEDIR, new File( "src/test/projects/config-illegal"
).getCanonicalPath() );
+        CliRequest request = new CliRequest( new String[0], null );
+
+        try
+        {
+            cli.cli( request );
+            fail();
+        }
+        catch ( ParseException expected )
+        {
+
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
new file mode 100644
index 0000000..8541464
--- /dev/null
+++ b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
@@ -0,0 +1 @@
+deploy

http://git-wip-us.apache.org/repos/asf/maven/blob/0a76e91b/maven-embedder/src/test/projects/config/.mvn/maven.config
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/projects/config/.mvn/maven.config b/maven-embedder/src/test/projects/config/.mvn/maven.config
new file mode 100644
index 0000000..bf41c83
--- /dev/null
+++ b/maven-embedder/src/test/projects/config/.mvn/maven.config
@@ -0,0 +1,2 @@
+--builder
+multithreaded


Mime
View raw message