gcc/libjava/classpath/gnu/java/net/loader/JarURLLoader.java
Matthias Klose e1bea0c068 libjava/classpath/ChangeLog.gcj:
2007-05-31  Matthias Klose  <doko@ubuntu.com>

        * javax/management/NotificationBroadcasterSupport.java
        (getNotificationInfo): Add cast.
        * native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
        directories.
        * native/jni/qt-peer/Makefile.in: Regenerate.

libjava/ChangeLog:

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        * java/io/natFileWin32.cc (setFilePermissions): New (stub only).
        _access: Handle EXEC query, stub only.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        Merged from classpath:
        * gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
        * java/lang/System.java(inheritedChannel): New.
        * java/lang/Character.java: Remove stray`;'.
        * java/net/MulticastSocket.java: Merged.
        * java/text/DateFormatSymbols.java(getInstance): New, comment updates.
        * java/text/Collator.java(getInstance): Merged.
        * java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
        getDisplayName, getDisplayNames: New.
        * java/util/logging/Logger.java: Merged.
        * Regenerate .class and .h files.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        * java/io/File.java: Merge with classpath-0.95, new method
        setFilePermissions, new attribute EXEC.
        * java/io/natFilePosix.cc (setFilePermissions): New.
        _access: Handle EXEC query.
        * classpath/lib/java/io/File.class, java/io/File.h: Regenerate.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        Imported GNU Classpath 0.95.

        * classpath/Makefile.in,
        classpath/native/jni/midi-dssi/Makefile.in,
        classpath/native/jni/classpath/Makefile.in,
        classpath/native/jni/Makefile.in,
        classpath/native/jni/gconf-peer/Makefile.in,
        classpath/native/jni/java-io/Makefile.in,
        classpath/native/jni/native-lib/Makefile.in,
        classpath/native/jni/java-util/Makefile.in,
        classpath/native/jni/midi-alsa/Makefile.in,
        classpath/native/jni/java-lang/Makefile.in,
        classpath/native/jni/java-nio/Makefile.in,
        classpath/native/jni/java-net/Makefile.in,
        classpath/native/jni/xmlj/Makefile.in,
        classpath/native/jni/qt-peer/Makefile.in,
        classpath/native/jni/gtk-peer/Makefile.in,
        classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
        classpath/native/fdlibm/Makefile.in,
        classpath/native/plugin/Makefile.in,
        classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
        classpath/tools/Makefile.in, classpath/doc/Makefile.in,
        classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
        classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
        classpath/external/sax/Makefile.in,
        classpath/external/w3c_dom/Makefile.in,
        classpath/external/relaxngDatatype/Makefile.in,
        classpath/include/Makefile.in,
        classpath/examples/Makefile.in: Regenerate.
        * classpath/config.guess, classpath/config.sub,
        classpath/ltmain.sh : Update.
        * classpath/configure, classpath/depcomp, classpath/missing,
        classpath/aclocal.m4, classpath/install-sh: Regenerate.

        * gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
        * sources.am: Regenerate.
        * Makefile.in: Regenerate.

        * Update the .class files and generated CNI header files, add new
        .class and generated CNI header files.
        * Remove generated files for removed java source files:
        classpath/gnu/java/net/BASE64.java,
        classpath/gnu/java/security/util/Base64.java,
        classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
        classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
        classpath/gnu/java/awt/font/autofit/Scaler.java,
        classpath/gnu/classpath/jdwp/util/Value.java,
        classpath/gnu/javax/net/ssl/Base64.java.
        * Remove empty directories.

        * Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
        * java/lang/Class.java(setAccessible): Merge from classpath.
        * java/util/Locale.java: Remove.
        * gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
        gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
        * gcj/javaprims.h: Update class declarations.
        * scripts/classes.pl: Update usage.
        * HACKING: Mention to build all peers.

From-SVN: r125302
2007-06-03 23:18:43 +00:00

215 lines
7.4 KiB
Java

package gnu.java.net.loader;
import gnu.java.net.IndexListParser;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
* A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
* only loading from jar url.
*/
public final class JarURLLoader extends URLLoader
{
// True if we've initialized -- i.e., tried open the jar file.
boolean initialized;
// The jar file for this url.
JarFile jarfile;
// Base jar: url for all resources loaded from jar.
final URL baseJarURL;
// The "Class-Path" attribute of this Jar's manifest.
ArrayList<URLLoader> classPath;
// If not null, a mapping from INDEX.LIST for this jar only.
// This is a set of all prefixes and top-level files that
// ought to be available in this jar.
Set indexSet;
// This constructor is used internally. It purposely does not open
// the jar file -- it defers this until later. This allows us to
// implement INDEX.LIST lazy-loading semantics.
private JarURLLoader(URLClassLoader classloader, URLStreamHandlerCache cache,
URLStreamHandlerFactory factory,
URL baseURL, URL absoluteUrl,
Set indexSet)
{
super(classloader, cache, factory, baseURL, absoluteUrl);
URL newBaseURL = null;
try
{
// Cache url prefix for all resources in this jar url.
String base = baseURL.toExternalForm() + "!/";
newBaseURL = new URL("jar", "", -1, base, cache.get(factory, "jar"));
}
catch (MalformedURLException ignore)
{
// Ignore.
}
this.baseJarURL = newBaseURL;
this.classPath = null;
this.indexSet = indexSet;
}
// This constructor is used by URLClassLoader. It will immediately
// try to read the jar file, in case we've found an index or a class-path
// setting. FIXME: it would be nice to defer this as well, but URLClassLoader
// makes this hard.
public JarURLLoader(URLClassLoader classloader, URLStreamHandlerCache cache,
URLStreamHandlerFactory factory,
URL baseURL, URL absoluteUrl)
{
this(classloader, cache, factory, baseURL, absoluteUrl, null);
initialize();
}
private void initialize()
{
JarFile jarfile = null;
try
{
jarfile =
((JarURLConnection) baseJarURL.openConnection()).getJarFile();
Manifest manifest;
Attributes attributes;
String classPathString;
IndexListParser parser = new IndexListParser(jarfile, baseJarURL,
baseURL);
LinkedHashMap<URL, Set<String>> indexMap = parser.getHeaders();
if (indexMap != null)
{
// Note that the index also computes
// the resulting Class-Path -- there are jars out there
// where the index lists some required jars which do
// not appear in the Class-Path attribute in the manifest.
this.classPath = new ArrayList<URLLoader>();
Iterator<Map.Entry<URL, Set<String>>> it = indexMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry<URL, Set<String>> entry = it.next();
URL subURL = entry.getKey();
Set<String> prefixes = entry.getValue();
if (subURL.equals(baseURL))
this.indexSet = prefixes;
else
{
JarURLLoader subLoader = new JarURLLoader(classloader,
cache,
factory, subURL,
subURL,
prefixes);
// Note that we don't care if the sub-loader itself has an
// index or a class-path -- only the top-level jar
// file gets this treatment; its index should cover
// everything.
this.classPath.add(subLoader);
}
}
}
else if ((manifest = jarfile.getManifest()) != null
&& (attributes = manifest.getMainAttributes()) != null
&& ((classPathString
= attributes.getValue(Attributes.Name.CLASS_PATH))
!= null))
{
this.classPath = new ArrayList<URLLoader>();
StringTokenizer st = new StringTokenizer(classPathString, " ");
while (st.hasMoreElements ())
{
String e = st.nextToken ();
try
{
URL subURL = new URL(baseURL, e);
// We've seen at least one jar file whose Class-Path
// attribute includes the original jar. If we process
// that normally we end up with infinite recursion.
if (subURL.equals(baseURL))
continue;
JarURLLoader subLoader = new JarURLLoader(classloader,
cache, factory,
subURL, subURL);
this.classPath.add(subLoader);
ArrayList<URLLoader> extra = subLoader.getClassPath();
if (extra != null)
this.classPath.addAll(extra);
}
catch (java.net.MalformedURLException xx)
{
// Give up
}
}
}
}
catch (IOException ioe)
{
/* ignored */
}
this.jarfile = jarfile;
this.initialized = true;
}
/** get resource with the name "name" in the jar url */
public Resource getResource(String name)
{
if (name.startsWith("/"))
name = name.substring(1);
if (indexSet != null)
{
// Trust the index.
String basename = name;
int offset = basename.lastIndexOf('/');
if (offset != -1)
basename = basename.substring(0, offset);
if (! indexSet.contains(basename))
return null;
// FIXME: if the index claim to hold the resource, and jar file
// doesn't have it, we're supposed to throw an exception. However,
// in our model this is tricky to implement, as another URLLoader from
// the same top-level jar may have an overlapping index entry.
}
if (! initialized)
initialize();
if (jarfile == null)
return null;
JarEntry je = jarfile.getJarEntry(name);
if (je != null)
return new JarURLResource(this, name, je);
else
return null;
}
public Manifest getManifest()
{
try
{
return (jarfile == null) ? null : jarfile.getManifest();
}
catch (IOException ioe)
{
return null;
}
}
public ArrayList<URLLoader> getClassPath()
{
return classPath;
}
}