Skip to content

Commit e55d2e4

Browse files
committed
Throw IOException if an artifact couldn't be installed
1 parent 0d97fd1 commit e55d2e4

File tree

1 file changed

+80
-68
lines changed

1 file changed

+80
-68
lines changed

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

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,32 @@ public static void main(String[] args) throws ParseException {
8484
overwrite = parsedArgs.hasOption("overwrite");
8585
System.out.println("Installing specified OpenCV components");
8686
if (parsedArgs.hasOption("java") || parsedArgs.hasOption("all")) {
87-
installJava();
87+
try {
88+
installJava();
89+
} catch (IOException e) {
90+
e.printStackTrace();
91+
}
8892
}
8993
if (parsedArgs.hasOption("jni") || parsedArgs.hasOption("all")) {
90-
installJni();
94+
try {
95+
installJni();
96+
} catch (IOException e) {
97+
e.printStackTrace();
98+
}
9199
}
92100
if (parsedArgs.hasOption("headers") || parsedArgs.hasOption("all")) {
93-
installHeaders();
101+
try {
102+
installHeaders();
103+
} catch (IOException e) {
104+
e.printStackTrace();
105+
}
94106
}
95107
if (parsedArgs.hasOption("natives") || parsedArgs.hasOption("all")) {
96-
installNatives();
108+
try {
109+
installNatives();
110+
} catch (IOException e) {
111+
e.printStackTrace();
112+
}
97113
}
98114

99115
System.out.println("==========================");
@@ -141,7 +157,7 @@ public static String getOpenCvVersion() {
141157
/**
142158
* Downloads the Java API jar.
143159
*/
144-
public static void installJava() {
160+
public static void installJava() throws IOException {
145161
System.out.println("====================");
146162
System.out.println("Installing Java");
147163
System.out.println("====================");
@@ -151,7 +167,7 @@ public static void installJava() {
151167
/**
152168
* Installs the JNI bindings.
153169
*/
154-
public static void installJni() {
170+
public static void installJni() throws IOException {
155171
System.out.println("====================");
156172
System.out.println("Installing JNI");
157173
System.out.println("====================");
@@ -161,7 +177,7 @@ public static void installJni() {
161177
/**
162178
* Installs the C++ headers.
163179
*/
164-
public static void installHeaders() {
180+
public static void installHeaders() throws IOException {
165181
System.out.println("====================");
166182
System.out.println("Installing headers");
167183
System.out.println("====================");
@@ -171,79 +187,75 @@ public static void installHeaders() {
171187
/**
172188
* Installs the C++ native libraries.
173189
*/
174-
public static void installNatives() {
190+
public static void installNatives() throws IOException {
175191
System.out.println("====================");
176192
System.out.println("Installing natives");
177193
System.out.println("====================");
178194
install(ArtifactType.NATIVES);
179195
}
180196

181-
private static void install(ArtifactType type) {
197+
private static void install(ArtifactType type) throws IOException {
182198
if (!overridePlatform && InstallChecker.isInstalled(type, openCvVersion)) {
183199
System.out.println("Artifacts for the version " + openCvVersion + " " + type.getArtifactName() + " have already been installed!");
184200
if (!overwrite) {
185201
return;
186202
}
187203
}
188-
try {
189-
String artifactId;
190-
String v = version;
191-
String installLocation = "";
192-
if (overridePlatform) {
193-
installLocation = "install";
194-
}
195-
switch (type) {
196-
case JAVA:
197-
artifactId = javaJarName;
198-
v = openCvVersion;
199-
installLocation += platform.getJavaInstallLocation();
200-
break;
201-
case JNI:
202-
artifactId = jniName;
203-
installLocation += platform.getJniInstallLocation();
204-
break;
205-
case HEADERS:
206-
artifactId = headersName;
207-
v = openCvVersion;
208-
installLocation += platform.getHeadersInstallLocation();
209-
break;
210-
case NATIVES:
211-
artifactId = nativesName;
212-
installLocation += platform.getNativesInstallLocation();
213-
break;
214-
default:
215-
throw new UnsupportedOperationException("Unknown artifact type: " + type);
216-
}
217-
URL remote = resolveRemote(artifactId, v);
218-
File local = resolveLocal(artifactId, v);
219-
File source;
220-
if (!local.exists()) {
221-
copyToMavenLocal(githubRepo, groupId, artifactId, v);
222-
}
223-
if (local.exists()) {
224-
System.out.println("Using local file at " + local.toURI());
225-
source = local;
226-
} else {
227-
throw new NoSuchFileException("Could not find artifacts. Looked in:\n" +
228-
" " + remote + "\n" +
229-
" " + local.toURI());
230-
}
231-
Path unzipped;
232-
if (type != ArtifactType.JAVA) {
233-
unzipped = unzip(source);
234-
} else {
235-
Path dst = unzippedDir.resolve(artifactId + '-' + v).resolve(artifactId + '-' + v + ".jar");
236-
Files.createDirectories(dst.getParent());
237-
Files.copy(source.toPath(), dst);
238-
System.out.println(" Downloaded Java to " + dst);
239-
unzipped = dst.getParent();
240-
}
241-
copyAll(unzipped, Paths.get(installLocation));
242-
if (!overridePlatform) {
243-
InstallChecker.registerSuccessfulInstall(type, openCvVersion);
244-
}
245-
} catch (Exception e) {
246-
e.printStackTrace(System.out);
204+
String artifactId;
205+
String v = version;
206+
String installLocation = "";
207+
if (overridePlatform) {
208+
installLocation = "install";
209+
}
210+
switch (type) {
211+
case JAVA:
212+
artifactId = javaJarName;
213+
v = openCvVersion;
214+
installLocation += platform.getJavaInstallLocation();
215+
break;
216+
case JNI:
217+
artifactId = jniName;
218+
installLocation += platform.getJniInstallLocation();
219+
break;
220+
case HEADERS:
221+
artifactId = headersName;
222+
v = openCvVersion;
223+
installLocation += platform.getHeadersInstallLocation();
224+
break;
225+
case NATIVES:
226+
artifactId = nativesName;
227+
installLocation += platform.getNativesInstallLocation();
228+
break;
229+
default:
230+
throw new UnsupportedOperationException("Unknown artifact type: " + type);
231+
}
232+
URL remote = resolveRemote(artifactId, v);
233+
File local = resolveLocal(artifactId, v);
234+
File source;
235+
if (!local.exists()) {
236+
copyToMavenLocal(githubRepo, groupId, artifactId, v);
237+
}
238+
if (local.exists()) {
239+
System.out.println("Using local file at " + local.toURI());
240+
source = local;
241+
} else {
242+
throw new NoSuchFileException("Could not find artifacts. Looked in:\n" +
243+
" " + remote + "\n" +
244+
" " + local.toURI());
245+
}
246+
Path unzipped;
247+
if (type != ArtifactType.JAVA) {
248+
unzipped = unzip(source);
249+
} else {
250+
Path dst = unzippedDir.resolve(artifactId + '-' + v).resolve(artifactId + '-' + v + ".jar");
251+
Files.createDirectories(dst.getParent());
252+
Files.copy(source.toPath(), dst);
253+
System.out.println(" Downloaded Java to " + dst);
254+
unzipped = dst.getParent();
255+
}
256+
copyAll(unzipped, Paths.get(installLocation));
257+
if (!overridePlatform) {
258+
InstallChecker.registerSuccessfulInstall(type, openCvVersion);
247259
}
248260
}
249261

0 commit comments

Comments
 (0)