Cleaned up API to match bld operations aand options APIs

This commit is contained in:
Erik C. Thauvin 2024-08-28 10:43:07 -07:00
parent 06a6777e7a
commit cdcf900767
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 246 additions and 14 deletions

View file

@ -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

View file

@ -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;

View file

@ -35,7 +35,6 @@ import java.io.IOException;
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 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @param classFiles the class files
* @return this operation instance
* @see #classFiles(File...)
*/
public JacocoReportOperation classFiles(Collection<File> 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<Path> 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<String> classFiles) {
return classFiles(classFiles.stream().map(File::new).toList());
}
/**
* Sets the location of the CSV report.
*
@ -169,6 +203,15 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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<File> execFiles) {
execFiles_.addAll(execFiles);
@ -244,6 +309,28 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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<Path> 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<String> 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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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,10 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @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));
}
/**
@ -429,6 +526,18 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*
* @param sourceFiles the source files
* @return this operation instance
* @see #sourceFilesPaths(Collection)
*/
public JacocoReportOperation sourceFiles(Path... sourceFiles) {
return sourceFilesPaths(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 #sourceFiles(File...)
*/
public JacocoReportOperation sourceFiles(Collection<File> sourceFiles) {
sourceFiles_.addAll(sourceFiles);
@ -444,6 +553,28 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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<Path> 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<String> 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 class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
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());
}
}

View file

@ -31,6 +31,7 @@ import java.util.Objects;
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 @@ class JacocoReportOperationTest {
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();
}
}