This commit is contained in:
Erik C. Thauvin 2019-04-23 15:47:03 -07:00
parent 06263ee003
commit cd10d5325a
12 changed files with 50 additions and 121 deletions

View file

@ -6,7 +6,7 @@
<compilerSettings />
<compilerArguments>
<option name="destination" value="$MODULE_DIR$/../../examples/kotlin/build/classes/kotlin/main" />
<option name="classpath" value="$MAVEN_REPOSITORY$/net/thauvin/erik/semver/1.1.1/semver-1.1.1.jar;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.21/4bcc2012b84840e19e1e28074284cac908be0295/kotlin-stdlib-1.3.21.jar;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.21/f30e4a9897913e53d778f564110bafa1fef46643/kotlin-stdlib-common-1.3.21.jar;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar" />
<option name="classpath" value="$MAVEN_REPOSITORY$/net/thauvin/erik/semver/1.2.0/semver-1.2.0.jar;K:/maven/repository/org/jetbrains/kotlin/kotlin-stdlib/1.3.30/kotlin-stdlib-1.3.30.jar;K:/maven/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.30/kotlin-stdlib-common-1.3.30.jar;K:/maven/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar" />
<option name="noStdlib" value="true" />
<option name="noReflect" value="true" />
<option name="moduleName" value="examples-kotlin" />

View file

@ -6,7 +6,7 @@
<compilerSettings />
<compilerArguments>
<option name="destination" value="$MODULE_DIR$/../../examples/kotlin/build/classes/kotlin/test" />
<option name="classpath" value="$MODULE_DIR$/../../examples/kotlin/build/classes/java/main;K:/java/semver/examples/kotlin/build/classes/kotlin/main;K:/java/semver/examples/kotlin/build/tmp/kapt3/classes/main;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.21/4bcc2012b84840e19e1e28074284cac908be0295/kotlin-stdlib-1.3.21.jar;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.21/f30e4a9897913e53d778f564110bafa1fef46643/kotlin-stdlib-common-1.3.21.jar;C:/Users/erik/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar" />
<option name="classpath" value="$MODULE_DIR$/../../examples/kotlin/build/classes/java/main;K:/java/semver/examples/kotlin/build/classes/kotlin/main;K:/java/semver/examples/kotlin/build/tmp/kapt3/classes/main;K:/maven/repository/org/jetbrains/kotlin/kotlin-stdlib/1.3.30/kotlin-stdlib-1.3.30.jar;K:/maven/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.30/kotlin-stdlib-common-1.3.30.jar;K:/maven/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar" />
<option name="noStdlib" value="true" />
<option name="noReflect" value="true" />
<option name="moduleName" value="examples-kotlin" />

View file

