3
3
import com .google .gson .GsonBuilder ;
4
4
import com .google .gson .Gson ;
5
5
6
- import org .ajoberstar .grgit .Grgit ;
7
-
8
6
import javax .inject .Inject ;
9
7
10
8
import org .codehaus .groovy .runtime .ResourceGroovyMethods ;
11
-
9
+ import org .eclipse .jgit .lib .Repository ;
10
+ import org .eclipse .jgit .storage .file .FileRepositoryBuilder ;
12
11
import org .gradle .api .DefaultTask ;
13
12
import org .gradle .api .GradleException ;
14
13
import org .gradle .api .tasks .TaskAction ;
17
16
import java .util .HashMap ;
18
17
import java .io .IOException ;
19
18
import java .io .File ;
20
- import java .lang .Runtime ;
21
19
import java .time .LocalDateTime ;
22
20
23
21
public class CreateLogFileTask extends DefaultTask {
@@ -40,39 +38,37 @@ public CreateLogFileTask() {
40
38
GsonBuilder builder = new GsonBuilder ();
41
39
builder .setPrettyPrinting ();
42
40
Gson jsongen = builder .create ();
43
- Grgit grgit ;
44
41
45
42
try {
46
- HashMap <String , Object > openargs = new HashMap <String , Object >();
47
- openargs .put ("dir" , gitDirectory );
48
- grgit = Grgit .open (openargs );
43
+ Repository repository = new FileRepositoryBuilder ().setGitDir (new File (gitDirectory ))
44
+ .readEnvironment () // scan environment GIT_* variables
45
+ .findGitDir () // scan up the file system tree
46
+ .build ();
49
47
50
48
try {
51
- data .put (DEPLOY_ITEMS [4 ], grgit . getResolve (). toRevisionString ( "HEAD" ));
49
+ data .put (DEPLOY_ITEMS [4 ], repository . resolve ( "HEAD" ). toString ( ));
52
50
} catch (Exception e ) {
53
51
throw new GradleException ("Couldn't get git hash" , e );
54
52
}
55
53
56
54
try {
57
- data .put (DEPLOY_ITEMS [5 ], grgit . getResolve (). toBranchName ( "HEAD" ));
55
+ data .put (DEPLOY_ITEMS [5 ], repository . getBranch ( ));
58
56
} catch (Exception e ) {
59
57
throw new GradleException ("Couldn't get git branch" , e );
60
58
}
61
59
62
60
try {
63
- HashMap <String , Object > args = new HashMap <String , Object >();
64
- args .put ("dirty" , "-dirty" );
65
- args .put ("always" , true );
66
-
67
- data .put (DEPLOY_ITEMS [6 ], grgit .describe (args ));
61
+ data .put (DEPLOY_ITEMS [6 ], repository .getGitwebDescription ());
68
62
} catch (Exception e ) {
69
63
throw new GradleException ("Couldn't get git description" , e );
70
64
}
71
65
} catch (Exception e ) {
72
66
}
73
67
74
68
try {
75
- data .put (DEPLOY_ITEMS [0 ], Runtime .getRuntime ().exec ("hostname" ).getOutputStream ().toString ().strip ());
69
+ var pb = new ProcessBuilder ("hostname" );
70
+ var process = pb .start ();
71
+ data .put (DEPLOY_ITEMS [0 ], process .getOutputStream ().toString ());
76
72
} catch (IOException e ) {
77
73
throw new GradleException ("Couldn't get hostname" , e );
78
74
}
0 commit comments