Skip to content

Commit

Permalink
Cleaned up API to match bld operations aand options APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 28, 2024
1 parent 06a6777 commit cdcf900
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
163 changes: 152 additions & 11 deletions src/main/java/rife/bld/extension/JacocoReportOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}

/**
Expand All @@ -142,12 +153,35 @@ public Collection<File> classFiles() {
*
* @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.
*
Expand All @@ -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.
Expand All @@ -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.
*
Expand All @@ -207,28 +260,40 @@ 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));
}

/**
* Sets the locations of the JaCoCo *.exec files to read.
*
* @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));
}

/**
* Sets the locations of the JaCoCo *.exec files to read.
*
* @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);
Expand All @@ -244,6 +309,28 @@ public Collection<File> 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<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.
*/
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -407,28 +504,40 @@ 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));
}

/**
* Sets the locations of the source files. (e.g., {@code src/main/java})
*
* @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));
}

/**
* 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);
Expand All @@ -444,6 +553,28 @@ public Collection<File> 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<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_);
Expand Down Expand Up @@ -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());
}
}
Loading

0 comments on commit cdcf900

Please sign in to comment.