Initial commit

This commit is contained in:
Erik C. Thauvin 2023-04-30 14:27:22 -07:00
commit 57b0fa5b55
26 changed files with 860 additions and 0 deletions

View file

@ -0,0 +1,93 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension;
import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.dependencies.VersionNumber;
import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishLicense;
import rife.bld.publish.PublishScm;
import java.util.List;
import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.*;
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
public class JacocoReportOperationBuild extends Project {
public JacocoReportOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-jacoco-report";
version = version(0, 9, 0, "SNAPSHOT");
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
var jacocoVersion = new VersionNumber(0, 8, 10);
scope(compile)
.include(dependency("org.jacoco", "jacoco", jacocoVersion))
.include(dependency("com.uwyn.rife2", "rife2", version(1, 6, 1)));
scope(runtime)
.include(dependency("org.jacoco", "jacoco", jacocoVersion));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 9, 2)))
.include(dependency("org.assertj:assertj-joda-time:2.2.0"));
testOperation().mainClass("rife.bld.extension.JacocoReportOperationTest");
javadocOperation()
.javadocOptions()
.docLint(NO_MISSING)
.link("https://rife2.github.io/rife2/");
publishOperation()
.repository(MAVEN_LOCAL)
// .repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
.info()
.groupId("com.uwyn.rife2")
.artifactId("bld-jacoco-report")
.description("bld Extension to Generate JaCoCo Reports")
.url("https://github.com/rife2/bld-pmd")
.developer(new PublishDeveloper().id("ethauvin").name("Erik C. Thauvin").email("erik@thauvin.net")
.url("https://erik.thauvin.net/"))
.license(new PublishLicense().name("The Apache License, Version 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
.scm(new PublishScm().connection("scm:git:https://github.com/rife2/bld-pmd.git")
.developerConnection("scm:git:git@github.com:rife2/bld-pmd.git")
.url("https://github.com/rife2/bld-pmd"))
.signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase"));
}
public static void main(String[] args) {
new JacocoReportOperationBuild().start(args);
}
@BuildCommand(summary = "Runs PMD analysis")
public void pmd() throws Exception {
new PmdOperation()
.fromProject(this)
.failOnViolation(true)
.ruleSets("config/pmd.xml")
.execute();
}
}

View file

@ -0,0 +1,177 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension;
import rife.bld.BaseProject;
import rife.bld.operations.AbstractOperation;
import rife.tools.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
/**
* Generates <a href="https://www.jacoco.org/jacoco">JaCoCo</a> reports.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class JacocoReportOperation extends AbstractOperation<JacocoReportOperation> {
private static final Logger LOGGER = Logger.getLogger(JacocoReportOperation.class.getName());
private final List<File> classFiles = new ArrayList<>();
private final List<File> execFiles = new ArrayList<>();
private final List<File> sourceFiles = new ArrayList<>();
private File csv;
private String encoding;
private File html;
private String name;
private BaseProject project;
private boolean quiet = false;
private int tabWidth = 4;
private File xml;
/**
* Set the locations of Java class files.
**/
public JacocoReportOperation classFiles(ArrayList<File> classFiles) {
this.classFiles.addAll(classFiles);
return this;
}
/**
* Sets the location of the CSV report.
*/
public JacocoReportOperation csv(File cvs) {
this.csv = cvs;
return this;
}
/**
* Sets the source file encoding. The platform encoding is used by default.
*/
public JacocoReportOperation encoding(String encoding) {
this.encoding = encoding;
return this;
}
/**
* Sets a list of JaCoCo *.exec files to read.
**/
public JacocoReportOperation execFiles(ArrayList<File> execFiles) {
this.execFiles.addAll(execFiles);
return this;
}
/**
* Performs the operation execution that can be wrapped by the {@code #executeOnce} call.
*
* @throws Exception when an exception occurs during the execution
* @since 1.5.10
*/
@Override
public void execute() throws Exception {
if (project == null && LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.severe("A project must be specified.");
} else {
if (execFiles.isEmpty()) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("No execution data files provided.");
}
}
if (sourceFiles.isEmpty()) {
sourceFiles.addAll(project.mainSourceFiles());
sourceFiles.addAll(project.testSourceFiles());
}
if (classFiles.isEmpty()) {
classFiles.addAll(getClassFiles(project.buildMainDirectory()));
classFiles.addAll(getClassFiles(project.buildTestDirectory()));
}
}
}
private List<File> getClassFiles(File directory) {
return FileUtils.getFileList(directory, Pattern.compile("^.*\\.class$"), null)
.stream().map(f -> new File(directory, f)).toList();
}
/**
* Configure the operation from a {@link BaseProject}.
*/
public JacocoReportOperation fromProject(BaseProject project) {
this.project = project;
return this;
}
public String getMessage() {
return "Hello World!";
}
/**
* Sets the location of the HTML report.
*/
public JacocoReportOperation html(File html) {
this.html = html;
return this;
}
/**
* Sets the name used for the report.
*/
public JacocoReportOperation name(String name) {
this.name = name;
return this;
}
/**
* Suppresses all output.
*/
public JacocoReportOperation quiet(boolean quiet) {
this.quiet = quiet;
return this;
}
/**
* Sets the locations of the source files.
**/
public JacocoReportOperation sourceFiles(ArrayList<File> sourceFiles) {
this.sourceFiles.addAll(sourceFiles);
return this;
}
/**
* Sets the tab stop width for the source pages. Default is {@code 4}.
*/
public JacocoReportOperation tabWidth(int tabWitdh) {
this.tabWidth = tabWitdh;
return this;
}
/**
* Sets the location of the XML report.
*/
public JacocoReportOperation xml(File xml) {
this.xml = xml;
return this;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension;
public class JacocoReportOperationTest {
void verifyHello() {
if (!"Hello World!".equals(new JacocoReportOperation().getMessage())) {
throw new AssertionError();
} else {
System.out.println("Succeeded");
}
}
public static void main(String[] args) {
new JacocoReportOperationTest().verifyHello();
}
}