|
13 | 13 | import com.github.jknack.handlebars.Helper;
|
14 | 14 | import com.github.jknack.handlebars.Template;
|
15 | 15 | import java.io.File;
|
16 |
| -import java.io.FileNotFoundException; |
17 | 16 | import java.io.IOException;
|
18 | 17 | import java.io.StringWriter;
|
19 | 18 | import java.io.Writer;
|
20 |
| -import java.net.URISyntaxException; |
21 | 19 | import java.net.URL;
|
22 |
| -import java.nio.charset.StandardCharsets; |
23 | 20 | import java.nio.file.Files;
|
24 |
| -import java.nio.file.Path; |
25 |
| -import java.nio.file.Paths; |
26 | 21 | import java.text.SimpleDateFormat;
|
27 | 22 | import java.util.Date;
|
28 | 23 | import java.util.List;
|
|
47 | 42 | import se.bjurr.gitchangelog.internal.semantic.SemanticVersioning;
|
48 | 43 | import se.bjurr.gitchangelog.internal.settings.Settings;
|
49 | 44 | import se.bjurr.gitchangelog.internal.settings.SettingsIssue;
|
| 45 | +import se.bjurr.gitchangelog.internal.util.ResourceLoader; |
50 | 46 |
|
51 | 47 | public class GitChangelogApi {
|
52 | 48 |
|
@@ -127,28 +123,8 @@ public String getTemplateString() {
|
127 | 123 | if (this.templateContent != null) {
|
128 | 124 | return this.templateContent;
|
129 | 125 | }
|
130 |
| - String templateString = null; |
131 |
| - try { |
132 |
| - byte[] templateBytes = null; |
133 |
| - final Path templatePath = Paths.get(this.settings.getTemplatePath()); |
134 |
| - if (templatePath.toFile().exists()) { |
135 |
| - templateBytes = Files.readAllBytes(templatePath); |
136 |
| - } else { |
137 |
| - URL templateUrl = GitChangelogApi.class.getResource(this.settings.getTemplatePath()); |
138 |
| - if (templateUrl == null) { |
139 |
| - templateUrl = GitChangelogApi.class.getResource("/" + this.settings.getTemplatePath()); |
140 |
| - if (templateUrl == null) { |
141 |
| - throw new FileNotFoundException( |
142 |
| - "Was unable to find file, or resouce, \"" + this.settings.getTemplatePath() + "\""); |
143 |
| - } |
144 |
| - } |
145 |
| - templateBytes = Files.readAllBytes(Paths.get(templateUrl.toURI())); |
146 |
| - templateString = new String(templateBytes, StandardCharsets.UTF_8); |
147 |
| - } |
148 |
| - } catch (final IOException | URISyntaxException e) { |
149 |
| - throw new RuntimeException(this.settings.getTemplatePath(), e); |
150 |
| - } |
151 |
| - return templateString; |
| 126 | + final String resourceName = this.settings.getTemplatePath(); |
| 127 | + return ResourceLoader.getResourceOrFile(resourceName); |
152 | 128 | }
|
153 | 129 |
|
154 | 130 | static boolean shouldUseIntegrationIfConfigured(final String templateContent) {
|
|
0 commit comments