2
2
3
3
import com .google .gson .GsonBuilder ;
4
4
import com .google .gson .Gson ;
5
+
5
6
import java .util .Map ;
7
+
8
+ import org .gradle .api .GradleException ;
9
+
6
10
import java .util .HashMap ;
7
- import java .io .File ;
11
+ import java .io .IOException ;
12
+ import java .nio .charset .StandardCharsets ;
13
+ import java .nio .file .Files ;
14
+ import java .nio .file .Path ;
15
+ import java .nio .file .Paths ;
8
16
9
17
class DeployLogFile {
10
18
public String deployHost ;
@@ -14,7 +22,7 @@ class DeployLogFile {
14
22
public String gitHash ;
15
23
public String gitBranch ;
16
24
public String gitDesc ;
17
- public static final String LOG_FILE_PATH = "/home/lvuser/deploy.json" ;
25
+ public static final Path LOG_FILE_PATH = Paths . get ( "/home/lvuser/deploy.json" ) ;
18
26
public String [] deployItems = {
19
27
"deployHost" ,
20
28
"deployUser" ,
@@ -28,7 +36,6 @@ class DeployLogFile {
28
36
Gson builder = new GsonBuilder ().create ();
29
37
Map <String , String > data = new HashMap <String , String >();
30
38
String jsonDeploy ;
31
- File deployDotJson ;
32
39
33
40
DeployLogFile () {
34
41
data .put (deployItems [0 ], deployHost );
@@ -41,6 +48,10 @@ class DeployLogFile {
41
48
42
49
jsonDeploy = builder .toJson (data );
43
50
44
- deployDotJson = new File (LOG_FILE_PATH );
51
+ try {
52
+ Files .writeString (LOG_FILE_PATH , jsonDeploy , StandardCharsets .UTF_8 );
53
+ } catch (IOException e ) {
54
+ throw new GradleException ("Could not write deploy log file" );
55
+ }
45
56
}
46
57
}
0 commit comments