From 74313a4331a94f7b5b93bb7d7560ebb632e267bf Mon Sep 17 00:00:00 2001 From: "Mcshane, James P" Date: Sat, 11 Mar 2017 00:32:23 -0600 Subject: [PATCH 1/3] Downloading external files using gradle --- build.gradle | 8 +++- strongback/build.gradle | 104 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1014c02..99095d7 100755 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,14 @@ +plugins { + id 'java' +} + ext { baseDir = project.projectDir } allprojects { - apply plugin: "java" + + apply plugin: 'java' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -16,6 +21,7 @@ allprojects { version = "2017.2.1-SNAPSHOT" } + task wrapper(type: Wrapper) { gradleVersion = '2.10' } diff --git a/strongback/build.gradle b/strongback/build.gradle index 3959f90..a15cbf8 100644 --- a/strongback/build.gradle +++ b/strongback/build.gradle @@ -1,7 +1,18 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' + } +} + plugins { id "maven" } +apply plugin: DownloadPlugin + dependencies { compile fileTree(dir: "${project.baseDir}/libs/ctre", include: '**/*.jar') compile fileTree(dir: "${project.baseDir}/libs/nvax-mxp", include: '**/*.jar') @@ -11,3 +22,96 @@ dependencies { testCompile('org.easytesting:fest-assert:1.4') compile('junit:junit:4.11') } + + +import groovyx.net.http.* +import groovy.xml.* + +//plugins/_.jar +//plugins/edu.wpi.first.wpilib.plugins.java_2017.3.1.jar + +class DownloadPlugin implements Plugin { + def rootUrl = 'http://first.wpi.edu/FRC/roborio/release/eclipse/' + void apply(Project project) { + + project.task('hello') { + doLast { + } + } + + def wpiLibFile = new File(project.getBuildDir().getAbsolutePath() + "/wpilib/lib/WPILib.jar"); + + if (wpiLibFile.exists()) { + println "Already downloaded wpilib" + } else { + def client = new HTTPBuilder(rootUrl) + client.headers = [Accept : 'application/xml'] + + def javaUrl = client.get( path : 'site.xml') {resp, xml -> + xml.feature + .find { it.@id == 'edu.wpi.first.wpilib.plugins.java.feature'} + .@url.text() + } + + client.parser.'application/java-archive' = client.parser.defaultParser + client.headers = [Accept : 'application/java-archive'] + + def jar = client.get( path: javaUrl) + def outputFile = new File(project.getBuildDir(), 'wpilib-plugin.jar') + outputFile.parentFile.mkdirs() + outputFile.createNewFile() + outputFile.append jar + + def zipFile = new java.util.zip.ZipFile(outputFile) + def zipEntry = zipFile.entries().find { it.name == "feature.xml"} + def featureText = zipFile.getInputStream(zipEntry).text + def featureXml = new XmlParser().parseText(featureText) + + def id = featureXml.plugin.get(0).@id + def version = featureXml.plugin.get(0).@version + outputFile.delete() + + def javaDep = client.get( path: "plugins/${id}_${version}.jar") + def pluginFile = new File(project.getBuildDir(), 'wpi-java-plugin.jar') + pluginFile.createNewFile() + pluginFile.append javaDep + + def pluginZip = new java.util.zip.ZipFile(pluginFile) + def javaZip = pluginZip.entries().find {it.name == "resources/java.zip" } + def javaZipBytes = pluginZip.getInputStream(javaZip).bytes + def zipOutput = new File(project.getBuildDir(), 'zipOut/') + def javaZipFile = new File(zipOutput, 'java.zip') + javaZipFile.parentFile.mkdirs() + javaZipFile.createNewFile() + javaZipFile.append javaZipBytes + + pluginFile.delete() + + def outputDir = new File(project.getBuildDir(), 'wpilib/') + outputDir.mkdirs() + def zip = new java.util.zip.ZipFile(javaZipFile) + zip.entries().each{ + if (!it.isDirectory()){ + def fOut = new File(outputDir.getAbsolutePath()+ File.separator + it.name) + //create output dir if not exists + new File(fOut.parent).mkdirs() + fOut.createNewFile() + //println "name:${it.name}, size:${it.size}" + def bytes = zip.getInputStream(it).bytes //println zip.getInputStream(it).text + fOut.append bytes + } + } + zip.close() + + zipOutput.delete() + } + project.dependencies.add 'compile', project.fileTree(dir: 'build/wpilib/lib', include: '**/*.jar', exclude: '**/*-sources.jar') + + // def id = featureXml.plugin[0].@id + // def version = featureXml.plugin[0].@version + // println id + " " + version + // Add the 'greeting' extension object + // project.extensions.create("greeting", DownloadPluginExtension) + // Add a task that uses the configuration + } +} From f41c626ea1d5401d5d6416642fc7983efe741203 Mon Sep 17 00:00:00 2001 From: "Mcshane, James P" Date: Sat, 11 Mar 2017 12:30:58 -0600 Subject: [PATCH 2/3] Completing wpilib work by adding the gradlerio plugin, which can reference any currently deployed version of wpilib to compile against --- build.gradle | 17 ++++-- strongback-tests/build.gradle | 4 +- strongback-tools/build.gradle | 2 +- strongback/build.gradle | 111 ++-------------------------------- 4 files changed, 20 insertions(+), 114 deletions(-) diff --git a/build.gradle b/build.gradle index 99095d7..c66a283 100755 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,8 @@ -plugins { - id 'java' -} - ext { baseDir = project.projectDir } -allprojects { +subprojects { apply plugin: 'java' @@ -20,6 +16,17 @@ allprojects { group = "org.strongback" version = "2017.2.1-SNAPSHOT" + repositories { + maven { + url 'http://first.wpi.edu/FRC/roborio/maven/release' + } + } + + dependencies { + testCompile('junit:junit:4.12') + testCompile('org.easytesting:fest-assert:1.4') + } + } task wrapper(type: Wrapper) { diff --git a/strongback-tests/build.gradle b/strongback-tests/build.gradle index fbe59db..fc3c898 100644 --- a/strongback-tests/build.gradle +++ b/strongback-tests/build.gradle @@ -1,4 +1,4 @@ dependencies { - compile project(":strongback") - compile project(":strongback-testing") + testCompile project(":strongback") + testCompile project(":strongback-testing") } \ No newline at end of file diff --git a/strongback-tools/build.gradle b/strongback-tools/build.gradle index d72ab41..c0b1b9c 100644 --- a/strongback-tools/build.gradle +++ b/strongback-tools/build.gradle @@ -1,3 +1,3 @@ plugins { id "maven" -} \ No newline at end of file +} diff --git a/strongback/build.gradle b/strongback/build.gradle index a15cbf8..950f81c 100644 --- a/strongback/build.gradle +++ b/strongback/build.gradle @@ -1,117 +1,16 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' - } -} - plugins { id "maven" + id "jaci.openrio.gradle.GradleRIO" version "2017.1.5" } -apply plugin: DownloadPlugin +wpi { + wpilibVersion = '2017.3.1' +} dependencies { + compile wpilib() compile fileTree(dir: "${project.baseDir}/libs/ctre", include: '**/*.jar') compile fileTree(dir: "${project.baseDir}/libs/nvax-mxp", include: '**/*.jar') - compile fileTree(dir: "${project.baseDir}/libs/wpilib", include: '**/*.jar') compile('io.dropwizard.metrics:metrics-core:3.1.0') - - testCompile('org.easytesting:fest-assert:1.4') compile('junit:junit:4.11') } - - -import groovyx.net.http.* -import groovy.xml.* - -//plugins/_.jar -//plugins/edu.wpi.first.wpilib.plugins.java_2017.3.1.jar - -class DownloadPlugin implements Plugin { - def rootUrl = 'http://first.wpi.edu/FRC/roborio/release/eclipse/' - void apply(Project project) { - - project.task('hello') { - doLast { - } - } - - def wpiLibFile = new File(project.getBuildDir().getAbsolutePath() + "/wpilib/lib/WPILib.jar"); - - if (wpiLibFile.exists()) { - println "Already downloaded wpilib" - } else { - def client = new HTTPBuilder(rootUrl) - client.headers = [Accept : 'application/xml'] - - def javaUrl = client.get( path : 'site.xml') {resp, xml -> - xml.feature - .find { it.@id == 'edu.wpi.first.wpilib.plugins.java.feature'} - .@url.text() - } - - client.parser.'application/java-archive' = client.parser.defaultParser - client.headers = [Accept : 'application/java-archive'] - - def jar = client.get( path: javaUrl) - def outputFile = new File(project.getBuildDir(), 'wpilib-plugin.jar') - outputFile.parentFile.mkdirs() - outputFile.createNewFile() - outputFile.append jar - - def zipFile = new java.util.zip.ZipFile(outputFile) - def zipEntry = zipFile.entries().find { it.name == "feature.xml"} - def featureText = zipFile.getInputStream(zipEntry).text - def featureXml = new XmlParser().parseText(featureText) - - def id = featureXml.plugin.get(0).@id - def version = featureXml.plugin.get(0).@version - outputFile.delete() - - def javaDep = client.get( path: "plugins/${id}_${version}.jar") - def pluginFile = new File(project.getBuildDir(), 'wpi-java-plugin.jar') - pluginFile.createNewFile() - pluginFile.append javaDep - - def pluginZip = new java.util.zip.ZipFile(pluginFile) - def javaZip = pluginZip.entries().find {it.name == "resources/java.zip" } - def javaZipBytes = pluginZip.getInputStream(javaZip).bytes - def zipOutput = new File(project.getBuildDir(), 'zipOut/') - def javaZipFile = new File(zipOutput, 'java.zip') - javaZipFile.parentFile.mkdirs() - javaZipFile.createNewFile() - javaZipFile.append javaZipBytes - - pluginFile.delete() - - def outputDir = new File(project.getBuildDir(), 'wpilib/') - outputDir.mkdirs() - def zip = new java.util.zip.ZipFile(javaZipFile) - zip.entries().each{ - if (!it.isDirectory()){ - def fOut = new File(outputDir.getAbsolutePath()+ File.separator + it.name) - //create output dir if not exists - new File(fOut.parent).mkdirs() - fOut.createNewFile() - //println "name:${it.name}, size:${it.size}" - def bytes = zip.getInputStream(it).bytes //println zip.getInputStream(it).text - fOut.append bytes - } - } - zip.close() - - zipOutput.delete() - } - project.dependencies.add 'compile', project.fileTree(dir: 'build/wpilib/lib', include: '**/*.jar', exclude: '**/*-sources.jar') - - // def id = featureXml.plugin[0].@id - // def version = featureXml.plugin[0].@version - // println id + " " + version - // Add the 'greeting' extension object - // project.extensions.create("greeting", DownloadPluginExtension) - // Add a task that uses the configuration - } -} From d105bfe606be088bac1a8c025ab872475b521d90 Mon Sep 17 00:00:00 2001 From: "Mcshane, James P" Date: Sat, 11 Mar 2017 13:22:35 -0600 Subject: [PATCH 3/3] Completing refactoring for the correct amount of gradle dependencies on existing ant tasks, while using the gradle plugin for wpilib to specify the exact version rather than downloading from releases. This will force compilation of strongback to specific wpilib version and can publish multiple artifacts against these versions --- build.gradle | 5 +++ build.properties | 12 -------- build.xml | 62 ++------------------------------------ strongback/build.gradle | 5 ++- third-party.xml | 67 +++++++++++++++++++++++++++++++++++++++++ thirdparty.properties | 11 +++++++ 6 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 third-party.xml create mode 100644 thirdparty.properties diff --git a/build.gradle b/build.gradle index c66a283..9078bc1 100755 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +plugins { + id 'java' +} ext { baseDir = project.projectDir } @@ -32,3 +35,5 @@ subprojects { task wrapper(type: Wrapper) { gradleVersion = '2.10' } + +ant.importBuild 'third-party.xml' diff --git a/build.properties b/build.properties index b83ee35..b85fd64 100644 --- a/build.properties +++ b/build.properties @@ -5,15 +5,3 @@ strongback.version=2017.2.0 # replace the value with the URL of the WPILib Eclipse Update Site # wpilib.updatesite.url=http://first.wpi.edu/FRC/roborio/release/eclipse/ - -# -# Starting in 2017, WPILib will no longer have built-in support for the TalonSRX -# from Cross the Road Electronics (CTRE). Instead, the `CANTalon` class and associated -# functionality is available directly from CTRE as a separate JAR. -# -ctre.download.url=http://www.ctr-electronics.com/downloads/lib/CTRE_FRCLibs_NON-WINDOWS.zip - -# -# The navX-MXP library is available in a ZIP file that has only the Java and C++ libraries. -# -navx.download.url=http://www.kauailabs.com/public_files/navx-mxp/navx-mxp-libs.zip \ No newline at end of file diff --git a/build.xml b/build.xml index c7a1ac0..a67adf4 100644 --- a/build.xml +++ b/build.xml @@ -13,12 +13,12 @@ + + - - @@ -256,62 +256,4 @@ - - - - - - - - - - - Downloading the CTRE library and installing into '${ctre.dir}'. - - - - - - - - - - - - - - - - - - # Downloaded and installed by Strongback build system${line.separator} - ${ctre.version.properties} - - - - - - - - - - - - Downloading the navX-MXP library and installing into '${navx.dir}'. - - - - - - - - - - - - - - - - diff --git a/strongback/build.gradle b/strongback/build.gradle index 950f81c..2b7b838 100644 --- a/strongback/build.gradle +++ b/strongback/build.gradle @@ -10,7 +10,10 @@ wpi { dependencies { compile wpilib() compile fileTree(dir: "${project.baseDir}/libs/ctre", include: '**/*.jar') - compile fileTree(dir: "${project.baseDir}/libs/nvax-mxp", include: '**/*.jar') + compile fileTree(dir: "${project.baseDir}/libs/navx-mxp", include: '**/*.jar') compile('io.dropwizard.metrics:metrics-core:3.1.0') compile('junit:junit:4.11') } + +compileJava.dependsOn(':download-navx') +compileJava.dependsOn(':download-ctre') \ No newline at end of file diff --git a/third-party.xml b/third-party.xml new file mode 100644 index 0000000..f61abad --- /dev/null +++ b/third-party.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + Downloading the CTRE library and installing into '${ctre.dir}'. + + + + + + + + + + + + + + + + + + # Downloaded and installed by Strongback build system${line.separator} + ${ctre.version.properties} + + + + + + + + + + + Downloading the navX-MXP library and installing into '${navx.dir}'. + + + + + + + + + + + + + + + + + diff --git a/thirdparty.properties b/thirdparty.properties new file mode 100644 index 0000000..864fad5 --- /dev/null +++ b/thirdparty.properties @@ -0,0 +1,11 @@ +# +# Starting in 2017, WPILib will no longer have built-in support for the TalonSRX +# from Cross the Road Electronics (CTRE). Instead, the `CANTalon` class and associated +# functionality is available directly from CTRE as a separate JAR. +# +ctre.download.url=http://www.ctr-electronics.com/downloads/lib/CTRE_FRCLibs_NON-WINDOWS.zip + +# +# The navX-MXP library is available in a ZIP file that has only the Java and C++ libraries. +# +navx.download.url=http://www.kauailabs.com/public_files/navx-mxp/navx-mxp-libs.zip \ No newline at end of file