diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index bf6e607..538acb3 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -1,7 +1,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.downloadLocation= -bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.2 -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.7 +bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.3-SNAPSHOT +bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.8-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.version=2.0.1 diff --git a/src/bld/java/rife/bld/extension/JacocoReportOperationBuild.java b/src/bld/java/rife/bld/extension/JacocoReportOperationBuild.java index 5282d47..a581707 100644 --- a/src/bld/java/rife/bld/extension/JacocoReportOperationBuild.java +++ b/src/bld/java/rife/bld/extension/JacocoReportOperationBuild.java @@ -34,7 +34,7 @@ public class JacocoReportOperationBuild extends Project { public JacocoReportOperationBuild() { pkg = "rife.bld.extension"; name = "JacocoReportOperation"; - version = version(0, 9, 7); + version = version(0, 9, 8, "SNAPSHOT"); javaRelease = 17; diff --git a/src/main/java/rife/bld/extension/JacocoReportOperation.java b/src/main/java/rife/bld/extension/JacocoReportOperation.java index fbcad47..81e8262 100644 --- a/src/main/java/rife/bld/extension/JacocoReportOperation.java +++ b/src/main/java/rife/bld/extension/JacocoReportOperation.java @@ -35,7 +35,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.logging.Level; @@ -111,6 +110,7 @@ private IBundleCoverage analyze(ExecutionDataStore data) throws IOException { * * @param classFiles the class files * @return this operation instance + * @see #classFiles(Collection) */ public JacocoReportOperation classFiles(File... classFiles) { classFiles_.addAll(List.of(classFiles)); @@ -122,10 +122,21 @@ public JacocoReportOperation classFiles(File... classFiles) { * * @param classFiles the class files * @return this operation instance + * @see #classFilesStrings(Collection) */ public JacocoReportOperation classFiles(String... classFiles) { - classFiles_.addAll(Arrays.stream(classFiles).map(File::new).toList()); - return this; + return classFilesStrings(List.of(classFiles)); + } + + /** + * Sets the locations of Java class files. + * + * @param classFiles the class files + * @return this operation instance + * @see #classFilesPaths(Collection) + */ + public JacocoReportOperation classFiles(Path... classFiles) { + return classFilesPaths(List.of(classFiles)); } /** @@ -142,12 +153,35 @@ public Collection classFiles() { * * @param classFiles the class files * @return this operation instance + * @see #classFiles(File...) */ public JacocoReportOperation classFiles(Collection classFiles) { classFiles_.addAll(classFiles); return this; } + /** + * Sets the locations of Java class files. + * + * @param classFiles the class files + * @return this operation instance + * @see #classFiles(Path...) + */ + public JacocoReportOperation classFilesPaths(Collection classFiles) { + return classFiles(classFiles.stream().map(Path::toFile).toList()); + } + + /** + * Sets the locations of Java class files. + * + * @param classFiles the class files + * @return this operation instance + * @see #classFiles(String...) + */ + public JacocoReportOperation classFilesStrings(Collection classFiles) { + return classFiles(classFiles.stream().map(File::new).toList()); + } + /** * Sets the location of the CSV report. * @@ -169,6 +203,15 @@ public JacocoReportOperation csv(String csv) { return csv(new File(csv)); } + /** + * Sets the location of the CSV report. + * + * @param csv the report location + * @return this operation instance + */ + public JacocoReportOperation csv(Path csv) { + return csv(csv.toFile()); + } /** * Sets the file to write execution data to. @@ -191,6 +234,16 @@ public JacocoReportOperation destFile(String destFile) { return destFile(new File(destFile)); } + /** + * Sets the file to write execution data to. + * + * @param destFile the file + * @return this operation instance + */ + public JacocoReportOperation destFile(Path destFile) { + return destFile(destFile.toFile()); + } + /** * Sets the source file encoding. The platform encoding is used by default. * @@ -207,10 +260,10 @@ public JacocoReportOperation encoding(String encoding) { * * @param execFiles the exec files * @return this operation instance + * @see #execFiles(Collection) */ public JacocoReportOperation execFiles(File... execFiles) { - execFiles_.addAll(List.of(execFiles)); - return this; + return execFiles(List.of(execFiles)); } /** @@ -218,10 +271,10 @@ public JacocoReportOperation execFiles(File... execFiles) { * * @param execFiles the exec files * @return this operation instance + * @see #execFilesStrings(Collection) */ public JacocoReportOperation execFiles(String... execFiles) { - execFiles_.addAll(Arrays.stream(execFiles).map(File::new).toList()); - return this; + return execFilesStrings(List.of(execFiles)); } /** @@ -229,6 +282,18 @@ public JacocoReportOperation execFiles(String... execFiles) { * * @param execFiles the exec files * @return this operation instance + * @see #execFilesPaths(Collection) + */ + public JacocoReportOperation execFiles(Path... execFiles) { + return execFilesPaths(List.of(execFiles)); + } + + /** + * Sets the locations of the JaCoCo *.exec files to read. + * + * @param execFiles the exec files + * @return this operation instance + * @see #execFiles(File...) */ public JacocoReportOperation execFiles(Collection execFiles) { execFiles_.addAll(execFiles); @@ -244,6 +309,28 @@ public Collection execFiles() { return execFiles_; } + /** + * Sets the locations of the JaCoCo *.exec files to read. + * + * @param execFiles the exec files + * @return this operation instance + * @see #execFiles(Path...) + */ + public JacocoReportOperation execFilesPaths(Collection execFiles) { + return execFiles(execFiles.stream().map(Path::toFile).toList()); + } + + /** + * Sets the locations of the JaCoCo *.exec files to read. + * + * @param execFiles the exec files + * @return this operation instance + * @see #execFiles(String...) + */ + public JacocoReportOperation execFilesStrings(Collection execFiles) { + return execFiles(execFiles.stream().map(File::new).toList()); + } + /** * Performs the operation execution that can be wrapped by the {@code #executeOnce} call. */ @@ -343,6 +430,16 @@ public JacocoReportOperation html(String html) { return html(new File(html)); } + /** + * Sets the location of the HTML report. + * + * @param html the html + * @return this operation instance + */ + public JacocoReportOperation html(Path html) { + return html(html.toFile()); + } + private ExecFileLoader loadExecFiles() throws IOException { var loader = new ExecFileLoader(); if (execFiles_.isEmpty() && LOGGER.isLoggable(Level.WARNING) && !silent()) { @@ -407,10 +504,10 @@ private IReportVisitor reportVisitor() throws IOException { * * @param sourceFiles the source files * @return this operation instance + * @see #sourceFiles(Collection) */ public JacocoReportOperation sourceFiles(File... sourceFiles) { - sourceFiles_.addAll(List.of(sourceFiles)); - return this; + return sourceFiles(List.of(sourceFiles)); } /** @@ -418,10 +515,21 @@ public JacocoReportOperation sourceFiles(File... sourceFiles) { * * @param sourceFiles the source files * @return this operation instance + * @see #sourceFilesStrings(Collection) */ public JacocoReportOperation sourceFiles(String... sourceFiles) { - sourceFiles_.addAll(Arrays.stream(sourceFiles).map(File::new).toList()); - return this; + return sourceFilesStrings(List.of(sourceFiles)); + } + + /** + * Sets the locations of the source files. (e.g., {@code src/main/java}) + * + * @param sourceFiles the source files + * @return this operation instance + * @see #sourceFilesPaths(Collection) + */ + public JacocoReportOperation sourceFiles(Path... sourceFiles) { + return sourceFilesPaths(List.of(sourceFiles)); } /** @@ -429,6 +537,7 @@ public JacocoReportOperation sourceFiles(String... sourceFiles) { * * @param sourceFiles the source files * @return this operation instance + * @see #sourceFiles(File...) */ public JacocoReportOperation sourceFiles(Collection sourceFiles) { sourceFiles_.addAll(sourceFiles); @@ -444,6 +553,28 @@ public Collection sourceFiles() { return sourceFiles_; } + /** + * Sets the locations of the source files. (e.g., {@code src/main/java}) + * + * @param sourceFiles the source files + * @return this operation instance + * @see #sourceFiles(Path...) + */ + public JacocoReportOperation sourceFilesPaths(Collection sourceFiles) { + return sourceFiles(sourceFiles.stream().map(Path::toFile).toList()); + } + + /** + * Sets the locations of the source files. (e.g., {@code src/main/java}) + * + * @param sourceFiles the source files + * @return this operation instance + * @see #sourceFiles(String...) + */ + public JacocoReportOperation sourceFilesStrings(Collection sourceFiles) { + return sourceFiles(sourceFiles.stream().map(File::new).toList()); + } + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private ISourceFileLocator sourceLocator() { var multi = new MultiSourceFileLocator(tabWidth_); @@ -502,4 +633,14 @@ public JacocoReportOperation xml(File xml) { public JacocoReportOperation xml(String xml) { return xml(new File(xml)); } + + /** + * Sets the location of the XML report. + * + * @param xml the report location + * @return this operation instance + */ + public JacocoReportOperation xml(Path xml) { + return xml(xml.toFile()); + } } diff --git a/src/test/java/rife/bld/extension/JacocoReportOperationTest.java b/src/test/java/rife/bld/extension/JacocoReportOperationTest.java index 66e66df..3deadf3 100644 --- a/src/test/java/rife/bld/extension/JacocoReportOperationTest.java +++ b/src/test/java/rife/bld/extension/JacocoReportOperationTest.java @@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +@SuppressWarnings("PMD.AvoidDuplicateLiterals") class JacocoReportOperationTest { final File csv; final File html; @@ -109,4 +110,94 @@ JacocoReportOperation newJacocoReportOperation() { return op; } + + @Test + void testClassFiles() { + var foo = new File("foo"); + var bar = new File("bar"); + + var op = new JacocoReportOperation().classFiles("foo", "bar"); + assertThat(op.classFiles()).as("String...").contains(foo, bar); + op.classFiles().clear(); + + op = op.classFiles(foo, bar); + assertThat(op.classFiles()).as("File...").contains(foo, bar); + op.classFiles().clear(); + + op = op.classFiles(foo.toPath(), bar.toPath()); + assertThat(op.classFiles()).as("Path...").contains(foo, bar); + op.classFiles().clear(); + + op = op.classFilesStrings(List.of("foo", "bar")); + assertThat(op.classFiles()).as("List(String...)").contains(foo, bar); + op.classFiles().clear(); + + op = op.classFiles(List.of(foo, bar)); + assertThat(op.classFiles()).as("File...").contains(foo, bar); + op.classFiles().clear(); + + op = op.classFilesPaths(List.of(foo.toPath(), bar.toPath())); + assertThat(op.classFiles()).as("Path...").contains(foo, bar); + op.classFiles().clear(); + } + + @Test + void testExecFiles() { + var foo = new File("foo"); + var bar = new File("bar"); + + var op = new JacocoReportOperation().execFiles("foo", "bar"); + assertThat(op.execFiles()).as("String...").contains(foo, bar); + op.execFiles().clear(); + + op = op.execFiles(foo, bar); + assertThat(op.execFiles()).as("File...").contains(foo, bar); + op.execFiles().clear(); + + op = op.execFiles(foo.toPath(), bar.toPath()); + assertThat(op.execFiles()).as("Path...").contains(foo, bar); + op.execFiles().clear(); + + op = op.execFilesStrings(List.of("foo", "bar")); + assertThat(op.execFiles()).as("List(String...)").contains(foo, bar); + op.execFiles().clear(); + + op = op.execFiles(List.of(foo, bar)); + assertThat(op.execFiles()).as("File...").contains(foo, bar); + op.execFiles().clear(); + + op = op.execFilesPaths(List.of(foo.toPath(), bar.toPath())); + assertThat(op.execFiles()).as("Path...").contains(foo, bar); + op.execFiles().clear(); + } + + @Test + void testSourceFiles() { + var foo = new File("foo"); + var bar = new File("bar"); + + var op = new JacocoReportOperation().sourceFiles("foo", "bar"); + assertThat(op.sourceFiles()).as("String...").contains(foo, bar); + op.sourceFiles().clear(); + + op = op.sourceFiles(foo, bar); + assertThat(op.sourceFiles()).as("File...").contains(foo, bar); + op.sourceFiles().clear(); + + op = op.sourceFiles(foo.toPath(), bar.toPath()); + assertThat(op.sourceFiles()).as("Path...").contains(foo, bar); + op.sourceFiles().clear(); + + op = op.sourceFilesStrings(List.of("foo", "bar")); + assertThat(op.sourceFiles()).as("List(String...)").contains(foo, bar); + op.sourceFiles().clear(); + + op = op.sourceFiles(List.of(foo, bar)); + assertThat(op.sourceFiles()).as("File...").contains(foo, bar); + op.sourceFiles().clear(); + + op = op.sourceFilesPaths(List.of(foo.toPath(), bar.toPath())); + assertThat(op.sourceFiles()).as("Path...").contains(foo, bar); + op.sourceFiles().clear(); + } }