From b37b68daaf5ec37350ff2c73f6cf6b968cc5808a Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 18 Nov 2019 19:52:56 -0800 Subject: [PATCH] Add JRE deployment to MyRobot Deploy (#2099) --- .gitignore | 1 + buildSrc/src/main/groovy/JREArtifact.groovy | 48 +++++++++++++++++++++ myRobot/build.gradle | 5 +++ 3 files changed, 54 insertions(+) create mode 100644 buildSrc/src/main/groovy/JREArtifact.groovy diff --git a/.gitignore b/.gitignore index 85c56af14b..bdf94fe5e3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ dependency-reduced-pom.xml doxygen.log build*/ +!buildSrc/ # Created by the jenkins test script test-reports diff --git a/buildSrc/src/main/groovy/JREArtifact.groovy b/buildSrc/src/main/groovy/JREArtifact.groovy new file mode 100644 index 0000000000..e57249ab38 --- /dev/null +++ b/buildSrc/src/main/groovy/JREArtifact.groovy @@ -0,0 +1,48 @@ +import groovy.transform.CompileStatic +import javax.inject.Inject +import jaci.gradle.deploy.artifact.MavenArtifact +import jaci.gradle.deploy.context.DeployContext +import org.gradle.api.Project +import jaci.gradle.ActionWrapper + +import java.util.function.Function + +@CompileStatic +class JREArtifact extends MavenArtifact { + Function buildRequiresJre = (Function){ true } + + void setJreDependency(String dep) { + dependency = project.dependencies.add(configuration(), dep) + } + + @Inject + JREArtifact(String name, Project project) { + super(name, project) + configuration = project.configurations.create(configuration()) + + onlyIf = { DeployContext ctx -> + (buildRequiresJre.apply(ctx) && jreMissing(ctx)) || project.hasProperty("force-redeploy-jre") + } + + predeploy << new ActionWrapper({ DeployContext ctx -> + ctx.logger.log('Deploying RoboRIO JRE (this will take a while)...') + }) + + directory = '/tmp' + filename = 'frcjre.ipk' + + postdeploy << new ActionWrapper({ DeployContext ctx -> + ctx.logger.log('Installing JRE...') + ctx.execute('opkg remove frc2020-openjdk*; opkg install /tmp/frcjre.ipk; rm /tmp/frcjre.ipk') + ctx.logger.log('JRE Deployed!') + }) + } + + String configuration() { + return name + 'frcjre' + } + + boolean jreMissing(DeployContext ctx) { + return ctx.execute('if [[ -f "/usr/local/frc/JRE/bin/java" ]]; then echo OK; else echo MISSING; fi').result.contains("MISSING") + } +} diff --git a/myRobot/build.gradle b/myRobot/build.gradle index fa34957510..012dea1cd0 100644 --- a/myRobot/build.gradle +++ b/myRobot/build.gradle @@ -50,6 +50,10 @@ deploy { } } + artifact('jre', JREArtifact) { + jreDependency = 'edu.wpi.first.jdk:roborio-2020:11.0.4u10-2' + } + javaArtifact('myRobotJava') { jar = 'shadowJar' postdeploy << { ctx -> @@ -82,6 +86,7 @@ deploy { } tasks.register('deployJava') { + dependsOn tasks.named('deployJreRoborio') dependsOn tasks.named('deployMyRobotJavaRoborio') dependsOn tasks.named('deployMyRobotCppLibrariesRoborio') }