55
66import org .ajoberstar .grgit .Grgit ;
77
8+ import javax .inject .Inject ;
9+
10+ import org .codehaus .groovy .runtime .ResourceGroovyMethods ;
11+
812import org .gradle .api .DefaultTask ;
913import org .gradle .api .GradleException ;
10- import org .gradle .api .file .RegularFileProperty ;
1114import org .gradle .api .tasks .TaskAction ;
1215import org .gradle .api .tasks .OutputFile ;
1316
@@ -28,12 +31,15 @@ public class CreateLogFileTask extends DefaultTask {
2831 "gitDesc" ,
2932 };
3033 private File deployFile ;
34+ private String json ;
3135
32- @ TaskAction
33- public void execute () {
34- Gson builder = new GsonBuilder ().create ();
35- Grgit grgit ;
36+ @ Inject
37+ public CreateLogFileTask () {
3638 HashMap <String , String > data = new HashMap <String , String >();
39+ GsonBuilder builder = new GsonBuilder ();
40+ builder .setPrettyPrinting ();
41+ Gson jsongen = builder .create ();
42+ Grgit grgit ;
3743
3844 try {
3945 grgit = Grgit .open ();
@@ -59,7 +65,8 @@ public void execute() {
5965 } catch (Exception e ) {
6066 throw new GradleException ("Couldn't get git description" , e );
6167 }
62- } catch (Exception e ) {}
68+ } catch (Exception e ) {
69+ }
6370
6471 try {
6572 data .put (DEPLOY_ITEMS [0 ], Runtime .getRuntime ().exec ("hostname" ).getOutputStream ().toString ().strip ());
@@ -71,12 +78,21 @@ public void execute() {
7178 data .put (DEPLOY_ITEMS [2 ], LocalDateTime .now ().toString ());
7279 data .put (DEPLOY_ITEMS [3 ], System .getProperty ("user.dir" ));
7380
74- deployFile = new File (builder .toJson (data ));
81+ json = jsongen .toJson (data );
82+ }
83+
84+ @ TaskAction
85+ public void execute () throws IOException {
86+ deployFile .getParentFile ().mkdirs ();
87+ ResourceGroovyMethods .setText (deployFile , json );
88+ }
89+
90+ public void setDeployFile (String path ) {
91+ deployFile = new File (path );
7592 }
7693
7794 @ OutputFile
78- public RegularFileProperty getDeployFile () {
79- // TODO! figure out how to do this
95+ public File getDeployFile () {
8096 return deployFile ;
8197 };
8298}
0 commit comments