Skip to content

Commit 9589c76

Browse files
authored
Merge branch 'develop' into fix-86
2 parents 40703e9 + 6354307 commit 9589c76

File tree

26 files changed

+303
-93
lines changed

26 files changed

+303
-93
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
6+
jobs:
7+
test:
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
include:
12+
- os: ubuntu-latest
13+
java: 8
14+
jobtype: 1
15+
- os: ubuntu-latest
16+
java: 11
17+
jobtype: 1
18+
runs-on: ${{ matrix.os }}
19+
env:
20+
# define Java options for both official sbt and sbt-extras
21+
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
22+
JVM_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
- name: Setup
27+
uses: olafurpg/setup-scala@v10
28+
with:
29+
java-version: "adopt@1.${{ matrix.java }}"
30+
- name: Coursier cache
31+
uses: coursier/cache-action@v6
32+
- name: Build and test
33+
shell: bash
34+
run: |
35+
sbt -v test scripted
36+
rm -rf "$HOME/.ivy2/local" || true
37+
rm -r $(find $HOME/.sbt/boot -name "*-SNAPSHOT") || true
38+
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
39+
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
40+
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
41+
find $HOME/.sbt -name "*.lock" -delete || true

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
env:
10+
# define Java options for both official sbt and sbt-extras
11+
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
12+
JVM_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Setup
17+
uses: olafurpg/setup-scala@v10
18+
with:
19+
java-version: "adopt@1.8"
20+
- name: Coursier cache
21+
uses: coursier/cache-action@v5
22+
- name: Test
23+
run: |
24+
sbt test scripted packagedArtifacts
25+
- name: Release
26+
env:
27+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
28+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
29+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
30+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
31+
CI_CLEAN: clean
32+
CI_RELEASE: publishSigned
33+
run: |
34+
sbt ci-release
35+
rm -rf "$HOME/.ivy2/local" || true
36+
rm -r $(find $HOME/.sbt/boot -name "*-SNAPSHOT") || true
37+
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
38+
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
39+
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
40+
find $HOME/.sbt -name "*.lock" -delete || true

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

build.sbt

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
1-
name := "junit-interface"
1+
ThisBuild / version := {
2+
val orig = (ThisBuild / version).value
3+
if (orig.endsWith("-SNAPSHOT")) "-SNAPSHOT"
4+
else orig
5+
}
6+
ThisBuild / organization := "com.github.sbt"
7+
ThisBuild / description := "An implementation of sbt's test interface for JUnit 4"
8+
ThisBuild / dynverSonatypeSnapshots := true
29

3-
organization := "com.novocode"
4-
version := "0.12-SNAPSHOT"
10+
lazy val `junit-interface` = (project in file("."))
11+
.enablePlugins(SbtPlugin)
12+
.settings(nocomma {
13+
name := "junit-interface"
514

6-
autoScalaLibrary := false
7-
crossPaths := false
8-
sbtPlugin := false
15+
autoScalaLibrary := false
16+
crossPaths := false
17+
sbtPlugin := false
918

10-
libraryDependencies ++= Seq(
11-
"junit" % "junit" % "4.13",
12-
"org.scala-sbt" % "test-interface" % "1.0"
13-
)
19+
libraryDependencies ++= Seq(
20+
"junit" % "junit" % "4.12",
21+
"org.scala-sbt" % "test-interface" % "1.0",
22+
)
23+
24+
Compile / javacOptions ++= List("-target", "1.8", "-source", "1.8")
25+
26+
// javadoc: error - invalid flag: -target.
27+
Compile / doc / javacOptions --= List("-target", "1.8")
28+
29+
Test / publishArtifact := false
1430

15-
javacOptions in Compile ++= List("-target", "1.8", "-source", "1.8")
31+
scriptedBufferLog := false
32+
scriptedLaunchOpts ++= Seq(
33+
s"-Dplugin.version=${version.value}",
34+
"-Xmx256m"
35+
)
1636

17-
// javadoc: error - invalid flag: -target.
18-
javacOptions in (Compile, doc) --= List("-target", "1.8")
37+
publishMavenStyle := true
38+
pomIncludeRepository := { _ => false }
39+
})
1940

