Skip to content

Commit

Permalink
Merge pull request #53 from frc5024/bundlejars
Browse files Browse the repository at this point in the history
  • Loading branch information
ewpratten authored Jul 24, 2020
2 parents 835edf6 + 2d96dfd commit 368bbee
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 126 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The software libraries that power all Raider Robotics projects.

## Using

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)).
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)).

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

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

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

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).
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).

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.frc5024.lib5k.autonomous;

import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
Expand All @@ -9,6 +10,7 @@

import io.github.frc5024.lib5k.logging.RobotLogger;
import io.github.frc5024.lib5k.hardware.ni.roborio.FaultReporter;
import io.github.frc5024.lib5k.hardware.ni.roborio.fpga.RR_HAL;

/**
* RobotProgram is the base class for all robot programs.
Expand Down Expand Up @@ -67,17 +69,33 @@ public RobotProgram(boolean runSchedulerInTestMode, boolean stopAutonomousInTele
this.stopAutonomousInTeleop = stopAutonomousInTeleop;
this.dashboard = primaryDashboard;

// Send chooser to dashboard
// Create a chooser
chooser = new SendableChooser<>();
dashboard.add(chooser);

// Start logger
logger.start(0.02);

// Start a fault reporter
// Report language
RR_HAL.reportFRCVersion("Java", RR_HAL.getLibraryVersion());

}

/**
* For publishing the chooser (this can be overridden for custom dashboards)
*
* @param component Chooser component
*/
public void publishChooser(Sendable component) {
dashboard.add(component);
}

/**
* This is run all the time
*
* @param init Did the robot just start?
*/
public abstract void periodic(boolean init);

/**
* This is run during autonomous
*
Expand Down Expand Up @@ -106,6 +124,24 @@ public RobotProgram(boolean runSchedulerInTestMode, boolean stopAutonomousInTele
*/
public abstract void test(boolean init);

@Override
public void robotInit() {

// Publish the chooser
publishChooser(chooser);

// Call robot
periodic(true);

}

@Override
public void robotPeriodic() {

// Call robot
periodic(false);
}

/**
* Set the default autonomous sequence
*
Expand Down Expand Up @@ -134,6 +170,16 @@ public void addAutonomous(AutonomousSequence sequence) {
chooser.addOption(sequence.getName(), sequence);
}

/**
* Get the selected autonomous. If this is not called in autonomous(), it will
* return the default
*
* @return Selected autonomous sequence
*/
public AutonomousSequence getSelectedAutonomous() {
return autonomous;
}

@Override
public void autonomousInit() {
logger.log("Autonomous started");
Expand Down
201 changes: 134 additions & 67 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,133 +1,200 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds/
*/


// This is the main build script. This mostly contains the gradle tasks for building the library JAR files and documentation

// This injects the gradlerio version info into all projects
buildscript {
repositories {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:2.2.+'
classpath "edu.wpi.first:GradleRIO:2020.+"
// Update this version number to update GradleRIO
classpath "edu.wpi.first:GradleRIO:2020.+"
}
}

// All plugins used by the buildscript
plugins {
id "com.gradle.build-scan" version "3.3.4"
id "java-library"
}

apply plugin: 'nebula-aggregate-javadocs'
apply plugin: "java-library"
// Load project dependancy configurations
apply from: "gradle_utils/libversions.gradle"
apply from: "gradle_utils/mavenrepos.gradle"

// LIB VERSION
project.version = "1.2.1"

// Enable Java support for all projects
allprojects{
apply plugin: "java"
}

// This enables some fancy gradle enterprise features for us
gradleEnterprise {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}

// This will automatically pull in everything that isnt the "examples" project
dependencies{
rootProject.subprojects.each{
if ( it.name != "examples"){
api it
}
}
}

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

task document(type: Javadoc, description: 'Generate javadocs from all child projects as if it was a single project', group: 'Documentation') {
// Set the jars to be generated into the build directory
destinationDir = file("$buildDir/docs/javadoc")

// Set the JavaDoc webpage title
title = "$project.name $version API"

// Set the custom CSS file containing our logo and theme
options.setStylesheetFile(file("javadoc.css"))

// These fix a JavaDoc bug
options.addBooleanOption('-no-module-directories', true)
options.author true

// If you add a new dependancy to the project, add its javadoc URL to this list
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/'
options.addStringOption 'Xdoclint:none', '-quiet'
println "Building recursive JavaDoc"

// Any JavaDoc options should go here
options.addStringOption 'Xdoclint:none', '-quiet'

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

// Don't document the "examples" project
if (proj.name != "examples"){
println 'Adding ' + proj.projectDir + "/src/main/java"

// Read form every JavaDoc task in the subproject
proj.tasks.withType(Javadoc).each { javadocTask ->
println 'Found JavaDoc task'

// Add the task sources to the main JavaDoc
source += javadocTask.source
classpath += javadocTask.classpath
excludes += javadocTask.excludes
includes += javadocTask.includes

}

}

}

doLast {
println "Copying javadoc to docs folder"
delete "docs"
file("$rootProject.buildDir/docs/javadoc").renameTo(file("docs"))
}
}

