diff --git a/README.md b/README.md index 9332eed..925e813 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Semantic Version Annotation Processor -[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![release](https://img.shields.io/github/release/ethauvin/semver.svg)](https://github.com/ethauvin/semver/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver)\ +[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![release](https://img.shields.io/github/release/ethauvin/semver.svg)](https://github.com/ethauvin/semver/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver) [![Known Vulnerabilities](https://snyk.io/test/github/ethauvin/semver/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/ethauvin/semver?targetFile=build.gradle) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_semver) [![GitHub CI](https://github.com/ethauvin/semver/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/semver/actions/workflows/gradle.yml) [![Build status](https://ci.appveyor.com/api/projects/status/nbv4mxd1gpxtx69o?svg=true)](https://ci.appveyor.com/project/ethauvin/semver) [![CircleCI](https://circleci.com/gh/ethauvin/semver/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/semver/tree/master) An [annotation processor](https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html) that automatically generates a `GeneratedVersion` class based on a [Mustache](https://mustache.github.io/) template and containing the [semantic version](http://semver.org/) (major, minor, patch, etc.) that is read from a [Properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file or defined in the [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html). diff --git a/build.gradle b/build.gradle index 8aad299..e3ad8c6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'maven-publish' id 'pmd' id 'signing' - id 'com.github.ben-manes.versions' version '0.38.0' + id 'com.github.ben-manes.versions' version '0.39.0' id 'net.thauvin.erik.gradle.semver' version '1.0.4' id 'com.github.spotbugs' version '4.7.1' id 'org.sonarqube' version '3.2.0' @@ -27,6 +27,7 @@ final def mavenScmCon = 'https://github.com/ethauvin/semver.git' final def mavenScmDevCon = 'git@github.com:ethauvin/semver.git' ext.versions = [ + pmd: '6.35.0', spotbugs: '4.2.3' ] @@ -36,7 +37,7 @@ repositories { } dependencies { - implementation 'com.github.spullara.mustache.java:compiler:0.9.7' + implementation 'com.github.spullara.mustache.java:compiler:0.9.10' spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0' spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.4.7' @@ -60,6 +61,7 @@ java { } pmd { + toolVersion = versions.pmd ignoreFailures = true ruleSets = [] ruleSetFiles = files("${projectDir}/config/pmd.xml") @@ -69,9 +71,9 @@ pmd { publishing { publications { mavenJava(MavenPublication) { - from components.java - groupId project.group - artifactId rootProject.name + from(components.java) + groupId = project.group + artifactId = rootProject.name pom { name = mavenName @@ -133,8 +135,8 @@ javadoc { test { testLogging { - exceptionFormat "full" - events "passed", "skipped", "failed" + exceptionFormat = "full" + events("passed", "skipped", "failed") } useTestNG() @@ -179,8 +181,8 @@ task pandoc(type: Exec) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) } else { - executable 'pandoc' - args pandoc_args + executable = 'pandoc' + args(pandoc_args) } standardOutput = new ByteArrayOutputStream() ext.output = { @@ -198,9 +200,9 @@ jacocoTestReport { sonarqube { properties { - property "sonar.organization", "ethauvin-github" - property "sonar.projectKey", "ethauvin_semver" - property "sonar.host.url", "https://sonarcloud.io" + property("sonar.organization", "ethauvin-github") + property("sonar.projectKey", "ethauvin_semver") + property("sonar.host.url", "https://sonarcloud.io") property("sonar.sourceEncoding", "UTF-8") } } diff --git a/config/pmd.xml b/config/pmd.xml index a3a25a4..890a490 100644 --- a/config/pmd.xml +++ b/config/pmd.xml @@ -5,109 +5,78 @@ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> Erik's Ruleset - - - - - - - - - + + + + + + + value="//MethodDeclaration[@Name='hashCode' or @Name='equals' or @Name='toString']"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + @@ -115,86 +84,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -202,59 +96,16 @@ - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + diff --git a/examples/kotlin/build.gradle.kts b/examples/kotlin/build.gradle.kts index 771cf48..cb842f0 100644 --- a/examples/kotlin/build.gradle.kts +++ b/examples/kotlin/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - kotlin("jvm").version("1.5.0") - application - id("org.jetbrains.kotlin.kapt").version("1.5.0") - id("com.github.ben-manes.versions").version("0.38.0") + id("application") + id("com.github.ben-manes.versions") version "0.39.0" + kotlin("jvm") version "1.5.10" + kotlin("kapt") version "1.5.10" } // ./gradlew diff --git a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java index fdb05cc..3e78f54 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java +++ b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java @@ -70,7 +70,7 @@ import java.util.Set; * @created 2016-01-13 * @since 1.0 */ -@SuppressWarnings("PMD.GuardLogStatement") +@SuppressWarnings({ "PMD.GuardLogStatement", "PMD.BeanMembersShouldSerialize"}) @SupportedOptions({Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME, Constants.SEMVER_PROJECT_DIR_ARG}) public class VersionProcessor extends AbstractProcessor { private Filer filer; @@ -82,7 +82,7 @@ public class VersionProcessor extends AbstractProcessor { } private void error(final String s, final Throwable t) { - log(Diagnostic.Kind.ERROR, (t != null ? t.toString() : s)); + log(Diagnostic.Kind.ERROR, t != null ? t.toString() : s); } @SuppressFBWarnings({"PATH_TRAVERSAL_IN", "UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH"}) @@ -96,7 +96,7 @@ public class VersionProcessor extends AbstractProcessor { final Properties p = new Properties(); - try (final InputStreamReader reader = new InputStreamReader( + try (InputStreamReader reader = new InputStreamReader( Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) { p.load(reader); @@ -268,7 +268,7 @@ public class VersionProcessor extends AbstractProcessor { if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) { note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath()); } - try (final OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()), + try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()), StandardCharsets.UTF_8)) { mustache.execute(osw, versionInfo).flush(); } @@ -276,7 +276,7 @@ public class VersionProcessor extends AbstractProcessor { } else { final FileObject jfo = filer.createSourceFile( versionInfo.getPackageName() + '.' + versionInfo.getClassName()); - try (final Writer writer = jfo.openWriter()) { + try (Writer writer = jfo.openWriter()) { mustache.execute(writer, versionInfo).flush(); } note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')'); diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java index 833d4d5..be01241 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -36,7 +36,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.testng.Assert; import org.testng.annotations.Test; -import java.util.Calendar; +import java.util.Date; import static org.testng.Assert.assertEquals; @@ -49,7 +49,6 @@ import static org.testng.Assert.assertEquals; */ @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") public class VersionInfoTest { - private final Calendar now = Calendar.getInstance(); private VersionInfo versionInfo = new VersionInfo(); @SuppressWarnings("PMD.AvoidUsingHardCodedIP") @@ -159,7 +158,7 @@ public class VersionInfoTest { assertEquals(versionInfo.getClassName(), "Example", "getClassName(Example"); - Assert.assertTrue((versionInfo.getEpoch() - now.getTimeInMillis()) < 1000, "buildDate - now < 1s"); + Assert.assertTrue((versionInfo.getEpoch() - new Date().getTime()) < 1000, "buildDate - now < 1s"); } @Test