This repository has been archived by the owner on Jan 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
246 lines (207 loc) · 6.58 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
classpath 'commons-io:commons-io:2.4'
classpath 'org.ajoberstar:grgit:1.4.1'
}
}
plugins {
id 'java'
id 'idea'
id 'eclipse'
id 'jaci.openrio.gradle.GradleRIO' version '2017.1.0'
id 'org.ajoberstar.grgit' version '1.3.2'
id 'org.ajoberstar.release-opinion' version '1.3.2'
id 'maven-publish'
}
frc {
team = "1294"
robotClass = "org.usfirst.frc.team1294.robot.Robot"
rioIP = "169.254.224.42"
}
repositories {
mavenCentral()
}
dependencies {
compile wpilib()
compile talonSrx()
compile fileTree(dir: 'libs', include: '**/*.jar')
testCompile group: 'org.testng', name: 'testng', version: '6.9.13.6'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.5.2'
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
publishing {
publications {
MyPublication(MavenPublication) {
from components.java
groupId 'org.usfirst.frc.team1294'
artifactId 'frc2017'
version project.version.toString()
}
}
}
model {
tasks.generatePomFileForMyPublicationPublication {
destination = file("$buildDir/frc2017-${project.version.toString()}.pom")
}
}
jar {
archiveName = "frc1294.jar"
manifest {
attributes 'Main-Class': 'edu.wpi.first.wpilibj.RobotBase'
attributes 'Robot-Class': frc.robotClass
attributes 'Version' : project.version.toString()
attributes 'Author' : getAuthor()
}
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
task generateBintrayFile(type: Copy) {
def vcs_tag = project.version.toString() // default to version
grgit = org.ajoberstar.grgit.Grgit.open(project.file('.'))
try {
vcs_tag = grgit.log(maxCommits: 1).get(0).id
} catch(all) {}
from(projectDir) {
include 'bintray.json'
}
expand(
version: project.version.toString(),
date: new Date().format('yyyy-MM-dd'),
vcs_tag: vcs_tag
)
into 'build'
}
release {
// need to specify the repository to interact with
grgit = org.ajoberstar.grgit.Grgit.open(project.file('.'))
}
test {
useTestNG {
include('**/*')
if (!project.hasProperty('test.vision'))
getExcludeGroups().add('vision')
}
}
def getAuthor() {
def author = "unknown"
grgit = org.ajoberstar.grgit.Grgit.open(project.file('.'))
if (grgit.status().isClean()) {
def history = grgit.log(maxCommits: 1)
author = "${history.author.name[0]} <${history.author.email[0]}>"
} else {
author = System.env.USER ?: System.env.USERNAME
}
return author
}
import groovy.json.JsonSlurper
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import org.apache.commons.io.FilenameUtils
String[] getVersionsFromBintray() {
def http = new HTTPBuilder("https://bintray.com/api/v1/packages/frc-1294/Robot-Code/frc2016")
http.request(Method.GET, ContentType.TEXT ) { req ->
headers.'Accept' = 'application/json'
response.success = { resp, reader ->
def versions = new JsonSlurper().parseText(reader.text).versions
return versions;
}
}
}
String getVersionJarFileDownloadPath(version) {
def http = new HTTPBuilder("https://bintray.com/api/v1/packages/frc-1294/Robot-Code/frc2016/versions/" + version + "/files")
http.request(Method.GET, ContentType.TEXT ) { req ->
headers.'Accept' = 'application/json'
response.success = { resp, reader ->
def files = new JsonSlurper().parseText(reader.text)
def jarFileIndex = files.findIndexOf { it.path.endsWith('.jar') }
def file = files[jarFileIndex]
return String.format("https://bintray.com/artifact/download/%s/%s/%s", file.owner, file.repo, file.path.replaceAll("\\+", "%2B"))
}
}
}
def downloadFile(url, dest) {
def file = new FileOutputStream(dest)
def out = new BufferedOutputStream(file)
out << new URL(url).openStream()
out.close()
}
def downloadReleasesTask = project.task('downloadReleases') << {
String[] versions = getVersionsFromBintray()
versions.eachWithIndex{ a,i ->
def dest = new File("$buildDir/releases/${a}.jar")
if (dest.exists()) {
println "Already have ${a}, skipping."
} else {
println "Downloading ${a}"
downloadFile(getVersionJarFileDownloadPath(a), dest);
}
}
}
def deployRelease() {
File releaseFolder = new File("$buildDir/releases")
def releases = releaseFolder.listFiles().sort(false).reverse()
def console = System.console()
if (console) {
console.writer().println("\n\nAvailable Releases:")
releases.eachWithIndex { it, i ->
console.writer().println("[$i]: ${FilenameUtils.removeExtension(it.getName())}")
}
def releaseIndex = (console.readLine("Which release would you like to deploy? [0]")?:0).toInteger()
def releasePath = releases[releaseIndex].toPath()
try {
def host = "roboRIO-${project.gradlerio.team}.local"
println "Attempting to send new code to RoboRIO..."
project.ant.scp(file: "${releasePath}",
todir:"lvuser@${host}:${project.gradlerio.deployFile}",
password:"",
port:22,
trust:true)
println "Deploy Successful! Loaded in: ${project.gradlerio.deployFile}"
println "Attempting to restart the RoboRIO code..."
project.ant.sshexec(host: "${host}",
username:"lvuser",
port:22,
trust:true,
password:"",
command:"/etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t -r"
)
println "Robot Code is restarting..."
} catch (Exception ex) {
println "RoboRIO not available... Falling back to IP..."
String ip = project.gradlerio.rioIP
if (ip == "{DEFAULT}") {
String team = project.gradlerio.team
int length = team.length();
if (length < 4)
for (int i = 0; i < 4 - length; i++)
team = "0" + team;
ip = "10." + team.substring(0, 2) + "." + team.substring(2, 4) + ".20"
}
println "Attempting to send new code to RoboRIO..."
project.ant.scp(file: "${releasePath}",
todir:"lvuser@${ip}:${project.gradlerio.deployFile}",
password:"",
port:22,
trust:true)
println "Deploy Successful! Loaded in: ${project.gradlerio.deployFile}"
println "Attempting to restart the RoboRIO code..."
project.ant.sshexec(host: "${ip}",
username:"lvuser",
port:22,
trust:true,
password:"",
command:"/etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t -r"
)
println "Robot Code is restarting..."
}
}
}
def deployReleaseTask = project.task('deployRelease') << {
deployRelease()
}