Ensure execution stops on failure
Bumped JUnit to version 5.10.3 Bumped PMD extension to version 1.1.2
This commit is contained in:
parent
a6747fdfe5
commit
8ff14ff9f9
6 changed files with 93 additions and 87 deletions
|
@ -14,7 +14,7 @@ To run the tests and generate the code coverage reports, add the floowing to you
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@BuildCommand(summary = "Generates Jacoco Reports")
|
@BuildCommand(summary = "Generates Jacoco Reports")
|
||||||
public void jacoco() throws IOException {
|
public void jacoco() throws Exception {
|
||||||
new JacocoReportOperation()
|
new JacocoReportOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
|
@ -25,8 +25,8 @@ public class ExamplesBuild extends Project {
|
||||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
||||||
|
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)));
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -34,7 +34,7 @@ public class ExamplesBuild extends Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Generates Jacoco Reports")
|
@BuildCommand(summary = "Generates Jacoco Reports")
|
||||||
public void jacoco() throws IOException {
|
public void jacoco() throws Exception {
|
||||||
new JacocoReportOperation()
|
new JacocoReportOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0
|
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.2
|
||||||
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.version=1.9.1
|
bld.version=1.9.1
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class JacocoReportOperationBuild extends Project {
|
||||||
.include(dependency("org.jacoco", "jacoco", jacocoVersion).exclude("*", "org.jacoco.doc"))
|
.include(dependency("org.jacoco", "jacoco", jacocoVersion).exclude("*", "org.jacoco.doc"))
|
||||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)));
|
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)));
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
|
||||||
|
|
||||||
javadocOperation()
|
javadocOperation()
|
||||||
|
@ -91,7 +91,7 @@ public class JacocoReportOperationBuild extends Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Runs PMD analysis")
|
@BuildCommand(summary = "Runs PMD analysis")
|
||||||
public void pmd() {
|
public void pmd() throws Exception {
|
||||||
new PmdOperation()
|
new PmdOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
.failOnViolation(true)
|
.failOnViolation(true)
|
||||||
|
|
|
@ -82,10 +82,6 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
* The project reference.
|
* The project reference.
|
||||||
*/
|
*/
|
||||||
private BaseProject project_;
|
private BaseProject project_;
|
||||||
/**
|
|
||||||
* The quiet flag.
|
|
||||||
*/
|
|
||||||
private boolean quiet_;
|
|
||||||
/**
|
/**
|
||||||
* The report name.
|
* The report name.
|
||||||
*/
|
*/
|
||||||
|
@ -252,67 +248,67 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
* Performs the operation execution that can be wrapped by the {@code #executeOnce} call.
|
* Performs the operation execution that can be wrapped by the {@code #executeOnce} call.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws IOException {
|
public void execute() throws Exception {
|
||||||
if ((project_ == null) && LOGGER.isLoggable(Level.SEVERE)) {
|
if ((project_ == null)) {
|
||||||
LOGGER.severe("A project must be specified.");
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
} else {
|
LOGGER.severe("A project must be specified.");
|
||||||
var buildJacocoReportsDir = Path.of(project_.buildDirectory().getPath(), "reports", "jacoco", "test").toFile();
|
|
||||||
var buildJacocoExecDir = Path.of(project_.buildDirectory().getPath(), "jacoco").toFile();
|
|
||||||
var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
|
|
||||||
|
|
||||||
if (destFile_ == null) {
|
|
||||||
destFile_ = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
|
|
||||||
}
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
if (execFiles_.isEmpty()) {
|
|
||||||
var testOperation = project_.testOperation().fromProject(project_);
|
|
||||||
testOperation.javaOptions().javaAgent(Path.of(project_.libBldDirectory().getPath(),
|
|
||||||
"org.jacoco.agent-" + JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.'))
|
|
||||||
+ "-runtime.jar").toFile(), "destfile=" + destFile_.getPath());
|
|
||||||
try {
|
|
||||||
testOperation.execute();
|
|
||||||
} catch (InterruptedException | ExitStatusException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
|
|
||||||
LOGGER.log(Level.INFO, "Execution Data: {0}", destFile_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildJacocoExec.exists()) {
|
|
||||||
execFiles_.add(buildJacocoExec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceFiles_.isEmpty()) {
|
|
||||||
sourceFiles_.add(project_.srcMainJavaDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classFiles_.isEmpty()) {
|
|
||||||
classFiles_.add(project_.buildMainDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (html_ == null) {
|
|
||||||
html_ = new File(buildJacocoReportsDir, "html");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xml_ == null) {
|
|
||||||
xml_ = new File(buildJacocoReportsDir, "jacocoTestReport.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (csv_ == null) {
|
|
||||||
csv_ = new File(buildJacocoReportsDir, "jacocoTestReport.csv");
|
|
||||||
}
|
|
||||||
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
buildJacocoReportsDir.mkdirs();
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
buildJacocoExecDir.mkdirs();
|
|
||||||
|
|
||||||
var loader = loadExecFiles();
|
|
||||||
var bundle = analyze(loader.getExecutionDataStore());
|
|
||||||
writeReports(bundle, loader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var buildJacocoReportsDir = Path.of(project_.buildDirectory().getPath(), "reports", "jacoco", "test").toFile();
|
||||||
|
var buildJacocoExecDir = Path.of(project_.buildDirectory().getPath(), "jacoco").toFile();
|
||||||
|
var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
|
||||||
|
|
||||||
|
if (destFile_ == null) {
|
||||||
|
destFile_ = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (execFiles_.isEmpty()) {
|
||||||
|
var testOperation = project_.testOperation().fromProject(project_);
|
||||||
|
testOperation.javaOptions().javaAgent(Path.of(project_.libBldDirectory().getPath(),
|
||||||
|
"org.jacoco.agent-" + JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.'))
|
||||||
|
+ "-runtime.jar").toFile(), "destfile=" + destFile_.getPath());
|
||||||
|
|
||||||
|
testOperation.execute();
|
||||||
|
|
||||||
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
|
LOGGER.log(Level.INFO, "Execution Data: {0}", destFile_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildJacocoExec.exists()) {
|
||||||
|
execFiles_.add(buildJacocoExec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceFiles_.isEmpty()) {
|
||||||
|
sourceFiles_.add(project_.srcMainJavaDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classFiles_.isEmpty()) {
|
||||||
|
classFiles_.add(project_.buildMainDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (html_ == null) {
|
||||||
|
html_ = new File(buildJacocoReportsDir, "html");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xml_ == null) {
|
||||||
|
xml_ = new File(buildJacocoReportsDir, "jacocoTestReport.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (csv_ == null) {
|
||||||
|
csv_ = new File(buildJacocoReportsDir, "jacocoTestReport.csv");
|
||||||
|
}
|
||||||
|
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
buildJacocoReportsDir.mkdirs();
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
buildJacocoExecDir.mkdirs();
|
||||||
|
|
||||||
|
var loader = loadExecFiles();
|
||||||
|
var bundle = analyze(loader.getExecutionDataStore());
|
||||||
|
writeReports(bundle, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -349,11 +345,11 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
|
|
||||||
private ExecFileLoader loadExecFiles() throws IOException {
|
private ExecFileLoader loadExecFiles() throws IOException {
|
||||||
var loader = new ExecFileLoader();
|
var loader = new ExecFileLoader();
|
||||||
if (execFiles_.isEmpty() && LOGGER.isLoggable(Level.WARNING) && !quiet_) {
|
if (execFiles_.isEmpty() && LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||||
LOGGER.warning("No execution data files provided.");
|
LOGGER.warning("No execution data files provided.");
|
||||||
} else {
|
} else {
|
||||||
for (var f : execFiles_) {
|
for (var f : execFiles_) {
|
||||||
if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.log(Level.INFO, "Loading execution data: {0}",
|
LOGGER.log(Level.INFO, "Loading execution data: {0}",
|
||||||
f.getAbsolutePath());
|
f.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -381,7 +377,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
* @return this operation instance
|
* @return this operation instance
|
||||||
*/
|
*/
|
||||||
public JacocoReportOperation quiet(boolean quiet) {
|
public JacocoReportOperation quiet(boolean quiet) {
|
||||||
quiet_ = quiet;
|
silent(quiet);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +466,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
|
|
||||||
private void writeReports(IBundleCoverage bundle, ExecFileLoader loader)
|
private void writeReports(IBundleCoverage bundle, ExecFileLoader loader)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.log(Level.INFO, "Analyzing {0} classes.",
|
LOGGER.log(Level.INFO, "Analyzing {0} classes.",
|
||||||
bundle.getClassCounter().getTotalCount());
|
bundle.getClassCounter().getTotalCount());
|
||||||
}
|
}
|
||||||
|
@ -479,7 +475,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
||||||
loader.getExecutionDataStore().getContents());
|
loader.getExecutionDataStore().getContents());
|
||||||
visitor.visitBundle(bundle, sourceLocator());
|
visitor.visitBundle(bundle, sourceLocator());
|
||||||
visitor.visitEnd();
|
visitor.visitEnd();
|
||||||
if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.log(Level.INFO, "XML Report: file://{0}", xml_.toURI().getPath());
|
LOGGER.log(Level.INFO, "XML Report: file://{0}", xml_.toURI().getPath());
|
||||||
LOGGER.log(Level.INFO, "CSV Report: file://{0}", csv_.toURI().getPath());
|
LOGGER.log(Level.INFO, "CSV Report: file://{0}", csv_.toURI().getPath());
|
||||||
LOGGER.log(Level.INFO, "HTML Report: file://{0}index.html", html_.toURI().getPath());
|
LOGGER.log(Level.INFO, "HTML Report: file://{0}index.html", html_.toURI().getPath());
|
||||||
|
|
|
@ -18,6 +18,7 @@ package rife.bld.extension;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -26,6 +27,7 @@ import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
|
||||||
class JacocoReportOperationTest {
|
class JacocoReportOperationTest {
|
||||||
final File csv;
|
final File csv;
|
||||||
|
@ -52,7 +54,13 @@ class JacocoReportOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void executeTest() throws IOException {
|
void executeFailureTest() {
|
||||||
|
var op = new JacocoReportOperation().fromProject(new Project());
|
||||||
|
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void executeTest() throws Exception {
|
||||||
newJacocoReportOperation().execute();
|
newJacocoReportOperation().execute();
|
||||||
|
|
||||||
assertThat(csv).exists();
|
assertThat(csv).exists();
|
||||||
|
@ -64,18 +72,20 @@ class JacocoReportOperationTest {
|
||||||
}
|
}
|
||||||
assertThat(Path.of(html.getPath(), "com.example", "Examples.java.html")).exists();
|
assertThat(Path.of(html.getPath(), "com.example", "Examples.java.html")).exists();
|
||||||
|
|
||||||
deleteOnExit(tempDir.toFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JacocoReportOperation newJacocoReportOperation() {
|
JacocoReportOperation newJacocoReportOperation() {
|
||||||
var o = new JacocoReportOperation();
|
var op = new JacocoReportOperation()
|
||||||
o.fromProject(new Project());
|
.fromProject(new Project())
|
||||||
o.csv(csv);
|
.csv(csv)
|
||||||
o.html(html);
|
.html(html)
|
||||||
o.xml(xml);
|
.xml(xml)
|
||||||
o.classFiles(new File("src/test/resources/Examples.class"));
|
.classFiles(new File("src/test/resources/Examples.class"))
|
||||||
o.sourceFiles(new File("examples/src/main/java"));
|
.sourceFiles(new File("examples/src/main/java"))
|
||||||
o.execFiles(new File("src/test/resources/jacoco.exec"));
|
.execFiles(new File("src/test/resources/jacoco.exec"));
|
||||||
return o;
|
|
||||||
|
deleteOnExit(tempDir.toFile());
|
||||||
|
|
||||||
|
return op;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue