From 963e7b3b9cebf6d182951c79ea4ee7c42847188b Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Thu, 28 Mar 2024 14:15:29 +0800 Subject: [PATCH] should be working now --- .../gradlerio/deploy/CreateLogFileTask.java | 34 ++++++++++++++----- .../first/gradlerio/deploy/FRCExtension.java | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java index 0479e544..a4fad345 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -5,9 +5,12 @@ import org.ajoberstar.grgit.Grgit; +import javax.inject.Inject; + +import org.codehaus.groovy.runtime.ResourceGroovyMethods; + import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; -import org.gradle.api.file.RegularFileProperty; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.OutputFile; @@ -28,12 +31,15 @@ public class CreateLogFileTask extends DefaultTask { "gitDesc", }; private File deployFile; + private String json; - @TaskAction - public void execute() { - Gson builder = new GsonBuilder().create(); - Grgit grgit; + @Inject + public CreateLogFileTask() { HashMap data = new HashMap(); + GsonBuilder builder = new GsonBuilder(); + builder.setPrettyPrinting(); + Gson jsongen = builder.create(); + Grgit grgit; try { grgit = Grgit.open(); @@ -59,7 +65,8 @@ public void execute() { } catch (Exception e) { throw new GradleException("Couldn't get git description", e); } - } catch (Exception e) {} + } catch (Exception e) { + } try { data.put(DEPLOY_ITEMS[0], Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip()); @@ -71,12 +78,21 @@ public void execute() { data.put(DEPLOY_ITEMS[2], LocalDateTime.now().toString()); data.put(DEPLOY_ITEMS[3], System.getProperty("user.dir")); - deployFile = new File(builder.toJson(data)); + json = jsongen.toJson(data); + } + + @TaskAction + public void execute() throws IOException { + deployFile.getParentFile().mkdirs(); + ResourceGroovyMethods.setText(deployFile, json); + } + + public void setDeployFile(String path) { + deployFile = new File(path); } @OutputFile - public RegularFileProperty getDeployFile() { - // TODO! figure out how to do this + public File getDeployFile() { return deployFile; }; } diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java index ead647a1..44876580 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java @@ -26,7 +26,7 @@ public FRCExtension(Project project, DeployExtension deployExtension) { }); deployLogFile = project.getTasks().register("writeDeployFile", CreateLogFileTask.class, t -> { - t.getDeployFile().set(project.getLayout().getBuildDirectory().file("debug/deploy.json")); + t.setDeployFile(project.getLayout().getBuildDirectory().toString() + "debug/debug_info.json"); }); deployExtension.getDeployTask().configure(t -> {