@@ -32,40 +32,21 @@ public class CreateLogFileTask extends DefaultTask {
3232 @ TaskAction
3333 public void execute () {
3434 Gson builder = new GsonBuilder ().create ();
35- Grgit grgit = Grgit . open () ;
35+ Grgit grgit ;
3636 HashMap <String , String > data = new HashMap <String , String >();
37- boolean inGitRepo = false ;
3837
39- String [] command = { "git" , "rev-parse" , "--is-inside-work-tree" };
4038 try {
41- // TODO! use grgit for this
42- Runtime .getRuntime ().exec (command );
43- } catch (IOException e ) {
44- }
45-
46- try {
47- data .put (DEPLOY_ITEMS [0 ], Runtime .getRuntime ().exec ("hostname" ).getOutputStream ().toString ().strip ());
48- } catch (IOException e ) {
49- throw new GradleException ("Couldn't get hostname" , e );
50- }
51-
52- data .put (DEPLOY_ITEMS [1 ], System .getProperty ("user.name" ));
53- data .put (DEPLOY_ITEMS [2 ], LocalDateTime .now ().toString ());
54- data .put (DEPLOY_ITEMS [3 ], System .getProperty ("user.dir" ));
39+ grgit = Grgit .open ();
5540
56- if (inGitRepo ) {
57- String [] command2 = { "git" , "rev-parse" , "HEAD" };
5841 try {
59- // TODO! use grgit for this
60- data .put (DEPLOY_ITEMS [4 ], Runtime .getRuntime ().exec (command2 ).getOutputStream ().toString ().strip ());
61- } catch (IOException e ) {
42+ data .put (DEPLOY_ITEMS [4 ], grgit .getResolve ().toRevisionString ("HEAD" ));
43+ } catch (Exception e ) {
6244 throw new GradleException ("Couldn't get git hash" , e );
6345 }
6446
65- String [] command3 = { "git" , "rev-parse" , "--abbrev-ref" , "HEAD" };
6647 try {
67- data .put (DEPLOY_ITEMS [5 ], Runtime . getRuntime ().exec ( command3 ). getOutputStream (). toString (). strip ( ));
68- } catch (IOException e ) {
48+ data .put (DEPLOY_ITEMS [5 ], grgit . getResolve ().toBranchName ( "HEAD" ));
49+ } catch (Exception e ) {
6950 throw new GradleException ("Couldn't get git branch" , e );
7051 }
7152
@@ -78,8 +59,18 @@ public void execute() {
7859 } catch (Exception e ) {
7960 throw new GradleException ("Couldn't get git description" , e );
8061 }
62+ } catch (Exception e ) {}
63+
64+ try {
65+ data .put (DEPLOY_ITEMS [0 ], Runtime .getRuntime ().exec ("hostname" ).getOutputStream ().toString ().strip ());
66+ } catch (IOException e ) {
67+ throw new GradleException ("Couldn't get hostname" , e );
8168 }
8269
70+ data .put (DEPLOY_ITEMS [1 ], System .getProperty ("user.name" ));
71+ data .put (DEPLOY_ITEMS [2 ], LocalDateTime .now ().toString ());
72+ data .put (DEPLOY_ITEMS [3 ], System .getProperty ("user.dir" ));
73+
8374 deployFile = new File (builder .toJson (data ));
8475 }
8576
0 commit comments