Skip to content

Commit 17a107e

Browse files
committed
Include a Verification Routine to aid building with CI. Update to version 1.1.0. Gradle files auto-update toast/gradlerio
1 parent 47ca273 commit 17a107e

10 files changed

Lines changed: 158 additions & 7 deletions

File tree

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ language: java
33
install:
44
- "./gradlew wpi"
55
- "./gradlew assemble"
6-
6+
7+
script:
8+
- "./gradlew verify"
9+
710
jdk:
811
- oraclejdk8
912

build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,39 @@ class BuildGradle implements Plugin<Project> {
177177
}
178178
ant.zip(destfile: "releases/Toast-Deployment-Utility.zip", basedir: "build/deployment")
179179
}
180+
181+
project.getConfigurations().maybeCreate('verify')
182+
project.task('verify') << {
183+
File toast_dir = new File('run/verification')
184+
if (toast_dir.exists()) {
185+
project.ant.delete(dir: toast_dir.getAbsolutePath())
186+
}
187+
188+
toast_dir.mkdirs()
189+
File modules_dir = new File(toast_dir, "toast/modules")
190+
modules_dir.mkdirs()
191+
192+
println "Beginning Assets Copying..."
193+
File toast = new File(toast_dir, 'Toast.jar')
194+
String archive = project.jar.archivePath
195+
project.ant.copy(tofile: toast.getAbsolutePath(), file: archive)
196+
197+
project.getConfigurations().verify.resolve().each {
198+
File file = it
199+
File toFile = new File(modules_dir, file.getName())
200+
project.ant.copy(tofile: toFile.getAbsolutePath(), file: file.getAbsolutePath())
201+
}
202+
203+
println "Assets Copied..."
204+
println "Beginning Verification..."
205+
206+
project.javaexec {
207+
workingDir = toast_dir.getAbsolutePath()
208+
args = ["Toast.jar", "-verify"]
209+
main = '-jar'
210+
}
211+
212+
println "Verification Complete..."
213+
}
180214
}
181215
}

build.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
toast.version=1.0.0
1+
toast.version=1.1.0

release/.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: java
2+
3+
install:
4+
- "./gradlew assemble"
5+
6+
script:
7+
- "./gradlew verify"
8+
jdk:
9+
- oraclejdk8
10+
11+
notifications:
12+
email: false

release/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
}
1313
}
1414
dependencies {
15-
classpath group: 'jaci.openrio.gradle', name: 'GradleRIO', version: '1.1.6', classifier: 'Toast' //Change this line if you wish to Update GradleRIO
15+
classpath group: 'jaci.openrio.gradle', name: 'GradleRIO', version: '+', classifier: 'Toast' //Change this line if you wish to Update GradleRIO
1616
}
1717
}
1818

@@ -36,5 +36,5 @@ gradlerio.team = "5333" //Your FRC team number
3636
gradlerio.deployFile = "toast/modules/${archivesBaseName}"
3737

3838
dependencies {
39-
compile group: 'jaci.openrio.toast', name: 'Toast', version: '0.5.0' //Change this line to update Toast
39+
compile group: 'jaci.openrio.toast', name: 'Toast', version: '+' //Change this line to update Toast
4040
}

