Skip to content

Commit 7b3f34f

Browse files
author
TheSnoozer
committed
make the PropertiesOutputFormat an Enum
1 parent 295e2f2 commit 7b3f34f

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of git-commit-id-plugin-core by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
3+
*
4+
* git-commit-id-plugin-core is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* git-commit-id-plugin-core is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with git-commit-id-plugin-core. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package pl.project13.core;
19+
20+
/**
21+
* An enum to indicate in what format the {@code generateGitPropertiesFilename} should be generated.
22+
*/
23+
public enum CommitIdPropertiesOutputFormat {
24+
/**
25+
* Indicator to generate a properties file.
26+
*
27+
*/
28+
PROPERTIES,
29+
/**
30+
* Indicator to generate a json file.
31+
*/
32+
JSON,
33+
}

src/main/java/pl/project13/core/GitCommitIdPlugin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ default Map<String, String> getSystemEnv() {
248248
void performPropertiesReplacement(Properties properties);
249249

250250
/**
251-
* @return The output format of the generated properties file. Can either be "properties" or "json".
251+
* @return The output format of the generated properties file.
252252
*/
253-
// TODO: Why is this a String and not an enum?
254-
String getPropertiesOutputFormat();
253+
CommitIdPropertiesOutputFormat getPropertiesOutputFormat();
255254

256255
/**
257256
* @return The BuildFileChangeListener that will be called when an output file of the plugin has changed

src/main/java/pl/project13/core/PropertiesFileGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ public class PropertiesFileGenerator {
3434

3535
private LogInterface log;
3636
private BuildFileChangeListener buildFileChangeListener;
37-
private String format;
37+
private CommitIdPropertiesOutputFormat propertiesOutputFormat;
3838
private String prefixDot;
3939
private String projectName;
4040

41-
public PropertiesFileGenerator(LogInterface log, BuildFileChangeListener buildFileChangeListener, String format, String prefixDot, String projectName) {
41+
public PropertiesFileGenerator(LogInterface log, BuildFileChangeListener buildFileChangeListener, CommitIdPropertiesOutputFormat propertiesOutputFormat, String prefixDot, String projectName) {
4242
this.log = log;
4343
this.buildFileChangeListener = buildFileChangeListener;
44-
this.format = format;
44+
this.propertiesOutputFormat = propertiesOutputFormat;
4545
this.prefixDot = prefixDot;
4646
this.projectName = projectName;
4747
}
4848

4949
public void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, File base, String propertiesFilename, Charset sourceCharset, boolean escapeUnicode) throws GitCommitIdExecutionException {
5050
try {
5151
final File gitPropsFile = craftPropertiesOutputFile(base, propertiesFilename);
52-
final boolean isJsonFormat = "json".equalsIgnoreCase(format);
52+
final boolean isJsonFormat = CommitIdPropertiesOutputFormat.JSON.equals(propertiesOutputFormat);
5353

5454
boolean shouldGenerate = true;
5555

src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public void shouldGenerateCustomPropertiesFileJson(boolean useNativeGit) throws
450450
.setUseNativeGit(useNativeGit)
451451
.setShouldGenerateGitPropertiesFile(true)
452452
.setGenerateGitPropertiesFilename(targetFilePath.getCanonicalPath())
453-
.setPropertiesOutputFormat("json")
453+
.setPropertiesOutputFormat(CommitIdPropertiesOutputFormat.JSON)
454454
.build();
455455
Properties properties = new Properties();
456456

src/test/java/pl/project13/core/GitCommitIdTestCallback.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class GitCommitIdTestCallback {
5151
private String evaluateOnCommit = "HEAD";
5252
private File dotGitDirectory;
5353
private boolean shouldGenerateGitPropertiesFile = false;
54-
private String propertiesOutputFormat = "properties";
54+
private CommitIdPropertiesOutputFormat propertiesOutputFormat = CommitIdPropertiesOutputFormat.PROPERTIES;
5555
private String projectName = "dummy-project";
5656
private File projectBaseDir;
5757
private String generateGitPropertiesFilename = "src/main/resources/git.properties";
@@ -161,7 +161,7 @@ public GitCommitIdTestCallback setShouldGenerateGitPropertiesFile(boolean should
161161
return this;
162162
}
163163

164-
public GitCommitIdTestCallback setPropertiesOutputFormat(String propertiesOutputFormat) {
164+
public GitCommitIdTestCallback setPropertiesOutputFormat(CommitIdPropertiesOutputFormat propertiesOutputFormat) {
165165
this.propertiesOutputFormat = propertiesOutputFormat;
166166
return this;
167167
}
@@ -304,7 +304,7 @@ public void performPropertiesReplacement(Properties properties) {
304304
}
305305

306306
@Override
307-
public String getPropertiesOutputFormat() {
307+
public CommitIdPropertiesOutputFormat getPropertiesOutputFormat() {
308308
return propertiesOutputFormat;
309309
}
310310

src/test/java/pl/project13/core/PropertiesFileGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setUp() {
4646
// Ignore
4747
};
4848

49-
propertiesFileGenerator = new PropertiesFileGenerator(logInterface, buildFileChangeListener, "properties", "", "test");
49+
propertiesFileGenerator = new PropertiesFileGenerator(logInterface, buildFileChangeListener, CommitIdPropertiesOutputFormat.PROPERTIES, "", "test");
5050
}
5151

5252
@Test

0 commit comments

Comments
 (0)