Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpiutil] Remove RuntimeDetector and greatly simplify RuntimeLoader #6600

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
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,10 +46,7 @@ private Helper() {}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"apriltagjni", RuntimeLoader.getDefaultExtractionRoot(), AprilTagJNI.class);
loader.loadLibrary();
RuntimeLoader.loadLibrary("apriltagjni");
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ 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();
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (IOException 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
12 changes: 2 additions & 10 deletions cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
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,10 +44,7 @@ private Helper() {}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"cscorejni", RuntimeLoader.getDefaultExtractionRoot(), CameraServerJNI.class);
loader.loadLibrary();
RuntimeLoader.loadLibrary("cscorejni");
} catch (IOException 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();
RuntimeLoader.loadLibrary("cscorejni");
libraryLoaded = true;
}

Expand Down
13 changes: 2 additions & 11 deletions cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ 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,12 +41,9 @@ private Helper() {}
}

static {
String opencvName = Core.NATIVE_LIBRARY_NAME;
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(opencvName, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
loader.loadLibraryHashed();
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (IOException 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();
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
libraryLoaded = true;
}

Expand Down
13 changes: 3 additions & 10 deletions hal/src/main/java/edu/wpi/first/hal/JNIWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/** Base class for all JNI wrappers. */
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) {
RuntimeLoader.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();
RuntimeLoader.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
11 changes: 2 additions & 9 deletions ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
/** NetworkTables JNI. */
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,10 +47,7 @@ public final class NetworkTablesJNI {
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader.loadLibrary();
RuntimeLoader.loadLibrary("ntcorejni");
} catch (IOException 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();
RuntimeLoader.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
13 changes: 3 additions & 10 deletions wpimath/src/main/java/edu/wpi/first/math/WPIMathJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
/** WPIMath JNI. */
public final class WPIMathJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<WPIMathJNI> loader = null;

static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"wpimathjni", RuntimeLoader.getDefaultExtractionRoot(), WPIMathJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
RuntimeLoader.loadLibrary("wpimathjni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -37,10 +33,7 @@ public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>(
"wpimathjni", RuntimeLoader.getDefaultExtractionRoot(), WPIMathJNI.class);
loader.loadLibrary();
RuntimeLoader.loadLibrary("wpimathjni");
libraryLoaded = true;
}

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

package edu.wpi.first.net;

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());
}

private DevMain() {}
Expand Down
12 changes: 3 additions & 9 deletions wpinet/src/main/java/edu/wpi/first/net/WPINetJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/** WPINet JNI. */
public class WPINetJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<WPINetJNI> 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<>(
"wpinetjni", RuntimeLoader.getDefaultExtractionRoot(), WPINetJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
RuntimeLoader.loadLibrary("wpinetjni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Expand All @@ -63,9 +59,7 @@ public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader =
new RuntimeLoader<>("wpinetjni", RuntimeLoader.getDefaultExtractionRoot(), WPINetJNI.class);
loader.loadLibrary();
RuntimeLoader.loadLibrary("wpinetjni");
libraryLoaded = true;
}

Expand Down
2 changes: 1 addition & 1 deletion wpiutil/src/dev/java/edu/wpi/first/util/DevMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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());
}

private DevMain() {}
Expand Down
Loading
Loading