Skip to content

Commit 4718fa4

Browse files
committed
start switching to proper gradle way
- grgit not fully used see ajoberstar/grgit#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
1 parent c31c8a6 commit 4718fa4

File tree

5 files changed

+99
-113
lines changed

5 files changed

+99
-113
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies {
2121

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

24+
implementation 'org.ajoberstar.grgit:grgit-core:5.0.0'
25+
2426
testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0') {
2527
exclude group: 'org.codehaus.groovy'
2628
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package edu.wpi.first.gradlerio.deploy;
2+
3+
import com.google.gson.GsonBuilder;
4+
import com.google.gson.Gson;
5+
6+
import org.ajoberstar.grgit.Grgit;
7+
8+
import org.gradle.api.DefaultTask;
9+
import org.gradle.api.GradleException;
10+
import org.gradle.api.file.RegularFileProperty;
11+
import org.gradle.api.tasks.TaskAction;
12+
import org.gradle.api.tasks.OutputFile;
13+
14+
import java.util.HashMap;
15+
import java.io.IOException;
16+
import java.io.File;
17+
import java.lang.Runtime;
18+
import java.time.LocalDateTime;
19+
20+
public class CreateLogFileTask extends DefaultTask {
21+
public static final String[] DEPLOY_ITEMS = {
22+
"deployHost",
23+
"deployUser",
24+
"deployDate",
25+
"codePath",
26+
"gitHash",
27+
"gitBranch",
28+
"gitDesc",
29+
};
30+
private File deployFile;
31+
32+
@TaskAction
33+
public void execute() {
34+
Gson builder = new GsonBuilder().create();
35+
Grgit grgit = Grgit.open();
36+
HashMap<String, String> data = new HashMap<String, String>();
37+
boolean inGitRepo = false;
38+
39+
String[] command = { "git", "rev-parse", "--is-inside-work-tree" };
40+
try {
41+
// TODO! use grgit for this
42+
Runtime.getRuntime().exec(command);
43+
} catch (IOException e) {
44+
}
45+
46+
try {
47+
data.put(DEPLOY_ITEMS[0], Runtime.getRuntime().exec("hostname").getOutputStream().toString().strip());
48+
} catch (IOException e) {
49+
throw new GradleException("Couldn't get hostname", e);
50+
}
51+
52+
data.put(DEPLOY_ITEMS[1], System.getProperty("user.name"));
53+
data.put(DEPLOY_ITEMS[2], LocalDateTime.now().toString());
54+
data.put(DEPLOY_ITEMS[3], System.getProperty("user.dir"));
55+
56+
if (inGitRepo) {
57+
String[] command2 = { "git", "rev-parse", "HEAD" };
58+
try {
59+
// TODO! use grgit for this
60+
data.put(DEPLOY_ITEMS[4], Runtime.getRuntime().exec(command2).getOutputStream().toString().strip());
61+
} catch (IOException e) {
62+
throw new GradleException("Couldn't get git hash", e);
63+
}
64+
65+
String[] command3 = { "git", "rev-parse", "--abbrev-ref", "HEAD" };
66+
try {
67+
data.put(DEPLOY_ITEMS[5], Runtime.getRuntime().exec(command3).getOutputStream().toString().strip());
68+
} catch (IOException e) {
69+
throw new GradleException("Couldn't get git branch", e);
70+
}
71+
72+
try {
73+
HashMap<String, Object> args = new HashMap<String, Object>();
74+
args.put("dirty", "-dirty");
75+
args.put("always", true);
76+
77+
data.put(DEPLOY_ITEMS[6], grgit.describe(args));
78+
} catch (Exception e) {
79+
throw new GradleException("Couldn't get git description", e);
80+
}
81+
}
82+
83+
deployFile = new File(builder.toJson(data));
84+
}
85+
86+
@OutputFile
87+
public RegularFileProperty getDeployFile() {
88+
// TODO! figure out how to do this
89+
return deployFile;
90+
};
91+
}

src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/main/java/edu/wpi/first/gradlerio/deploy/FRCDeployPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import edu.wpi.first.gradlerio.deploy.roborio.RoboRIO;
2020
import edu.wpi.first.gradlerio.deploy.roborio.RobotCommandArtifact;
2121
import edu.wpi.first.deployutils.deploy.NamedObjectFactory;
22-
import edu.wpi.first.gradlerio.deploy.DeployLogFile;
2322

2423
public class FRCDeployPlugin implements Plugin<Project> {
2524

@@ -58,7 +57,6 @@ public void apply(Project project) {
5857
deployExtension.getTargets().registerFactory(RoboRIO.class, name -> {
5958
RoboRIO target = project.getObjects().newInstance(RoboRIO.class, name, project, deployExtension, frcExtension);
6059
configureRoboRIOTypes(target);
61-
new DeployLogFile(target);
6260
return target;
6361
});
6462
}

src/main/java/edu/wpi/first/gradlerio/deploy/FRCExtension.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ public FRCExtension(Project project, DeployExtension deployExtension) {
2525
t.getDebugFile().set(project.getLayout().getBuildDirectory().file("debug/debug_info.json"));
2626
});
2727

28+
deployLogFile = project.getTasks().register("writeDeployFile", CreateLogFileTask.class, t -> {
29+
t.getDeployFile().set(project.getLayout().getBuildDirectory().file("debug/deploy.json"));
30+
});
31+
2832
deployExtension.getDeployTask().configure(t -> {
2933
t.dependsOn(debugFileTask);
34+
t.dependsOn(deployLogFile);
3035
});
3136
}
3237

3338
private final TaskProvider<DebugFileTask> debugFileTask;
39+
private final TaskProvider<CreateLogFileTask> deployLogFile;
3440

3541
public TaskProvider<DebugFileTask> getDebugFileTask() {
3642
return debugFileTask;

0 commit comments

Comments
 (0)