Skip to content

Commit 58a5a92

Browse files
committed
Remove dependency on jcip-annotations
2 parents 02f1486 + cc7d45b commit 58a5a92

11 files changed

+37
-80
lines changed

Diff for: .classpath

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
<classpathentry kind="src" path="src/test/java"/>
55
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
66
<classpathentry exported="true" kind="lib" path="lib/hamcrest-core-1.3.jar" sourcepath="lib/hamcrest-core-1.3-sources.jar"/>
7-
<classpathentry exported="true" kind="lib" path="lib/jcip-annotations-1.0.jar" sourcepath="jcip-annotations-1.0-sources.jar"/>
87
<classpathentry kind="output" path="bin"/>
98
</classpath>

Diff for: build.xml

+4-12
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
<property name="hamcrestlib" location="lib/hamcrest-core-1.3.jar" />
3232
<property name="hamcrestlibsources" location="lib/hamcrest-core-1.3-sources.jar" />
3333
<property name="hamcrestsrc" location="${dist}/temp.hamcrest.source" />
34-
<property name="jciplib" location="lib/jcip-annotations-1.0.jar" />
35-
<property name="jciplibsources" location="lib/jcip-annotations-1.0-sources.jar" />
36-
<property name="jciplib" location="lib/jcip-annotations-1.0.jar" />
37-
<property name="jciplibsources" location="lib/jcip-annotations-1.0-sources.jar" />
3834

3935
<property name="maven.deploy.goal" value="org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file" />
4036

@@ -84,10 +80,9 @@
8480
</macrodef>
8581

8682
<target name="build" depends="versiontag">
87-
<junit_compilation srcdir="${src}" destdir="${bin}" classpath="${hamcrestlib};${jciplib}"/>
83+
<junit_compilation srcdir="${src}" destdir="${bin}" classpath="${hamcrestlib}"/>
8884
<unjar src="${hamcrestlib}" dest="${bin}" />
89-
<unjar src="${jciplib}" dest="${bin}" />
90-
<junit_compilation srcdir="${testsrc}" destdir="${testbin}" classpath="${hamcrestlib};${jciplib};${bin}"/>
85+
<junit_compilation srcdir="${testsrc}" destdir="${testbin}" classpath="${hamcrestlib};${bin}"/>
9186
</target>
9287

9388
<target name="jars" depends="build">
@@ -130,9 +125,8 @@
130125
</copy>
131126
</target>
132127

133-
<target name="unjar.deps">
128+
<target name="unjar.hamcrest">
134129
<unjar src="${hamcrestlibsources}" dest="${hamcrestsrc}" />
135-
<unjar src="${jciplibsources}" dest="${jcipsrc}" />
136130
</target>
137131

138132
<target name="release-notes">
@@ -144,7 +138,7 @@
144138
</exec>
145139
</target>
146140

147-
<target name="javadoc" depends="unjar.deps">
141+
<target name="javadoc" depends="unjar.hamcrest">
148142
<javadoc destdir="${javadocdir}"
149143
author="false"
150144
version="false"
@@ -158,7 +152,6 @@
158152

159153
<sourcepath location="${src}" />
160154
<sourcepath location="${hamcrestsrc}" />
161-
<sourcepath location="${jcipsrc}" />
162155
<link href="http://java.sun.com/javase/6/docs/api/" />
163156
</javadoc>
164157
</target>
@@ -205,7 +198,6 @@
205198
<pathelement location="${bin}" />
206199
<pathelement location="${testbin}" />
207200
<pathelement location="${hamcrestlib}" />
208-
<pathelement location="${jciplib}" />
209201
</classpath>
210202
</java>
211203
</sequential>

Diff for: lib/jcip-annotations-1.0-sources.jar

-4.88 KB
Binary file not shown.

Diff for: lib/jcip-annotations-1.0.jar

-2.2 KB
Binary file not shown.

Diff for: pom.xml

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<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/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

@@ -93,11 +93,6 @@
9393
<artifactId>hamcrest-core</artifactId>
9494
<version>1.3</version>
9595
</dependency>
96-
<dependency>
97-
<groupId>net.jcip</groupId>
98-
<artifactId>jcip-annotations</artifactId>
99-
<version>1.0</version>
100-
</dependency>
10196
</dependencies>
10297

10398
<build>
@@ -261,7 +256,6 @@
261256
<includeDependencySources>true</includeDependencySources>
262257
<dependencySourceIncludes>
263258
<dependencySourceInclude>org.hamcrest:hamcrest-core:*</dependencySourceInclude>
264-
<dependencySourceInclude>net.jcip:jcip-annotations:*</dependencySourceInclude>
265259
</dependencySourceIncludes>
266260
</configuration>
267261
</plugin>
@@ -346,4 +340,4 @@
346340
</build>
347341
</profile>
348342
</profiles>
349-
</project>
343+
</project>

Diff for: src/main/java/org/junit/runner/Result.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.junit.runner;
22

3-
import net.jcip.annotations.ThreadSafe;
4-
import org.junit.runner.notification.Failure;
5-
import org.junit.runner.notification.RunListener;
6-
73
import java.io.Serializable;
84
import java.util.List;
95
import java.util.concurrent.CopyOnWriteArrayList;
106
import java.util.concurrent.atomic.AtomicInteger;
117
import java.util.concurrent.atomic.AtomicLong;
128

