Skip to content

Commit 368bbee

Browse files
authored
Merge pull request #53 from frc5024/bundlejars
2 parents 835edf6 + 2d96dfd commit 368bbee

File tree

17 files changed

+242
-126
lines changed

17 files changed

+242
-126
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The software libraries that power all Raider Robotics projects.
66

77
## Using
88

9-
The simplest way to use lib5k is to import the entire library (warning: this is quite big). This can be done by grabbing the latest `lib5k-bundle-<version>-monolithic.jar` file from the [releases page](https://github.com/frc5024/lib5k/releases/latest), and adding it to your project (here is a [tutorial](https://medium.com/@petehouston/compile-local-jar-files-with-gradle-a078e5c7a520)).
9+
The simplest way to use lib5k is to import the entire library (warning: this is quite big). This can be done by grabbing the latest `lib5k-<version>-all.jar` file from the [releases page](https://github.com/frc5024/lib5k/releases/latest), and adding it to your project (here is a [tutorial](https://medium.com/@petehouston/compile-local-jar-files-with-gradle-a078e5c7a520)).
1010

1111
If you would like to pick and choose which components you want, reference the chart below, and only add the jars you want.
1212

@@ -67,7 +67,7 @@ Any folder containing a `build.gradle` file can be a module. Make sure to add th
6767

6868
To build a new release, first update the version number at the top of `build.gradle`.
6969

70-
Next, run `./gradlew clean build buildRelease`. This will build all modules individually, then also build a packaged jar with everything in it. All files will be exported to the `_release` folder. Team members with permission to publish releases can then create a new GitHub release [here](https://github.com/frc5024/lib5k/releases/new).
70+
Next, run `./gradlew clean buildRelease`. This will build all modules individually, then also build a packaged jar with everything in it. All files will be exported to the `_release` folder. Team members with permission to publish releases can then create a new GitHub release [here](https://github.com/frc5024/lib5k/releases/new).
7171

7272
Otherwise, you can just use these files, and follow [the instructions above](#using).
7373

autonomous/src/main/java/io/github/frc5024/lib5k/autonomous/RobotProgram.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.frc5024.lib5k.autonomous;
22

3+
import edu.wpi.first.wpilibj.Sendable;
34
import edu.wpi.first.wpilibj.TimedRobot;
45
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
56
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
@@ -9,6 +10,7 @@
910

1011
import io.github.frc5024.lib5k.logging.RobotLogger;
1112
import io.github.frc5024.lib5k.hardware.ni.roborio.FaultReporter;
13+
import io.github.frc5024.lib5k.hardware.ni.roborio.fpga.RR_HAL;
1214

1315
/**
1416
* RobotProgram is the base class for all robot programs.
@@ -67,17 +69,33 @@ public RobotProgram(boolean runSchedulerInTestMode, boolean stopAutonomousInTele
6769
this.stopAutonomousInTeleop = stopAutonomousInTeleop;
6870
this.dashboard = primaryDashboard;
6971

70-
// Send chooser to dashboard
72+
// Create a chooser
7173
chooser = new SendableChooser<>();
72-
dashboard.add(chooser);
7374

7475
// Start logger
7576
logger.start(0.02);
7677

77-
// Start a fault reporter
78+
// Report language
79+
RR_HAL.reportFRCVersion("Java", RR_HAL.getLibraryVersion());
7880

7981
}
8082

83+
/**
84+
* For publishing the chooser (this can be overridden for custom dashboards)
85+
*
86+
* @param component Chooser component
87+
*/
88+
public void publishChooser(Sendable component) {
89+
dashboard.add(component);
90+
}
91+
92+
/**
93+
* This is run all the time
94+
*
95+
* @param init Did the robot just start?
96+
*/
97+
public abstract void periodic(boolean init);
98+
8199
/**
82100
* This is run during autonomous
83101
*
@@ -106,6 +124,24 @@ public RobotProgram(boolean runSchedulerInTestMode, boolean stopAutonomousInTele
106124
*/
107125
public abstract void test(boolean init);
108126

127+
@Override
128+
public void robotInit() {
129+
130+
// Publish the chooser
131+
publishChooser(chooser);
132+
133+
// Call robot
134+
periodic(true);
135+
136+
}
137+
138+
@Override
139+
public void robotPeriodic() {
140+
141+
// Call robot
142+
periodic(false);
143+
}
144+
109145
/**
110146
* Set the default autonomous sequence
111147
*
@@ -134,6 +170,16 @@ public void addAutonomous(AutonomousSequence sequence) {
134170
chooser.addOption(sequence.getName(), sequence);
135171
}
136172

173+
/**
174+
* Get the selected autonomous. If this is not called in autonomous(), it will
175+
* return the default
176+
*
177+
* @return Selected autonomous sequence
178+
*/
179+
public AutonomousSequence getSelectedAutonomous() {
180+
return autonomous;
181+
}
182+
137183
@Override
138184
public void autonomousInit() {
139185
logger.log("Autonomous started");

build.gradle

Lines changed: 134 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,200 @@
1-
/*
2-
* This file was generated by the Gradle 'init' task.
3-
*
4-
* This is a general purpose Gradle build.
5-
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds/
6-
*/
7-
8-
1+
// This is the main build script. This mostly contains the gradle tasks for building the library JAR files and documentation
92

3+
// This injects the gradlerio version info into all projects
104
buildscript {
115
repositories {
126
jcenter()
137
maven { url "https://plugins.gradle.org/m2/" }
148
}
159

1610
dependencies {
17-
classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:2.2.+'
18-
classpath "edu.wpi.first:GradleRIO:2020.+"
11+
// Update this version number to update GradleRIO
12+
classpath "edu.wpi.first:GradleRIO:2020.+"
1913
}
2014
}
2115

16+
// All plugins used by the buildscript
2217
plugins {
2318
id "com.gradle.build-scan" version "3.3.4"
19+
id "java-library"
2420
}
2521

26-
apply plugin: 'nebula-aggregate-javadocs'
27-
apply plugin: "java-library"
22+
// Load project dependancy configurations
23+
apply from: "gradle_utils/libversions.gradle"
24+
apply from: "gradle_utils/mavenrepos.gradle"
2825

2926
// LIB VERSION
3027
project.version = "1.2.1"
3128

29+
// Enable Java support for all projects
3230
allprojects{
3331
apply plugin: "java"
3432
}
3533

34+
// This enables some fancy gradle enterprise features for us
3635
gradleEnterprise {
3736
buildScan {
3837
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
3938
termsOfServiceAgree = 'yes'
4039
}
4140
}
4241

42+
// This will automatically pull in everything that isnt the "examples" project
43+
dependencies{
44+
rootProject.subprojects.each{
45+
if ( it.name != "examples"){
46+
api it
47+
}
48+
}
49+
}
4350

44-
// task document {
45-
// dependsOn "aggregateJavadocs"
46-
// doLast {
47-
// file("$rootProject.buildDir/docs/javadoc").renameTo(file("docs"))
48-
// }
49-
// }
51+
// This task takes every subproject's Javadoc, and merges it into one
52+
task combineJavadoc(type: Javadoc, description: 'Generate javadocs from all child projects as if it was a single project', group: 'Documentation') {
5053

51-
task document(type: Javadoc, description: 'Generate javadocs from all child projects as if it was a single project', group: 'Documentation') {
54+
// Set the jars to be generated into the build directory
5255
destinationDir = file("$buildDir/docs/javadoc")
56+
57+
// Set the JavaDoc webpage title
5358
title = "$project.name $version API"
59+
60+
// Set the custom CSS file containing our logo and theme
5461
options.setStylesheetFile(file("javadoc.css"))
62+
63+
// These fix a JavaDoc bug
5564
options.addBooleanOption('-no-module-directories', true)
5665
options.author true
66+
67+
// If you add a new dependancy to the project, add its javadoc URL to this list
5768
options.links 'http://docs.spring.io/spring/docs/4.3.x/javadoc-api/', 'http://docs.oracle.com/javase/8/docs/api/', 'http://docs.spring.io/spring-ws/docs/2.3.0.RELEASE/api/', 'http://docs.spring.io/spring-security/site/docs/4.0.4.RELEASE/apidocs/', 'https://first.wpi.edu/FRC/roborio/release/docs/java/', 'https://www.revrobotics.com/content/sw/max/sw-docs/java/', 'https://www.kauailabs.com/public_files/navx-mxp/apidocs/java/', 'https://knowm.org/javadocs/xchart/'
58-
options.addStringOption 'Xdoclint:none', '-quiet'
59-
println "Building recursive JavaDoc"
69+
70+
// Any JavaDoc options should go here
71+
options.addStringOption 'Xdoclint:none', '-quiet'
6072

61-
// source subprojects.collect { proj -> proj.sourceSets.main.allJava }
73+
// Load the configuraation from every subproject
6274
subprojects.each { proj ->
6375

76+
// Don't document the "examples" project
6477
if (proj.name != "examples"){
65-
println 'Adding ' + proj.projectDir + "/src/main/java"
78+
79+
// Read form every JavaDoc task in the subproject
6680
proj.tasks.withType(Javadoc).each { javadocTask ->
67-
println 'Found JavaDoc task'
81+
82+
// Add the task sources to the main JavaDoc
6883
source += javadocTask.source
6984
classpath += javadocTask.classpath
7085
excludes += javadocTask.excludes
7186
includes += javadocTask.includes
87+
7288
}
89+
7390
}
91+
7492
}
7593

76-
doLast {
77-
println "Copying javadoc to docs folder"
78-
delete "docs"
79-
file("$rootProject.buildDir/docs/javadoc").renameTo(file("docs"))
80-
}
94+
}
95+
96+
// This task is used to make the "clean" task clean out the docs directory
97+
task _cleanDocs(type: Delete){
98+
delete "docs"
8199
}
100+
tasks.clean.dependsOn(tasks._cleanDocs)
82101

102+
// This is just a compatibility thing
83103
subprojects.each { subproject ->
84104
evaluationDependsOn(subproject.path)
85105
}
86-
task mmJar(type: Jar, dependsOn: subprojects.jar) {
87-
subprojects.each { subproject ->
88-
from subproject.configurations.archives.artifacts.files.collect {
89-
zipTree(it)
90-
}
106+
107+
// This gets run by our CI pipeline to generate https://frc5024.github.io/lib5k
108+
task document(dependsOn: combineJavadoc){
109+
// Clear out the docs folder, and move the JavaDoc into it
110+
dependsOn _cleanDocs
111+
doLast{
112+
file("$rootProject.buildDir/docs/javadoc").renameTo(file("docs"))
91113
}
92114
}
93115

94-
task copyPyLogReader(type: Copy){
95-
from "scripts/logreader.py"
96-
into "_release"
116+
/* Build all the required JARs */
117+
118+
// This will take every JavaDoc and pack it into a single JAR
119+
task _buildJavaDocJar(type: Jar, dependsOn: document){
120+
classifier = "javadoc"
121+
from file("docs")
97122
}
98123

99-
task copyPySim(type: Copy){
100-
from "scripts/simulate.py"
101-
into "_release"
124+
// This will create a Jar file containing all the source code. This isn't used on-robot, but is just used by IDEs to generate the 'F12' info
125+
task _buildAllSourcesJar(type: Jar){
126+
classifier = "sources"
127+
128+
// Iterate through each project, and add it's source code
129+
from allprojects.collect { it.sourceSets.main.allSource }
102130
}
103131

104-
task packModules(type: Zip){
105-
archiveFileName = "modules.zip"
106-
destinationDirectory = file("_release")
107-
from "_release/modules"
132+
// This task bundles together all the .class files into a single JAR
133+
task _buildAllClassesJar(type: Jar){
134+
classifier = "classes"
135+
136+
// Needs to build the project
137+
dependsOn build
138+
139+
// Disable support for 64-bit JARs (The RoboRIO is a 32-bit system)
140+
zip64 = false
141+
142+
// Load all class files
143+
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
144+
145+
}
146+
147+
// This will bundle EVERYTHING into one Jar
148+
task _buildAllJar(type: Jar){
149+
classifier = "all"
150+
151+
// Needs to build the project
152+
dependsOn build
153+
dependsOn document
154+
155+
// Load all files for the bug JAR
156+
from file("docs"), allprojects.collect { it.sourceSets.main.allSource }, { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
157+
}
158+
159+
// This task is used to copy all python scripts from scripts/ to _release/python/
160+
task _copyPy(type: Copy){
161+
from "scripts"
162+
into "_release/python"
163+
include "*.py"
108164
}
109165

110-
task buildRelease(type: Jar){
111-
delete file("_release")
112-
delete file("$rootProject.buildDir/libs")
113-
dependsOn subprojects.fatJar
114-
dependsOn subprojects.jar
115-
dependsOn project(":bundle").buildBundle
116-
dependsOn copyPyLogReader
117-
dependsOn copyPySim
118-
dependsOn packModules
119-
// doLast{
120-
// subprojects.each { subproject ->
121-
// from subproject.configurations.archives.artifacts.files.collect {
122-
// zipTree(it)
123-
// }
124-
// }
125-
// // fileTree("_release/modules").each {
126-
// // from it
127-
// // }
128-
129-
// // from fileTree("_release/modules").files.collect
130-
// println "$rootProject.buildDir/libs/lib5k-"+project.version+".jar"
131-
// file("$rootProject.buildDir/libs/lib5k-"+project.version+".jar").renameTo(file("_release/lib5k-"+project.version+"-monolithic.jar"))
132-
// }
166+
// This task is used to copy all jar files from build/libs/ to _release/jar/
167+
task _copyJar(type: Copy){
168+
169+
// Copy dependancies
170+
dependsOn _buildJavaDocJar
171+
dependsOn _buildAllSourcesJar
172+
dependsOn _buildAllClassesJar
173+
dependsOn _buildAllJar
174+
175+
// Where and how to copy
176+
from "build/libs"
177+
into "_release/jar"
178+
include project.name + "-" + project.version +"-*.jar"
179+
}
180+
181+
// This task is used to clean out the _release directory
182+
task _cleanRelease(type: Delete){
183+
delete "_release"
184+
}
185+
tasks.clean.dependsOn(tasks._cleanRelease)
186+
187+
// This will build everything needed for release
188+
task buildRelease {
189+
dependsOn _copyPy
190+
dependsOn _copyJar
191+
}
192+
193+
// This will build only a JAR file to be used for beta testing
194+
task buildBeta(type: Copy) {
195+
dependsOn _buildAllJar
196+
197+
from "build/libs"
198+
into "_release/jar"
199+
include project.name + "-" + project.version +"-all.jar"
133200
}

0 commit comments

Comments
 (0)