@@ -58,10 +58,38 @@ public class Installer {
58
58
public static void main (String [] args ) throws ParseException {
59
59
CommandLineParser p = new DefaultParser ();
60
60
Options options = new Options () {{
61
- addOption ("j" , "java" , false , "Install the Java API jar in the working directory" );
62
- addOption ("jni" , "jni" , false , "Install the JNI bindings for this operating system in " + platform .getJniInstallLocation ());
63
- addOption ("h" , "headers" , false , "Install the C++ headers in " + platform .getHeadersInstallLocation ());
64
- addOption ("n" , "natives" , false , "Install the C++ native libraries in " + platform .getNativesInstallLocation ());
61
+ addOption (Option .builder ("j" )
62
+ .longOpt ("java" )
63
+ .optionalArg (true )
64
+ .numberOfArgs (1 )
65
+ .argName ("install-path" )
66
+ .desc ("Install the OpenCV Java library" )
67
+ .build ()
68
+ );
69
+ addOption (Option .builder ("jni" )
70
+ .longOpt ("jni" )
71
+ .optionalArg (true )
72
+ .numberOfArgs (1 )
73
+ .argName ("install-path" )
74
+ .desc ("Install the OpenCV JNI bindings" )
75
+ .build ()
76
+ );
77
+ addOption (Option .builder ("h" )
78
+ .longOpt ("headers" )
79
+ .optionalArg (true )
80
+ .numberOfArgs (1 )
81
+ .argName ("install-path" )
82
+ .desc ("Install the OpenCV C++ headers" )
83
+ .build ()
84
+ );
85
+ addOption (Option .builder ("n" )
86
+ .longOpt ("natives" )
87
+ .optionalArg (true )
88
+ .numberOfArgs (1 )
89
+ .argName ("install-path" )
90
+ .desc ("Install the OpenCV native libraries" )
91
+ .build ()
92
+ );
65
93
addOption ("help" , "help" , false , "Prints this help message" );
66
94
addOption ("a" , "all" , false , "Installs all artifacts" );
67
95
addOption ("v" , "version" , true , "Set the version of OpenCV to install" );
@@ -85,28 +113,28 @@ public static void main(String[] args) throws ParseException {
85
113
System .out .println ("Installing specified OpenCV components" );
86
114
if (parsedArgs .hasOption ("java" ) || parsedArgs .hasOption ("all" )) {
87
115
try {
88
- installJava ();
116
+ installJava (parsedArgs . getOptionValue ( "java" , platform . getJavaInstallLocation ()) );
89
117
} catch (IOException e ) {
90
118
e .printStackTrace ();
91
119
}
92
120
}
93
121
if (parsedArgs .hasOption ("jni" ) || parsedArgs .hasOption ("all" )) {
94
122
try {
95
- installJni ();
123
+ installJni (parsedArgs . getOptionValue ( "jni" , platform . getJniInstallLocation ()) );
96
124
} catch (IOException e ) {
97
125
e .printStackTrace ();
98
126
}
99
127
}
100
128
if (parsedArgs .hasOption ("headers" ) || parsedArgs .hasOption ("all" )) {
101
129
try {
102
- installHeaders ();
130
+ installHeaders (parsedArgs . getOptionValue ( "headers" , platform . getHeadersInstallLocation ()) );
103
131
} catch (IOException e ) {
104
132
e .printStackTrace ();
105
133
}
106
134
}
107
135
if (parsedArgs .hasOption ("natives" ) || parsedArgs .hasOption ("all" )) {
108
136
try {
109
- installNatives ();
137
+ installNatives (parsedArgs . getOptionValue ( "natives" , platform . getNativesInstallLocation ()) );
110
138
} catch (IOException e ) {
111
139
e .printStackTrace ();
112
140
}
@@ -157,45 +185,49 @@ public static String getOpenCvVersion() {
157
185
/**
158
186
* Downloads the Java API jar.
159
187
*/
160
- public static void installJava () throws IOException {
188
+ public static void installJava (String location ) throws IOException {
161
189
System .out .println ("====================" );
162
- System .out .println ("Installing Java" );
190
+ System .out .println ("Installing Java to " + location );
163
191
System .out .println ("====================" );
164
- install (ArtifactType .JAVA );
192
+ install (ArtifactType .JAVA , location );
165
193
}
166
194
167
195
/**
168
196
* Installs the JNI bindings.
169
197
*/
170
- public static void installJni () throws IOException {
198
+ public static void installJni (String location ) throws IOException {
171
199
System .out .println ("====================" );
172
- System .out .println ("Installing JNI" );
200
+ System .out .println ("Installing JNI to " + location );
173
201
System .out .println ("====================" );
174
- install (ArtifactType .JNI );
202
+ install (ArtifactType .JNI , location );
175
203
}
176
204
177
205
/**
178
206
* Installs the C++ headers.
179
207
*/
180
- public static void installHeaders () throws IOException {
208
+ public static void installHeaders (String location ) throws IOException {
181
209
System .out .println ("====================" );
182
- System .out .println ("Installing headers" );
210
+ System .out .println ("Installing headers to " + location );
183
211
System .out .println ("====================" );
184
- install (ArtifactType .HEADERS );
212
+ install (ArtifactType .HEADERS , location );
185
213
}
186
214
187
215
/**
188
216
* Installs the C++ native libraries.
189
217
*/
190
- public static void installNatives () throws IOException {
218
+ public static void installNatives (String location ) throws IOException {
191
219
System .out .println ("====================" );
192
- System .out .println ("Installing natives" );
220
+ System .out .println ("Installing natives to " + location );
193
221
System .out .println ("====================" );
194
- install (ArtifactType .NATIVES );
222
+ install (ArtifactType .NATIVES , location );
195
223
}
196
224
197
- private static void install (ArtifactType type ) throws IOException {
198
- if (!overridePlatform && InstallChecker .isInstalled (type , openCvVersion )) {
225
+ private static void install (ArtifactType type , String location ) throws IOException {
226
+ if (!Paths .get (location ).isAbsolute ()) {
227
+ // Force location to be an absolute path
228
+ location = Paths .get (location ).toAbsolutePath ().toString ();
229
+ }
230
+ if (!overridePlatform && InstallChecker .isInstalled (type , location , openCvVersion )) {
199
231
System .out .println ("Artifacts for the version " + openCvVersion + " " + type .getArtifactName () + " have already been installed!" );
200
232
if (!overwrite ) {
201
233
return ;
@@ -211,20 +243,20 @@ private static void install(ArtifactType type) throws IOException {
211
243
case JAVA :
212
244
artifactId = javaJarName ;
213
245
v = openCvVersion ;
214
- installLocation += platform . getJavaInstallLocation () ;
246
+ installLocation += location ;
215
247
break ;
216
248
case JNI :
217
249
artifactId = jniName ;
218
- installLocation += platform . getJniInstallLocation () ;
250
+ installLocation += location ;
219
251
break ;
220
252
case HEADERS :
221
253
artifactId = headersName ;
222
254
v = openCvVersion ;
223
- installLocation += platform . getHeadersInstallLocation () ;
255
+ installLocation += location ;
224
256
break ;
225
257
case NATIVES :
226
258
artifactId = nativesName ;
227
- installLocation += platform . getNativesInstallLocation () ;
259
+ installLocation += location ;
228
260
break ;
229
261
default :
230
262
throw new UnsupportedOperationException ("Unknown artifact type: " + type );
@@ -255,7 +287,7 @@ private static void install(ArtifactType type) throws IOException {
255
287
}
256
288
copyAll (unzipped , Paths .get (installLocation ));
257
289
if (!overridePlatform ) {
258
- InstallChecker .registerSuccessfulInstall (type , openCvVersion );
290
+ InstallChecker .registerSuccessfulInstall (type , location , openCvVersion );
259
291
}
260
292
}
261
293
0 commit comments