Split photon-server and photon-core (#211)

Uses multiple Gradle projects to support the split.
This commit is contained in:
Banks T
2021-01-14 21:45:26 -05:00
committed by GitHub
parent dc0f8cf296
commit 58b39f47aa
531 changed files with 310 additions and 1317 deletions

View File

@@ -50,11 +50,6 @@ jobs:
path: photon-client/dist/
build-server:
# Let all steps run within the photon-server dir.
defaults:
run:
working-directory: photon-server
# The type of runner that the job will run on.
runs-on: ubuntu-latest
@@ -84,11 +79,16 @@ jobs:
run: ./gradlew jacocoTestReport
# Publish Coverage Report.
- name: Publish Coverage Report
- name: Publish Server Coverage Report
uses: codecov/codecov-action@v1
with:
file: ./photon-server/build/reports/jacoco/test/jacocoTestReport.xml
- name: Publish Core Coverage Report
uses: codecov/codecov-action@v1
with:
file: ./photon-core/build/reports/jacoco/test/jacocoTestReport.xml
build-offline-docs:
runs-on: ubuntu-latest
@@ -128,11 +128,6 @@ jobs:
build-package:
needs: [build-client, build-server, build-offline-docs]
# Let all steps run within the photon-server dir.
defaults:
run:
working-directory: photon-server
# The type of runner that the job will run on.
runs-on: ubuntu-latest
@@ -147,8 +142,8 @@ jobs:
# Clear any existing web resources.
- run: |
rm -rf src/main/resources/web/*
mkdir -p src/main/resources/web/docs
rm -rf photon-server/src/main/resources/web/*
mkdir -p photon-server/src/main/resources/web/docs
# Download client artifact to resources folder.
- uses: actions/download-artifact@v2
@@ -162,16 +157,10 @@ jobs:
name: built-docs
path: photon-server/src/main/resources/web/docs
# Print folder contents.
- run: ls
working-directory: photon-server/src/main/resources/web/
# Build fat jar.
- run: |
chmod +x gradlew
./gradlew shadowJar
working-directory: photon-server
./gradlew photon-server:shadowJar
# Upload final fat jar as artifact.
- uses: actions/upload-artifact@master
@@ -189,11 +178,6 @@ jobs:
if: github.event_name == 'push'
check-lint:
# Let all steps run within the photon-server dir.
defaults:
run:
working-directory: photon-server
# The type of runner that the job will run on.
runs-on: ubuntu-latest

5
.gitignore vendored
View File

@@ -126,3 +126,8 @@ photon-server/photon-vision
photon-server/src/main/resources/web
photon-server/src/main/java/org/photonvision/PhotonVersion.java
photon-server/src/main/generated/native/include/org_photonvision_raspi_PicamJNI.h
*.bin
.gradle
.gradle/*
photonvision_config
build/spotlessJava

32
build.gradle Normal file
View File

@@ -0,0 +1,32 @@
plugins {
id "com.diffplug.gradle.spotless" version "3.28.0"
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url = "https://maven.photonvision.org/repository/internal/"
}
maven {
url = 'https://frcmaven.wpi.edu:443/artifactory/development'
}
}
}
spotless {
java {
googleJavaFormat()
paddedCell()
indentWithTabs(2)
indentWithSpaces(4)
removeUnusedImports()
}
java {
target '**/*.java'
licenseHeaderFile "$rootDir/LicenseHeader.txt"
targetExclude('photon-core/src/main/java/org/photonvision/PhotonVersion.java')
}
}

93
common.gradle Normal file
View File

