ICU-12386 Search for an actual resource, not a directory.

X-SVN-Rev: 38563
This commit is contained in:
Fredrik Roubert 2016-03-23 20:21:59 +00:00
parent 2ecaf41472
commit bf1ec3b2cd

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2015, International Business Machines Corporation and
* Copyright (C) 1996-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
@ -17,6 +17,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.MissingResourceException;
@ -231,6 +232,12 @@ public class CompatibilityTest extends TestFmwk
}
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();
ix = urlAsString.indexOf("!/");
jarURL = new URL(urlAsString.substring(0, ix + 2));
JarURLConnection conn = (JarURLConnection) jarURL.openConnection();
JarFile jarFile = conn.getJarFile();
try {
@ -287,10 +294,24 @@ element_loop:
return target;
}
/**
* 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";
protected Target getTargets(String targetName)
{
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();
if (protocol.equals("jar")) {