20-
publishTo := Some(
41+
ThisBuild / publishTo := Some(
2142
if(version.value.trim.endsWith("SNAPSHOT")) "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
2243
else "releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"
2344
)
24-
25-
publishMavenStyle := true
26-
publishArtifact in Test := false
27-
pomIncludeRepository := { _ => false }
28-
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
29-
description := "An implementation of sbt's test interface for JUnit 4"
30-
homepage := Some(url("http://github.com/sbt/junit-interface/"))
31-
startYear := Some(2009)
32-
licenses += ("Two-clause BSD-style license", url("http://github.com/sbt/junit-interface/blob/master/LICENSE.txt"))
33-
34-
developers := List(
45+
ThisBuild / homepage := Some(url("http://github.com/sbt/junit-interface/"))
46+
ThisBuild / startYear := Some(2009)
47+
ThisBuild / licenses += ("Two-clause BSD-style license", url("http://github.com/sbt/junit-interface/blob/master/LICENSE.txt"))
48+
ThisBuild / developers := List(
3549
Developer(
3650
id = "szeiger",
3751
name = "Stefan Zeiger",
3852
email = "szeiger@novocode.com",
3953
url = url("http://szeiger.de")
40-
)
54+
),
55+
Developer(
56+
id = "eed3si9n",
57+
name = "Eugene Yokota",
58+
email = "@eed3si9n",
59+
url = url("https://eed3si9n.com/")
60+
),
4161
)
42-
43-
scmInfo := Some(
62+
ThisBuild / scmInfo := Some(
4463
ScmInfo(
4564
url("https://github.com/sbt/junit-interface"),
4665
"scm:git@github.com:sbt/junit-interface.git"
4766
)
4867
)
49-
50-
// curl -X POST http://ls.implicit.ly/api/1/libraries -d 'user=szeiger&repo=junit-interface&version=0.8'
51-
52-
enablePlugins(SbtPlugin)
53-
scriptedBufferLog := false
54-
scriptedLaunchOpts ++= Seq(
55-
s"-Dplugin.version=${version.value}",
56-
"-Xmx256m"
57-
)
58-
59-
resolvers += Resolver.typesafeIvyRepo("releases")

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.3
1+
sbt.version=1.5.2

project/plugins.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
resolvers += Resolver.typesafeIvyRepo("releases")
1+
addSbtPlugin("com.eed3si9n" % "sbt-nocomma" % "0.1.0")
2+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")

src/main/java/com/novocode/junit/EventDispatcher.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.novocode.junit;
22

3-
import java.util.ArrayList;
43
import java.util.Collections;
54
import java.util.Set;
65
import java.util.concurrent.ConcurrentHashMap;
@@ -20,8 +19,8 @@
2019
final class EventDispatcher extends RunListener
2120
{
2221
private final RichLogger logger;
23-
private final Set<String> reported = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
24-
private final ConcurrentHashMap<String, Long> startTimes = new ConcurrentHashMap<String, Long>();
22+
private final Set<String> reported = Collections.newSetFromMap(new ConcurrentHashMap<>());
23+
private final ConcurrentHashMap<String, Long> startTimes = new ConcurrentHashMap<>();
2524
private final EventHandler handler;
2625
private final RunSettings settings;
2726
private final Fingerprint fingerprint;
@@ -100,7 +99,7 @@ void logTo(RichLogger logger) {
10099
@Override
101100
public void testIgnored(Description desc)
102101
{
103-
postIfFirst(new InfoEvent(desc, Status.Skipped) {
102+
postIfFirst(new InfoEvent(desc, Status.Ignored) {
104103
void logTo(RichLogger logger) {
105104
logger.info("Test "+ansiName+" ignored");
106105
}
@@ -123,7 +122,7 @@ private void recordStartTime(Description description) {
123122
private Long elapsedTime(Description description) {
124123
Long startTime = startTimes.get(settings.buildPlainName(description));
125124
if( startTime == null ) {
126-
return 0l;
125+
return 0L;
127126
} else {
128127
return System.currentTimeMillis() - startTime;
129128
}
@@ -136,7 +135,7 @@ public void testRunFinished(Result result)
136135
c(result.getFailureCount()+" failed", result.getFailureCount() > 0 ? ERRCOUNT : INFO)+
137136
c(", ", INFO)+
138137
c(result.getIgnoreCount()+" ignored", result.getIgnoreCount() > 0 ? IGNCOUNT : INFO)+
139-
c(", "+result.getRunCount()+" total, "+(result.getRunTime()/1000.0)+"s", INFO), RunSettings.Verbosity.RUN_FINISHED);
138+
c(", "+result.getRunCount()+" total, "+ result.getRunTime() / 1000.0 +"s", INFO), RunSettings.Verbosity.RUN_FINISHED);
140139
runStatistics.addTime(result.getRunTime());
141140
}
142141

@@ -148,7 +147,7 @@ public void testRunStarted(Description description)
148147

149148
void testExecutionFailed(String testName, Throwable err)
150149
{
151-
post(new Event(Ansi.c(testName, Ansi.ERRMSG), settings.buildErrorMessage(err), Status.Error, 0l, err) {
150+
post(new Event(Ansi.c(testName, Ansi.ERRMSG), settings.buildErrorMessage(err), Status.Error, 0L, err) {
152151
void logTo(RichLogger logger) {
153152
logger.error("Execution of test "+ansiName+" failed: "+ansiMsg, error);
154153
}
@@ -158,13 +157,30 @@ void logTo(RichLogger logger) {
158157
private void postIfFirst(AbstractEvent e)
159158
{
160159
e.logTo(logger);
161-
if(reported.add(e.fullyQualifiedName())) {
160+
161+
String fqn = e.fullyQualifiedName();
162+
if (reported.add(fqn)) {
162163
runStatistics.captureStats(e);
163164
handler.handle(e);
164165
}
166+
167+
// NOTE: Status.Success is used to indicate that test is finished with any result (Success or Failure)
168+
// When test has failed, two events are actually generated:
169+
// 1) with Status.Failure
170+
// 2) with Status.Success (actually meaning that test has finished)
171+
// For non-failed tests, single event is emitted: Status.Success OR Status.Skipped OR Status.Ignored
172+
boolean testProcessed = e.status == Status.Success || e.status == Status.Skipped || e.status == Status.Ignored;
173+
if (testProcessed) {
174+
// JUnit can run tests with the same name multiple times: https://github.com/sbt/junit-interface/issues/96
175+
// Once test is finished, we mark it as unreported to allow running it again.
176+
//
177+
// There should be no issues with running tests in parallel (default behaviour of SBT)
178+
// For each JUnitTask a dedicated EventDispatcher will be created with it's own `reported` map
179+
reported.remove(fqn);
180+
}
165181
}
166182

167-
void post(AbstractEvent e)
183+
private void post(AbstractEvent e)
168184
{
169185
e.logTo(logger);
170186
runStatistics.captureStats(e);

src/main/java/com/novocode/junit/GlobFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public final class GlobFilter extends Filter
1010
{
11-
private final ArrayList<Pattern> patterns = new ArrayList<Pattern>();
11+
private final ArrayList<Pattern> patterns = new ArrayList<>();
1212
private final RunSettings settings;
1313

1414
public GlobFilter(RunSettings settings, Iterable<String> globPatterns)

src/main/java/com/novocode/junit/JUnitRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ final class JUnitRunner implements Runner {
2828
logAssert = true, logExceptionClass = true;
2929
RunSettings.Verbosity verbosity = RunSettings.Verbosity.TERSE;
3030
RunSettings.Summary summary = RunSettings.Summary.SBT;
31-
HashMap<String, String> sysprops = new HashMap<String, String>();
32-
ArrayList<String> globPatterns = new ArrayList<String>();
33-
Set<String> includeCategories = new HashSet<String>();
34-
Set<String> excludeCategories = new HashSet<String>();
31+
HashMap<String, String> sysprops = new HashMap<>();
32+
ArrayList<String> globPatterns = new ArrayList<>();
33+
Set<String> includeCategories = new HashSet<>();
34+
Set<String> excludeCategories = new HashSet<>();
3535

3636
String testFilter = "";
3737
String ignoreRunners = "org.junit.runners.Suite";

src/main/java/com/novocode/junit/JUnitTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private boolean shouldRun(Fingerprint fingerprint, Class<?> clazz, RunSettings s
9292
}
9393

9494
private static Set<Class<?>> loadClasses(ClassLoader classLoader, Set<String> classNames) throws ClassNotFoundException {
95-
Set<Class<?>> classes = new HashSet<Class<?>>();
95+
Set<Class<?>> classes = new HashSet<>();
9696
for(String className : classNames) {
9797
classes.add(classLoader.loadClass(className));
9898
}

src/main/java/com/novocode/junit/RichLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final class RichLogger
1010
private final Logger[] loggers;
1111
private final RunSettings settings;
1212
/* The top element is the test class of the currently executing test */
13-
private final Stack<String> currentTestClassName = new Stack<String>();
13+
private final Stack<String> currentTestClassName = new Stack<>();
1414

1515
RichLogger(Logger[] loggers, RunSettings settings, String testClassName)
1616
{
@@ -132,7 +132,7 @@ private String stackTraceElementToString(StackTraceElement e, String testClassNa
132132
{
133133
boolean highlight = settings.color && (
134134
testClassName.equals(e.getClassName()) ||
135-
(testFileName != null && testFileName.equals(e.getFileName()))
135+
testFileName != null && testFileName.equals(e.getFileName())
136136
);
137137
StringBuilder b = new StringBuilder();
138138
b.append(settings.decodeName(e.getClassName() + '.' + e.getMethodName()));

0 commit comments

Comments
 (0)