Skip to content

Commit 85c9240

Browse files
committed
Fix classifiers. Only tested on windows
1 parent bbc9527 commit 85c9240

File tree

1 file changed

+55
-31
lines changed

1 file changed

+55
-31
lines changed

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

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class Installer {
4848
private static final String headersName = "opencv-headers";
4949
private static final String nativesName = "opencv-natives";
5050
private static String openCvVersion = "";
51-
private static String version = "";
5251

5352
/**
5453
* Sets a specific platform to install. Artifacts will be downloaded into the working directory and will need to be
@@ -61,10 +60,15 @@ public class Installer {
6160
*/
6261
public static void setPlatform(Platform p) {
6362
platform = p;
64-
calculateVersion();
6563
overridePlatform = true;
6664
}
6765

66+
/**
67+
* Gets the platform that artifacts will be installed for. This will return the platform that the installer is
68+
* running on, unless it's been overridden by {@link #setPlatform(Platform)}.
69+
*
70+
* @return the current platform
71+
*/
6872
public static Platform getPlatform() {
6973
return platform;
7074
}
@@ -76,11 +80,6 @@ public static Platform getPlatform() {
7680
*/
7781
public static void setOpenCvVersion(String v) {
7882
openCvVersion = v;
79-
calculateVersion();
80-
}
81-
82-
private static void calculateVersion() {
83-
version = platform.name() + "-" + openCvVersion;
8483
}
8584

8685
/**
@@ -151,38 +150,35 @@ private static void install(ArtifactType type, String location) throws IOExcepti
151150
}
152151
}
153152
String artifactId;
154-
String v = version;
155-
String installLocation = "";
153+
String v = openCvVersion;
154+
String classifier = null;
155+
String installLocation = location;
156156
if (overridePlatform) {
157-
installLocation = "install";
157+
installLocation = "install/" + location;
158158
}
159159
switch (type) {
160160
case JAVA:
161161
artifactId = javaJarName;
162-
v = openCvVersion;
163-
installLocation += location;
164162
break;
165163
case JNI:
166164
artifactId = jniName;
167-
installLocation += location;
165+
classifier = platform.name();
168166
break;
169167
case HEADERS:
170168
artifactId = headersName;
171-
v = openCvVersion;
172-
installLocation += location;
173169
break;
174170
case NATIVES:
175171
artifactId = nativesName;
176-
installLocation += location;
172+
classifier = platform.name();
177173
break;
178174
default:
179175
throw new UnsupportedOperationException("Unknown artifact type: " + type);
180176
}
181-
URL remote = resolveRemote(artifactId, v);
182-
File local = resolveLocal(artifactId, v);
177+
URL remote = resolveRemote(artifactId, v, classifier);
178+
File local = resolveLocal(artifactId, v, classifier);
183179
File source;
184180
if (!local.exists()) {
185-
copyToMavenLocal(mavenUrl, groupId, artifactId, v);
181+
copyToMavenLocal(mavenUrl, artifactId, v, classifier);
186182
}
187183
if (local.exists()) {
188184
System.out.println("Using local file at " + local.toURI());
@@ -208,16 +204,22 @@ private static void install(ArtifactType type, String location) throws IOExcepti
208204
}
209205
}
210206

211-
private static URL resolveRemote(String artifactId, String version) throws MalformedURLException {
212-
return new URL(resolveRelative(mavenUrl, artifactId, version));
207+
private static URL resolveRemote(String artifactId, String version, String classifier) throws MalformedURLException {
208+
return new URL(resolveRelative(mavenUrl, artifactId, version, classifier));
213209
}
214210

215-
private static File resolveLocal(String artifactId, String version) {
216-
return new File(resolveRelative(mavenLocal, artifactId, version));
211+
private static File resolveLocal(String artifactId, String version, String classifier) {
212+
File local = new File(resolveRelative(mavenLocal, artifactId, version, classifier));
213+
System.out.println("Local = " + local.getAbsolutePath());
214+
return local;
217215
}
218216

219-
private static String resolveRelative(String repo, String artifactId, String version) {
220-
return String.format("%s/%s/%s/%s/%s-%s.jar", repo, groupId.replace('.', '/'), artifactId, version, artifactId, version);
217+
private static String resolveRelative(String repo, String artifactId, String version, String classifier) {
218+
return String.format(
219+
"%s/%s.jar",
220+
resolveDir(repo, groupId, artifactId, version),
221+
resolveFullArtifactName(artifactId, version, classifier)
222+
);
221223
}
222224

223225
/**
@@ -233,6 +235,10 @@ private static Path unzip(File zipFile) {
233235
Files.createDirectories(dstDir);
234236
for (ZipEntry e = zis.getNextEntry(); e != null; e = zis.getNextEntry()) {
235237
String fileName = e.getName();
238+
if (fileName.contains("META-INF")) {
239+
// This stuff doesn't matter, don't bother extracting it
240+
continue;
241+
}
236242
System.out.println(" File: " + fileName);
237243
Path dst = dstDir.resolve(fileName);
238244
System.out.println(" Unzipping to " + dst);
@@ -271,7 +277,7 @@ private static void unsafeCopy(Path src, Path dst) {
271277
if (dst.getParent() != null && !Files.exists(dst.getParent())) {
272278
Files.createDirectories(dst.getParent());
273279
}
274-
if (Files.isDirectory(dst)) {
280+
if (Files.isDirectory(src)) {
275281
copyAll(src, dst);
276282
} else {
277283
if (Files.exists(dst)) {
@@ -291,26 +297,44 @@ private static void unsafeCopy(Path src, Path dst) {
291297
*
292298
* @return the path to the copied jar
293299
*/
294-
private static Path copyToMavenLocal(String repo, String groupId, String artifactId, String version) throws IOException {
295-
String remoteDir = String.format("%s/%s/%s/%s/", repo, groupId.replace('.', '/'), artifactId, openCvVersion);
296-
String name = String.format("%s-%s", artifactId, version);
300+
private static Path copyToMavenLocal(String repo, String artifactId, String version, String classifier) throws IOException {
301+
String remoteDir = resolveDir(repo, groupId, artifactId, version);
297302
String dstDir = remoteDir.replace(repo, mavenLocal);
298303
if (!Files.exists(Paths.get(dstDir))) {
299304
Files.createDirectories(Paths.get(dstDir));
300305
}
301306

302-
String jar = name + ".jar";
307+
String jar = resolveFullArtifactName(artifactId, version, classifier) + ".jar";
303308
String jarPath = remoteDir + jar;
304309
System.out.println("Copying " + jarPath + " to the local maven repository");
305310
Files.deleteIfExists(Paths.get(dstDir, jar));
306311
Files.copy(new URL(jarPath).openStream(), Paths.get(dstDir, jar));
307312

308-
String pom = name + ".pom";
313+
String pom = String.format("%s-%s.pom", artifactId, version);
309314
String pomPath = remoteDir + pom;
310315
Files.deleteIfExists(Paths.get(dstDir, pom));
311316
Files.copy(new URL(pomPath).openStream(), Paths.get(dstDir, pom));
312317

313318
return Paths.get(dstDir, jar);
314319
}
315320

321+
public static String resolveDir(String repo, String group, String artifact, String version) {
322+
return String.format(
323+
"%s/%s/%s/%s",
324+
repo,
325+
group.replace('.', '/'),
326+
artifact,
327+
version
328+
);
329+
}
330+
331+
public static String resolveFullArtifactName(String artifact, String version, String classifier) {
332+
return String.format(
333+
"%s-%s%s",
334+
artifact,
335+
version,
336+
classifier == null ? "" : "-" + classifier
337+
);
338+
}
339+
316340
}

0 commit comments

Comments
 (0)