Cleanup.
This commit is contained in:
parent
06263ee003
commit
cd10d5325a
12 changed files with 50 additions and 121 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* This file is automatically generated.
|
||||
* Do not modify! -- ALL CHANGES WILL BE ERASED!
|
||||
*/
|
||||
|
||||
package {{packageName}}
|
||||
|
||||
import java.util.Date
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue