Skip to content

Commit c18a566

Browse files
Fixes #57 using un-modifyable lists & judicious synchronization (#63)
Co-authored-by: Chris Albright <[email protected]>
1 parent 8f6a8f6 commit c18a566

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>org.scalatest</groupId>
1212
<artifactId>scalatest-maven-plugin</artifactId>
1313
<packaging>maven-plugin</packaging>
14-
<version>2.0.0</version>
14+
<version>2.0.1-SNAPSHOT</version>
1515
<name>ScalaTest Maven Plugin</name>
1616
<description>Integrates ScalaTest into Maven</description>
1717

src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
import org.apache.maven.project.MavenProject;
77
import org.codehaus.plexus.util.cli.*;
88

9-
import java.io.File;
9+
import static java.util.Collections.unmodifiableList;
10+
import static org.scalatest.tools.maven.MojoUtils.*;
11+
12+
import java.io.*;
13+
import java.util.Arrays;
14+
import java.util.Collections;
15+
import java.util.List;
16+
import java.util.ArrayList;
17+
import java.util.Map;
18+
19+
import static java.util.Collections.singletonList;
20+
21+
import java.net.MalformedURLException;
22+
import java.net.URLClassLoader;
23+
import java.net.URL;
1024
import java.lang.reflect.InvocationTargetException;
1125
import java.lang.reflect.Method;
1226
import java.net.MalformedURLException;
@@ -388,7 +402,8 @@ private List<String> testClasspathElements() {
388402

389403
// This is the configuration parameters shared by all concrete Mojo subclasses
390404
List<String> sharedConfiguration() {
391-
return new ArrayList<String>() {{
405+
return unmodifiableList(
406+
new ArrayList<String>() {{
392407
addAll(runpath());
393408
addAll(config());
394409
addAll(tagsToInclude());
@@ -404,15 +419,15 @@ List<String> sharedConfiguration() {
404419
addAll(testsFiles());
405420
addAll(junitClasses());
406421
addAll(spanScaleFactor());
407-
}};
422+
}});
408423
}
409424

410425
private List<String> config() {
411426
List<String> c = new ArrayList<String>();
412427
for(String pair : splitOnComma(config)){
413428
c.add("-D"+pair);
414429
}
415-
return c;
430+
return unmodifiableList(c);
416431
}
417432

418433
private List<String> runpath() {
@@ -431,7 +446,7 @@ private List<String> tagsToExclude() {
431446
}
432447

433448
private List<String> parallel() {
434-
return parallel ? singletonList("-P") : Collections.<String>emptyList();
449+
return parallel ? unmodifiableList(singletonList("-P")) : Collections.<String>emptyList();
435450
}
436451

437452
//
@@ -459,7 +474,7 @@ private List<String> suites() {
459474
}
460475
}
461476
}
462-
return list;
477+
return unmodifiableList(list);
463478
}
464479

465480
//
@@ -526,7 +541,7 @@ private List<String> tests() {
526541
for (String test: splitOnComma(tests)) {
527542
addTest(list, test);
528543
}
529-
return list;
544+
return unmodifiableList(list);
530545
}
531546

532547
private List<String> spanScaleFactor() {
@@ -535,7 +550,7 @@ private List<String> spanScaleFactor() {
535550
list.add("-F");
536551
list.add(spanScaleFactor + "");
537552
}
538-
return list;
553+
return unmodifiableList(list);
539554
}
540555

541556
private List<String> suffixes() {
@@ -567,7 +582,7 @@ private List<String> testsFiles() {
567582
list.add(param);
568583
}
569584
}
570-
return list;
585+
return unmodifiableList(list);
571586
}
572587

573588
private List<String> junitClasses() {

src/main/java/org/scalatest/tools/maven/MojoUtils.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.scalatest.tools.maven;
22

3+
import java.util.Collections;
34
import java.util.List;
45
import java.util.ArrayList;
56
import java.io.File;
67

78
import static org.apache.commons.lang3.StringUtils.isEmpty;
89

10+
import static java.util.Collections.unmodifiableList;
11+
912
/**
1013
* Provides internal utilities for the Mojo's operations.
1114
*
@@ -47,7 +50,7 @@ public String f(String in){
4750
}
4851

4952
// sideeffect!
50-
private static void createIfNotExists(File dir) {
53+
private static synchronized void createIfNotExists(File dir) {
5154
if(!dir.exists() && !dir.mkdirs()){
5255
throw new IllegalStateException("Cannot create directory " + dir);
5356
}
@@ -70,7 +73,7 @@ static List<String> compoundArg(String name, String...strings){
7073
}
7174
list.add(a);
7275
}
73-
return list;
76+
return unmodifiableList(list);
7477
}
7578

7679
static List<String> suiteArg(String name, String commaSeparated) {
@@ -79,7 +82,7 @@ static List<String> suiteArg(String name, String commaSeparated) {
7982
list.add(name);
8083
list.add(param);
8184
}
82-
return list;
85+
return unmodifiableList(list);
8386
}
8487

8588
static List<String> reporterArg(String name, String commaSeparated, F map) {
@@ -94,7 +97,7 @@ static List<String> reporterArg(String name, String commaSeparated, F map) {
9497
r.add(map.f(split[1]));
9598
}
9699
}
97-
return r;
100+
return unmodifiableList(r);
98101
}
99102

100103
//
@@ -105,13 +108,13 @@ static List<String> reporterArg(String name, String commaSeparated, F map) {
105108
static List<String> splitOnComma(String cs) {
106109
List<String> args = new ArrayList<String>();
107110
if (cs == null) {
108-
return args;
111+
return unmodifiableList(args);
109112
} else {
110113
String[] split = cs.split("(?<!\\\\),");
111114
for (String arg : split) {
112115
args.add(arg.trim().replaceAll("\\\\,", ","));
113116
}
114-
return args;
117+
return unmodifiableList(args);
115118
}
116119
}
117120

src/main/java/org/scalatest/tools/maven/TestMojo.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88
import java.util.Collections;
99
import static java.util.Collections.singletonList;
10+
import static java.util.Collections.unmodifiableList;
1011
import java.util.List;
1112
import java.util.ArrayList;
1213

@@ -21,6 +22,7 @@
2122
* @author Bill Venners
2223
* @phase test
2324
* @goal test
25+
* @threadSafe
2426
*/
2527
public class TestMojo extends AbstractScalaTestMojo {
2628

@@ -124,15 +126,15 @@ String[] configuration() {
124126
// These private methods create the relevant portion of the command line
125127
// to pass to Runner based on the corresponding Maven configuration parameter.
126128
private List<String> stdout() {
127-
return singletonList(stdout == null ? "-o" : "-o" + stdout);
129+
return unmodifiableList(singletonList(stdout == null ? "-o" : "-o" + stdout));
128130
}
129131

130132
private List<String> stderr() {
131-
return stderr == null ? Collections.<String>emptyList() : singletonList("-e" + stderr);
133+
return stderr == null ? Collections.<String>emptyList() : unmodifiableList(singletonList("-e" + stderr));
132134
}
133135

134136
private List<String> filereports() {
135-
return reporterArg("-f", filereports, fileRelativeTo(reportsDirectory));
137+
return unmodifiableList(reporterArg("-f", filereports, fileRelativeTo(reportsDirectory)));
136138
}
137139

138140
private List<String> htmlreporters() {
@@ -151,7 +153,7 @@ private List<String> htmlreporters() {
151153
}
152154
}
153155
}
154-
return r;
156+
return unmodifiableList(r);
155157
}
156158

157159
private List<String> reporters() {

0 commit comments

Comments
 (0)