[MINVOKER-190] build.log file location causes problems
authorrfscholte <rfscholte@apache.org>
Fri, 11 Jan 2019 21:11:48 +0000 (22:11 +0100)
committerrfscholte <rfscholte@apache.org>
Fri, 11 Jan 2019 21:11:48 +0000 (22:11 +0100)
src/it/MINVOKER-190-logDirectory/pom.xml [new file with mode: 0644]
src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml [new file with mode: 0644]
src/it/MINVOKER-190-logDirectory/verify.groovy [new file with mode: 0644]
src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

diff --git a/src/it/MINVOKER-190-logDirectory/pom.xml b/src/it/MINVOKER-190-logDirectory/pom.xml
new file mode 100644 (file)
index 0000000..46237d9
--- /dev/null
@@ -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 (file)
index 0000000..5badb32
--- /dev/null
@@ -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 (file)
index 0000000..514b93d
--- /dev/null
@@ -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()
index f835d7b..e2291ed 100644 (file)
@@ -335,6 +335,15 @@ public abstract class AbstractInvokerMojo
      */\r
     @Parameter( property = "invoker.noLog", defaultValue = "false" )\r
     private boolean noLog;\r
+    \r
+    /**\r
+     * By default a {@code build.log} is created in the root of the project. By setting this folder \r
+     * files are written to a different folder, respecting the structure of the projectsDirectory. \r
+     * \r
+     * @since 3.2.0\r
+     */\r
+    @Parameter\r
+    private File logDirectory;\r
 \r
     /**\r
      * List of profile identifiers to explicitly trigger in the build.\r
@@ -2072,23 +2081,38 @@ public abstract class AbstractInvokerMojo
 \r
         if ( !noLog )\r
         {\r
-            File outputLog = new File( basedir, "build.log" );\r
+            Path projectLogDirectory;\r
+            if ( logDirectory == null )\r
+            {\r
+                projectLogDirectory = basedir.toPath();\r
+            }\r
+            else if ( cloneProjectsTo != null )\r
+            {\r
+                projectLogDirectory =\r
+                    logDirectory.toPath().resolve( cloneProjectsTo.toPath().relativize( basedir.toPath() ) );\r
+            }\r
+            else\r
+            {\r
+                projectLogDirectory =\r
+                    logDirectory.toPath().resolve( projectsDirectory.toPath().relativize( basedir.toPath() ) );\r
+            }            \r
+            \r
             try\r
             {\r
                 if ( streamLogs )\r
                 {\r
-                    logger = new FileLogger( outputLog, getLog() );\r
+                    logger = new FileLogger( projectLogDirectory.resolve( "build.log" ).toFile(), getLog() );\r
                 }\r
                 else\r
                 {\r
-                    logger = new FileLogger( outputLog );\r
+                    logger = new FileLogger( projectLogDirectory.resolve( "build.log" ).toFile() );\r
                 }\r
 \r
-                getLog().debug( "Build log initialized in: " + outputLog );\r
+                getLog().debug( "Build log initialized in: " + projectLogDirectory );\r
             }\r
             catch ( IOException e )\r
             {\r
-                throw new MojoExecutionException( "Error initializing build logfile in: " + outputLog, e );\r
+                throw new MojoExecutionException( "Error initializing build logfile in: " + projectLogDirectory, e );\r
             }\r
         }\r
 \r