From e8ed6addfb8dbf6ed8ecbfd4bf2cd74577f9be18 Mon Sep 17 00:00:00 2001 From: Dean Brettle Date: Fri, 19 Apr 2024 08:24:21 -0700 Subject: [PATCH 1/2] Support running unit tests from vscode --- .vscode/settings.json | 8 +- .vscode/tasks.json | 22 ++++ build.gradle | 227 +++++++++++++++++++++--------------------- 3 files changed, 141 insertions(+), 116 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ed293b7..c108faec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, - "bin/": true, +"bin/": true, "**/.classpath": true, "**/.project": true, "**/.settings": true, @@ -22,8 +22,10 @@ "env": { "LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release" , "DYLD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release" - } + }, + "preLaunchTask": "gradle: assemble" }, ], - "java.test.defaultConfig": "WPIlibUnitTests" + "java.test.defaultConfig": "WPIlibUnitTests", + "java.gradle.buildServer.enabled":"on" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..f17592cf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,22 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "gradle", + "id": "assemblelib199", + "script": "assemble", + "description": "Assembles the outputs of this project.", + "project": "lib199", + "buildFile": "${workspaceFolder}/build.gradle", + "rootProject": "lib199", + "projectFolder": "${workspaceFolder}", + "workspaceFolder": "${workspaceFolder}", + "args": "", + "javaDebug": false, + "problemMatcher": [ + "$gradle" + ], + "label": "gradle: assemble" + } + ], +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0e2a9c1a..8b82b5a1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,113 +1,114 @@ -plugins { - id "java" - id "edu.wpi.first.GradleRIO" version "2024.3.1" - id "maven-publish" -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -group 'org.carlmontrobotics' - -def ROBOT_MAIN_CLASS = "" - -// Define my targets (RoboRIO) and artifacts (deployable files) -// This is added by GradleRIO's backing project DeployUtils. -deploy { - targets { - roborio(getTargetTypeClass('RoboRIO')) { - // Team number is loaded either from the .wpilib/wpilib_preferences.json - // or from command line. If not found an exception will be thrown. - // You can use getTeamOrDefault(team) instead of getTeamNumber if you - // want to store a team number in this file. - team = project.frc.getTeamNumber() - debug = project.frc.getDebugOrDefault(false) - - artifacts { - // First part is artifact name, 2nd is artifact type - // getTargetTypeClass is a shortcut to get the class type using a string - - frcJava(getArtifactTypeClass('FRCJavaArtifact')) { - } - - // Static files artifact - frcStaticFileDeploy(getArtifactTypeClass('FileTreeArtifact')) { - files = project.fileTree('src/main/deploy') - directory = '/home/lvuser/deploy' - } - } - } - } -} - -def deployArtifact = deploy.targets.roborio.artifacts.frcJava - -// Set to true to use debug for JNI. -wpi.java.debugJni = false - -// Set this to true to enable desktop support. -def includeDesktopSupport = true - -// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries. -// Also defines JUnit 5. -dependencies { - implementation wpi.java.deps.wpilib() - implementation wpi.java.vendor.java() - - roborioDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.roborio) - roborioDebug wpi.java.vendor.jniDebug(wpi.platforms.roborio) - - roborioRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.roborio) - roborioRelease wpi.java.vendor.jniRelease(wpi.platforms.roborio) - - nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop) - nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop) - simulationDebug wpi.sim.enableDebug() - - nativeRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.desktop) - nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop) - simulationRelease wpi.sim.enableRelease() - - testImplementation 'junit:junit:4.13.2' - - implementation 'org.mockito:mockito-core:3.6.0' - implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.6' -} - -// Simulation configuration (e.g. environment variables). -wpi.sim.addGui().defaultEnabled = true -wpi.sim.addDriverstation() - -// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') -// in order to make them all available at runtime. Also adding the manifest so WPILib -// knows where to look for our Robot Class. -jar { - from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } - from sourceSets.main.allSource - manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS) - duplicatesStrategy = DuplicatesStrategy.INCLUDE -} - -publishing { - publications { - gpr(MavenPublication) { - groupId = 'org.carlmontrobotics' - artifactId = 'lib199' - version = '4.0.2' - - from components.java - } - } -} - -// Configure jar and deploy tasks -deployArtifact.jarTask = jar -wpi.java.configureExecutableTasks(jar) -wpi.java.configureTestTasks(test) - -// Configure string concat to always inline compile -tasks.withType(JavaCompile) { - options.compilerArgs.add '-XDstringConcat=inline' -} +plugins { + id "java" + id "edu.wpi.first.GradleRIO" version "2024.3.1" + id "maven-publish" + id "eclipse" +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +group 'org.carlmontrobotics' + +def ROBOT_MAIN_CLASS = "" + +// Define my targets (RoboRIO) and artifacts (deployable files) +// This is added by GradleRIO's backing project DeployUtils. +deploy { + targets { + roborio(getTargetTypeClass('RoboRIO')) { + // Team number is loaded either from the .wpilib/wpilib_preferences.json + // or from command line. If not found an exception will be thrown. + // You can use getTeamOrDefault(team) instead of getTeamNumber if you + // want to store a team number in this file. + team = project.frc.getTeamNumber() + debug = project.frc.getDebugOrDefault(false) + + artifacts { + // First part is artifact name, 2nd is artifact type + // getTargetTypeClass is a shortcut to get the class type using a string + + frcJava(getArtifactTypeClass('FRCJavaArtifact')) { + } + + // Static files artifact + frcStaticFileDeploy(getArtifactTypeClass('FileTreeArtifact')) { + files = project.fileTree('src/main/deploy') + directory = '/home/lvuser/deploy' + } + } + } + } +} + +def deployArtifact = deploy.targets.roborio.artifacts.frcJava + +// Set to true to use debug for JNI. +wpi.java.debugJni = false + +// Set this to true to enable desktop support. +def includeDesktopSupport = true + +// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries. +// Also defines JUnit 5. +dependencies { + implementation wpi.java.deps.wpilib() + implementation wpi.java.vendor.java() + + roborioDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.roborio) + roborioDebug wpi.java.vendor.jniDebug(wpi.platforms.roborio) + + roborioRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.roborio) + roborioRelease wpi.java.vendor.jniRelease(wpi.platforms.roborio) + + nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop) + nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop) + simulationDebug wpi.sim.enableDebug() + + nativeRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.desktop) + nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop) + simulationRelease wpi.sim.enableRelease() + + testImplementation 'junit:junit:4.13.2' + + implementation 'org.mockito:mockito-core:3.6.0' + implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.6' +} + +// Simulation configuration (e.g. environment variables). +wpi.sim.addGui().defaultEnabled = true +wpi.sim.addDriverstation() + +// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') +// in order to make them all available at runtime. Also adding the manifest so WPILib +// knows where to look for our Robot Class. +jar { + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + from sourceSets.main.allSource + manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS) + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + +publishing { + publications { + gpr(MavenPublication) { + groupId = 'org.carlmontrobotics' + artifactId = 'lib199' + version = '4.0.2' + + from components.java + } + } +} + +// Configure jar and deploy tasks +deployArtifact.jarTask = jar +wpi.java.configureExecutableTasks(jar) +wpi.java.configureTestTasks(test) + +// Configure string concat to always inline compile +tasks.withType(JavaCompile) { + options.compilerArgs.add '-XDstringConcat=inline' +} From 3eed230e2573661b82cdeb52e7c0c778c55db707 Mon Sep 17 00:00:00 2001 From: CoolSpy3 Date: Fri, 19 Apr 2024 11:09:30 -0700 Subject: [PATCH 2/2] formatting --- .vscode/settings.json | 10 ++++++---- .vscode/tasks.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c108faec..0228f9dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, -"bin/": true, + "bin/": true, "**/.classpath": true, "**/.project": true, "**/.settings": true, @@ -18,14 +18,16 @@ { "name": "WPIlibUnitTests", "workingDirectory": "${workspaceFolder}/build/jni/release", - "vmargs": [ "-Djava.library.path=${workspaceFolder}/build/jni/release" ], + "vmargs": [ + "-Djava.library.path=${workspaceFolder}/build/jni/release" + ], "env": { - "LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release" , + "LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release", "DYLD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release" }, "preLaunchTask": "gradle: assemble" }, ], "java.test.defaultConfig": "WPIlibUnitTests", - "java.gradle.buildServer.enabled":"on" + "java.gradle.buildServer.enabled": "on" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f17592cf..14200a31 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -19,4 +19,4 @@ "label": "gradle: assemble" } ], -} \ No newline at end of file +}