Skip to content

Commit

Permalink
Release v3.0.0. Clean Up WPILib fetching and add ability for custom d…
Browse files Browse the repository at this point in the history
…eploy jars/modules
  • Loading branch information
JaciBrunning committed Nov 3, 2015
1 parent 00d5fb6 commit 9c2d184
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 83 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {

group = "jaci.openrio.gradle"
archivesBaseName = "GradleRIO"
version = "2.3.0"
version = "3.0.0"

jar {
manifest {
Expand Down
106 changes: 25 additions & 81 deletions src/main/groovy/jaci/openrio/gradle/GradleRIO.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@ import groovy.util.*;

class GradleRIO implements Plugin<Project> {

def project
String pluginDest
public static def project
public static String pluginDest
public static String apiDest

void apply(Project project) {
this.project = project
GradleRIO.project = project
project.extensions.create("gradlerio", GradleRIOExtensions)

String apiDest = System.getProperty("user.home") + "/wpilib/java/extracted/library/"

def riotask = project.task('roboRIO') << {
String roboRIO = rioHost(project);
String rioIP = rioIP(project)

println "Host: ${roboRIO}"
println "IP: ${rioIP}"
}
riotask.setDescription "Get details about the RoboRIO's IP Address and Hostname"
apiDest = System.getProperty("user.home") + "/wpilib/java/extracted/library/"
pluginDest = System.getProperty("user.home") + "/wpilib/java/plugin/current/"

project.repositories.add(project.repositories.mavenCentral())

project.getConfigurations().maybeCreate('compile')

def sshAntTask = project.getConfigurations().maybeCreate('sshAntTask')
Expand All @@ -39,64 +31,10 @@ class GradleRIO implements Plugin<Project> {
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
classpath: sshAntTask.asPath)

WPIProvider.doDeps(project, apiDest)

pluginDest = System.getProperty("user.home") + "/wpilib/java/plugin/current/"
WPIProvider.init(project, apiDest)

def wpiTask = project.task('wpi') << {
String extractedDest = System.getProperty("user.home") + "/wpilib/java/extracted/current/"
String urlBase = "http://first.wpi.edu/FRC/roborio/release/eclipse/"
String wpiVersion = "java_0.1.0.201501221609"
println "Checking WPILib Version..."

String wpiInstalledVersion = ""
try {
def versionXML=new XmlSlurper().parse(pluginDest+"content/content.xml")
def vNode = versionXML.depthFirst().find{it.@id == 'edu.wpi.first.wpilib.plugins.java'}
wpiInstalledVersion = vNode.@version
println "Currently Installed WPILib Version: ${wpiInstalledVersion}"
} catch (Exception e) { }

try {
download(pluginDest, urlBase+"content.jar", "content.jar")
ant.unzip(src: pluginDest+"content.jar",
dest: pluginDest+"content",
overwrite:"true")

def xml=new XmlSlurper().parse(pluginDest+"content/content.xml")
def node = xml.depthFirst().find{it.@id == 'edu.wpi.first.wpilib.plugins.java'}
String wpiVersionLatest = node.@version
println "WPILib Latest Version: ${wpiVersionLatest}"

if (wpiInstalledVersion != wpiVersionLatest) {
println "WPILib Version Mismatch... Updating..."
wpiVersion = "java_${wpiVersionLatest}"
} else {
println "WPILib Version Match. Skipping Update..."
return;
}

println "Deleting WPILib Caches..."
ant.delete(dir: extractedDest)
} catch (Exception e) {
println "Could not check WPI Version..."
return
}

String from = urlBase + "plugins/edu.wpi.first.wpilib.plugins.${wpiVersion}.jar"
println "Downloading WPILib..."
download(pluginDest, from, "plugin.jar")
println "Extracting WPILib..."

ant.unzip(src:pluginDest+"plugin.jar",
dest:extractedDest,
overwrite:"false")
println "WPILib Extracted..."
println "Extracting API Resources..."
ant.unzip( src:extractedDest+"resources/java.zip",
dest:apiDest,
overwrite:"false")
println "API Resources extracted..."
WPIProvider.update(project)
}
wpiTask.setDescription "Download and Extract the latest version of WPILib"

Expand Down Expand Up @@ -209,11 +147,24 @@ class GradleRIO implements Plugin<Project> {
void deploy(String host) {
println "Attempting to send new code to RoboRIO..."

if (WPIProvider.isToast()) ToastDeploy.mapToastDeps(project)

project.ant.scp(file: "${project.jar.archivePath}",
todir:"lvuser@${host}:${project.gradlerio.deployFile}",
password:"",
port:22,
trust:true)
todir:"lvuser@${host}:${project.gradlerio.deployFile}",
password:"",
port:22,
trust:true)

for (def deployer : project.gradlerio.deployers) {
def from = deployer.from
def to = deployer.to
def user = deployer.elevated == null ? "lvuser" : "admin"
project.ant.scp(file: from,
todir: "${user}@${host}:${to}",
password: "",
port:22,
trust:true)
}

println "Deploy Successful! Loaded in: ${project.gradlerio.deployFile}"
}
Expand Down Expand Up @@ -285,10 +236,3 @@ class GradleRIO implements Plugin<Project> {
}

}

class GradleRIOExtensions {
String team = "0000";
String rioIP = "{DEFAULT}";
String robotClass = "org.usfirst.frc.team0000.Robot"
String deployFile = "FRCUserProgram.jar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class GradleRIOExtensions {
String team = "0000"
String rioIP = "{DEFAULT}"
String robotClass = "org.usfirst.frc.team0000.Robot"
String deployFile = "FRCUserProgram.jar"
def deployers = []
}
23 changes: 23 additions & 0 deletions src/main/groovy/jaci/openrio/gradle/ToastDeploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import java.io.File;
public class ToastDeploy {

static void init(Project project) {
project.getConfigurations().maybeCreate('toastLibrary')
project.getConfigurations().maybeCreate('toastModule')

def deploy_task = project.task('toastDeploy') << {
def toast_resource = getToastResource(project)
def nashorn = new File("build/caches/GradleRIO/nashorn.jar")
Expand All @@ -32,6 +35,26 @@ public class ToastDeploy {
trust:true)
}

public static void mapToastDeps(Project project) {
def lib_config = project.getConfigurations().toastLibrary
def libraries = lib_config.dependencies.collect {
[file: lib_config.files(it)[0], name: it.getName()]
}

def mod_config = project.getConfigurations().toastModule
def modules = mod_config.dependencies.collect {
[file: mod_config.files(it)[0], name: it.getName()]
}

libraries.each {
project.gradlerio.deployers += [ to: "/home/lvuser/toast/libs/${it.name}.jar", from: it.file ]
}

modules.each {
project.gradlerio.deployers += [ to: "/home/lvuser/toast/modules/${it.name}.jar", from: it.file ]
}
}

public static File getToastResource(Project project) {
def comp = project.getConfigurations().compile
def toast_dep = comp.getDependencies().find {
Expand Down
62 changes: 61 additions & 1 deletion src/main/groovy/jaci/openrio/gradle/WPIProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WPIProvider {

public static def flavour = "GRADLERIO"

public static void doDeps(Project project, String apiDest) {
public static void init(Project project, String apiDest) {
readManifest()
if (flavour == "GRADLERIO") {
addWPILibraries(project, apiDest)
Expand All @@ -18,6 +18,10 @@ public class WPIProvider {
}
}

public static boolean isToast() {
return flavour == "TOAST"
}

public static void addWPILibraries(Project project, String apidest) {
project.repositories.flatDir() {
dirs "${apidest}/lib"
Expand All @@ -43,4 +47,60 @@ public class WPIProvider {
}
}

public static void update(Project project) {
String extractedDest = System.getProperty("user.home") + "/wpilib/java/extracted/current/"
String urlBase = "http://first.wpi.edu/FRC/roborio/release/eclipse/"
String wpiVersion = "java_0.1.0.201501221609"
println "Checking WPILib Version..."

String wpiInstalledVersion = ""
try {
def versionXML=new XmlSlurper().parse(GradleRIO.pluginDest+"content/content.xml")
def vNode = versionXML.depthFirst().find{it.@id == 'edu.wpi.first.wpilib.plugins.java'}
wpiInstalledVersion = vNode.@version
println "Currently Installed WPILib Version: ${wpiInstalledVersion}"
} catch (Exception e) { }

try {
download(GradleRIO.pluginDest, urlBase+"content.jar", "content.jar")
project.ant.unzip(src: GradleRIO.pluginDest+"content.jar",
dest: GradleRIO.pluginDest+"content",
overwrite:"true")

def xml=new XmlSlurper().parse(GradleRIO.pluginDest+"content/content.xml")
def node = xml.depthFirst().find{it.@id == 'edu.wpi.first.wpilib.plugins.java'}
String wpiVersionLatest = node.@version
println "WPILib Latest Version: ${wpiVersionLatest}"

if (wpiInstalledVersion != wpiVersionLatest) {
println "WPILib Version Mismatch... Updating..."
wpiVersion = "java_${wpiVersionLatest}"
} else {
println "WPILib Version Match. Skipping Update..."
return;
}

println "Deleting WPILib Caches..."
project.ant.delete(dir: extractedDest)
} catch (Exception e) {
println "Could not check WPI Version..."
return
}

String from = urlBase + "plugins/edu.wpi.first.wpilib.plugins.${wpiVersion}.jar"
println "Downloading WPILib..."
download(GradleRIO.pluginDest, from, "plugin.jar")
println "Extracting WPILib..."

project.ant.unzip(src:GradleRIO.pluginDest+"plugin.jar",
dest:extractedDest,
overwrite:"false")
println "WPILib Extracted..."
println "Extracting API Resources..."
project.ant.unzip(src:extractedDest+"resources/java.zip",
dest:GradleRIO.apiDest,
overwrite:"false")
println "API Resources extracted..."
}

}

0 comments on commit 9c2d184

Please sign in to comment.