Thanks for your submission. I have applied it to my own copy and am
testing it out.
Is there something i can try to break the older version that your fix fixes=
?
On 1/1/06, Bertalan Fodor <fodber@...> wrote:
> Hello,
>
> I desperately need this fix in JARClassLoader. The problem is that jEdit
> doesn't store package information in loaded classes, so getPackage()
> returns null in classes loaded from JARs. That makes impossible to
> include certain libraries.
>
> Please include the attached patch (or something similar) in the next
> release.
>
> Thank you,
>
> Bert
>
>
>
>
> --- JARClassLoader.old 2006-01-01 18:05:46.109375000 +0100
> +++ JARClassLoader.new 2006-01-01 18:05:33.765625000 +0100
> @@ -31,13 +31,19 @@
> import java.util.zip.ZipEntry;
> import java.util.zip.ZipFile;
> import org.gjt.sp.util.Log;
> +
> +import java.util.jar.Manifest;
> +import java.util.jar.JarFile;
> +import java.net.MalformedURLException;
> +import java.util.jar.Attributes;
> +import java.util.jar.Attributes.Name;
> //}}}
>
> /**
> * A class loader implementation that loads classes from JAR files. All
> * instances share the same set of classes.
> * @author Slava Pestov
> - * @version $Id: JARClassLoader.java,v 1.35 2005/02/14 02:54:29 spestov =
Exp $
> + * @version $Id: JARClassLoader.java,v 1.2 2005/05/13 20:59:16 fodber Ex=
p $
> */
> public class JARClassLoader extends ClassLoader
> {
> @@ -331,6 +337,7 @@
>
> try
> {
> + definePackage(clazz);
> ZipFile zipFile =3D jar.getZipFile();
> ZipEntry entry =3D zipFile.getEntry(name)=
;
>
> @@ -372,6 +379,62 @@
> }
> } //}}}
>
> + //{{{ definePackage(clazz) method
> + private void definePackage(String clazz) throws IOException
> + {
> + int idx =3D clazz.lastIndexOf('.');
> + if (idx !=3D -1) {
> + String name =3D clazz.substring(0, idx);
> + if (getPackage(name) =3D=3D null) definePackage(n=
ame, new JarFile(jar.getFile()).getManifest());
> + }
> + } //}}}
> +
> + //{{{ getMfValue() method
> + private String getMfValue(Attributes sectionAttrs, Attributes mai=
nAttrs, Attributes.Name name)
> + {
> + String value=3Dnull;
> + if (sectionAttrs !=3D null)
> + value =3D sectionAttrs.getValue(name);
> + else if (mainAttrs !=3D null) {
> + value =3D mainAttrs.getValue(name);
> + }
> + return value;
> + }
> + //}}}
> +
> + //{{{ definePackage(packageName, manifest) method
> + private void definePackage(String name, Manifest mf)
> + {
> + if (mf=3D=3Dnull)
> + {
> + definePackage(name, null, null, null, null, null,
> + null, null);
> + return;
> + }
> +
> + Attributes sa =3D mf.getAttributes(name.replace('.', '/')=
+ "/");
> + Attributes ma =3D mf.getMainAttributes();
> +
> + URL sealBase =3D null;
> + if (Boolean.valueOf(getMfValue(sa, ma, Name.SEALED)).bool=
eanValue())
> + {
> + try
> + {
> + sealBase =3D jar.getFile().toURL();
> + } catch (MalformedURLException e) { }
> + }
> +
> + Package pkg=3DdefinePackage(
> + name,
> + getMfValue(sa, ma, Name.SPECIFICATION_TITLE),
> + getMfValue(sa, ma, Name.SPECIFICATION_VERSION),
> + getMfValue(sa, ma, Name.SPECIFICATION_VENDOR),
> + getMfValue(sa, ma, Name.IMPLEMENTATION_TITLE),
> + getMfValue(sa, ma, Name.IMPLEMENTATION_VERSION),
> + getMfValue(sa, ma, Name.IMPLEMENTATION_VENDOR),
> + sealBase);
> + } //}}}
> +
> //}}}
> }
>
>
>
>
|