ICU-12386 Search for an actual resource, not a directory.
R=markus.icu@gmail.com, yoshito_umaoka@us.ibm.com BUG= Review URL: https://codereview.appspot.com/318730043 . X-SVN-Rev: 39502
This commit is contained in:
parent
fad9b48931
commit
ac2430a58a
@ -2,7 +2,7 @@
|
|||||||
// License & terms of use: http://www.unicode.org/copyright.html#License
|
// License & terms of use: http://www.unicode.org/copyright.html#License
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* Copyright (C) 1996-2015, International Business Machines Corporation and
|
* Copyright (C) 1996-2016, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*
|
*
|
||||||
@ -15,6 +15,7 @@ import java.io.FileFilter;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.JarURLConnection;
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@ -95,9 +96,23 @@ public class CompatibilityTest extends TestFmwk
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path to an actual data resource file in the JAR. This is needed because when the
|
||||||
|
* code is packaged for Android the resulting archive does not have entries for directories
|
||||||
|
* and so only actual resources can be found.
|
||||||
|
*/
|
||||||
|
private static final String ACTUAL_RESOURCE = "/ICU_3.6/com.ibm.icu.impl.OlsonTimeZone.dat";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private List<FileHolder> generateClassList() throws IOException {
|
private List<FileHolder> generateClassList() throws IOException {
|
||||||
URL dataURL = getClass().getResource("data");
|
// Get the URL to an actual resource and then compute the URL to the directory just in
|
||||||
|
// case the resources are in a JAR file that doesn't have entries for directories.
|
||||||
|
URL dataURL = getClass().getResource("data" + ACTUAL_RESOURCE);
|
||||||
|
try {
|
||||||
|
dataURL = new URL(dataURL.toExternalForm().replace(ACTUAL_RESOURCE, ""));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
String protocol = dataURL.getProtocol();
|
String protocol = dataURL.getProtocol();
|
||||||
|
|
||||||
if (protocol.equals("jar")) {
|
if (protocol.equals("jar")) {
|
||||||
@ -152,6 +167,8 @@ public class CompatibilityTest extends TestFmwk
|
|||||||
|
|
||||||
JarFile jarFile = null;
|
JarFile jarFile = null;
|
||||||
try {
|
try {
|
||||||
|
// Need to trim the directory off the JAR entry before opening the connection otherwise
|
||||||
|
// it could fail as it will try and find the entry within the JAR which may not exist.
|
||||||
String urlAsString = jarURL.toExternalForm();
|
String urlAsString = jarURL.toExternalForm();
|
||||||
ix = urlAsString.indexOf("!/");
|
ix = urlAsString.indexOf("!/");
|
||||||
jarURL = new URL(urlAsString.substring(0, ix + 2));
|
jarURL = new URL(urlAsString.substring(0, ix + 2));
|
||||||
|
Loading…
Reference in New Issue
Block a user