src/main/java/jaci/openrio/toast/core/StateTracker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
44
import edu.wpi.first.wpilibj.communication.UsageReporting;
55
import jaci.openrio.toast.core.loader.groovy.GroovyLoader;
6+
import jaci.openrio.toast.core.loader.verification.VerificationWorker;
67
import jaci.openrio.toast.lib.FRCHooks;
78
import jaci.openrio.toast.lib.state.RobotState;
89
import jaci.openrio.toast.lib.state.StateListener;
@@ -44,6 +45,8 @@ public static void init(Toast impl) {
4445
UsageReporting.report(FRCNetworkCommunicationsLibrary.tResourceType.kResourceType_Framework, FRCNetworkCommunicationsLibrary.tInstances.kFramework_Iterative);
4546
StateTracker.impl = impl;
4647
boolean isAlive;
48+
if (ToastBootstrap.isVerification)
49+
VerificationWorker.begin();
4750
while (true) {
4851
if (impl.isDisabled()) {
4952
if (!_state_disabled_init) {

src/main/java/jaci/openrio/toast/core/Toast.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ public void startCompetition() {
112112

113113
public void shutdownSafely() {
114114
log().info("Robot Shutting Down...");
115-
System.exit(1);
115+
System.exit(0);
116116
}
117117

118+
public void shutdownCrash() {
119+
log().info("Robot Error Detected... Shutting Down...");
120+
System.exit(-1);
121+
}
122+
123+
/** Verification Overrides **/
124+
125+
126+
118127
}

src/main/java/jaci/openrio/toast/core/ToastBootstrap.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public class ToastBootstrap {
3131
*/
3232
public static boolean isSimulation;
3333

34+
/**
35+
* Is this a verification? Verifications are headless routines to 'test' the
36+
* build process.
37+
*/
38+
public static boolean isVerification;
39+
3440
/**
3541
* Get the root folder for Toast. This is where logs, modules,
3642
* and just about everything for toast is saved.
@@ -65,6 +71,9 @@ public static void main(String[] args) {
6571
if (!nextArg.equals("."))
6672
GroovyLoader.customClasses.add(nextArg);
6773
} catch (Exception e) {}
74+
} else if (arg.equalsIgnoreCase("-verify") || arg.equalsIgnoreCase("-vf")) {
75+
isSimulation = true;
76+
isVerification = true;
6877
}
6978
}
7079

@@ -87,7 +96,7 @@ public static void main(String[] args) {
8796
startTimeNS = System.nanoTime();
8897
startTimeMS = System.currentTimeMillis();
8998

90-
if (isSimulation) {
99+
if (isSimulation && !isVerification) {
91100
SimulationGUI.main(args);
92101
}
93102

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package jaci.openrio.toast.core.loader.verification;
2+
3+
import groovy.lang.GroovyObject;
4+
import jaci.openrio.toast.core.Toast;
5+
import jaci.openrio.toast.core.loader.groovy.GroovyLoader;
6+
import jaci.openrio.toast.core.loader.module.ModuleContainer;
7+
import jaci.openrio.toast.core.loader.module.ModuleManager;
8+
import jaci.openrio.toast.core.loader.simulation.SimulationData;
9+
import jaci.openrio.toast.lib.log.Logger;
10+
import jaci.openrio.toast.lib.module.GroovyScript;
11+
import jaci.openrio.toast.lib.state.RobotState;
12+
13+
import java.util.Map;
14+
15+
/**
16+
* The Verification Worker. This class is called when the Toast Jar file is launched with the arguments -vf or -verify.
17+
* This thread runs through the Disabled -> Autonomous -> Teleoperated -> End lifecycle of the robot, and if any errors
18+
* or uncaught exceptions are encountered along the way, the program will exit with error code -1. If this is launched from
19+
* gradle using 'gradlew verify', the build will fail. This class is mostly used in Travis CI builds and exists to give
20+
* a proper 'yes, this code works' requirement to a successful build instead of the typical 'there's no compile errors'
21+
* requirement, giving repos an accurate look at how the build is passing.
22+
*
23+
* @author Jaci
24+
*/
25+
public class VerificationWorker extends Thread {
26+
27+
static VerificationWorker worker;
28+
static Logger logger;
29+
30+
public VerificationWorker() {
31+
this.setName("Verification Worker");
32+
}
33+
34+
public static void begin() {
35+
logger = new Logger("Verification", Logger.ATTR_DEFAULT);
36+
worker = new VerificationWorker();
37+
worker.start();
38+
}
39+
40+
@Override
41+
public void run() {
42+
try {
43+
logger.info("Beginning Code Verification. Echoing environmental data...");
44+
echoEnvironment();
45+
logger.info("Starting Code Verification in 5 seconds...");
46+
Thread.sleep(5 * 1000);
47+
logger.info("Transferring into Autonomous... (Switching to Teleop in 15 seconds)");
48+
SimulationData.currentState = RobotState.AUTONOMOUS;
49+
Thread.sleep(15 * 1000);
50+
logger.info("Transferring into Teleoperated... (Switching to Disabled in 1 minute)");
51+
SimulationData.currentState = RobotState.TELEOP;
52+
Thread.sleep(60 * 1000);
53+
logger.info("Disabling Robot... (Shutting Down in 10 seconds)");
54+
SimulationData.currentState = RobotState.DISABLED;
55+
Thread.sleep(10 * 1000);
56+
logger.info("Code Verification Successful! Shutting Down...");
57+
Toast.getToast().shutdownSafely();
58+
} catch (Exception e) {
59+
logger.error("Exception encountered during verification: " + e);
60+
logger.exception(e);
61+
Toast.getToast().shutdownCrash();
62+
}
63+
}
64+
65+
void echoEnvironment() {
66+
logger.info("\tLoaded Modules:");
67+
for (ModuleContainer module : ModuleManager.getContainers())
68+
logger.info("\t\t" + module.getDetails());
69+
70+
logger.info("\tLoaded Groovy Scripts:");
71+
for (GroovyScript script : GroovyLoader.scripts)
72+
logger.info("\t\t" + script.getClass());
73+
74+
logger.info("\tLoaded Groovy Files:");
75+
for (Map.Entry<String, GroovyObject> entry : GroovyLoader.groovyObjects.entrySet())
76+
logger.info("\t\t" + entry.getKey() + " : " + entry.getValue());
77+
78+
79+
}
80+
81+
}

src/main/java/jaci/openrio/toast/lib/crash/CrashHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void handle(Throwable t) {
8888

8989
Files.copy(recentLog.toPath(), cpFile.toPath());
9090

91-
Toast.getToast().shutdownSafely();
91+
Toast.getToast().shutdownCrash();
9292
} catch (Exception e) {
9393
}
9494
}

0 commit comments

Comments
 (0)