@@ -0,0 +1,93 @@
// Plugins
apply plugin: 'jacoco'
apply plugin: 'java'
sourceCompatibility = 11
// Common version config
ext {
wpilibVersion = '2020.3.2-99-g9f4de91'
joglVersion = '2.4.0-rc-20200307'
openCVVersion = '3.4.7-2'
}
// Common deps
dependencies {
// Jackson
implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
implementation "com.fasterxml.jackson.core:jackson-core:2.10.0"
implementation "com.fasterxml.jackson.core:jackson-databind:2.10.0"
// Apache commons
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
implementation 'org.apache.commons:commons-math3:3.6.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'org.apache.commons:commons-exec:1.3'
// WPILib deps
implementation "edu.wpi.first.wpiutil:wpiutil-java:$wpilibVersion"
implementation "edu.wpi.first.cameraserver:cameraserver-java:$wpilibVersion"
implementation "edu.wpi.first.cscore:cscore-java:$wpilibVersion"
compile "edu.wpi.first.cscore:cscore-jni:$wpilibVersion:linuxaarch64bionic"
compile "edu.wpi.first.cscore:cscore-jni:$wpilibVersion:linuxraspbian"
compile "edu.wpi.first.cscore:cscore-jni:$wpilibVersion:linuxx86-64"
compile "edu.wpi.first.cscore:cscore-jni:$wpilibVersion:osxx86-64"
compile "edu.wpi.first.cscore:cscore-jni:$wpilibVersion:windowsx86-64"
implementation "edu.wpi.first.ntcore:ntcore-java:$wpilibVersion"
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxaarch64bionic"
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxraspbian"
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxx86-64"
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:osxx86-64"
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:windowsx86-64"
implementation "edu.wpi.first.thirdparty.frc2020.opencv:opencv-java:$openCVVersion"
compile "edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:$openCVVersion:linuxaarch64bionic"
compile "edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:$openCVVersion:linuxraspbian"
compile "edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:$openCVVersion:linuxx86-64"
compile "edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:$openCVVersion:osxx86-64"
compile "edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:$openCVVersion:windowsx86-64"
implementation 'edu.wpi.first.wpimath:wpimath-java:2021.1.2-9-g26584ff'
// test stuff
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
}
test {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
task testHeadless(type: Test) {
group = 'verification'
systemProperty("java.awt.headless", "true")
useJUnitPlatform()
}
task generateJavaDocs(type: Javadoc) {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
destinationDir = file("${projectDir}/build/docs")
}
jacocoTestReport {
dependsOn test // Tests are required to run before generating the report
reports {
xml.enabled true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it,
exclude: 'edu/wpi/**'
)
}))
}
}

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
distributionSha256Sum=5a3578b9f0bb162f5e08cf119f447dfb8fa950cedebb4d2a977e912a11a74b91
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionSha256Sum=3239b5ed86c3838a37d983ac100573f64c1f3fd8e1eb6c89fa5f9529b5ec091d
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0
photon-server/gradlew → gradlew vendored Executable file → Normal file
View File

