Skip to content

Commit

Permalink
jgit
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Jun 30, 2024
1 parent e3dcd14 commit 3e09be4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ dependencies {

api 'edu.wpi.first:native-utils:2024.6.1'

api 'de.undercouch:gradle-download-task:4.1.2'
api 'org.eclipse.jgit:org.eclipse.jgit:6.10.+'


implementation 'org.ajoberstar.grgit:grgit-core:5.0.0'
api 'de.undercouch:gradle-download-task:4.1.2'

testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
Expand Down
28 changes: 12 additions & 16 deletions src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.google.gson.GsonBuilder;
import com.google.gson.Gson;

import org.ajoberstar.grgit.Grgit;

import javax.inject.Inject;

import org.codehaus.groovy.runtime.ResourceGroovyMethods;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.TaskAction;
Expand All @@ -17,7 +16,6 @@
import java.util.HashMap;
import java.io.IOException;
import java.io.File;
import java.lang.Runtime;
import java.time.LocalDateTime;

public class CreateLogFileTask extends DefaultTask {
Expand All @@ -40,39 +38,37 @@ public CreateLogFileTask() {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson jsongen = builder.create();
Grgit grgit;

try {
HashMap<String, Object> openargs = new HashMap<String, Object>();
openargs.put("dir", gitDirectory);
grgit = Grgit.open(openargs);
Repository repository = new FileRepositoryBuilder().setGitDir(new File(gitDirectory))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();

try {
data.put(DEPLOY_ITEMS[4], grgit.getResolve().toRevisionString("HEAD"));
data.put(DEPLOY_ITEMS[4], repository.resolve("HEAD").toString());
} catch (Exception e) {
throw new GradleException("Couldn't get git hash", e);
}

try {
data.put(DEPLOY_ITEMS[5], grgit.getResolve().toBranchName("HEAD"));
data.put(DEPLOY_ITEMS[5], repository.getBranch());
} catch (Exception e) {
throw new GradleException("Couldn't get git branch", e);
}

try {
HashMap<String, Object> args = new HashMap<String, Object>();
args.put("dirty", "-dirty");
args.put("always", true);

data.put(DEPLOY_ITEMS[6], grgit.describe(args));
data.put(DEPLOY_ITEMS[6], repository.getGitwebDescription());
} catch (Exception e) {
throw new GradleException("Couldn't get git description", e);
}
} catch (Exception e) {
}

try {
data.put(DEPLOY_ITEMS[0], Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip());
var pb = new ProcessBuilder("hostname");
var process = pb.start();
data.put(DEPLOY_ITEMS[0], process.getOutputStream().toString());
} catch (IOException e) {
throw new GradleException("Couldn't get hostname", e);
}
Expand Down

0 comments on commit 3e09be4

Please sign in to comment.