diff --git a/.idea/misc.xml b/.idea/misc.xml index 542659b..61cdf16 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,12 @@ + + + + + + + diff --git a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java index 5f65a23..3ffd457 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java +++ b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java @@ -78,9 +78,20 @@ public class VersionProcessor extends AbstractProcessor { return template; } - private Mustache compileTemplate(final File dir, final String template) { - final var mf = new DefaultMustacheFactory(dir); - return mf.compile(template); + private Mustache compileTemplate(final File dir, final String template) throws IOException { + if (Constants.DEFAULT_JAVA_TEMPLATE.equals(template) || Constants.DEFAULT_KOTLIN_TEMPLATE.equals(template)) { + try (var in = getClass().getResourceAsStream("/" + template)) { + if (in != null) { + try (var reader = new BufferedReader(new InputStreamReader(in))) { + return new DefaultMustacheFactory().compile(reader, template); + } + } else { + throw new IOException("Resource not found: " + template); + } + } + } else { + return new DefaultMustacheFactory(dir).compile(template); + } } private void error(final String s) { @@ -237,7 +248,7 @@ public class VersionProcessor extends AbstractProcessor { private void writeTemplate(final String type, final VersionInfo versionInfo, final String template) throws IOException { final var dir = getLocalFile(""); - final var mustache = compileTemplate(dir, template); + final Mustache mustache = compileTemplate(dir, template); final var templateName = switch (mustache.getName()) { case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)"; diff --git a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java index 8a68def..f1a457e 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java @@ -74,11 +74,11 @@ class VersionProcessorTest { * This file is automatically generated. * Do not modify! -- ALL CHANGES WILL BE ERASED! */ - + package %s; - + import java.util.Date; - + /** * Provides semantic version information. * @@ -96,7 +96,7 @@ class VersionProcessorTest { public static final String BUILDMETA_PREFIX = "%s"; public static final String SEPARATOR = "%s"; public static final String VERSION = ""; - + /** * Disables the default constructor. */