13
photon-core/.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
bin/*
.settings/*
.project
.classpath
*.prefs
.gradle
.gradle/*
build
build/*
photonvision/*
photonvision_config/*
src/main/java/org/photonvision/PhotonVersion.java

19
photon-core/build.gradle Normal file
View File

@@ -0,0 +1,19 @@
apply from: '../common.gradle'
apply from: 'versioningHelper.gradle'
dependencies {
implementation 'io.javalin:javalin:3.7.0'
implementation 'org.msgpack:msgpack-core:0.8.20'
implementation 'org.msgpack:jackson-dataformat-msgpack:0.8.20'
// JOGL stuff (currently we only distribute for aarch64, which is Pi 4)
implementation "org.jogamp.gluegen:gluegen-rt:$joglVersion"
implementation "org.jogamp.jogl:jogl-all:$joglVersion"
implementation "org.jogamp.gluegen:gluegen-rt:$joglVersion:natives-linux-aarch64"
implementation "org.jogamp.jogl:jogl-all:$joglVersion:natives-linux-aarch64"
// Zip
compile 'org.zeroturnaround:zt-zip:1.14'
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionSha256Sum=3239b5ed86c3838a37d983ac100573f64c1f3fd8e1eb6c89fa5f9529b5ec091d
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -0,0 +1,2 @@
rootProject.name = 'photon-core'

View File

@@ -34,6 +34,13 @@ public class OutgoingUIEvent<T> extends DataChangeEvent<T> {
this.originContext = originContext;
}
public static OutgoingUIEvent<HashMap<String, Object>> wrappedOf(
String commandName, Object value) {
HashMap<String, Object> data = new HashMap<>();
data.put(commandName, value);
return new OutgoingUIEvent<>(commandName, data);
}
public static OutgoingUIEvent<HashMap<String, Object>> wrappedOf(
String commandName, String propertyName, Object value, WsContext originContext) {
HashMap<String, Object> data = new HashMap<>();

View File

@@ -17,14 +17,13 @@
package org.photonvision.common.dataflow.websocket;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import org.photonvision.common.dataflow.CVPipelineResultConsumer;
import org.photonvision.common.dataflow.DataChangeService;
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.server.SocketHandler;
import org.photonvision.vision.pipeline.result.CVPipelineResult;
public class UIDataPublisher implements CVPipelineResultConsumer {
@@ -57,18 +56,10 @@ public class UIDataPublisher implements CVPipelineResultConsumer {
uiTargets.add(t.toHashMap());
}
dataMap.put("targets", uiTargets);
uiMap.put(index, dataMap);
var retMap = new HashMap<String, Object>();
retMap.put("updatePipelineResult", uiMap);
try {
SocketHandler.getInstance().broadcastMessage(retMap, null);
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
logger.error(Arrays.toString(e.getStackTrace()));
}
DataChangeService.getInstance()
.publishEvent(OutgoingUIEvent.wrappedOf("updatePipelineResult", uiMap));
lastUIResultUpdateTime = now;
}
}

View File

@@ -17,13 +17,13 @@
package org.photonvision.common.hardware.metrics;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.HashMap;
import org.photonvision.common.dataflow.DataChangeService;
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
import org.photonvision.common.hardware.Platform;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TimedTaskManager;
import org.photonvision.server.SocketHandler;
public class MetricsPublisher {
private static final Logger logger = new Logger(MetricsPublisher.class, LogGroup.General);
@@ -65,14 +65,7 @@ public class MetricsPublisher {
metrics.put("gpuMemUtil", gpuMetrics.getMallocedMemory());
metrics.put("diskUtilPct", diskMetrics.getUsedDiskPct());
var retMap = new HashMap<String, Object>();
retMap.put("metrics", metrics);
try {
SocketHandler.getInstance().broadcastMessage(retMap, null);
} catch (JsonProcessingException e) {
logger.error("Exception while sending metrics!", e);
}
DataChangeService.getInstance().publishEvent(OutgoingUIEvent.wrappedOf("metrics", metrics));
}
private static class Singleton {

View File

@@ -33,7 +33,6 @@ import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.dataflow.DataChangeService;
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
import org.photonvision.common.util.TimedTaskManager;
import org.photonvision.server.SocketHandler;
@SuppressWarnings("unused")
public class Logger {
@@ -302,12 +301,12 @@ public class Logger {
private static class UILogAppender implements LogAppender {
@Override
public void log(String message, LogLevel level) {
var messageMap = new SocketHandler.UIMap();
var messageMap = new HashMap<String, Object>();
messageMap.put("logMessage", message);
messageMap.put("logLevel", level.code);
var superMap = new SocketHandler.UIMap();
var superMap = new HashMap<String, Object>();
superMap.put("logMessage", messageMap);
DataChangeService.getInstance().publishEvent(new OutgoingUIEvent<>("log", superMap));
DataChangeService.getInstance().publishEvent(OutgoingUIEvent.wrappedOf("log", superMap));
}
}

View File

@@ -59,4 +59,17 @@ public class MathUtils {
public static int map(int value, int inMin, int inMax, int outMin, int outMax) {
return (int) Math.floor(map((double) value, inMin, inMax, outMin, outMax) + 0.5);
}
/**
* Linearly interpolates between two values.
*
* @param startValue The start value.
* @param endValue The end value.
* @param t The fraction for interpolation.
* @return The interpolated value.
*/
@SuppressWarnings("ParameterName")
public static double lerp(double startValue, double endValue, double t) {
return startValue + (endValue - startValue) * t;
}
}

Some files were not shown because too many files have changed in this diff Show More