9+
import org.junit.runner.notification.Concurrent;
10+
import org.junit.runner.notification.Failure;
11+
import org.junit.runner.notification.RunListener;
12+
1313
/**
1414
* A <code>Result</code> collects and summarizes information from running multiple tests.
1515
* All tests are counted -- additional information is collected from tests that fail.
@@ -66,7 +66,7 @@ public boolean wasSuccessful() {
6666
return getFailureCount() == 0;
6767
}
6868

69-
@ThreadSafe
69+
@Concurrent
7070
private class Listener extends RunListener {
7171
@Override
7272
public void testRunStarted(Description description) throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 Google Inc. All Rights Reserved.
2+
3+
package org.junit.runner.notification;
4+
5+
import java.lang.annotation.Documented;
6+
import java.lang.annotation.ElementType;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
import java.lang.annotation.Target;
10+
11+
/**
12+
* Indicates a {@link RunListener} that can have its methods called
13+
* concurrently. This implies that the class is thread-safe (i.e. no set of
14+
* listener calls can put the listener into an invalid state, even if those
15+
* listener calls are being made by multiple threads without synchronization.
16+
*/
17+
@Documented
18+
@Target(ElementType.TYPE)
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface Concurrent {
21+
}

Diff for: src/main/java/org/junit/runner/notification/SynchronizedRunListener.java

+2-43
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.junit.runner.notification;
22

3-
import java.lang.annotation.Annotation;
4-
5-
import net.jcip.annotations.ThreadSafe;
6-
73
import org.junit.runner.Description;
84
import org.junit.runner.Result;
95

@@ -20,17 +16,13 @@
2016
*
2117
* @see RunNotifier
2218
*/
23-
@ThreadSafe
19+
@Concurrent
2420
final class SynchronizedRunListener extends RunListener {
2521
private static final Object sMonitor = new Object();
2622
private final RunListener fListener;
2723

2824
public static RunListener wrapIfNotThreadSafe(RunListener listener) {
29-
Class<? extends Annotation> annotation= getThreadSafeAnnotationClass();
30-
if (annotation == null) {
31-
return listener;
32-
}
33-
boolean isThreadSafe = listener.getClass().isAnnotationPresent(annotation);
25+
boolean isThreadSafe = listener.getClass().isAnnotationPresent(Concurrent.class);
3426
return isThreadSafe ? listener : new SynchronizedRunListener(listener);
3527
}
3628

@@ -109,37 +101,4 @@ public boolean equals(Object other) {
109101
public String toString() {
110102
return fListener.toString();
111103
}
112-
113-
/**
114-
* Loads {@link net.jcip.annotations.ThreadSafe} via reflection. Uses the
115-
* Initialization on Demand Holder pattern (see
116-
* http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#dcl for details).
117-
*/
118-
private static class ThreadSafeAnnotationHolder {
119-
private static Class<? extends Annotation> annotation = loadThreadSafeAnnotation();
120-
121-
122-
private static Class<? extends Annotation> loadThreadSafeAnnotation() {
123-
try {
124-
ClassLoader classLoader= Thread.currentThread().getContextClassLoader();
125-
Class<?> loadedAnnotation= classLoader.loadClass(
126-
"net.jcip.annotations.ThreadSafe");
127-
return loadedAnnotation.asSubclass(Annotation.class);
128-
} catch (ClassNotFoundException e) {
129-
return null;
130-
} catch (ClassCastException e) {
131-
return null;
132-
}
133-
}
134-
}
135-
136-
/**
137-
* Gets the {@link net.jcip.annotations.ThreadSafe} annotation if it is on
138-
* the classpath
139-
*
140-
* @return the annotation or {@code null} if it isn't on the classpath
141-
*/
142-
static Class<? extends Annotation> getThreadSafeAnnotationClass() {
143-
return ThreadSafeAnnotationHolder.annotation;
144-
}
145104
}

Diff for: src/test/java/org/junit/runner/notification/AddRemoveListenerTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.util.concurrent.atomic.AtomicInteger;
77

8-
import net.jcip.annotations.ThreadSafe;
98
import org.junit.Test;
109
import org.junit.runner.Description;
1110

@@ -28,7 +27,7 @@ public void testStarted(Description description) throws Exception {
2827
}
2928
}
3029

31-
@ThreadSafe
30+
@Concurrent
3231
public static class ThreadSafeListener extends RunListener {
3332
final AtomicInteger testStarted = new AtomicInteger(0);
3433

Diff for: src/test/java/org/junit/runner/notification/RunNotifierTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.concurrent.atomic.AtomicInteger;
77

88
import junit.framework.TestCase;
9-
import net.jcip.annotations.ThreadSafe;
109
import org.junit.runner.Description;
1110
import org.junit.runner.Result;
1211

@@ -114,7 +113,7 @@ public void testStarted(Description description) throws Exception {
114113
}
115114
}
116115

117-
@ThreadSafe
116+
@Concurrent
118117
private static class ThreadSafeListener extends CountingListener {
119118
}
120119

Diff for: src/test/java/org/junit/runner/notification/SynchronizedRunListenerTest.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.List;
1515
import java.util.Set;
1616

17-
import net.jcip.annotations.ThreadSafe;
1817
import org.junit.Test;
1918

2019
/**
@@ -100,7 +99,7 @@ public boolean equals(Object obj) {
10099
}
101100
}
102101

103-
@ThreadSafe
102+
@Concurrent
104103
private static class ThreadSafeRunListener extends RunListener {
105104
}
106105

@@ -165,9 +164,4 @@ public void wrapIfNotThreadSafeShouldWrapNonThreadSafeListeners() {
165164
RunListener wrappedListener= SynchronizedRunListener.wrapIfNotThreadSafe(listener);
166165
assertThat(wrappedListener, instanceOf(SynchronizedRunListener.class));
167166
}
168-
169-
@Test
170-
public void dynamicallyLoadsThreadSafeAnnotatoin() {
171-
assertEquals(ThreadSafe.class, SynchronizedRunListener.getThreadSafeAnnotationClass());
172-
}
173167
}

0 commit comments

Comments
 (0)