Skip to content

Commit 99bac98

Browse files
committed
Make stuff public and add documentation so this may be used as a library
1 parent deb26c8 commit 99bac98

3 files changed

Lines changed: 90 additions & 16 deletions

File tree

src/main/java/edu/wpi/first/wpilib/opencv/installer/Installer.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.io.File;
77
import java.io.FileInputStream;
88
import java.io.IOException;
9-
import java.io.InputStream;
10-
import java.net.HttpURLConnection;
119
import java.net.MalformedURLException;
1210
import java.net.URL;
1311
import java.nio.file.Files;
@@ -20,6 +18,8 @@
2018
/**
2119
* A command line application that downloads and installs OpenCV. This assumes that the OpenCV artifacts will be
2220
* available on the FRC maven server at http://first.wpi.edu/FRC/roborio/maven or in the local maven repository.
21+
*
22+
* <p>Install locations are specified by the current {@link Platform}</p>
2323
*/
2424
@UtilityClass
2525
public class Installer {
@@ -58,7 +58,10 @@ private enum ArtifactType {
5858
}
5959

6060

61-
public static void main(String... args) throws ParseException {
61+
/**
62+
* Main entry point.
63+
*/
64+
public static void main(String[] args) throws ParseException {
6265
CommandLineParser p = new DefaultParser();
6366
Options options = new Options() {{
6467
addOption("j", "java", false, "Install the Java API jar in the working directory");
@@ -81,11 +84,9 @@ public static void main(String... args) throws ParseException {
8184
throw new MissingOptionException("-v <version>");
8285
}
8386
if (parsedArgs.hasOption("platform")) {
84-
overridePlatform = true;
85-
platform = Platform.valueOf(parsedArgs.getOptionValue("platform"));
87+
setPlatform(Platform.valueOf(parsedArgs.getOptionValue("platform")));
8688
}
87-
openCvVersion = parsedArgs.getOptionValue("version");
88-
version = platform + "-" + openCvVersion;
89+
setVersion(parsedArgs.getOptionValue("version"));
8990
overwrite = !parsedArgs.hasOption("no-overwrite");
9091
System.out.println("Installing specified OpenCV components");
9192
System.out.println("======================================");
@@ -106,22 +107,60 @@ public static void main(String... args) throws ParseException {
106107
System.out.println("Finished installing OpenCV");
107108
}
108109

109-
private static void installJava() {
110+
/**
111+
* Sets a specific platform to install. Artifacts will be downloaded into the working directory and will need to be
112+
* manually installed.
113+
*
114+
* @param p the platform to get the artifacts for
115+
*/
116+
public static void setPlatform(Platform p) {
117+
platform = p;
118+
calculateVersion();
119+
overridePlatform = true;
120+
}
121+
122+
/**
123+
* Sets the version of OpenCV to get artifacts for.
124+
*
125+
* @param v the version of OpenCV to install
126+
*/
127+
public static void setVersion(String v) {
128+
openCvVersion = v;
129+
calculateVersion();
130+
}
131+
132+
private static void calculateVersion() {
133+
version = platform + "-" + openCvVersion;
134+
}
135+
136+
/**
137+
* Downloads the Java API jar.
138+
*/
139+
public static void installJava() {
110140
System.out.println("Installing Java");
111141
install(ArtifactType.JAVA);
112142
}
113143

114-
private static void installJni() {
144+
/**
145+
* Installs the JNI bindings.
146+
*/
147+
public static void installJni() {
115148
System.out.println("Installing JNI");
116149
install(ArtifactType.JNI);
117150
}
118151

119-
private static void installHeaders() {
152+
/**
153+
* Installs the C++ headers.
154+
*/
155+
public static void installHeaders() {
120156
System.out.println("Installing headers");
121157
install(ArtifactType.HEADERS);
122158
}
123159

124-
private static void installNatives() {
160+
/**
161+
* Installs the C++ native libraries.
162+
*/
163+
public static void installNatives() {
125164
System.out.println("Installing natives");
126165
install(ArtifactType.NATIVES);
127166
}

src/main/java/edu/wpi/first/wpilib/opencv/installer/Platform.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,53 @@
44
import lombok.RequiredArgsConstructor;
55

66

7+
/**
8+
* Enum values for supported platforms.
9+
*/
710
@Getter
811
@RequiredArgsConstructor
9-
enum Platform {
12+
public enum Platform {
1013

1114
// TODO figure out Windows install locations
15+
/**
16+
* 32-bit Windows.
17+
*/
1218
win32(
1319
"",
1420
"",
1521
"",
1622
""
1723
),
24+
/**
25+
* 64-bit Windows.
26+
*/
1827
win64(
1928
"",
2029
"",
2130
"",
2231
""
2332
),
33+
/**
34+
* Mac OS X. Only versions 10.4 and above are supported.
35+
*/
2436
osx(
2537
"",
2638
UserHomeHolder.userHome + "/Library/Java/Extensions",
2739
"/usr/local/include",
2840
"/usr/local/lib"
2941
),
42+
/**
43+
* 32-bit linux.
44+
*/
3045
linux32(
3146
"",
3247
"usr/local",
3348
"/usr/local/include",
3449
"/usr/local/lib"
3550
),
51+
/**
52+
* 64-bit linux.
53+
*/
3654
linux64(
3755
"",
3856
"/usr/local",
@@ -44,9 +62,26 @@ private static final class UserHomeHolder {
4462
static final String userHome = System.getProperty("user.home");
4563
}
4664

65+
/**
66+
* The location of installs for the Java library.
67+
*/
4768
private final String javaInstallLocation;
69+
70+
/**
71+
* The location of installs for the JNI bindings. This should be in a location that is on {@code java.library.path}
72+
* by default.
73+
*/
4874
private final String jniInstallLocation;
75+
76+
/**
77+
* The location of installs for the C++ header files.
78+
*/
4979
private final String headersInstallLocation;
80+
81+
/**
82+
* The location of installs for the native C++ libraries. This should be a default location on the path
83+
* (e.g. {@code /usr/local/}).
84+
*/
5085
private final String nativesInstallLocation;
5186

5287
}

src/main/java/edu/wpi/first/wpilib/opencv/installer/PlatformDetector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import lombok.experimental.UtilityClass;
44

55
@UtilityClass
6-
class PlatformDetector {
6+
public class PlatformDetector {
77

88
private static String os = null;
99
private static String arch = null;
@@ -20,7 +20,7 @@ class PlatformDetector {
2020
* @return the current operating system
2121
* @throws UnsupportedOperatingSystemError if the current operating system is not supported
2222
*/
23-
private static String getOs() throws UnsupportedOperatingSystemError {
23+
public static String getOs() throws UnsupportedOperatingSystemError {
2424
if (os != null) {
2525
return os;
2626
}
@@ -47,7 +47,7 @@ private static String getOs() throws UnsupportedOperatingSystemError {
4747
* @return the operating system architecture
4848
* @throws UnsupportedOperatingSystemError if the architecture is not supported
4949
*/
50-
private static String getArch() throws UnsupportedOperatingSystemError {
50+
public static String getArch() throws UnsupportedOperatingSystemError {
5151
if (arch != null) {
5252
return arch;
5353
}
@@ -67,7 +67,7 @@ private static String getArch() throws UnsupportedOperatingSystemError {
6767
*
6868
* @return the current platform
6969
*/
70-
static Platform getPlatform() {
70+
public static Platform getPlatform() {
7171
if (platform != null) {
7272
return platform;
7373
}

0 commit comments

Comments
 (0)