Not sure. "top level" and "base" don't sound that much different to me.
And, frankly, don't add much clarify to the term either. Maybe it should
be "multiModuleProjectDirectory", i.e. without "base" or "top level"
adjective?


--
Regards,
Igor


On 2015-02-21 11:27, Robert Scholte wrote:
It's lengthly, but indeed better. And now that we don't care about its
length, how about TopLevelDirectory instead of BaseDirectory, just to
reflect that it is has nothing to with the location of uber
module-parent like in a flattened multimodule structure?

Robert


Op Sat, 21 Feb 2015 16:44:24 +0100 schreef Igor Fedorenko
<i...@ifedorenko.com>:

Correct. What I called "projectBaseDirectory" represents root directory
of a multimodule project. It is not related to parent/child relationship
among project modules. And it is not the same as "reactor base
directory" as it is currently implemented, but I agree reactor build
should behave like you describe.

I think multiModuleProjectBaseDirectory properly reflects the concept I
am trying to introduce and will change the code unless somebody objects.

--
Regards,
Igor

On 2015-02-21 9:49, Jason van Zyl wrote:
Technically the reactor right now are the projects in modules from
where you start the build.

I think what this variable is trying to represent is the base
directory of the multi-module project. I would argue that,
ultimately, the reactor base directory should be the same as the
multi-module project base directory but they are not. I would also
argue that the reactor should always contain all the projects as if
you started the build from the multi-module project but this is also
not the case which I believe is highly confusing the users because
they expect the in-situ build results to be used. At least from my
un-scientific polling from a few hundred users.

But whether there is one project or many what we are trying to
express here is the multi-module project base directory and I think
we need a concept for this so this would be a good place to start.

How about multiModuleProjectBaseDirectory? Lengthly but I think it's
clear. >
On Feb 21, 2015, at 8:57 AM, Robert Scholte <rfscho...@apache.org>
wrote:

Op Sat, 21 Feb 2015 14:12:22 +0100 schreef Igor Fedorenko
<i...@ifedorenko.com>:


On 2015-02-21 7:02, Robert Scholte wrote:
Hi Igor,

I agree that something like MNG-5767 can indeed help with the
experience.

Looking at the implementation I find the name projectBaseDirectory
confusing, I would have thought that this is a per project(module)
baseDirectory.
We already have things like project.basedir and project.executionRoot
Couldn't you (re)use the executionRoot, which seems to be exactly
what
you want.
I just think that projectBaseDirectory is too abstract, I'd prefer a
more concrete name.


MavenSession#executionRoot is normally set to user work directory. For
example, consider typical multimodule project

   project          <= the new "basedir" I need to introduce
   |- pom.xml
   |- moduleA       <= executionRoot == user.home
   |  \- pom.xml
   \- moduleB
      \- pom.xml

When the user executes the build from project/moduleA directory,
session
execution root will be set to project/moduleA directory. The new
"basedir" I need to introduce must always point at the root of the
project source tree, regardless where the build is started.


Are you sure this will work?
IIRC there's a difference between
project> mvn <phase> -pl :moduleA  (here's the executionRoot
project/ , right?)
and
project/moduleA> mvn <phase>

You should not assume that module-parent and children always point
to each other.
MNG-4324[1] is a feature request which is very related to your
issue: Find the real root. And is is tricky :)
Once MNG-4324 is fixed, your issue is a simple enhancement on it.
How about reactorBaseDirectory/reactorRootDirectory?

thanks,
Robert

[1] https://jira.codehaus.org/browse/MNG-4324


I can see how projectBaseDirectory name can be confusing, however, and
happy to change the code if we find a better name. Does
"sourceBaseDirectory" look better? Can you suggest a better name?

How about using the script-name as basename for the config.
mvn.config (or mvn.opts) for mvn.sh/mvn.bat
mvndebug.config (or mvndebug.opts) for mvndebug.sh/mvndebug.bat
In the end you want override the "global" (i.e environment variable
based) properties and with project specific values *for these
scripts*,
right?

