Skip to content

Commit

Permalink
[wpiutil] Remove RuntimeLoader and RuntimeDetector
Browse files Browse the repository at this point in the history
Resolves #6598
  • Loading branch information
spacey-sooty committed May 8, 2024
1 parent dc00a13 commit 00449e4
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 528 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import edu.wpi.first.apriltag.AprilTagPoseEstimate;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.util.RawFrame;
import edu.wpi.first.util.RuntimeLoader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

/** AprilTag JNI. */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public class AprilTagJNI {
static boolean libraryLoaded = false;

static RuntimeLoader<AprilTagJNI> loader = null;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
Expand Down Expand Up @@ -48,11 +45,8 @@ private Helper() {}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"apriltagjni", RuntimeLoader.getDefaultExtractionRoot(), AprilTagJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
System.loadLibrary("apriltagjni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.util.RuntimeLoader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,21 +23,16 @@
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

@SuppressWarnings("PMD.MutableStaticState")
@SuppressWarnings({"PMD.MutableStaticState", "PMD.AvoidCatchingGenericException"})
class AprilTagDetectorTest {
@SuppressWarnings("MemberName")
AprilTagDetector detector;

static RuntimeLoader<Core> loader;

@BeforeAll
static void beforeAll() {
try {
loader =
new RuntimeLoader<>(
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
loader.loadLibrary();
} catch (IOException ex) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (Exception ex) {
fail(ex);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cscore/src/dev/java/edu/wpi/first/cscore/DevMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

package edu.wpi.first.cscore;

import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.CombinedRuntimeLoader;

public final class DevMain {
/** Main method. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CombinedRuntimeLoader.getPlatformPath());
System.out.println(CameraServerJNI.getHostname());
}

Expand Down
16 changes: 4 additions & 12 deletions cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
package edu.wpi.first.cscore;

import edu.wpi.first.util.RawFrame;
import edu.wpi.first.util.RuntimeLoader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/** CameraServer JNI. */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public class CameraServerJNI {
static boolean libraryLoaded = false;

static RuntimeLoader<CameraServerJNI> loader = null;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
Expand Down Expand Up @@ -46,11 +44,8 @@ private Helper() {}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"cscorejni", RuntimeLoader.getDefaultExtractionRoot(), CameraServerJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
System.loadLibrary("cscorejni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -67,10 +62,7 @@ public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>(
"cscorejni", RuntimeLoader.getDefaultExtractionRoot(), CameraServerJNI.class);
loader.loadLibrary();
System.loadLibrary("cscorejni");
libraryLoaded = true;
}

Expand Down
17 changes: 4 additions & 13 deletions cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

package edu.wpi.first.cscore;

import edu.wpi.first.util.RuntimeLoader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.opencv.core.Core;

/** OpenCV Native Loader. */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public final class OpenCvLoader {
@SuppressWarnings("PMD.MutableStaticState")
static boolean libraryLoaded;

@SuppressWarnings("PMD.MutableStaticState")
static RuntimeLoader<Core> loader;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
Expand Down Expand Up @@ -44,13 +41,10 @@ private Helper() {}
}

static {
String opencvName = Core.NATIVE_LIBRARY_NAME;
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(opencvName, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
loader.loadLibraryHashed();
} catch (IOException ex) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -76,10 +70,7 @@ public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>(
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
loader.loadLibrary();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
libraryLoaded = true;
}

Expand Down
15 changes: 4 additions & 11 deletions hal/src/main/java/edu/wpi/first/hal/JNIWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

package edu.wpi.first.hal;

import edu.wpi.first.util.RuntimeLoader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

/** Base class for all JNI wrappers. */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public class JNIWrapper {
static boolean libraryLoaded = false;
static RuntimeLoader<JNIWrapper> loader = null;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
Expand Down Expand Up @@ -42,11 +41,8 @@ private Helper() {}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"wpiHaljni", RuntimeLoader.getDefaultExtractionRoot(), JNIWrapper.class);
loader.loadLibrary();
} catch (IOException ex) {
System.loadLibrary("wpiHaljni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -63,10 +59,7 @@ public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>(
"wpiHaljni", RuntimeLoader.getDefaultExtractionRoot(), JNIWrapper.class);
loader.loadLibrary();
System.loadLibrary("wpiHaljni");
libraryLoaded = true;
}

Expand Down
4 changes: 2 additions & 2 deletions ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package edu.wpi.first.ntcore;

import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.CombinedRuntimeLoader;

public final class DevMain {
/** Main method. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CombinedRuntimeLoader.getPlatformPath());
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
}

Expand Down
15 changes: 4 additions & 11 deletions ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package edu.wpi.first.networktables;

import edu.wpi.first.util.RuntimeLoader;
import edu.wpi.first.util.datalog.DataLog;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -15,9 +14,9 @@ import java.util.OptionalLong;
import java.util.concurrent.atomic.AtomicBoolean;

/** NetworkTables JNI. */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public final class NetworkTablesJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<NetworkTablesJNI> loader = null;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
Expand Down Expand Up @@ -48,11 +47,8 @@ public final class NetworkTablesJNI {
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
System.loadLibrary("ntcorejni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -69,10 +65,7 @@ public final class NetworkTablesJNI {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>(
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader.loadLibrary();
System.loadLibrary("ntcorejni");
libraryLoaded = true;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.CombinedRuntimeLoader;

public final class DevMain {
/** Main entry point. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CombinedRuntimeLoader.getPlatformPath());
System.out.println(NetworkTablesJNI.now());
System.out.println(HALUtil.getHALRuntimeType());
}
Expand Down
4 changes: 0 additions & 4 deletions styleguide/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
<Source name="CombinedRuntimeLoader.java" />
</Match>
<Match>
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
<Source name="RuntimeLoader.java" />
</Match>
<Match>
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
<Source name="CameraServer.java" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.CombinedRuntimeLoader;

public final class DevMain {
/** Main entry point. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CombinedRuntimeLoader.getPlatformPath());
System.out.println(NetworkTablesJNI.now());
System.out.println(HALUtil.getHALRuntimeType());
}
Expand Down
4 changes: 2 additions & 2 deletions wpilibj/src/dev/java/edu/wpi/first/wpilibj/DevMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.CombinedRuntimeLoader;

public final class DevMain {
/** Main entry point. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CombinedRuntimeLoader.getPlatformPath());
System.out.println(NetworkTablesJNI.now());
System.out.println(HALUtil.getHALRuntimeType());
}
Expand Down
Loading

0 comments on commit 00449e4

Please sign in to comment.