3
3
import com .github .zafarkhaja .semver .Version ;
4
4
import io .jenkins .plugins .conventionalcommits .process .ProcessHelper ;
5
5
import java .io .BufferedReader ;
6
+ import java .io .BufferedWriter ;
6
7
import java .io .File ;
7
- import java .io .FileWriter ;
8
8
import java .io .IOException ;
9
+ import java .nio .charset .StandardCharsets ;
9
10
import java .nio .file .Files ;
10
11
import java .nio .file .Paths ;
11
12
import java .nio .file .StandardCopyOption ;
12
13
import java .util .Arrays ;
13
14
import java .util .List ;
14
15
import java .util .Objects ;
15
16
16
- /**
17
- * Represent a Gradle project type (i.e with a build.gradle file).
18
- */
17
+ /** Represent a Gradle project type (i.e with a build.gradle file). */
19
18
public class GradleProjectType extends ProjectType {
20
19
21
20
public boolean check (File directory ) {
@@ -50,13 +49,13 @@ public Version getCurrentVersion(File directory, ProcessHelper processHelper)
50
49
}
51
50
52
51
/**
53
- * Write the new calculated version in the build.gradle file.
54
- * If no version property is found, do nothing.
52
+ * Write the new calculated version in the build.gradle file. If no version property is found, do
53
+ * nothing.
55
54
*
56
- * @param directory The directory where find the build.gradle. <b>Mandatory</b>
57
- * @param nextVersion The next version to write. <b>Mandatory</b>
55
+ * @param directory The directory where find the build.gradle. <b>Mandatory</b>
56
+ * @param nextVersion The next version to write. <b>Mandatory</b>
58
57
* @param processHelper Not used.
59
- * @throws IOException If an error occurs when accessing to the build.gradle
58
+ * @throws java.io. IOException If an error occurs when accessing to the build.gradle
60
59
* @throws InterruptedException Not used.
61
60
*/
62
61
@ Override
@@ -77,7 +76,8 @@ public void writeVersion(File directory, Version nextVersion, ProcessHelper proc
77
76
String .format ("%s%sgradle.properties" , directory .getAbsolutePath (), File .separator );
78
77
79
78
try (BufferedReader reader = Files .newBufferedReader (Paths .get (buildPath ))) {
80
- try (FileWriter fw = new FileWriter (buildTempPath )) {
79
+ try (BufferedWriter fw =
80
+ Files .newBufferedWriter (Paths .get (buildTempPath ), StandardCharsets .UTF_8 )) {
81
81
while ((line = reader .readLine ()) != null ) {
82
82
if (line .contains ("version" )) {
83
83
fw .write (String .format ("version = %s%n" , nextVersion ));
@@ -91,8 +91,8 @@ public void writeVersion(File directory, Version nextVersion, ProcessHelper proc
91
91
92
92
if (isVersionTag ) {
93
93
// Replace gradle.properties with updated version
94
- Files .move (Paths . get ( buildTempPath ), Paths . get ( buildPath ),
95
- StandardCopyOption .REPLACE_EXISTING );
94
+ Files .move (
95
+ Paths . get ( buildTempPath ), Paths . get ( buildPath ), StandardCopyOption .REPLACE_EXISTING );
96
96
} else {
97
97
Files .deleteIfExists (Paths .get (buildPath ));
98
98
throw new IOException ("Unable to get version in gradle.properties" );
0 commit comments