Blob Blame History Raw
From e1d2e45e48a5e46b800cbedbb11dabb218b12e01 Mon Sep 17 00:00:00 2001
From: gboue <gboue@13f79535-47bb-0310-9956-ffa450edef68>
Date: Fri, 4 Nov 2016 19:48:26 +0000
Subject: [PATCH] [MCOMPILER-284] maven.test.skip doesn't skip test compilation

---
 src/it/MCOMPILER-284/pom.xml                       | 59 ++++++++++++++++++++++
 .../src/main/java/com/foo/MyClass.java             | 25 +++++++++
 .../src/test/java/com/foo/MyTest.java              | 28 ++++++++++
 src/it/MCOMPILER-284/verify.bsh                    | 37 ++++++++++++++
 .../maven/plugin/compiler/TestCompilerMojo.java    |  1 +
 .../plugin/compiler/CompilerMojoTestCase.java      | 42 +++++++++++++++
 .../unit/compiler-skip-main/plugin-config.xml      | 37 ++++++++++++++
 .../src/main/java/TestSkipMainCompile0.java        | 29 +++++++++++
 .../src/test/java/TestSkipMainCompile0Test.java    | 29 +++++++++++
 .../unit/compiler-skip-test/plugin-config.xml      | 37 ++++++++++++++
 .../src/main/java/TestSkipTestCompile0.java        | 29 +++++++++++
 .../src/test/java/TestSkipTestCompile0Test.java    | 29 +++++++++++
 12 files changed, 382 insertions(+)
 create mode 100644 src/it/MCOMPILER-284/pom.xml
 create mode 100644 src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java
 create mode 100644 src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java
 create mode 100644 src/it/MCOMPILER-284/verify.bsh
 create mode 100644 src/test/resources/unit/compiler-skip-main/plugin-config.xml
 create mode 100644 src/test/resources/unit/compiler-skip-main/src/main/java/TestSkipMainCompile0.java
 create mode 100644 src/test/resources/unit/compiler-skip-main/src/test/java/TestSkipMainCompile0Test.java
 create mode 100644 src/test/resources/unit/compiler-skip-test/plugin-config.xml
 create mode 100644 src/test/resources/unit/compiler-skip-test/src/main/java/TestSkipTestCompile0.java
 create mode 100644 src/test/resources/unit/compiler-skip-test/src/test/java/TestSkipTestCompile0Test.java

diff --git a/src/it/MCOMPILER-284/pom.xml b/src/it/MCOMPILER-284/pom.xml
new file mode 100644
index 0000000..2518d9c
--- /dev/null
+++ b/src/it/MCOMPILER-284/pom.xml
@@ -0,0 +1,59 @@
+<?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.compiler.it</groupId>
+  <artifactId>mcompiler284</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MCOMPILER-284</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <skipMain>true</skipMain>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java b/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java
new file mode 100644
index 0000000..7370ac0
--- /dev/null
+++ b/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java
@@ -0,0 +1,25 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class MyClass
+{
+
+}
diff --git a/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java b/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java
new file mode 100644
index 0000000..f152b90
--- /dev/null
+++ b/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java
@@ -0,0 +1,28 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+public class MyTest
+    extends TestCase
+{
+    private MyClass myClass = new MyClass();
+}
diff --git a/src/it/MCOMPILER-284/verify.bsh b/src/it/MCOMPILER-284/verify.bsh
new file mode 100644
index 0000000..35e28c7
--- /dev/null
+++ b/src/it/MCOMPILER-284/verify.bsh
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.util.*;
+
+File mainClass = new File( basedir, "target/classes/com/foo/MyClass.class" );
+if ( mainClass.isFile() )
+{
+    System.out.println( "Main class is present but was skipped: " + mainClass );
+    return false;
+}
+
+File testClass = new File( basedir, "target/test-classes/com/foo/MyTest.class" );
+if ( testClass.isFile() )
+{
+    System.out.println( "Test class is present but was skipped: " + testClass );
+    return false;
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 4f5d0db..56d0973 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -160,6 +160,7 @@ public class TestCompilerMojo
         if ( skip )
         {
             getLog().info( "Not compiling test sources" );
+            return;
         }
         super.execute();
     }
diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
index 36bf754..e80cbfc 100644
--- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
+++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
@@ -311,6 +311,48 @@ public class CompilerMojoTestCase
             fail( "The compilation error should have been consumed because failOnError = false" );
         }
     }
