Skip to content

Fixes #57 using un-modifyable lists & judicious synchronization #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>2.0.0</version>
<version>2.0.1-SNAPSHOT</version>
<name>ScalaTest Maven Plugin</name>
<description>Integrates ScalaTest into Maven</description>

Expand Down
33 changes: 24 additions & 9 deletions src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.cli.*;

import java.io.File;
import static java.util.Collections.unmodifiableList;
import static org.scalatest.tools.maven.MojoUtils.*;

import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import static java.util.Collections.singletonList;

import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.net.URL;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -388,7 +402,8 @@ private List<String> testClasspathElements() {

// This is the configuration parameters shared by all concrete Mojo subclasses
List<String> sharedConfiguration() {
return new ArrayList<String>() {{
return unmodifiableList(
new ArrayList<String>() {{
addAll(runpath());
addAll(config());
addAll(tagsToInclude());
Expand All @@ -404,15 +419,15 @@ List<String> sharedConfiguration() {
addAll(testsFiles());
addAll(junitClasses());
addAll(spanScaleFactor());
}};
}});
}

private List<String> config() {
List<String> c = new ArrayList<String>();
for(String pair : splitOnComma(config)){
c.add("-D"+pair);
}
return c;
return unmodifiableList(c);
}

private List<String> runpath() {
Expand All @@ -431,7 +446,7 @@ private List<String> tagsToExclude() {
}

private List<String> parallel() {
return parallel ? singletonList("-P") : Collections.<String>emptyList();
return parallel ? unmodifiableList(singletonList("-P")) : Collections.<String>emptyList();
}

//
Expand Down Expand Up @@ -459,7 +474,7 @@ private List<String> suites() {
}
}
}
return list;
return unmodifiableList(list);
}

//
Expand Down Expand Up @@ -526,7 +541,7 @@ private List<String> tests() {
for (String test: splitOnComma(tests)) {
addTest(list, test);
}
return list;
return unmodifiableList(list);
}

private List<String> spanScaleFactor() {
Expand All @@ -535,7 +550,7 @@ private List<String> spanScaleFactor() {
list.add("-F");
list.add(spanScaleFactor + "");
}
return list;
return unmodifiableList(list);
}

private List<String> suffixes() {
Expand Down Expand Up @@ -567,7 +582,7 @@ private List<String> testsFiles() {
list.add(param);
}
}
return list;
return unmodifiableList(list);
}

private List<String> junitClasses() {
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/org/scalatest/tools/maven/MojoUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.scalatest.tools.maven;

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.io.File;

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

import static java.util.Collections.unmodifiableList;

/**
* Provides internal utilities for the Mojo's operations.
*
Expand Down Expand Up @@ -47,7 +50,7 @@ public String f(String in){
}

// sideeffect!
private static void createIfNotExists(File dir) {
private static synchronized void createIfNotExists(File dir) {
if(!dir.exists() && !dir.mkdirs()){
throw new IllegalStateException("Cannot create directory " + dir);
}
Expand All @@ -70,7 +73,7 @@ static List<String> compoundArg(String name, String...strings){
}
list.add(a);
}
return list;
return unmodifiableList(list);
}

static List<String> suiteArg(String name, String commaSeparated) {
Expand All @@ -79,7 +82,7 @@ static List<String> suiteArg(String name, String commaSeparated) {
list.add(name);
list.add(param);
}
return list;
return unmodifiableList(list);
}

static List<String> reporterArg(String name, String commaSeparated, F map) {
Expand All @@ -94,7 +97,7 @@ static List<String> reporterArg(String name, String commaSeparated, F map) {
r.add(map.f(split[1]));
}
}
return r;
return unmodifiableList(r);
}

//
Expand All @@ -105,13 +108,13 @@ static List<String> reporterArg(String name, String commaSeparated, F map) {
static List<String> splitOnComma(String cs) {
List<String> args = new ArrayList<String>();
if (cs == null) {
return args;
return unmodifiableList(args);
} else {
String[] split = cs.split("(?<!\\\\),");
for (String arg : split) {
args.add(arg.trim().replaceAll("\\\\,", ","));
}
return args;
return unmodifiableList(args);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/scalatest/tools/maven/TestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.util.Collections;
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableList;
import java.util.List;
import java.util.ArrayList;

Expand All @@ -21,6 +22,7 @@
* @author Bill Venners
* @phase test
* @goal test
* @threadSafe
*/
public class TestMojo extends AbstractScalaTestMojo {

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

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

private List<String> filereports() {
return reporterArg("-f", filereports, fileRelativeTo(reportsDirectory));
return unmodifiableList(reporterArg("-f", filereports, fileRelativeTo(reportsDirectory)));
}

private List<String> htmlreporters() {
Expand All @@ -151,7 +153,7 @@ private List<String> htmlreporters() {
}
}
}
return r;
return unmodifiableList(r);
}

private List<String> reporters() {
Expand Down