@ -42,7 +42,11 @@ dependencies {
implementation 'com.github.spullara.mustache.java:compiler:0.9.6'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.11'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3.sb'
compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.12'
testCompileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.12'
testImplementation 'org.testng:testng:6.14.3'
}
@ -156,14 +160,6 @@ tasks.withType(Checkstyle) {
}
}
compileJava {
options.compilerArgs.add('-proc:none')
}
compileTestJava {
options.compilerArgs.add('-proc:none')
}
bintrayUpload {
versionName = "$project.version"
versionDesc = "version $project.version"

View file

@ -2,19 +2,20 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
package {{packageName}};
import java.util.Date;
public final class {{className}} {
public final static String PROJECT = "{{project}}";
public final static Date BUILDDATE = new Date({{epoch}}L);
public final static int MAJOR = {{major}};
public final static int MINOR = {{minor}};
public final static int PATCH = {{patch}};
public final static String PRERELEASE = "{{preRelease}}";
public final static String BUILDMETA = "{{buildMeta}}";
public final static String VERSION = "{{version}}";
public static final String PROJECT = "{{project}}";
public static final Date BUILDDATE = new Date({{epoch}}L);
public static final int MAJOR = {{major}};
public static final int MINOR = {{minor}};
public static final int PATCH = {{patch}};
public static final String PRERELEASE = "{{preRelease}}";
public static final String BUILDMETA = "{{buildMeta}}";
public static final String VERSION = "{{version}}";
/**
* Disables the default constructor.

View file

@ -6,95 +6,20 @@ package com.example;
import java.util.Date;
/**
* Provides semantic version information.
*
* @author <a href="https://github.com/ethauvin/semver">Semantic Version Annotation Processor</a>
*/
public final class GeneratedVersion {
public final static String PROJECT = "Example";
public final static Date BUILDDATE = new Date(1554108013631L);
public final static String PROJECT = "Java Example";
public final static Date BUILDDATE = new Date(1555703771370L);
public final static int MAJOR = 2;
public final static int MINOR = 0;
public final static int PATCH = 52;
public final static String PRERELEASE = "beta";
public final static String PRERELEASE_PREFIX = "-";
public final static String BUILDMETA = "007";
public final static String BUILDMETA_PREFIX = "+";
public final static String SEPARATOR = "";
/**
* The full version string.
* <p>
* Formatted as:
* <blockquote>
* <code>[MAJOR][SEPARATOR][MINOR][SEPARATOR][PATCH][[PRERELEASE_PREFIX][PRERELEASE]][[BUILDMETA_PREFIX][BUILDMETA]]</code>
* </blockquote>
* <p>
* For example:
* <ul>
* <li><code>1.0.0</code></li>
* <li><code>1.0.0-beta</code></li>
* <li><code>1.0.0+20160124144700</code></li>
* <li><code>1.0.0-alpha+001</code></li>
* </ul>
*/
public final static String VERSION = Integer.toString(MAJOR) + SEPARATOR + Integer.toString(MINOR) + SEPARATOR
+ Integer.toString(PATCH) + preReleaseWithPrefix() + buildMetaWithPrefix();
public final static String VERSION = "2.0.52-beta+007";
/**
* Disables the default constructor.
*
* @throws UnsupportedOperationException If the constructor is called.
*/
private GeneratedVersion()
throws UnsupportedOperationException {
private GeneratedVersion() {
throw new UnsupportedOperationException("Illegal constructor call.");
}
/**
* Returns the build metadata with {@value #BUILDMETA_PREFIX} prefix.
*
* @return The build metadata, if any.
*/
public static String buildMetaWithPrefix() {
return buildMetaWithPrefix(BUILDMETA_PREFIX);
}
/**
* Returns the build metadata.
*
* @param prefix Prefix to prepend.
* @return The build metadata, if any.
*/
public static String buildMetaWithPrefix(final String prefix) {
if (BUILDMETA.length() > 0) {
return prefix + BUILDMETA;
} else {
return BUILDMETA;
}
}
/**
* Returns the pre-release version with {@value #PRERELEASE_PREFIX} prefix.
*
* @return The pre-release version, if any.
*/
public static String preReleaseWithPrefix() {
return preReleaseWithPrefix(PRERELEASE_PREFIX);
}
/**
* Returns the pre-release version.
*
* @param prefix The prefix to prepend.
* @return The pre-release version, if any.
*/
public static String preReleaseWithPrefix(final String prefix) {
if (PRERELEASE.length() > 0) {
return prefix + PRERELEASE;
} else {
return PRERELEASE;
}
}
}

View file

@ -11,7 +11,7 @@ plugins {
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
var semverProcessor = "net.thauvin.erik:semver:1.1.1"
var semverProcessor = "net.thauvin.erik:semver:1.2.0"
dependencies {
kapt(semverProcessor)

View file

@ -2,6 +2,7 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
package {{packageName}}
import java.util.Date

View file

@ -52,14 +52,13 @@ import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@ -85,7 +84,7 @@ public class VersionProcessor extends AbstractProcessor {
log(Diagnostic.Kind.ERROR, (t != null ? t.toString() : s));
}
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN")
@SuppressFBWarnings(value = {"PATH_TRAVERSAL_IN", "UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH"})
private VersionInfo findValues(final Version version)
throws IOException {
final VersionInfo versionInfo = new VersionInfo(version);
@ -98,7 +97,7 @@ public class VersionProcessor extends AbstractProcessor {
final Properties p = new Properties();
try (final InputStreamReader reader =
new InputStreamReader(new FileInputStream(propsFile), StandardCharsets.UTF_8)) {
new InputStreamReader(Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
p.load(reader);
versionInfo.setProject(
@ -210,16 +209,16 @@ public class VersionProcessor extends AbstractProcessor {
final PackageElement packageElement = (PackageElement) enclosingElement;
try {
final VersionInfo versionInfo = findValues(version);
if (version.packageName().equals(Constants.EMPTY)) {
if (Constants.EMPTY.equals(version.packageName())) {
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
}
note("Found version: " + versionInfo.getVersion());
final String template;
if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE)
if (Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template())
&& new File(Constants.DEFAULT_TEMPLATE_NAME).exists()) {
template = Constants.DEFAULT_TEMPLATE_NAME;
} else if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE)
&& version.type().equals(Constants.KOTLIN_TYPE)) {
} else if (Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template())
&& Constants.KOTLIN_TYPE.equals(version.type())) {
template = Constants.DEFAULT_KOTLIN_TEMPLATE;
} else {
template = version.template();
@ -239,7 +238,7 @@ public class VersionProcessor extends AbstractProcessor {
log(Diagnostic.Kind.WARNING, s);
}
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN")
@SuppressFBWarnings(value = {"PATH_TRAVERSAL_IN", "UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH"})
private void writeTemplate(final String type,
final VersionInfo versionInfo,
final String template)
@ -263,7 +262,7 @@ public class VersionProcessor extends AbstractProcessor {
note("Loaded template: " + templateName);
final String fileName = versionInfo.getClassName() + '.' + type;
if (type.equalsIgnoreCase(Constants.KOTLIN_TYPE)) {
if (Constants.KOTLIN_TYPE.equalsIgnoreCase(type)) {
final String kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
if (kaptGenDir == null) {
throw new IOException("Could not find the target directory for generated Kotlin files.");
@ -272,7 +271,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(new FileOutputStream(ktFile),
try (final OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
StandardCharsets.UTF_8)) {
mustache.execute(osw, versionInfo).flush();
}

View file

@ -2,6 +2,7 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
package {{packageName}}
import java.util.Date

View file

@ -2,6 +2,7 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
package {{packageName}};
import java.util.Date;
@ -12,17 +13,17 @@ import java.util.Date;
* @author <a href="https://github.com/ethauvin/semver">Semantic Version Annotation Processor</a>
*/
public final class {{className}} {
public final static String PROJECT = "{{project}}";
public final static Date BUILDDATE = new Date({{epoch}}L);
public final static int MAJOR = {{major}};
public final static int MINOR = {{minor}};
public final static int PATCH = {{patch}};
public final static String PRERELEASE = "{{preRelease}}";
public final static String PRERELEASE_PREFIX = "{{preReleasePrefix}}";
public final static String BUILDMETA = "{{buildMeta}}";
public final static String BUILDMETA_PREFIX = "{{buildMetaPrefix}}";
public final static String SEPARATOR = "{{separator}}";
public final static String VERSION = "{{version}}";
public static final String PROJECT = "{{project}}";
public static final Date BUILDDATE = new Date({{epoch}}L);
public static final int MAJOR = {{major}};
public static final int MINOR = {{minor}};
public static final int PATCH = {{patch}};
public static final String PRERELEASE = "{{preRelease}}";
public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}";
public static final String BUILDMETA = "{{buildMeta}}";
public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}";
public static final String SEPARATOR = "{{separator}}";
public static final String VERSION = "{{version}}";
/**
* Disables the default constructor.

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.semver;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.testng.Assert;
import org.testng.annotations.Test;
@ -44,6 +45,7 @@ import java.util.Calendar;
* @created 2016-02-03
* @since 1.0
*/
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public class VersionInfoTest {
private final Calendar now = Calendar.getInstance();
private VersionInfo versionInfo = new VersionInfo();

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.semver;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.testng.Assert;
import org.testng.annotations.Test;
@ -50,6 +51,7 @@ public class VersionProcessorTest {
private final VersionProcessor processor = new VersionProcessor();
private final Version version = new VersionTest();
@SuppressFBWarnings("RFI_SET_ACCESSIBLE")
@Test
public void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Method method = processor.getClass().getDeclaredMethod("findValues", Version.class);
@ -60,6 +62,7 @@ public class VersionProcessorTest {
Assert.assertEquals(versionInfo.getProject(), "James Bond", "getProject(James Bond)");
}
@SuppressFBWarnings("RFI_SET_ACCESSIBLE")
@Test
public void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Properties p = new Properties();