Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Turner <[email protected]>
  • Loading branch information
spacey-sooty committed Dec 2, 2024
1 parent df72f28 commit 91d1498
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {

api 'org.eclipse.jgit:org.eclipse.jgit:6.10.+'


api 'de.undercouch:gradle-download-task:4.1.2'

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

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.file.RegularFileProperty;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.OutputFile;

import java.util.HashMap;
import java.io.IOException;
import java.net.InetAddress;
import java.io.File;
import java.time.LocalDateTime;

Expand All @@ -28,12 +28,13 @@ public class CreateLogFileTask extends DefaultTask {
"gitBranch",
"gitDesc",
};
private File deployFile;
private RegularFileProperty deployFile;
private String json;
private String gitDirectory;

@Inject
public CreateLogFileTask() {
@TaskAction
public void execute() throws IOException {
deployFile.getAsFile().get().getParentFile().mkdirs();
HashMap<String, String> data = new HashMap<String, String>();
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Expand All @@ -48,54 +49,47 @@ public CreateLogFileTask() {
try {
data.put(DEPLOY_ITEMS[4], repository.resolve("HEAD").toString());
} catch (Exception e) {
throw new GradleException("Couldn't get git hash", e);
getLogger().log(LogLevel.WARN, "Couldn't get git hash");
}

try {
data.put(DEPLOY_ITEMS[5], repository.getBranch());
} catch (Exception e) {
throw new GradleException("Couldn't get git branch", e);
getLogger().log(LogLevel.WARN, "Couldn't get git branch");
}

try {
data.put(DEPLOY_ITEMS[6], repository.getGitwebDescription());
} catch (Exception e) {
throw new GradleException("Couldn't get git description", e);
getLogger().log(LogLevel.WARN, "Couldn't get git description");
}
} catch (Exception e) {
getLogger().log(LogLevel.WARN, "Couldn't find git");
}

try {
var pb = new ProcessBuilder("hostname");
var process = pb.start();
data.put(DEPLOY_ITEMS[0], process.getOutputStream().toString());
data.put(DEPLOY_ITEMS[0], InetAddress.getLocalHost().getHostName());
} catch (IOException e) {
throw new GradleException("Couldn't get hostname", e);
getLogger().log(LogLevel.WARN, "Couldn't get host name");
}

data.put(DEPLOY_ITEMS[1], System.getProperty("user.name"));
data.put(DEPLOY_ITEMS[2], LocalDateTime.now().toString());
data.put(DEPLOY_ITEMS[3], System.getProperty("user.dir"));

json = jsongen.toJson(data);
}

@TaskAction
public void execute() throws IOException {
deployFile.getParentFile().mkdirs();
ResourceGroovyMethods.setText(deployFile, json);
ResourceGroovyMethods.setText(deployFile.getAsFile().get(), json);
}

public void setDeployFile(String path) {
deployFile = new File(path);
deployFile.fileValue(new File(path));
}

public void setGitDirectory(String dir) {
gitDirectory = dir;
}

@OutputFile
public File getDeployFile() {
public RegularFileProperty getDeployFile() {
return deployFile;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public FRCExtension(Project project, DeployExtension deployExtension) {

deployLogFile = project.getTasks().register("writeDeployFile", CreateLogFileTask.class, t -> {
t.setGitDirectory(project.getRootDir().toString());
t.setDeployFile(project.getLayout().getBuildDirectory().toString() + "debug/debug_info.json");
t.setDeployFile(project.getLayout().getBuildDirectory().toString() + "debug/deploy_info.json");
});

deployExtension.getDeployTask().configure(t -> {
Expand Down

0 comments on commit 91d1498

Please sign in to comment.