From e0b462ac76902ae5c13e98ea0f6ddbd2c9d520dc Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Tue, 28 Nov 2023 21:16:09 +0800 Subject: [PATCH 1/9] start working on deploy data --- .../first/gradlerio/deploy/DeployData.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java b/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java new file mode 100644 index 00000000..191472f1 --- /dev/null +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java @@ -0,0 +1,46 @@ +package edu.wpi.first.gradlerio.deploy; + +import com.google.gson.GsonBuilder; +import com.google.gson.Gson; +import java.util.Map; +import java.util.HashMap; +import java.io.File; + +class DeployLogFile { + public String deployHost; + public String deployUser; + public String deployDate; + public String codePath; + public String gitHash; + public String gitBranch; + public String gitDesc; + public static final String LOG_FILE_PATH = "/home/lvuser/deploy.json"; + public String[] deployItems = { + "deployHost", + "deployUser", + "deployDate", + "codePath", + "gitHash", + "gitBranch", + "gitDesc", + }; + + Gson builder = new GsonBuilder().create(); + Map data = new HashMap(); + String jsonDeploy; + File deployDotJson; + + DeployLogFile() { + data.put(deployItems[0], deployHost); + data.put(deployItems[1], deployUser); + data.put(deployItems[2], deployDate); + data.put(deployItems[3], codePath); + data.put(deployItems[4], gitHash); + data.put(deployItems[5], gitBranch); + data.put(deployItems[6], gitDesc); + + jsonDeploy = builder.toJson(data); + + deployDotJson = new File(LOG_FILE_PATH); + } +} From d63d80ab3dc3ea9dc4f28875416d8cf6ac8ad92f Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Fri, 1 Dec 2023 10:21:36 +0800 Subject: [PATCH 2/9] create file to be deployed just need to get the data get git data write to build/ instead --- .../first/gradlerio/deploy/DeployData.java | 81 +++++++++++++++++-- .../gradlerio/deploy/FRCDeployPlugin.java | 2 + 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java b/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java index 191472f1..6f8746ee 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java @@ -1,10 +1,21 @@ package edu.wpi.first.gradlerio.deploy; import com.google.gson.GsonBuilder; + +import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO; +import edu.wpi.first.deployutils.deploy.artifact.FileArtifact; + import com.google.gson.Gson; + import java.util.Map; + +import org.gradle.api.GradleException; + import java.util.HashMap; +import java.io.IOException; import java.io.File; +import java.lang.Runtime; +import java.time.LocalDateTime; class DeployLogFile { public String deployHost; @@ -14,7 +25,8 @@ class DeployLogFile { public String gitHash; public String gitBranch; public String gitDesc; - public static final String LOG_FILE_PATH = "/home/lvuser/deploy.json"; + public static final String LOG_FILE_PATH = "/tmp/deploy.json"; + public File deployFile; public String[] deployItems = { "deployHost", "deployUser", @@ -28,19 +40,72 @@ class DeployLogFile { Gson builder = new GsonBuilder().create(); Map data = new HashMap(); String jsonDeploy; - File deployDotJson; + FileArtifact deployArtifact; + boolean inGitRepo; + + DeployLogFile(RoboRIO target) { + String[] command = {"git", "rev-parse", "--is-inside-work-tree"}; + + try { + Runtime.getRuntime().exec(command); + } catch(IOException e) { + inGitRepo = false; + } + + try { + deployHost = Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip(); + data.put(deployItems[0], deployHost); + } catch (IOException e) { + throw new GradleException("Couldn't get hostname", e); + } - DeployLogFile() { - data.put(deployItems[0], deployHost); + deployUser = System.getProperty("user.name"); data.put(deployItems[1], deployUser); + + deployDate = LocalDateTime.now().toString(); data.put(deployItems[2], deployDate); + + codePath = System.getProperty("user.dir"); data.put(deployItems[3], codePath); - data.put(deployItems[4], gitHash); - data.put(deployItems[5], gitBranch); - data.put(deployItems[6], gitDesc); + + if (inGitRepo) { + String[] command2 = {"git", "rev-parse", "HEAD"}; + try { + gitHash = Runtime.getRuntime().exec(command2).getOutputStream().toString().strip(); + data.put(deployItems[4], gitHash); + } catch (IOException e) { + throw new GradleException("Couldn't get git hash", e); + } + + String[] command3 = {"git", "rev-parse", "--abbrev-ref" ,"HEAD"}; + try { + gitBranch = Runtime.getRuntime().exec(command3).getOutputStream().toString().strip(); + data.put(deployItems[5], gitBranch); + } catch (IOException e) { + throw new GradleException("Couldn't get git branch", e); + } + + try { + String[] command4 = {"git", "describe", "--dirty=-dirty", "--always"}; + gitDesc = Runtime.getRuntime().exec(command4).getOutputStream().toString().strip(); + data.put(deployItems[6], gitDesc); + } catch (IOException e) { + throw new GradleException("Couldn't get git description", e); + } + } jsonDeploy = builder.toJson(data); - deployDotJson = new File(LOG_FILE_PATH); + deployFile = new File(LOG_FILE_PATH, jsonDeploy); + + try { + deployFile.createNewFile(); + } catch (IOException e) { + throw new GradleException("Couldn't write deploy log file", e); + } + + deployArtifact = new FileArtifact("/home/lvuser/deploy.json", target); + + target.getArtifacts().add(deployArtifact); } } diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java index 85d7367d..1fd1370d 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java @@ -19,6 +19,7 @@ import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO; import edu.wpi.first.gradlerio.deploy.roborio.RobotCommandArtifact; import edu.wpi.first.deployutils.deploy.NamedObjectFactory; +import edu.wpi.first.gradlerio.deploy.DeployLogFile; public class FRCDeployPlugin implements Plugin { @@ -57,6 +58,7 @@ public void apply(Project project) { deployExtension.getTargets().registerFactory(RoboRIO.class, name -> { RoboRIO target = project.getObjects().newInstance(RoboRIO.class, name, project, deployExtension, frcExtension); configureRoboRIOTypes(target); + new DeployLogFile(target); return target; }); } From 32cbe68a0b87652e146dad3df30c9e36231d822e Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Wed, 27 Mar 2024 21:33:23 +0800 Subject: [PATCH 3/9] start switching to proper gradle way - grgit not fully used see https://github.com/ajoberstar/grgit/issues/398 - doesn't fully use tasks properly I don't think - file needs to be properly set to output dir revert plugin changes fix: use gradle output dir call the thingy --- build.gradle | 2 + .../gradlerio/deploy/CreateLogFileTask.java | 91 ++++++++++++++ .../first/gradlerio/deploy/DeployData.java | 111 ------------------ .../gradlerio/deploy/FRCDeployPlugin.java | 2 - .../first/gradlerio/deploy/FRCExtension.java | 6 + 5 files changed, 99 insertions(+), 113 deletions(-) create mode 100644 src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java delete mode 100644 src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java diff --git a/build.gradle b/build.gradle index f3c582c8..ae148b54 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,8 @@ dependencies { api 'de.undercouch:gradle-download-task:4.1.2' + implementation 'org.ajoberstar.grgit:grgit-core:5.0.0' + testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0') { exclude group: 'org.codehaus.groovy' } diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java new file mode 100644 index 00000000..c6eaef1c --- /dev/null +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -0,0 +1,91 @@ +package edu.wpi.first.gradlerio.deploy; + +import com.google.gson.GsonBuilder; +import com.google.gson.Gson; + +import org.ajoberstar.grgit.Grgit; + +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; + +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 { + public static final String[] DEPLOY_ITEMS = { + "deployHost", + "deployUser", + "deployDate", + "codePath", + "gitHash", + "gitBranch", + "gitDesc", + }; + private File deployFile; + + @TaskAction + public void execute() { + Gson builder = new GsonBuilder().create(); + Grgit grgit = Grgit.open(); + HashMap data = new HashMap(); + boolean inGitRepo = false; + + String[] command = { "git", "rev-parse", "--is-inside-work-tree" }; + try { + // TODO! use grgit for this + Runtime.getRuntime().exec(command); + } catch (IOException e) { + } + + try { + data.put(DEPLOY_ITEMS[0], Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip()); + } catch (IOException e) { + throw new GradleException("Couldn't get hostname", e); + } + + 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")); + + if (inGitRepo) { + String[] command2 = { "git", "rev-parse", "HEAD" }; + try { + // TODO! use grgit for this + data.put(DEPLOY_ITEMS[4], Runtime.getRuntime().exec(command2).getOutputStream().toString().strip()); + } catch (IOException e) { + throw new GradleException("Couldn't get git hash", e); + } + + String[] command3 = { "git", "rev-parse", "--abbrev-ref", "HEAD" }; + try { + data.put(DEPLOY_ITEMS[5], Runtime.getRuntime().exec(command3).getOutputStream().toString().strip()); + } catch (IOException e) { + throw new GradleException("Couldn't get git branch", e); + } + + try { + HashMap args = new HashMap(); + args.put("dirty", "-dirty"); + args.put("always", true); + + data.put(DEPLOY_ITEMS[6], grgit.describe(args)); + } catch (Exception e) { + throw new GradleException("Couldn't get git description", e); + } + } + + deployFile = new File(builder.toJson(data)); + } + + @OutputFile + public RegularFileProperty getDeployFile() { + // TODO! figure out how to do this + return deployFile; + }; +} diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java b/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java deleted file mode 100644 index 6f8746ee..00000000 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java +++ /dev/null @@ -1,111 +0,0 @@ -package edu.wpi.first.gradlerio.deploy; - -import com.google.gson.GsonBuilder; - -import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO; -import edu.wpi.first.deployutils.deploy.artifact.FileArtifact; - -import com.google.gson.Gson; - -import java.util.Map; - -import org.gradle.api.GradleException; - -import java.util.HashMap; -import java.io.IOException; -import java.io.File; -import java.lang.Runtime; -import java.time.LocalDateTime; - -class DeployLogFile { - public String deployHost; - public String deployUser; - public String deployDate; - public String codePath; - public String gitHash; - public String gitBranch; - public String gitDesc; - public static final String LOG_FILE_PATH = "/tmp/deploy.json"; - public File deployFile; - public String[] deployItems = { - "deployHost", - "deployUser", - "deployDate", - "codePath", - "gitHash", - "gitBranch", - "gitDesc", - }; - - Gson builder = new GsonBuilder().create(); - Map data = new HashMap(); - String jsonDeploy; - FileArtifact deployArtifact; - boolean inGitRepo; - - DeployLogFile(RoboRIO target) { - String[] command = {"git", "rev-parse", "--is-inside-work-tree"}; - - try { - Runtime.getRuntime().exec(command); - } catch(IOException e) { - inGitRepo = false; - } - - try { - deployHost = Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip(); - data.put(deployItems[0], deployHost); - } catch (IOException e) { - throw new GradleException("Couldn't get hostname", e); - } - - deployUser = System.getProperty("user.name"); - data.put(deployItems[1], deployUser); - - deployDate = LocalDateTime.now().toString(); - data.put(deployItems[2], deployDate); - - codePath = System.getProperty("user.dir"); - data.put(deployItems[3], codePath); - - if (inGitRepo) { - String[] command2 = {"git", "rev-parse", "HEAD"}; - try { - gitHash = Runtime.getRuntime().exec(command2).getOutputStream().toString().strip(); - data.put(deployItems[4], gitHash); - } catch (IOException e) { - throw new GradleException("Couldn't get git hash", e); - } - - String[] command3 = {"git", "rev-parse", "--abbrev-ref" ,"HEAD"}; - try { - gitBranch = Runtime.getRuntime().exec(command3).getOutputStream().toString().strip(); - data.put(deployItems[5], gitBranch); - } catch (IOException e) { - throw new GradleException("Couldn't get git branch", e); - } - - try { - String[] command4 = {"git", "describe", "--dirty=-dirty", "--always"}; - gitDesc = Runtime.getRuntime().exec(command4).getOutputStream().toString().strip(); - data.put(deployItems[6], gitDesc); - } catch (IOException e) { - throw new GradleException("Couldn't get git description", e); - } - } - - jsonDeploy = builder.toJson(data); - - deployFile = new File(LOG_FILE_PATH, jsonDeploy); - - try { - deployFile.createNewFile(); - } catch (IOException e) { - throw new GradleException("Couldn't write deploy log file", e); - } - - deployArtifact = new FileArtifact("/home/lvuser/deploy.json", target); - - target.getArtifacts().add(deployArtifact); - } -} diff --git a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java index 1fd1370d..85d7367d 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java @@ -19,7 +19,6 @@ import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO; import edu.wpi.first.gradlerio.deploy.roborio.RobotCommandArtifact; import edu.wpi.first.deployutils.deploy.NamedObjectFactory; -import edu.wpi.first.gradlerio.deploy.DeployLogFile; public class FRCDeployPlugin implements Plugin { @@ -58,7 +57,6 @@ public void apply(Project project) { deployExtension.getTargets().registerFactory(RoboRIO.class, name -> { RoboRIO target = project.getObjects().newInstance(RoboRIO.class, name, project, deployExtension, frcExtension); configureRoboRIOTypes(target); - new DeployLogFile(target); return target; }); } 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 6b98d33f..ead647a1 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java @@ -25,12 +25,18 @@ public FRCExtension(Project project, DeployExtension deployExtension) { t.getDebugFile().set(project.getLayout().getBuildDirectory().file("debug/debug_info.json")); }); + deployLogFile = project.getTasks().register("writeDeployFile", CreateLogFileTask.class, t -> { + t.getDeployFile().set(project.getLayout().getBuildDirectory().file("debug/deploy.json")); + }); + deployExtension.getDeployTask().configure(t -> { t.dependsOn(debugFileTask); + t.dependsOn(deployLogFile); }); } private final TaskProvider debugFileTask; + private final TaskProvider deployLogFile; public TaskProvider getDebugFileTask() { return debugFileTask; From b1866f527e6f6d8c7ee72c2d2ffc0d658c838b37 Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Thu, 28 Mar 2024 10:12:30 +0800 Subject: [PATCH 4/9] Use grgit for hash and branchname requires https://github.com/ajoberstar/grgit/pull/399 Try use grgit to check if in git repo not sure if this works see https://github.com/ajoberstar/grgit/issues/397 fix grgit --- .../gradlerio/deploy/CreateLogFileTask.java | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 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 c6eaef1c..0479e544 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -32,40 +32,21 @@ public class CreateLogFileTask extends DefaultTask { @TaskAction public void execute() { Gson builder = new GsonBuilder().create(); - Grgit grgit = Grgit.open(); + Grgit grgit; HashMap data = new HashMap(); - boolean inGitRepo = false; - String[] command = { "git", "rev-parse", "--is-inside-work-tree" }; try { - // TODO! use grgit for this - Runtime.getRuntime().exec(command); - } catch (IOException e) { - } - - try { - data.put(DEPLOY_ITEMS[0], Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip()); - } catch (IOException e) { - throw new GradleException("Couldn't get hostname", e); - } - - 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")); + grgit = Grgit.open(); - if (inGitRepo) { - String[] command2 = { "git", "rev-parse", "HEAD" }; try { - // TODO! use grgit for this - data.put(DEPLOY_ITEMS[4], Runtime.getRuntime().exec(command2).getOutputStream().toString().strip()); - } catch (IOException e) { + data.put(DEPLOY_ITEMS[4], grgit.getResolve().toRevisionString("HEAD")); + } catch (Exception e) { throw new GradleException("Couldn't get git hash", e); } - String[] command3 = { "git", "rev-parse", "--abbrev-ref", "HEAD" }; try { - data.put(DEPLOY_ITEMS[5], Runtime.getRuntime().exec(command3).getOutputStream().toString().strip()); - } catch (IOException e) { + data.put(DEPLOY_ITEMS[5], grgit.getResolve().toBranchName("HEAD")); + } catch (Exception e) { throw new GradleException("Couldn't get git branch", e); } @@ -78,8 +59,18 @@ public void execute() { } 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()); + } catch (IOException e) { + throw new GradleException("Couldn't get hostname", e); } + 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")); + deployFile = new File(builder.toJson(data)); } From a2c42c792bcbdff33713f73a8472b18b4dfb792f Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Thu, 28 Mar 2024 14:15:29 +0800 Subject: [PATCH 5/9] 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 -> { From e3dcd14e83c79a240cff2cca4dce6335764de7a9 Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Thu, 28 Mar 2024 14:27:40 +0800 Subject: [PATCH 6/9] pass args to grgit.open naming --- .../wpi/first/gradlerio/deploy/CreateLogFileTask.java | 9 ++++++++- .../edu/wpi/first/gradlerio/deploy/FRCExtension.java | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) 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 a4fad345..a8e319ab 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -32,6 +32,7 @@ public class CreateLogFileTask extends DefaultTask { }; private File deployFile; private String json; + private String gitDirectory; @Inject public CreateLogFileTask() { @@ -42,7 +43,9 @@ public CreateLogFileTask() { Grgit grgit; try { - grgit = Grgit.open(); + HashMap openargs = new HashMap(); + openargs.put("dir", gitDirectory); + grgit = Grgit.open(openargs); try { data.put(DEPLOY_ITEMS[4], grgit.getResolve().toRevisionString("HEAD")); @@ -91,6 +94,10 @@ public void setDeployFile(String path) { deployFile = new File(path); } + public void setGitDirectory(String dir) { + gitDirectory = dir; + } + @OutputFile 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 44876580..fd6d8227 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java @@ -26,6 +26,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"); }); From 3e09be43aa7bebf7ddcc00bba6df3f82c958d55f Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Sun, 30 Jun 2024 20:15:19 +0800 Subject: [PATCH 7/9] jgit --- build.gradle | 5 ++-- .../gradlerio/deploy/CreateLogFileTask.java | 28 ++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index ae148b54..0653ac43 100644 --- a/build.gradle +++ b/build.gradle @@ -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' 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 a8e319ab..f051d203 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -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; @@ -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 { @@ -40,31 +38,27 @@ public CreateLogFileTask() { GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson jsongen = builder.create(); - Grgit grgit; try { - HashMap openargs = new HashMap(); - 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 args = new HashMap(); - 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); } @@ -72,7 +66,9 @@ public CreateLogFileTask() { } 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); } From 91d149857d0836452f9947e35c4061d33435938c Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 2 Dec 2024 18:50:34 +0800 Subject: [PATCH 8/9] review fixes Signed-off-by: Jade Turner --- build.gradle | 1 - .../gradlerio/deploy/CreateLogFileTask.java | 38 ++++++++----------- .../first/gradlerio/deploy/FRCExtension.java | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 78de8b10..1b4cf004 100644 --- a/build.gradle +++ b/build.gradle @@ -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') { 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 f051d203..c8a532f6 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -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; @@ -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 data = new HashMap(); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); @@ -48,29 +49,27 @@ 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")); @@ -78,16 +77,11 @@ public CreateLogFileTask() { 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) { @@ -95,7 +89,7 @@ public void setGitDirectory(String dir) { } @OutputFile - public File getDeployFile() { + public RegularFileProperty 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 fd6d8227..42616705 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java @@ -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 -> { From d2f02b66ee0f45aa4bff6f71844d05bce9fb79ce Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 2 Dec 2024 19:09:16 +0800 Subject: [PATCH 9/9] working raaa Signed-off-by: Jade Turner --- .../first/gradlerio/deploy/CreateLogFileTask.java | 14 ++++++++++---- .../wpi/first/gradlerio/deploy/FRCExtension.java | 2 +- 2 files changed, 11 insertions(+), 5 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 c8a532f6..5238c122 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java @@ -7,12 +7,17 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.gradle.api.DefaultTask; +import org.gradle.api.Project; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.logging.LogLevel; +import org.gradle.api.provider.Provider; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.OutputFile; import java.util.HashMap; + +import javax.inject.Inject; + import java.io.IOException; import java.net.InetAddress; import java.io.File; @@ -32,6 +37,11 @@ public class CreateLogFileTask extends DefaultTask { private String json; private String gitDirectory; + @Inject + public CreateLogFileTask(Project project) { + deployFile = project.getObjects().fileProperty(); + } + @TaskAction public void execute() throws IOException { deployFile.getAsFile().get().getParentFile().mkdirs(); @@ -80,10 +90,6 @@ public void execute() throws IOException { ResourceGroovyMethods.setText(deployFile.getAsFile().get(), json); } - public void setDeployFile(String path) { - deployFile.fileValue(new File(path)); - } - public void setGitDirectory(String dir) { gitDirectory = dir; } 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 42616705..11ebaf6e 100644 --- a/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java +++ b/src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java @@ -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/deploy_info.json"); + t.getDeployFile().set(project.getLayout().getBuildDirectory().file("debug/deploy_info.json")); }); deployExtension.getDeployTask().configure(t -> {