Skip to content

Commit

Permalink
Multiproject build
Browse files Browse the repository at this point in the history
  • Loading branch information
msoucy committed Sep 25, 2021
1 parent 3b12034 commit 8a7ac29
Show file tree
Hide file tree
Showing 102 changed files with 1,303 additions and 119 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ $RECYCLE.BIN/

### Gradle ###
.gradle
/build/
build/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"java.configuration.updateBuildConfiguration": "automatic",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"kotlin.compiler.jvm.target": "1.8",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand All @@ -16,4 +17,4 @@
"**/.settings": true,
"**/.factorypath": true
}
}
}
13 changes: 13 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
// Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
id 'groovy-gradle-plugin'
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
// Apply the common convention plugin for shared build configuration between library and application projects.
id 'com.chopshop166.chopshoplib.java-common-conventions'

// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
// Apply the java Plugin to add support for Java.
id 'java'
}

dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'

// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

tasks.named('test') {
// Use junit platform for unit tests.
useJUnitPlatform()
}
37 changes: 12 additions & 25 deletions build.gradle → ...opshoplib.java-library-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
id "java-library"
id "pmd"
// Apply the common convention plugin for shared build configuration between library and application projects.
id 'com.chopshop166.chopshoplib.java-common-conventions'

// Apply the java-library plugin for API and implementation separation.
id 'java-library'

id 'pmd'
id 'maven-publish'
id "com.github.spotbugs" version "4.7.2"
id "edu.wpi.first.GradleRIO" version "2021.3.1"
}

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

group = 'com.chopshop166'
group = 'com.chopshop166.chopshoplib'

