2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-26 16:38:11 -07:00

Updated with support for latest JUnit in a backwards compatible way.

Updated some other blueprint dependencies.
This commit is contained in:
Geert Bevin 2023-10-20 14:48:38 -04:00
parent 6230db68af
commit 84a2bb337d
8 changed files with 255 additions and 160 deletions

View file

@ -37,7 +37,7 @@ public class BlankProjectBlueprint extends Project {
downloadSources = true;
repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,9,3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,9,3)));
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,10,0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,10,0)));
}
}

View file

@ -40,13 +40,13 @@ public class Rife2ProjectBlueprint extends WebProject {
scope(compile)
.include(dependency("com.uwyn.rife2", "rife2", version(1,7,2)));
scope(test)
.include(dependency("org.jsoup", "jsoup", version(1,16,1)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,9,3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,9,3)));
.include(dependency("org.jsoup", "jsoup", version(1,16,2)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,10,0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,10,0)));
scope(standalone)
.include(dependency("org.eclipse.jetty", "jetty-server", version(11,0,15)))
.include(dependency("org.eclipse.jetty", "jetty-servlet", version(11,0,15)))
.include(dependency("org.slf4j", "slf4j-simple", version(2,0,7)));
.include(dependency("org.slf4j", "slf4j-simple", version(2,0,9)));
precompileOperation().templateTypes(TemplateType.HTML);
}

View file

@ -5,6 +5,11 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.tools.FileUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* Tests a Java application with JUnit.
@ -24,6 +29,39 @@ public class JUnitOperation extends TestOperation<JUnitOperation, JUnitOptions>
return new JUnitOptions();
}
@Override
protected List<String> executeConstructProcessCommandList() {
if (mainClass() == null) {
throw new IllegalArgumentException("ERROR: Missing main class for test execution.");
}
var args = new ArrayList<String>();
args.add(javaTool());
args.addAll(javaOptions());
args.add("-cp");
var classpath = FileUtils.joinPaths(classpath());
args.add(classpath);
args.add(mainClass());
// the JUnit console launcher syntax changed in v1.10.x,
// this logic defaults to the new syntax but if it finds an older
// JUnit jar in the classpath, uses the old syntax
var junit_version_1_10_and_later = true;
var junit_version_pattern = Pattern.compile("junit-platform-console-standalone-(\\d+)\\.(\\d+)\\.");
var junit_version_matcher = junit_version_pattern.matcher(classpath);
if (junit_version_matcher.find() &&
(Integer.parseInt(junit_version_matcher.group(1)) < 1 ||
(Integer.parseInt(junit_version_matcher.group(1)) == 1 &&
Integer.parseInt(junit_version_matcher.group(2)) < 10))) {
junit_version_1_10_and_later = false;
}
if (junit_version_1_10_and_later) {
args.add("execute");
}
args.addAll(testToolOptions());
return args;
}
@Override
public JUnitOperation fromProject(BaseProject project) {
super.fromProject(project);