// This task is used to make the "clean" task clean out the docs directory
task _cleanDocs(type: Delete){
delete "docs"
}
tasks.clean.dependsOn(tasks._cleanDocs)

// This is just a compatibility thing
subprojects.each { subproject ->
evaluationDependsOn(subproject.path)
}
task mmJar(type: Jar, dependsOn: subprojects.jar) {
subprojects.each { subproject ->
from subproject.configurations.archives.artifacts.files.collect {
zipTree(it)
}

// This gets run by our CI pipeline to generate https://frc5024.github.io/lib5k
task document(dependsOn: combineJavadoc){
// Clear out the docs folder, and move the JavaDoc into it
dependsOn _cleanDocs
doLast{
file("$rootProject.buildDir/docs/javadoc").renameTo(file("docs"))
}
}

task copyPyLogReader(type: Copy){
from "scripts/logreader.py"
into "_release"
/* Build all the required JARs */

// This will take every JavaDoc and pack it into a single JAR
task _buildJavaDocJar(type: Jar, dependsOn: document){
classifier = "javadoc"
from file("docs")
}

task copyPySim(type: Copy){
from "scripts/simulate.py"
into "_release"
// 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
task _buildAllSourcesJar(type: Jar){
classifier = "sources"

// Iterate through each project, and add it's source code
from allprojects.collect { it.sourceSets.main.allSource }
}

task packModules(type: Zip){
archiveFileName = "modules.zip"
destinationDirectory = file("_release")
from "_release/modules"
// This task bundles together all the .class files into a single JAR
task _buildAllClassesJar(type: Jar){
classifier = "classes"

// Needs to build the project
dependsOn build

// Disable support for 64-bit JARs (The RoboRIO is a 32-bit system)
zip64 = false

// Load all class files
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

}

// This will bundle EVERYTHING into one Jar
task _buildAllJar(type: Jar){
classifier = "all"

// Needs to build the project
dependsOn build
dependsOn document

// Load all files for the bug JAR
from file("docs"), allprojects.collect { it.sourceSets.main.allSource }, { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}

// This task is used to copy all python scripts from scripts/ to _release/python/
task _copyPy(type: Copy){
from "scripts"
into "_release/python"
include "*.py"
}

task buildRelease(type: Jar){
delete file("_release")
delete file("$rootProject.buildDir/libs")
dependsOn subprojects.fatJar
dependsOn subprojects.jar
dependsOn project(":bundle").buildBundle
dependsOn copyPyLogReader
dependsOn copyPySim
dependsOn packModules
// doLast{
// subprojects.each { subproject ->
// from subproject.configurations.archives.artifacts.files.collect {
// zipTree(it)
// }
// }
// // fileTree("_release/modules").each {
// // from it
// // }

// // from fileTree("_release/modules").files.collect
// println "$rootProject.buildDir/libs/lib5k-"+project.version+".jar"
// file("$rootProject.buildDir/libs/lib5k-"+project.version+".jar").renameTo(file("_release/lib5k-"+project.version+"-monolithic.jar"))
// }
// This task is used to copy all jar files from build/libs/ to _release/jar/
task _copyJar(type: Copy){

// Copy dependancies
dependsOn _buildJavaDocJar
dependsOn _buildAllSourcesJar
dependsOn _buildAllClassesJar
dependsOn _buildAllJar

// Where and how to copy
from "build/libs"
into "_release/jar"
include project.name + "-" + project.version +"-*.jar"
}

// This task is used to clean out the _release directory
task _cleanRelease(type: Delete){
delete "_release"
}
tasks.clean.dependsOn(tasks._cleanRelease)

// This will build everything needed for release
task buildRelease {
dependsOn _copyPy
dependsOn _copyJar
}

// This will build only a JAR file to be used for beta testing
task buildBeta(type: Copy) {
dependsOn _buildAllJar

from "build/libs"
into "_release/jar"
include project.name + "-" + project.version +"-all.jar"
}
Loading

0 comments on commit 368bbee

Please sign in to comment.