+    
+    /**
+     * Tests that setting 'skipMain' to true skips compilation of the main Java source files, but that test Java source
+     * files are still compiled.
+     * @throws Exception
+     */
+    public void testCompileSkipMain()
+        throws Exception
+    {
+        CompilerMojo compileMojo = getCompilerMojo( "target/test-classes/unit/compiler-skip-main/plugin-config.xml" );
+        setVariableValueToObject( compileMojo, "skipMain", true );
+        compileMojo.execute();
+        File testClass = new File( compileMojo.getOutputDirectory(), "TestSkipMainCompile0.class" );
+        assertFalse( testClass.exists() );
+
+        TestCompilerMojo testCompileMojo =
+            getTestCompilerMojo( compileMojo, "target/test-classes/unit/compiler-skip-main/plugin-config.xml" );
+        testCompileMojo.execute();
+        testClass = new File( testCompileMojo.getOutputDirectory(), "TestSkipMainCompile0Test.class" );
+        assertTrue( testClass.exists() );
+    }
+    
+    /**
+     * Tests that setting 'skip' to true skips compilation of the test Java source files, but that main Java source
+     * files are still compiled.
+     * @throws Exception
+     */
+    public void testCompileSkipTest()
+        throws Exception
+    {
+        CompilerMojo compileMojo = getCompilerMojo( "target/test-classes/unit/compiler-skip-test/plugin-config.xml" );
+        compileMojo.execute();
+        File testClass = new File( compileMojo.getOutputDirectory(), "TestSkipTestCompile0.class" );
+        assertTrue( testClass.exists() );
+
+        TestCompilerMojo testCompileMojo =
+            getTestCompilerMojo( compileMojo, "target/test-classes/unit/compiler-skip-test/plugin-config.xml" );
+        setVariableValueToObject( testCompileMojo, "skip", true );
+        testCompileMojo.execute();
+        testClass = new File( testCompileMojo.getOutputDirectory(), "TestSkipTestCompile0Test.class" );
+        assertFalse( testClass.exists() );
+    }
 
     private CompilerMojo getCompilerMojo( String pomXml )
         throws Exception
diff --git a/src/test/resources/unit/compiler-skip-main/plugin-config.xml b/src/test/resources/unit/compiler-skip-main/plugin-config.xml
new file mode 100644
index 0000000..648718a
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-main/plugin-config.xml
@@ -0,0 +1,37 @@
+<!--
+  ~ 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>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <compileSourceRoots>
+            <compileSourceRoot>${basedir}/target/test-classes/unit/compiler-skip-main/src/main/java</compileSourceRoot>
+          </compileSourceRoots>
+          <compilerId>javac</compilerId>
+          <debug>true</debug>
+          <outputDirectory>${basedir}/target/test/unit/compiler-skip-main/target/classes</outputDirectory>
+          <buildDirectory>${basedir}/target/test/unit/compiler-skip-main/target</buildDirectory>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/test/resources/unit/compiler-skip-main/src/main/java/TestSkipMainCompile0.java b/src/test/resources/unit/compiler-skip-main/src/main/java/TestSkipMainCompile0.java
new file mode 100644
index 0000000..f1788b4
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-main/src/main/java/TestSkipMainCompile0.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+public class TestSkipMainCompile0
+{
+
+    public TestSkipMainCompile0()
+    {
+
+        System.out.println( "Woo Hoo!" );
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/unit/compiler-skip-main/src/test/java/TestSkipMainCompile0Test.java b/src/test/resources/unit/compiler-skip-main/src/test/java/TestSkipMainCompile0Test.java
new file mode 100644
index 0000000..3058998
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-main/src/test/java/TestSkipMainCompile0Test.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+public class TestSkipMainCompile0Test
+    extends TestCase
+{
+    public void testSkipMainCompile0Test()
+    {
+        
+    }
+}
\ No newline at end of file
diff --git a/src/test/resources/unit/compiler-skip-test/plugin-config.xml b/src/test/resources/unit/compiler-skip-test/plugin-config.xml
new file mode 100644
index 0000000..da593ea
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-test/plugin-config.xml
@@ -0,0 +1,37 @@
+<!--
+  ~ 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>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <compileSourceRoots>
+            <compileSourceRoot>${basedir}/target/test-classes/unit/compiler-skip-test/src/main/java</compileSourceRoot>
+          </compileSourceRoots>
+          <compilerId>javac</compilerId>
+          <debug>true</debug>
+          <outputDirectory>${basedir}/target/test/unit/compiler-skip-test/target/classes</outputDirectory>
+          <buildDirectory>${basedir}/target/test/unit/compiler-skip-test/target</buildDirectory>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/test/resources/unit/compiler-skip-test/src/main/java/TestSkipTestCompile0.java b/src/test/resources/unit/compiler-skip-test/src/main/java/TestSkipTestCompile0.java
new file mode 100644
index 0000000..95bcc5a
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-test/src/main/java/TestSkipTestCompile0.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+public class TestSkipTestCompile0
+{
+
+    public TestSkipTestCompile0()
+    {
+
+        System.out.println( "Woo Hoo!" );
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/unit/compiler-skip-test/src/test/java/TestSkipTestCompile0Test.java b/src/test/resources/unit/compiler-skip-test/src/test/java/TestSkipTestCompile0Test.java
new file mode 100644
index 0000000..aa5e09d
--- /dev/null
+++ b/src/test/resources/unit/compiler-skip-test/src/test/java/TestSkipTestCompile0Test.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+public class TestSkipTestCompile0Test
+    extends TestCase
+{
+    public void testSkipTestCompile0Test()
+    {
+        TestSkipTestCompile0 test = new TestSkipTestCompile0();
+    }
+}
\ No newline at end of file
-- 
2.7.4