You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2015/03/27 01:55:04 UTC

maven-surefire git commit: [SUREFIRE-1150] The surefire and failsafe plugin should not be dependent on JCIP

Repository: maven-surefire
Updated Branches:
  refs/heads/master a345f485c -> 46202284d


[SUREFIRE-1150] The surefire and failsafe plugin should not be dependent on JCIP


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

Branch: refs/heads/master
Commit: 46202284d0c3304d7dbc273c7cbe460f33dc3576
Parents: a345f48
Author: Tibor17 <ti...@lycos.com>
Authored: Fri Mar 27 01:55:07 2015 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Fri Mar 27 01:55:07 2015 +0100

----------------------------------------------------------------------
 .../its/JUnit47ParallelNotThreadSafeIT.java     | 52 ++++++++++++++
 .../test/resources/junit47-parallel-nts/pom.xml | 71 ++++++++++++++++++++
 .../java/surefireparallelnts/ParallelTest.java  | 37 ++++++++++
 .../RunningInSequenceTest.java                  | 37 ++++++++++
 surefire-providers/surefire-junit47/pom.xml     |  1 +
 .../junitcore/pc/ParallelComputerBuilder.java   | 21 +++++-
 6 files changed, 216 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit47ParallelNotThreadSafeIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit47ParallelNotThreadSafeIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit47ParallelNotThreadSafeIT.java
new file mode 100644
index 0000000..d6856b3
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit47ParallelNotThreadSafeIT.java
@@ -0,0 +1,52 @@
+package org.apache.maven.surefire.its;
+
+/*
+ * 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 org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Test;
+
+/**
+ * Testing <code>@net.jcip.annotations.NotThreadSafe</code> with ParallelComputerBuilder.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.19
+ */
+public class JUnit47ParallelNotThreadSafeIT
+    extends SurefireJUnit4IntegrationTestCase
+{
+
+    private SurefireLauncher unpack()
+    {
+        return unpack( "junit47-parallel-nts" );
+    }
+
+    @Test
+    public void test()
+    {
+        unpack()
+            .parallelAll()
+            .useUnlimitedThreads()
+            .executeTest()
+            .verifyErrorFree( 2 )
+            .verifyTextInLog( "xxx-maven-surefire-plugin@NotThreadSafe" )
+            .verifyTextInLog( "expected-thread" );
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-integration-tests/src/test/resources/junit47-parallel-nts/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-nts/pom.xml b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/pom.xml
new file mode 100644
index 0000000..eb3c7fe
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/pom.xml
@@ -0,0 +1,71 @@
+<?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>
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>junit47-parallel-nts</artifactId>
+  <version>1.0</version>
+  <name>junit47-parallel-nts</name>
+  <url>http://maven.apache.org</url>
+  <developers>
+    <developer>
+      <id>tibordigana</id>
+      <name>Tibor Digaňa (tibor17)</name>
+      <email>tibordigana@apache.org</email>
+      <roles>
+        <role>Committer</role>
+      </roles>
+      <timezone>Europe/Bratislava</timezone>
+    </developer>
+  </developers>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+    </dependency>
+    <dependency>
+      <groupId>com.github.stephenc.jcip</groupId>
+      <artifactId>jcip-annotations</artifactId>
+      <version>1.0-1</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/ParallelTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/ParallelTest.java b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/ParallelTest.java
new file mode 100644
index 0000000..b59c51b
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/ParallelTest.java
@@ -0,0 +1,37 @@
+package surefireparallelnts;
+
+/*
+ * 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 org.junit.Test;
+
+/**
+ * @author Tibor Digana (tibor17)
+ * @since 2.19
+ */
+public class ParallelTest
+{
+    @Test
+    public void test()
+        throws InterruptedException
+    {
+        String name = Thread.currentThread().getName();
+        System.out.println( "maven-surefire-plugin@NotThreadSafe".equals( name ) ? "wrong-thread" : "expected-thread" );
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/RunningInSequenceTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/RunningInSequenceTest.java b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/RunningInSequenceTest.java
new file mode 100644
index 0000000..7ec56ed
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/junit47-parallel-nts/src/test/java/surefireparallelnts/RunningInSequenceTest.java
@@ -0,0 +1,37 @@
+package surefireparallelnts;
+
+/*
+ * 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 org.junit.Test;
+
+/**
+ * @author Tibor Digana (tibor17)
+ * @since 2.19
+ */
+@net.jcip.annotations.NotThreadSafe
+public class RunningInSequenceTest
+{
+    @Test
+    public void test()
+        throws InterruptedException
+    {
+        System.out.println( "xxx-" + Thread.currentThread().getName() );
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-providers/surefire-junit47/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/pom.xml b/surefire-providers/surefire-junit47/pom.xml
index b28423a..78b35c8 100644
--- a/surefire-providers/surefire-junit47/pom.xml
+++ b/surefire-providers/surefire-junit47/pom.xml
@@ -36,6 +36,7 @@
       <groupId>com.github.stephenc.jcip</groupId>
       <artifactId>jcip-annotations</artifactId>
       <version>1.0-1</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/46202284/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
index 3238d34..2ef3fd1 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitcore.pc;
  * under the License.
  */
 
+import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -32,8 +33,6 @@ import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import net.jcip.annotations.NotThreadSafe;
-
 import org.apache.maven.surefire.junitcore.JUnitCoreParameters;
 import org.apache.maven.surefire.report.ConsoleLogger;
 import org.apache.maven.surefire.testset.TestSetFailedException;
@@ -79,6 +78,8 @@ import static org.apache.maven.surefire.junitcore.pc.Type.SUITES;
  */
 public final class ParallelComputerBuilder
 {
+    private static final Class<? extends Annotation> JCIP_NOT_THREAD_SAFE = loadNotThreadSafeAnnotations();
+
     private static final Set<?> NULL_SINGLETON = Collections.singleton( null );
 
     static final int TOTAL_POOL_SIZE_UNDEFINED = 0;
@@ -227,6 +228,20 @@ public final class ParallelComputerBuilder
         return parameters == null ? 0d : parameters.getParallelTestsTimeoutForcedInSeconds();
     }
 
+    @SuppressWarnings( "unchecked" )
+    private static Class<? extends Annotation> loadNotThreadSafeAnnotations()
+    {
+        try
+        {
+            Class c = Class.forName( "net.jcip.annotations.NotThreadSafe" );
+            return c.isAnnotation() ? (Class<? extends Annotation>) c : null;
+        }
+        catch ( ClassNotFoundException e )
+        {
+            return null;
+        }
+    }
+
     final class PC
         extends ParallelComputer
     {
@@ -609,7 +624,7 @@ public final class ParallelComputerBuilder
 
         private boolean isThreadSafe( Runner runner )
         {
-            return runner.getDescription().getAnnotation( NotThreadSafe.class ) == null;
+            return runner.getDescription().getAnnotation( JCIP_NOT_THREAD_SAFE ) == null;
         }
 
         private class SuiteFilter