$MAVEN_OPTS is supposed to override values provided in
.mvn/java.config
file. Likewise, explicitly specified mvn command line parameters are
supposed to override values specified in .mvn/maven.config file. The
idea is to allow users override project-provided configuration at
build
time. I believe I tested this, but if you see implementation behaves
differently, please show me how to reproduce and I'll fix it.

I do not believe configuration is specific to the script used to run
maven. If project requires 1G of heap to build, this requirement is
the
same regardless if 'mvn' or 'mvnDebug' is used to start the build.

--
Regards,
Igor


thanks,
Robert

Op Fri, 20 Feb 2015 14:15:15 +0100 schreef <ifedore...@apache.org>:

Repository: maven
Updated Branches:
  refs/heads/master ee7dbab69 -> 8ed9a1caa


MNG-5767 .mvn/ for project specific jvm options and maven parameters

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


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

Branch: refs/heads/master
Commit: 8ed9a1caa8890773b45c6c408a4e40acf4f4b0fd
Parents: ee7dbab
Author: Igor Fedorenko <ifedore...@apache.org>
Authored: Mon Jan 26 14:22:05 2015 -0500
Committer: Igor Fedorenko <ifedore...@apache.org>
Committed: Fri Feb 20 08:14:08 2015 -0500

----------------------------------------------------------------------

apache-maven/src/bin/mvn                        | 29 +++++++++-
.../execution/DefaultMavenExecutionRequest.java | 14 +++++
.../maven/execution/MavenExecutionRequest.java  |  9 +++
.../java/org/apache/maven/cli/MavenCli.java     | 57
++++++++++++++++++-
.../java/org/apache/maven/cli/MavenCliTest.java | 59
++++++++++++++++++++
.../projects/config-illegal/.mvn/maven.config   |  1 +
.../src/test/projects/config/.mvn/maven.config  |  2 +
7 files changed, 166 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/apache-maven/src/bin/mvn


----------------------------------------------------------------------

diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 1ed3024..26feda4 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -189,14 +189,39 @@ if $cygwin; then
     CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
+# traverses directory structure from process work directory to
filesystem root
+# first directory with .mvn subdirectory is considered project base
directory
+find_maven_basedir() {
+  local basedir=$(pwd)
+  local wdir=$(pwd)
+  while [ "$wdir" != '/' ] ; do
+    wdir=$(cd $wdir/..; pwd)
+    if [ -d "$wdir"/.mvn ] ; then
+      basedir=$wdir
+      break
+    fi
+  done
+  echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+  if [ -f "$1" ]; then
+    echo "$(tr -s '\n' ' ' < "$1")"
+  fi
+}
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$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.
-MAVEN_CMD_LINE_ARGS="$@"
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
exec "$JAVACMD" \
   $MAVEN_OPTS \
   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
-  "-Dmaven.home=${M2_HOME}"  \
+  "-Dmaven.home=${M2_HOME}"
"-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
   ${CLASSWORLDS_LAUNCHER} "$@"

http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java


----------------------------------------------------------------------

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 d88024d..f4439b1 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


@@ -93,6 +93,8 @@ public class DefaultMavenExecutionRequest
     // Request
     //
----------------------------------------------------------------------------


+    private File projectBasedir;
+
     private File basedir;
    private List<String> goals;
@@ -1149,4 +1151,16 @@ public class DefaultMavenExecutionRequest
         this.toolchains = toolchains;
         return this;
     }
+
+    @Override
+    public void setProjectBaseDirectory( File directory )
+    {
+        this.projectBasedir = directory;
+    }
+
+    @Override
+    public File getProjectBaseDirectory()
+    {
+        return projectBasedir;
+    }
}

http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java


----------------------------------------------------------------------

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 2b2a1d8..55d7ff2 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


@@ -415,4 +415,13 @@ public interface MavenExecutionRequest
      */
     Map<String, List<ToolchainModel>> getToolchains();
