Skip to content

Commit

Permalink
Make robot class property work nicely
Browse files Browse the repository at this point in the history
Now the jar task checks if the deploy task will run; if so, it does the
checking if the robot class is set. This is a good deal better than the
earlier band-aid solution which was to set it to a default.
Now the build will succeed if robotClass is not set but we aren't
deploying, but will fail if it is not set and we are deploying.
  • Loading branch information
RobinsonZ committed Oct 9, 2018
1 parent a7196f1 commit 17d6980
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ dependencies {

def TEAM = 1540

if (!project.hasProperty("robotClass")) {
println "Robot class not set! Pass a value in on the command line by adding -ProbotClass=<your robot class>. Using a default"
}

def ROBOT_CLASS = project.hasProperty("robotClass") ? project.robotClass : "org.team1540.base.testing.HelloWorldTestRobot"
println "Will deploy robot $ROBOT_CLASS"

deploy {
targets {
target("roborio", RoboRIO) {
Expand All @@ -44,6 +37,24 @@ deploy {
}

jar {
// declare the robot class property as an input, as normally since we
// set it at runtime this wouldn't run if the class changed due to up-to-date checking
inputs.property("robotClass", project.hasProperty("robotClass") ? project.robotClass : "")
gradle.taskGraph.whenReady {
/*
check if we are deploying to the robot. If we're building in CI, for example, the
robot class doesn't need to be set.
this is inside the gradle.taskGraph.whenReady so that we don't check if the deploy
task is being run before Gradle has figured it out.
*/
if (gradle.taskGraph.hasTask(":test:deploy")) { // fully qualified task name is needed
if (!project.hasProperty("robotClass")) {
throw new GradleException("Robot class not set. Pass a value in on the command line by adding -ProbotClass=<your robot class>.")
} else {
println "Creating JAR for robot ${project.robotClass}"
}
manifest GradleRIOPlugin.javaManifest(project.robotClass)
}
}
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
manifest GradleRIOPlugin.javaManifest(ROBOT_CLASS)
}

0 comments on commit 17d6980

Please sign in to comment.