Compare commits

..

No commits in common. "068b0b8be5ebdce4f94bcd62d69e4d0581d74dab" and "a6747fdfe51c4493aed0141a47b9909ae4c0772f" have entirely different histories.

7 changed files with 86 additions and 92 deletions

View file

@ -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 Exception { public void jacoco() throws IOException {
new JacocoReportOperation() new JacocoReportOperation()
.fromProject(this) .fromProject(this)
.execute(); .execute();

View file

@ -1,6 +1,6 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.6 bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.6-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.version=1.9.1 bld.version=1.9.1

View file

@ -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, 3))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3))); .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)));
} }
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 Exception { public void jacoco() throws IOException {
new JacocoReportOperation() new JacocoReportOperation()
.fromProject(this) .fromProject(this)
.execute(); .execute();

View file

@ -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.2 bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0
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

View file

@ -34,7 +34,7 @@ public class JacocoReportOperationBuild extends Project {
public JacocoReportOperationBuild() { public JacocoReportOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "JacocoReportOperation"; name = "JacocoReportOperation";
version = version(0, 9, 6); version = version(0, 9, 6, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
@ -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, 3))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
.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() throws Exception { public void pmd() {
new PmdOperation() new PmdOperation()
.fromProject(this) .fromProject(this)
.failOnViolation(true) .failOnViolation(true)

View file

@ -82,6 +82,10 @@ 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.
*/ */
@ -248,67 +252,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 Exception { public void execute() throws IOException {
if ((project_ == null)) { if ((project_ == null) && LOGGER.isLoggable(Level.SEVERE)) {
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) { LOGGER.severe("A project must be specified.");
LOGGER.severe("A project must be specified."); } else {
} var buildJacocoReportsDir = Path.of(project_.buildDirectory().getPath(), "reports", "jacoco", "test").toFile();
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE); var buildJacocoExecDir = Path.of(project_.buildDirectory().getPath(), "jacoco").toFile();
} var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
var buildJacocoReportsDir = Path.of(project_.buildDirectory().getPath(), "reports", "jacoco", "test").toFile(); if (destFile_ == null) {
var buildJacocoExecDir = Path.of(project_.buildDirectory().getPath(), "jacoco").toFile(); destFile_ = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").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()) { if (execFiles_.isEmpty()) {
execFiles_.add(buildJacocoExec); 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);
} }
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);
} }
/** /**
@ -345,11 +349,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) && !silent()) { if (execFiles_.isEmpty() && LOGGER.isLoggable(Level.WARNING) && !quiet_) {
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) && !silent()) { if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
LOGGER.log(Level.INFO, "Loading execution data: {0}", LOGGER.log(Level.INFO, "Loading execution data: {0}",
f.getAbsolutePath()); f.getAbsolutePath());
} }
@ -377,7 +381,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) {
silent(quiet); quiet_ = quiet;
return this; return this;
} }
@ -466,7 +470,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) && !silent()) { if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
LOGGER.log(Level.INFO, "Analyzing {0} classes.", LOGGER.log(Level.INFO, "Analyzing {0} classes.",
bundle.getClassCounter().getTotalCount()); bundle.getClassCounter().getTotalCount());
} }
@ -475,7 +479,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) && !silent()) { if (LOGGER.isLoggable(Level.INFO) && !quiet_) {
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());

View file

@ -18,7 +18,6 @@ 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;
@ -27,7 +26,6 @@ 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;
@ -54,13 +52,7 @@ class JacocoReportOperationTest {
} }
@Test @Test
void executeFailureTest() { void executeTest() throws IOException {
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();
@ -72,20 +64,18 @@ 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 op = new JacocoReportOperation() var o = new JacocoReportOperation();
.fromProject(new Project()) o.fromProject(new Project());
.csv(csv) o.csv(csv);
.html(html) o.html(html);
.xml(xml) o.xml(xml);
.classFiles(new File("src/test/resources/Examples.class")) o.classFiles(new File("src/test/resources/Examples.class"));
.sourceFiles(new File("examples/src/main/java")) o.sourceFiles(new File("examples/src/main/java"));
.execFiles(new File("src/test/resources/jacoco.exec")); o.execFiles(new File("src/test/resources/jacoco.exec"));
return o;
deleteOnExit(tempDir.toFile());
return op;
} }
} }