+    /**
+     * @since 3.2.6
+     */
+    void setProjectBaseDirectory( File file );
+
+    /**
+     * @since 3.2.6
+     */
+    File getProjectBaseDirectory();
}

http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/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 35ccbd2..238be22 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
@@ -23,8 +23,10 @@ import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -92,6 +94,8 @@ import
org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import org.sonatype.plexus.components.sec.dispatcher.SecUtil;
import
org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity;

+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
import com.google.inject.AbstractModule;
// TODO: push all common bits back to plexus cli and prepare for
transition to Guice. We don't need 50 ways to make CLIs
@@ -106,6 +110,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" );
@@ -257,13 +263,27 @@ public class MavenCli
         }
     }
-    private void initialize( CliRequest cliRequest )
+    void initialize( CliRequest cliRequest )
     {
         if ( cliRequest.workingDirectory == null )
         {
             cliRequest.workingDirectory = System.getProperty(
"user.dir" );
         }
+        if ( cliRequest.projectBaseDirectory == null )
+        {
+            String basedirProperty = System.getProperty(
PROJECT_BASEDIR );
+            File basedir = basedirProperty != null ? new File(
basedirProperty ) : new File( "" );
+            try
+            {
+                cliRequest.projectBaseDirectory =
basedir.getCanonicalFile();
+            }
+            catch ( IOException e )
+            {
+                cliRequest.projectBaseDirectory =
basedir.getAbsoluteFile();
+            }
+        }
+
         //
         // Make sure the Maven home directory is an absolute
path to
save us from confusion with say drive-relative
         // Windows paths.
@@ -276,7 +296,7 @@ public class MavenCli
         }
     }
-    private void cli( CliRequest cliRequest )
+    void cli( CliRequest cliRequest )
         throws Exception
     {
         //
@@ -287,9 +307,38 @@ public class MavenCli
        CLIManager cliManager = new CLIManager();
+        List<String> args = new ArrayList<String>();
+
+        try
+        {
+            File configFile = new File(
cliRequest.projectBaseDirectory, ".mvn/maven.config" );
+
+            if ( configFile.isFile() )
+            {
+                for ( String arg : Files.toString( configFile,
Charsets.UTF_8 ).split( "\\s+" ) )
+                {
+                    args.add( arg );
+                }
+
+                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 )
         {
@@ -1074,6 +1123,7 @@ public class MavenCli
             .setUpdateSnapshots( updateSnapshots ) // default:
false
             .setNoSnapshotUpdates( noSnapshotUpdates ) //
default: false
             .setGlobalChecksumPolicy( globalChecksumPolicy ) //
default: warn
+            .setProjectBaseDirectory(
cliRequest.projectBaseDirectory )
             ;
        if ( alternatePomFile != null )
@@ -1322,6 +1372,7 @@ public class MavenCli
         CommandLine commandLine;
         ClassWorld classWorld;
         String workingDirectory;
+        File projectBaseDirectory;
         boolean debug;
         boolean quiet;
         boolean showErrors = true;

http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/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..628ef20 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,40 @@ 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.initialize( request );
+        cli.cli( request );
+        assertEquals( "multithreaded",
request.commandLine.getOptionValue( "builder" ) );
+        assertEquals( "8", request.commandLine.getOptionValue(
"threads" ) );
+
+        // 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 );
+
+        cli.initialize( request );
+        try
+        {
+            cli.cli( request );
+            fail();
+        }
+        catch ( ParseException expected )
+        {
+
+        }
+    }
}

http://git-wip-us.apache.org/repos/asf/maven/blob/8ed9a1ca/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/8ed9a1ca/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..3d0f13b
--- /dev/null
+++ b/maven-embedder/src/test/projects/config/.mvn/maven.config
@@ -0,0 +1,2 @@
+-T8 --builder
+  multithreaded

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org


Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder, Takari and Apache Maven
http://twitter.com/jvanzyl
http://twitter.com/takari_io
---------------------------------------------------------

To think is easy. To act is hard. But the hardest thing in the world
is to act in accordance with your thinking.

  -- Johann von Goethe













---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org

Reply via email to