This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MINVOKER-190
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git

commit 81172af8516cbceca26a6235e3edba83bb097b30
Author: rfscholte <[email protected]>
AuthorDate: Fri Jan 11 22:11:48 2019 +0100

    [MINVOKER-190] build.log file location causes problems
---
 src/it/MINVOKER-190-logDirectory/pom.xml           | 65 ++++++++++++++++++++++
 .../src/it/module/pom.xml                          | 32 +++++++++++
 src/it/MINVOKER-190-logDirectory/verify.groovy     | 21 +++++++
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 34 +++++++++--
 4 files changed, 147 insertions(+), 5 deletions(-)

diff --git a/src/it/MINVOKER-190-logDirectory/pom.xml 
b/src/it/MINVOKER-190-logDirectory/pom.xml
new file mode 100644
index 0000000..46237d9
--- /dev/null
+++ b/src/it/MINVOKER-190-logDirectory/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>project-cloning</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>Test to check for proper project cloning</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>**/pom.xml</pomInclude>
+          </pomIncludes>
+          <logDirectory>${project.build.directory}/it-logs</logDirectory>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml 
b/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml
new file mode 100644
index 0000000..5badb32
--- /dev/null
+++ b/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.test</groupId>
+  <artifactId>unit</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+</project>
diff --git a/src/it/MINVOKER-190-logDirectory/verify.groovy 
b/src/it/MINVOKER-190-logDirectory/verify.groovy
new file mode 100644
index 0000000..514b93d
--- /dev/null
+++ b/src/it/MINVOKER-190-logDirectory/verify.groovy
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert !(new File(basedir,'target/it/module/build.log').exists())
+assert new File(basedir,'target/it-logs/module/build.log').exists()
diff --git 
a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java 
b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index f835d7b..e2291ed 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -335,6 +335,15 @@ public abstract class AbstractInvokerMojo
      */
     @Parameter( property = "invoker.noLog", defaultValue = "false" )
     private boolean noLog;
+    
+    /**
+     * By default a {@code build.log} is created in the root of the project. 
By setting this folder 
+     * files are written to a different folder, respecting the structure of 
the projectsDirectory. 
+     * 
+     * @since 3.2.0
+     */
+    @Parameter
+    private File logDirectory;
 
     /**
      * List of profile identifiers to explicitly trigger in the build.
@@ -2072,23 +2081,38 @@ public abstract class AbstractInvokerMojo
 
         if ( !noLog )
         {
-            File outputLog = new File( basedir, "build.log" );
+            Path projectLogDirectory;
+            if ( logDirectory == null )
+            {
+                projectLogDirectory = basedir.toPath();
+            }
+            else if ( cloneProjectsTo != null )
+            {
+                projectLogDirectory =
+                    logDirectory.toPath().resolve( 
cloneProjectsTo.toPath().relativize( basedir.toPath() ) );
+            }
+            else
+            {
+                projectLogDirectory =
+                    logDirectory.toPath().resolve( 
projectsDirectory.toPath().relativize( basedir.toPath() ) );
+            }            
+            
             try
             {
                 if ( streamLogs )
                 {
-                    logger = new FileLogger( outputLog, getLog() );
+                    logger = new FileLogger( projectLogDirectory.resolve( 
"build.log" ).toFile(), getLog() );
                 }
                 else
                 {
-                    logger = new FileLogger( outputLog );
+                    logger = new FileLogger( projectLogDirectory.resolve( 
"build.log" ).toFile() );
                 }
 
-                getLog().debug( "Build log initialized in: " + outputLog );
+                getLog().debug( "Build log initialized in: " + 
projectLogDirectory );
             }
             catch ( IOException e )
             {
-                throw new MojoExecutionException( "Error initializing build 
logfile in: " + outputLog, e );
+                throw new MojoExecutionException( "Error initializing build 
logfile in: " + projectLogDirectory, e );
             }
         }
 

Reply via email to