repositories {
mavenCentral()
Expand All @@ -18,14 +25,6 @@ repositories {

dependencies {

implementation wpi.deps.wpilib()
nativeDesktopZip wpi.deps.wpilibJni(wpi.platforms.desktop)

implementation wpi.deps.vendor.java()
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)

implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}
Expand All @@ -39,14 +38,6 @@ java {
withSourcesJar()
}

publishing {
publications {
chopshoplib(MavenPublication) {
from components.java
}
}
}

spotbugsMain {
reports {
xml {
Expand All @@ -68,7 +59,3 @@ pmd {
ruleSets = []
ruleSetFiles = files("$rootProject.projectDir/config/pmd-ruleset.xml")
}

wrapper {
gradleVersion = '6.9'
}
2 changes: 1 addition & 1 deletion config/findbugs-ignore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2,MS_EXPOSE_REP"/>
</Match>

</FindBugsFilter>
21 changes: 21 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'com.chopshop166.chopshoplib.java-library-conventions'
id 'com.github.spotbugs' version '4.7.3'
id 'edu.wpi.first.GradleRIO' version '2021.3.1'
}

dependencies {

api wpi.deps.wpilib()
api wpi.deps.vendor.java()

implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre'
}

publishing {
publications {
core(MavenPublication) {
from components.java
}
}
}
93 changes: 93 additions & 0 deletions core/src/main/java/com/chopshop166/chopshoplib/Dashboard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@file:OptIn(kotlin.experimental.ExperimentalTypeInference::class)
package com.chopshop166.chopshoplib

import edu.wpi.cscore.VideoSink
import edu.wpi.cscore.VideoSource
import edu.wpi.first.cameraserver.CameraServer
import edu.wpi.first.wpilibj.Sendable
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard

class DashboardWrapper internal constructor () {
operator fun set(name: String, value: Sendable) = (name displays value)
operator fun set(name: String, value: Boolean) = (name displays value)
operator fun set(name: String, value: String) = (name displays value)
operator fun set(name: String, value: Double) = (name displays value)
operator fun set(name: String, value: Int) = (name displays value)

operator fun get(name: String) = SmartDashboard.getData(name)

operator fun invoke(block: DashboardWrapper.() -> Unit = {}) = apply(block)

infix fun String.displays(value: Sendable) = SmartDashboard.putData(this, value)
infix fun String.displays(value: Boolean) = SmartDashboard.putBoolean(this, value)
infix fun String.displays(value: String) = SmartDashboard.putString(this, value)
infix fun String.displays(value: Double) = SmartDashboard.putNumber(this, value)
infix fun String.displays(value: Int) = SmartDashboard.putNumber(this, value.toDouble())

fun entry(name: String) = SmartDashboard.getEntry(name)
}
val dashboard = DashboardWrapper()

class ShuffleboardContainerWrapper internal constructor (val con : ShuffleboardContainer) {

val title : String get() { return con.getTitle() }

operator fun set(name: String, value: Sendable) = name(value)
@OverloadResolutionByLambdaReturnType
@JvmName("setBoolean") operator fun set(name: String, value: () -> Boolean) = name(value)
@JvmName("setString") operator fun set(name: String, value: () -> String) = name(value)
@JvmName("setNumber") operator fun set(name: String, value: () -> Double) = name(value)
@JvmName("setInt") operator fun set(name: String, value: () -> Int) = name(value)

operator fun get(name: String) = ShuffleboardContainerWrapper(con.getLayout(name))
fun layout(name : String, block: ShuffleboardContainerWrapper.() -> Unit = {}) = this[name].run(block)

operator fun String.invoke(value: Sendable) = con.add(this, value)
@OverloadResolutionByLambdaReturnType
@JvmName("invokeBoolean") operator fun String.invoke(value: () -> Boolean) = con.addBoolean(this, value)
@JvmName("invokeString") operator fun String.invoke(value: () -> String) = con.addString(this, value)
@JvmName("invokeNumber") operator fun String.invoke(value: () -> Double) = con.addNumber(this, value)
@JvmName("invokeInt") operator fun String.invoke(value: () -> Int) = con.addNumber(this) { value().toDouble() }
}
fun shuffleboard(name : String, block: ShuffleboardContainerWrapper.() -> Unit = {}) = ShuffleboardContainerWrapper(Shuffleboard.getTab(name)).apply(block)

class ChooserWrapper<T>(val chooser: SendableChooser<T>) {
infix fun String.default(value: T) { chooser.setDefaultOption(this, value) }
infix fun String.chooses(value: T) { chooser.addOption(this, value) }
}

inline fun <reified T> chooser(block: ChooserWrapper<T>.() -> Unit) = SendableChooser<T>().apply {
ChooserWrapper<T>(this).block()
}

class VideoSourceWrapper(val source: VideoSource) {
operator fun get(name: String) = source.getProperty(name).get()
operator fun set(name: String, value: Int) = source.getProperty(name).set(value)
}

class VideoSinkWrapper(val sink: VideoSink) {
operator fun get(name: String) = sink.getProperty(name).get()
operator fun set(name: String, value: Int) = sink.getProperty(name).set(value)
}

class CameraServerWrapper(private val base: CameraServer) {
fun server(block: VideoSinkWrapper.() -> Unit = {}) =
base.getServer().apply { VideoSinkWrapper(this).block() }
fun server(name: String, block: VideoSinkWrapper.() -> Unit = {}) =
base.getServer(name).apply { VideoSinkWrapper(this).block() }
fun source(block: VideoSourceWrapper.() -> Unit = {}) =
base.startAutomaticCapture().apply { VideoSourceWrapper(this).block() }
fun source(dev: Int, block: VideoSourceWrapper.() -> Unit = {}) =
base.startAutomaticCapture(dev).apply { VideoSourceWrapper(this).block() }
fun source(camera: VideoSource, block: VideoSinkWrapper.() -> Unit = {}) =
base.startAutomaticCapture(camera).apply { VideoSinkWrapper(this).block() }
fun source(name: String, dev: Int, block: VideoSourceWrapper.() -> Unit = {}) =
base.startAutomaticCapture(name, dev).apply { VideoSourceWrapper(this).block() }
fun source(name: String, path: String, block: VideoSourceWrapper.() -> Unit = {}) =
base.startAutomaticCapture(name, path).apply { VideoSourceWrapper(this).block() }
}

val cameraServer = CameraServerWrapper(CameraServer.getInstance())
18 changes: 18 additions & 0 deletions core/src/main/java/com/chopshop166/chopshoplib/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chopshop166.chopshoplib

import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.withSign

fun Double.clamped(minVal : Double, maxVal : Double) = max(minVal, min(maxVal, this))
fun Float.clamped(minVal : Float, maxVal : Float) = max(minVal, min(maxVal, this))
fun Int.clamped(minVal : Int, maxVal : Int) = max(minVal, min(maxVal, this))
fun Long.clamped(minVal : Long, maxVal : Long) = max(minVal, min(maxVal, this))

fun Double.signPow(exp : Double) = pow(exp).withSign(this)

typealias BoolFunc = ()->Boolean
operator fun BoolFunc.not() = {!this()}
infix fun BoolFunc.and(other : BoolFunc) = {this() && other()}
infix fun BoolFunc.or(other : BoolFunc) = {this() || other()}
Loading

0 comments on commit 8a7ac29

Please sign in to comment.