Skip to content

Commit cc64845

Browse files
committed
[wpiutil] Remove RuntimeLoader and RuntimeDetector
Resolves #6598
1 parent dc00a13 commit cc64845

File tree

22 files changed

+98
-471
lines changed

22 files changed

+98
-471
lines changed

apriltag/src/main/java/edu/wpi/first/apriltag/jni/AprilTagJNI.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
public class AprilTagJNI {
1818
static boolean libraryLoaded = false;
1919

20-
static RuntimeLoader<AprilTagJNI> loader = null;
21-
2220
/** Sets whether JNI should be loaded in the static block. */
2321
public static class Helper {
2422
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
@@ -48,10 +46,7 @@ private Helper() {}
4846
static {
4947
if (Helper.getExtractOnStaticLoad()) {
5048
try {
51-
loader =
52-
new RuntimeLoader<>(
53-
"apriltagjni", RuntimeLoader.getDefaultExtractionRoot(), AprilTagJNI.class);
54-
loader.loadLibrary();
49+
RuntimeLoader.loadLibrary("apriltagjni");
5550
} catch (IOException ex) {
5651
ex.printStackTrace();
5752
System.exit(1);

apriltag/src/test/java/edu/wpi/first/apriltag/AprilTagDetectorTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,10 @@ class AprilTagDetectorTest {
2929
@SuppressWarnings("MemberName")
3030
AprilTagDetector detector;
3131

32-
static RuntimeLoader<Core> loader;
33-
3432
@BeforeAll
3533
static void beforeAll() {
3634
try {
37-
loader =
38-
new RuntimeLoader<>(
39-
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
40-
loader.loadLibrary();
35+
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
4136
} catch (IOException ex) {
4237
fail(ex);
4338
}

cscore/src/dev/java/edu/wpi/first/cscore/DevMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
package edu.wpi.first.cscore;
66

7-
import edu.wpi.first.util.RuntimeDetector;
7+
import edu.wpi.first.util.CombinedRuntimeLoader;
88

99
public final class DevMain {
1010
/** Main method. */
1111
public static void main(String[] args) {
1212
System.out.println("Hello World!");
13-
System.out.println(RuntimeDetector.getPlatformPath());
13+
System.out.println(CombinedRuntimeLoader.getPlatformPath());
1414
System.out.println(CameraServerJNI.getHostname());
1515
}
1616

cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
public class CameraServerJNI {
1616
static boolean libraryLoaded = false;
1717

18-
static RuntimeLoader<CameraServerJNI> loader = null;
19-
2018
/** Sets whether JNI should be loaded in the static block. */
2119
public static class Helper {
2220
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
@@ -46,10 +44,7 @@ private Helper() {}
4644
static {
4745
if (Helper.getExtractOnStaticLoad()) {
4846
try {
49-
loader =
50-
new RuntimeLoader<>(
51-
"cscorejni", RuntimeLoader.getDefaultExtractionRoot(), CameraServerJNI.class);
52-
loader.loadLibrary();
47+
RuntimeLoader.loadLibrary("cscorejni");
5348
} catch (IOException ex) {
5449
ex.printStackTrace();
5550
System.exit(1);
@@ -67,10 +62,7 @@ public static synchronized void forceLoad() throws IOException {
6762
if (libraryLoaded) {
6863
return;
6964
}
70-
loader =
71-
new RuntimeLoader<>(
72-
"cscorejni", RuntimeLoader.getDefaultExtractionRoot(), CameraServerJNI.class);
73-
loader.loadLibrary();
65+
RuntimeLoader.loadLibrary("cscorejni");
7466
libraryLoaded = true;
7567
}
7668

cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public final class OpenCvLoader {
1414
@SuppressWarnings("PMD.MutableStaticState")
1515
static boolean libraryLoaded;
1616

17-
@SuppressWarnings("PMD.MutableStaticState")
18-
static RuntimeLoader<Core> loader;
19-
2017
/** Sets whether JNI should be loaded in the static block. */
2118
public static class Helper {
2219
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
@@ -44,12 +41,9 @@ private Helper() {}
4441
}
4542

4643
static {
47-
String opencvName = Core.NATIVE_LIBRARY_NAME;
4844
if (Helper.getExtractOnStaticLoad()) {
4945
try {
50-
loader =
51-
new RuntimeLoader<>(opencvName, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
52-
loader.loadLibraryHashed();
46+
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
5347
} catch (IOException ex) {
5448
ex.printStackTrace();
5549
System.exit(1);
@@ -76,10 +70,7 @@ public static synchronized void forceLoad() throws IOException {
7670
if (libraryLoaded) {
7771
return;
7872
}
79-
loader =
80-
new RuntimeLoader<>(
81-
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
82-
loader.loadLibrary();
73+
RuntimeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
8374
libraryLoaded = true;
8475
}
8576

hal/src/main/java/edu/wpi/first/hal/JNIWrapper.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/** Base class for all JNI wrappers. */
1212
public class JNIWrapper {
1313
static boolean libraryLoaded = false;
14-
static RuntimeLoader<JNIWrapper> loader = null;
1514

1615
/** Sets whether JNI should be loaded in the static block. */
1716
public static class Helper {
@@ -42,11 +41,8 @@ private Helper() {}
4241
static {
4342
if (Helper.getExtractOnStaticLoad()) {
4443
try {
45-
loader =
46-
new RuntimeLoader<>(
47-
"wpiHaljni", RuntimeLoader.getDefaultExtractionRoot(), JNIWrapper.class);
48-
loader.loadLibrary();
49-
} catch (IOException ex) {
44+
RuntimeLoader.loadLibrary("wpiHaljni");
45+
} catch (Exception ex) {
5046
ex.printStackTrace();
5147
System.exit(1);
5248
}
@@ -63,10 +59,7 @@ public static synchronized void forceLoad() throws IOException {
6359
if (libraryLoaded) {
6460
return;
6561
}
66-
loader =
67-
new RuntimeLoader<>(
68-
"wpiHaljni", RuntimeLoader.getDefaultExtractionRoot(), JNIWrapper.class);
69-
loader.loadLibrary();
62+
RuntimeLoader.loadLibrary("wpiHaljni");
7063
libraryLoaded = true;
7164
}
7265

ntcore/src/dev/java/edu/wpi/first/ntcore/DevMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
package edu.wpi.first.ntcore;
66

77
import edu.wpi.first.networktables.NetworkTablesJNI;
8-
import edu.wpi.first.util.RuntimeDetector;
8+
import edu.wpi.first.util.CombinedRuntimeLoader;
99

1010
public final class DevMain {
1111
/** Main method. */
1212
public static void main(String[] args) {
1313
System.out.println("Hello World!");
14-
System.out.println(RuntimeDetector.getPlatformPath());
14+
System.out.println(CombinedRuntimeLoader.getPlatformPath());
1515
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
1616
}
1717

ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
1717
/** NetworkTables JNI. */
1818
public final class NetworkTablesJNI {
1919
static boolean libraryLoaded = false;
20-
static RuntimeLoader<NetworkTablesJNI> loader = null;
2120

2221
/** Sets whether JNI should be loaded in the static block. */
2322
public static class Helper {
@@ -48,10 +47,7 @@ public final class NetworkTablesJNI {
4847
static {
4948
if (Helper.getExtractOnStaticLoad()) {
5049
try {
51-
loader =
52-
new RuntimeLoader<>(
53-
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
54-
loader.loadLibrary();
50+
RuntimeLoader.loadLibrary("ntcorejni");
5551
} catch (IOException ex) {
5652
ex.printStackTrace();
5753
System.exit(1);
@@ -69,10 +65,7 @@ public final class NetworkTablesJNI {
6965
if (libraryLoaded) {
7066
return;
7167
}
72-
loader =
73-
new RuntimeLoader<>(
74-
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
75-
loader.loadLibrary();
68+
RuntimeLoader.loadLibrary("ntcorejni");
7669
libraryLoaded = true;
7770
}
7871

ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

romiVendordep/src/dev/java/edu/wpi/first/wpilibj/romi/DevMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import edu.wpi.first.hal.HALUtil;
88
import edu.wpi.first.networktables.NetworkTablesJNI;
9-
import edu.wpi.first.util.RuntimeDetector;
9+
import edu.wpi.first.util.CombinedRuntimeLoader;
1010

1111
public final class DevMain {
1212
/** Main entry point. */
1313
public static void main(String[] args) {
1414
System.out.println("Hello World!");
15-
System.out.println(RuntimeDetector.getPlatformPath());
15+
System.out.println(CombinedRuntimeLoader.getPlatformPath());
1616
System.out.println(NetworkTablesJNI.now());
1717
System.out.println(HALUtil.getHALRuntimeType());
1818
}

0 commit comments

Comments
 (0)