@@ -84,16 +84,32 @@ public static void main(String[] args) throws ParseException {
84
84
overwrite = parsedArgs .hasOption ("overwrite" );
85
85
System .out .println ("Installing specified OpenCV components" );
86
86
if (parsedArgs .hasOption ("java" ) || parsedArgs .hasOption ("all" )) {
87
- installJava ();
87
+ try {
88
+ installJava ();
89
+ } catch (IOException e ) {
90
+ e .printStackTrace ();
91
+ }
88
92
}
89
93
if (parsedArgs .hasOption ("jni" ) || parsedArgs .hasOption ("all" )) {
90
- installJni ();
94
+ try {
95
+ installJni ();
96
+ } catch (IOException e ) {
97
+ e .printStackTrace ();
98
+ }
91
99
}
92
100
if (parsedArgs .hasOption ("headers" ) || parsedArgs .hasOption ("all" )) {
93
- installHeaders ();
101
+ try {
102
+ installHeaders ();
103
+ } catch (IOException e ) {
104
+ e .printStackTrace ();
105
+ }
94
106
}
95
107
if (parsedArgs .hasOption ("natives" ) || parsedArgs .hasOption ("all" )) {
96
- installNatives ();
108
+ try {
109
+ installNatives ();
110
+ } catch (IOException e ) {
111
+ e .printStackTrace ();
112
+ }
97
113
}
98
114
99
115
System .out .println ("==========================" );
@@ -141,7 +157,7 @@ public static String getOpenCvVersion() {
141
157
/**
142
158
* Downloads the Java API jar.
143
159
*/
144
- public static void installJava () {
160
+ public static void installJava () throws IOException {
145
161
System .out .println ("====================" );
146
162
System .out .println ("Installing Java" );
147
163
System .out .println ("====================" );
@@ -151,7 +167,7 @@ public static void installJava() {
151
167
/**
152
168
* Installs the JNI bindings.
153
169
*/
154
- public static void installJni () {
170
+ public static void installJni () throws IOException {
155
171
System .out .println ("====================" );
156
172
System .out .println ("Installing JNI" );
157
173
System .out .println ("====================" );
@@ -161,7 +177,7 @@ public static void installJni() {
161
177
/**
162
178
* Installs the C++ headers.
163
179
*/
164
- public static void installHeaders () {
180
+ public static void installHeaders () throws IOException {
165
181
System .out .println ("====================" );
166
182
System .out .println ("Installing headers" );
167
183
System .out .println ("====================" );
@@ -171,79 +187,75 @@ public static void installHeaders() {
171
187
/**
172
188
* Installs the C++ native libraries.
173
189
*/
174
- public static void installNatives () {
190
+ public static void installNatives () throws IOException {
175
191
System .out .println ("====================" );
176
192
System .out .println ("Installing natives" );
177
193
System .out .println ("====================" );
178
194
install (ArtifactType .NATIVES );
179
195
}
180
196
181
- private static void install (ArtifactType type ) {
197
+ private static void install (ArtifactType type ) throws IOException {
182
198
if (!overridePlatform && InstallChecker .isInstalled (type , openCvVersion )) {
183
199
System .out .println ("Artifacts for the version " + openCvVersion + " " + type .getArtifactName () + " have already been installed!" );
184
200
if (!overwrite ) {
185
201
return ;
186
202
}
187
203
}
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 );
247
259
}
248
260
}
249
261
0 commit comments