Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 124472 Details for
Bug 262746
[jar exporter] Create a builder for jar-rsrc-loader.zip
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Builder for jar-in-jar-loader.zip
patch_262746_20090202.txt (text/plain), 38.68 KB, created by
Ferenc Hechler
on 2009-02-02 16:15:05 EST
(
hide
)
Description:
Builder for jar-in-jar-loader.zip
Filename:
MIME Type:
Creator:
Ferenc Hechler
Created:
2009-02-02 16:15:05 EST
Size:
38.68 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarRsrcUrlBuilder.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarRsrcUrlBuilder.java,v >retrieving revision 1.1 >diff -u -r1.1 FatJarRsrcUrlBuilder.java >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarRsrcUrlBuilder.java 6 Jan 2009 15:30:16 -0000 1.1 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarRsrcUrlBuilder.java 2 Feb 2009 20:52:00 -0000 >@@ -37,6 +37,7 @@ > import org.eclipse.jdt.ui.jarpackager.IManifestProvider; > import org.eclipse.jdt.ui.jarpackager.JarPackageData; > >+import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; > > /** >@@ -48,7 +49,7 @@ > public class FatJarRsrcUrlBuilder extends FatJarBuilder { > > public static final String BUILDER_ID= "org.eclipse.jdt.ui.fat_jar_rsrc_url_builder"; //$NON-NLS-1$ >- public static final String JAR_RSRC_LOADER_ZIP= "jar-rsrc-loader.zip"; //$NON-NLS-1$ >+ public static final String JAR_RSRC_LOADER_ZIP= "jar-in-jar-loader.zip"; //$NON-NLS-1$ > > private Set jarNames; > private JarPackageData fJarPackage; >@@ -129,7 +130,7 @@ > } > > public void writeRsrcUrlClasses() throws IOException { >- InputStream is= getClass().getResourceAsStream(JAR_RSRC_LOADER_ZIP); >+ InputStream is= JavaPlugin.getDefault().getBundle().getEntry(JAR_RSRC_LOADER_ZIP).openStream(); > ZipInputStream zis= new ZipInputStream(is); > ZipEntry zipEntry= zis.getNextEntry(); > while (zipEntry != null) { >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java 6 Jan 2009 15:30:15 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,52 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.jarpackagerfat; >- >-import java.io.IOException; >-import java.net.URL; >- >-/** >- * If this class is modified the binary jar-rsrc-loader.zip has to be rebuilt using the ANT script >- * build_jar-rsrc-loader.xml. >- * >- * Handle URLs with protocol "rsrc". "rsrc:path/file.ext" identifies the content accessiblr as >- * classLoader.getResourceAsStream("path/file.ext"). "rsrc:path/" identifies a base-path for >- * resources to be searched. The spec "file.ext" is combined to "rsrc:path/file.ext". >- * >- * @since 3.5 >- */ >-public class RsrcURLStreamHandler extends java.net.URLStreamHandler { >- >- private ClassLoader classLoader; >- >- public RsrcURLStreamHandler(ClassLoader classLoader) { >- this.classLoader = classLoader; >- } >- >- protected java.net.URLConnection openConnection(URL u) throws IOException { >- return new RsrcURLConnection(u, classLoader); >- } >- >- protected void parseURL(URL url, String spec, int start, int limit) { >- String file; >- if (spec.startsWith("rsrc:")) //$NON-NLS-1$ >- file = spec.substring(5); >- else if (url.getFile().equals("./")) //$NON-NLS-1$ >- file = spec; >- else if (url.getFile().endsWith("/")) //$NON-NLS-1$ >- file = url.getFile() + spec; >- else >- file = spec; >- setURL(url, "rsrc", "", -1, null, null, file, null, null); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- >-} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java 28 Jan 2009 15:38:39 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,110 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008, 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.jarpackagerfat; >- >-import java.io.IOException; >-import java.io.InputStream; >-import java.lang.reflect.InvocationTargetException; >-import java.lang.reflect.Method; >-import java.net.URL; >-import java.net.URLClassLoader; >-import java.util.ArrayList; >-import java.util.Enumeration; >-import java.util.List; >-import java.util.jar.Attributes; >-import java.util.jar.Manifest; >- >-/** >- * If this class is modified the binary jar-rsrc-loader.zip has to be rebuilt using the ANT script >- * build_jar-rsrc-loader.xml. >- * >- * @since 3.5 >- */ >-public class JarRsrcLoader { >- >- private static class ManifestInfo { >- String rsrcMainClass; >- String[] rsrcClassPath; >- } >- >- public static void main(String[] args) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException, IOException { >- ClassLoader cl = Thread.currentThread().getContextClassLoader(); >- ManifestInfo mi = getManifestInfo(); >- URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(cl)); >- URL[] rsrcUrls = new URL[mi.rsrcClassPath.length]; >- for (int i = 0; i < mi.rsrcClassPath.length; i++) { >- String rsrcPath = mi.rsrcClassPath[i]; >- if (rsrcPath.endsWith("/")) //$NON-NLS-1$ >- rsrcUrls[i] = new URL("rsrc:" + rsrcPath); //$NON-NLS-1$ >- else >- rsrcUrls[i] = new URL("jar:rsrc:" + rsrcPath+ "!/"); //$NON-NLS-1$//$NON-NLS-2$ >- } >- ClassLoader jceClassLoader = new URLClassLoader(rsrcUrls, null); >- Thread.currentThread().setContextClassLoader(jceClassLoader); >- Class c = Class.forName(mi.rsrcMainClass, true, jceClassLoader); >- Method main = c.getMethod("main", new Class[]{args.getClass()}); //$NON-NLS-1$ >- main.invoke((Object)null, new Object[]{args}); >- } >- >- private static ManifestInfo getManifestInfo() throws IOException { >- Enumeration resEnum; >- resEnum = Thread.currentThread().getContextClassLoader().getResources("META-INF/MANIFEST.MF"); //$NON-NLS-1$ >- while (resEnum.hasMoreElements()) { >- try { >- URL url = (URL)resEnum.nextElement(); >- InputStream is = url.openStream(); >- if (is != null) { >- ManifestInfo result = new ManifestInfo(); >- Manifest manifest = new Manifest(is); >- Attributes mainAttribs = manifest.getMainAttributes(); >- result.rsrcMainClass = mainAttribs.getValue("Rsrc-Main-Class"); //$NON-NLS-1$ >- String rsrcCP = mainAttribs.getValue("Rsrc-Class-Path"); //$NON-NLS-1$ >- if (rsrcCP == null) >- rsrcCP = ""; //$NON-NLS-1$ >- result.rsrcClassPath = splitSpaces(rsrcCP); >- if ((result.rsrcMainClass != null) && !result.rsrcMainClass.trim().equals("")) //$NON-NLS-1$ >- return result; >- } >- } >- catch (Exception e) { >- // Silently ignore wrong manifests on classpath? >- } >- } >- System.err.println("Missing attributes for RsrcLoader in Manifest (Rsrc-Main-Class, Rsrc-Class-Path)"); //$NON-NLS-1$ >- return null; >- } >- >- /** >- * JDK 1.3.1 does not support String.split(), so we have to do it manually. Skip all spaces >- * (tabs are not handled) >- * >- * @param line the line to split >- * @return array of strings >- */ >- private static String[] splitSpaces(String line) { >- if (line == null) >- return null; >- List result = new ArrayList(); >- int firstPos = 0; >- while (firstPos < line.length()) { >- int lastPos = line.indexOf(' ', firstPos); >- if (lastPos == -1) >- lastPos = line.length(); >- if (lastPos > firstPos) { >- result.add(line.substring(firstPos, lastPos)); >- } >- firstPos = lastPos+1; >- } >- return (String[]) result.toArray(new String[result.size()]); >- } >- >-} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/jar-rsrc-loader_howto_create.txt >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/jar-rsrc-loader_howto_create.txt >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/jar-rsrc-loader_howto_create.txt >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/jar-rsrc-loader_howto_create.txt 6 Jan 2009 15:30:16 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,29 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >- >-How to create jar-rsrc-loader.zip: >--------------------------------------- >- >-The ZIP file "jar-rsrc-loader.zip" is used by the >-FatJarRsrcUrlBuilder and contains the binary boot-stub classes. >- >-The ZIP file can be built using the ANT script "build_jar-rsrc-loader.xml" >-from the following source files: >- >-JarRsrcLoader.java >-RsrcURLConnection.java >-RsrcUrlStreamHandler.java >-RsrcURLStreamHandlerFactory.java >- >-If any of the source files is modified, >-the ZIP file has to be rebuild. >- >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/build_jar-rsrc-loader.xml >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/build_jar-rsrc-loader.xml >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/build_jar-rsrc-loader.xml >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/build_jar-rsrc-loader.xml 6 Jan 2009 15:30:14 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,27 +0,0 @@ >-<?xml version="1.0" encoding="UTF-8" standalone="no"?> >-<!-- >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >---> >-<project default="create_jar_rsrc_loader" name="Create jar-rsrc-loader.zip for Runnable JAR File export wizard"> >- <target name="create_jar_rsrc_loader"> >- <mkdir dir="build_jrl"/> >- <javac srcdir="../../../../../.." >- includes="org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURL*.java,org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java" >- destdir="build_jrl" >- source="1.3" >- target="1.1" >- /> >- <zip destfile="jar-rsrc-loader.zip" basedir="build_jrl"/> >- <delete dir="build_jrl"/> >- </target> >-</project> >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java 6 Jan 2009 15:30:16 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,52 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.jarpackagerfat; >- >-import java.net.URLStreamHandler; >-import java.net.URLStreamHandlerFactory; >- >-/** >- * If this class is modified the binary jar-rsrc-loader.zip has to be rebuilt using the ANT script >- * build_jar-rsrc-loader.xml. >- * >- * @since 3.5 >- */ >-public class RsrcURLStreamHandlerFactory implements URLStreamHandlerFactory { >- >- private ClassLoader classLoader; >- private URLStreamHandlerFactory chainFac; >- >- public RsrcURLStreamHandlerFactory(ClassLoader cl) { >- this.classLoader = cl; >- } >- >- public URLStreamHandler createURLStreamHandler(String protocol) { >- if ("rsrc".equals(protocol)) //$NON-NLS-1$ >- return new RsrcURLStreamHandler(classLoader); >- if (chainFac != null) >- return chainFac.createURLStreamHandler(protocol); >- return null; >- } >- >- /** >- * Allow one other URLStreamHandler to be added. >- * URL.setURLStreamHandlerFactory does not allow >- * multiple factories to be added. >- * The chained factory is called for all other protocols, >- * except "rsrc". Use null to clear previously set Handler. >- * @param fac another factory to be chained with ours. >- */ >- public void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) { >- chainFac = fac; >- } >- >-} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >--- ui/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java 6 Jan 2009 15:30:14 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,48 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Ferenc Hechler - initial API and implementation >- * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.jarpackagerfat; >- >-import java.io.IOException; >-import java.io.InputStream; >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.net.URLConnection; >- >-/** >- * If this class is modified the binary jar-rsrc-loader.zip has to be rebuilt using the ANT script >- * build_jar-rsrc-loader.xml. >- * >- * @since 3.5 >- */ >-public class RsrcURLConnection extends URLConnection { >- >- private ClassLoader classLoader; >- >- public RsrcURLConnection(URL url, ClassLoader classLoader) { >- super(url); >- this.classLoader= classLoader; >- } >- >- public void connect() throws IOException { >- } >- >- public InputStream getInputStream() throws IOException { >- String file= url.getFile(); >- InputStream result= classLoader.getResourceAsStream(file); >- if (result == null) { >- throw new MalformedURLException("Could not open InputStream for URL '" + url + "'"); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- return result; >- } >- >- >-} >Index: scripts/exportplugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/scripts/exportplugin.xml,v >retrieving revision 1.31 >diff -u -r1.31 exportplugin.xml >--- scripts/exportplugin.xml 23 Apr 2007 16:16:34 -0000 1.31 >+++ scripts/exportplugin.xml 2 Feb 2009 20:52:00 -0000 >@@ -40,6 +40,7 @@ > <include name="plugin.properties" /> > <include name=".options" /> > <include name="serialsupport.jar" /> >+ <include name="jar-in-jar-loader.jar" /> > <include name="JavadocViewStyleSheet.css" /> > <include name="JavadocHoverStyleSheet.css" /> > <include name="icons/**"/> >Index: .cvsignore >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/.cvsignore,v >retrieving revision 1.4 >diff -u -r1.4 .cvsignore >--- .cvsignore 20 Oct 2004 12:19:44 -0000 1.4 >+++ .cvsignore 2 Feb 2009 20:52:00 -0000 >@@ -1,2 +1,3 @@ > bin >-serialsupport.jar >\ No newline at end of file >+serialsupport.jar >+jar-in-jar-loader.zip >Index: .classpath >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/.classpath,v >retrieving revision 1.46 >diff -u -r1.46 .classpath >--- .classpath 19 Jun 2007 12:23:35 -0000 1.46 >+++ .classpath 2 Feb 2009 20:52:00 -0000 >@@ -4,6 +4,7 @@ > <classpathentry kind="src" path="ui refactoring"/> > <classpathentry kind="src" path="core refactoring"/> > <classpathentry kind="src" path="core extension"/> >+ <classpathentry kind="src" path="jar in jar loader"/> > <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> > <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> > <classpathentry kind="output" path="bin"/> >Index: build.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/build.properties,v >retrieving revision 1.35 >diff -u -r1.35 build.properties >--- build.properties 19 Jun 2007 12:23:36 -0000 1.35 >+++ build.properties 2 Feb 2009 20:52:00 -0000 >@@ -17,6 +17,7 @@ > templates/,\ > plugin.properties,\ > .,\ >+ jar-in-jar-loader.zip,\ > META-INF/,\ > dictionaries/,\ > about_files/ >@@ -28,4 +29,6 @@ > ui/,\ > ui refactoring/,\ > core extension/ >-jars.compile.order = . >+jars.compile.order = jar-in-jar-loader.zip >+source.jar-in-jar-loader.zip = jar in jar loader/ >+output.jar-in-jar-loader.zip = bin/ >Index: .project >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/.project,v >retrieving revision 1.22 >diff -u -r1.22 .project >--- .project 17 Apr 2008 09:09:13 -0000 1.22 >+++ .project 2 Feb 2009 20:52:00 -0000 >@@ -25,6 +25,16 @@ > <arguments> > </arguments> > </buildCommand> >+ <buildCommand> >+ <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> >+ <triggers>auto,full,incremental,</triggers> >+ <arguments> >+ <dictionary> >+ <key>LaunchConfigHandle</key> >+ <value><project>/.externalToolBuilders/Build Jar in Jar Loader.launch</value> >+ </dictionary> >+ </arguments> >+ </buildCommand> > </buildSpec> > <natures> > <nature>org.eclipse.jdt.core.javanature</nature> >Index: scripts/build_jar-in-jar-loader.xml >=================================================================== >RCS file: scripts/build_jar-in-jar-loader.xml >diff -N scripts/build_jar-in-jar-loader.xml >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ scripts/build_jar-in-jar-loader.xml 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+<?xml version="1.0" encoding="UTF-8" standalone="no"?> >+<!-- >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ferenc Hechler - initial API and implementation >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262746 [jar exporter] Create a builder for jar-in-jar-loader.zip >+ *******************************************************************************/ >+--> >+<project name="Jar in Jar Loader" default="build" basedir=".."> >+ <target name="build" description="Cleans, builds and refreshes the impacted resources" depends="clean, jar-in-jar-loader.zip" /> >+ <target name="init" depends="properties"> >+ <property name="temp.folder" value="${basedir}/temp.folder" /> >+ <property name="build.result.folder" value="${basedir}" /> >+ </target> >+ <target name="properties" if="eclipse.running"> >+ <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" /> >+ </target> >+ <target name="jar-in-jar-loader.zip" depends="init" description="Creates the jar-in-jar-loader.zip"> >+ <property name="destdir" value="${temp.folder}/jar-in-jar-loader.zip.bin" /> >+ <delete dir="${temp.folder}/jar-in-jar-loader.zip.bin" /> >+ <mkdir dir="${temp.folder}/jar-in-jar-loader.zip.bin" /> >+ <javac target="1.1" source="1.3" destdir="${temp.folder}/jar-in-jar-loader.zip.bin" failonerror="true" verbose="false" debug="on" includeAntRuntime="no" classpath="${basedir}/bin"> >+ <src path="jar in jar loader/" /> >+ </javac> >+ <mkdir dir="${build.result.folder}" /> >+ <zip destfile="${build.result.folder}/jar-in-jar-loader.zip" basedir="${temp.folder}/jar-in-jar-loader.zip.bin"/> >+ <delete dir="${temp.folder}" /> >+ </target> >+ <target name="clean" depends="init"> >+ <delete file="${build.result.folder}/jar-in-jar-loader.zip" /> >+ <delete dir="${temp.folder}" /> >+ </target> >+</project> >+ >+<!-- >+<project default="create_jar_rsrc_loader" name="Create jar-rsrc-loader.zip for Runnable JAR File export wizard"> >+ <target name="create_jar_rsrc_loader"> >+ <mkdir dir="build_jrl"/> >+ <javac srcdir="../../../../../.." >+ includes="org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURL*.java,org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java" >+ destdir="build_jrl" >+ source="1.3" >+ target="1.1" >+ /> >+ <zip destfile="jar-rsrc-loader.zip" basedir="build_jrl"/> >+ <delete dir="build_jrl"/> >+ </target> >+</project> >+--> >\ No newline at end of file >Index: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >=================================================================== >RCS file: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >diff -N jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ferenc Hechler - initial API and implementation >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.IOException; >+import java.net.URL; >+ >+/** >+ * this class will be packed together into the binary jar-in-jar-loader.zip. This ZIP is used for >+ * the "Runnable JAR File Exporter" >+ * >+ * Handle URLs with protocol "rsrc". "rsrc:path/file.ext" identifies the content accessiblr as >+ * classLoader.getResourceAsStream("path/file.ext"). "rsrc:path/" identifies a base-path for >+ * resources to be searched. The spec "file.ext" is combined to "rsrc:path/file.ext". >+ * >+ * @since 3.5 >+ */ >+public class RsrcURLStreamHandler extends java.net.URLStreamHandler { >+ >+ private ClassLoader classLoader; >+ >+ public RsrcURLStreamHandler(ClassLoader classLoader) { >+ this.classLoader = classLoader; >+ } >+ >+ protected java.net.URLConnection openConnection(URL u) throws IOException { >+ return new RsrcURLConnection(u, classLoader); >+ } >+ >+ protected void parseURL(URL url, String spec, int start, int limit) { >+ String file; >+ if (spec.startsWith("rsrc:")) //$NON-NLS-1$ >+ file = spec.substring(5); >+ else if (url.getFile().equals("./")) //$NON-NLS-1$ >+ file = spec; >+ else if (url.getFile().endsWith("/")) //$NON-NLS-1$ >+ file = url.getFile() + spec; >+ else >+ file = spec; >+ setURL(url, "rsrc", "", -1, null, null, file, null, null); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+} >Index: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >=================================================================== >RCS file: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >diff -N jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLStreamHandlerFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ferenc Hechler - initial API and implementation >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.net.URLStreamHandler; >+import java.net.URLStreamHandlerFactory; >+ >+/** >+ * this class will be packed together into the binary jar-in-jar-loader.zip. This ZIP is used for >+ * the "Runnable JAR File Exporter" >+ * >+ * @since 3.5 >+ */ >+public class RsrcURLStreamHandlerFactory implements URLStreamHandlerFactory { >+ >+ private ClassLoader classLoader; >+ private URLStreamHandlerFactory chainFac; >+ >+ public RsrcURLStreamHandlerFactory(ClassLoader cl) { >+ this.classLoader = cl; >+ } >+ >+ public URLStreamHandler createURLStreamHandler(String protocol) { >+ if ("rsrc".equals(protocol)) //$NON-NLS-1$ >+ return new RsrcURLStreamHandler(classLoader); >+ if (chainFac != null) >+ return chainFac.createURLStreamHandler(protocol); >+ return null; >+ } >+ >+ /** >+ * Allow one other URLStreamHandler to be added. >+ * URL.setURLStreamHandlerFactory does not allow >+ * multiple factories to be added. >+ * The chained factory is called for all other protocols, >+ * except "rsrc". Use null to clear previously set Handler. >+ * @param fac another factory to be chained with ours. >+ */ >+ public void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) { >+ chainFac = fac; >+ } >+ >+} >Index: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >=================================================================== >RCS file: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >diff -N jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/RsrcURLConnection.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ferenc Hechler - initial API and implementation >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.IOException; >+import java.io.InputStream; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.net.URLConnection; >+ >+/** >+ * this class will be packed together into the binary jar-in-jar-loader.zip. This ZIP is used for >+ * the "Runnable JAR File Exporter" >+ * >+ * @since 3.5 >+ */ >+public class RsrcURLConnection extends URLConnection { >+ >+ private ClassLoader classLoader; >+ >+ public RsrcURLConnection(URL url, ClassLoader classLoader) { >+ super(url); >+ this.classLoader= classLoader; >+ } >+ >+ public void connect() throws IOException { >+ } >+ >+ public InputStream getInputStream() throws IOException { >+ String file= url.getFile(); >+ InputStream result= classLoader.getResourceAsStream(file); >+ if (result == null) { >+ throw new MalformedURLException("Could not open InputStream for URL '" + url + "'"); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ return result; >+ } >+ >+ >+} >Index: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >=================================================================== >RCS file: jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >diff -N jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ jar in jar loader/org/eclipse/jdt/internal/ui/jarpackagerfat/JarRsrcLoader.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,110 @@ >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ferenc Hechler - initial API and implementation >+ * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.IOException; >+import java.io.InputStream; >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import java.net.URL; >+import java.net.URLClassLoader; >+import java.util.ArrayList; >+import java.util.Enumeration; >+import java.util.List; >+import java.util.jar.Attributes; >+import java.util.jar.Manifest; >+ >+/** >+ * this class will be packed together into the binary jar-in-jar-loader.zip. This ZIP is used for >+ * the "Runnable JAR File Exporter" >+ * >+ * @since 3.5 >+ */ >+public class JarRsrcLoader { >+ >+ private static class ManifestInfo { >+ String rsrcMainClass; >+ String[] rsrcClassPath; >+ } >+ >+ public static void main(String[] args) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException, IOException { >+ ClassLoader cl = Thread.currentThread().getContextClassLoader(); >+ ManifestInfo mi = getManifestInfo(); >+ URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(cl)); >+ URL[] rsrcUrls = new URL[mi.rsrcClassPath.length]; >+ for (int i = 0; i < mi.rsrcClassPath.length; i++) { >+ String rsrcPath = mi.rsrcClassPath[i]; >+ if (rsrcPath.endsWith("/")) //$NON-NLS-1$ >+ rsrcUrls[i] = new URL("rsrc:" + rsrcPath); //$NON-NLS-1$ >+ else >+ rsrcUrls[i] = new URL("jar:rsrc:" + rsrcPath+ "!/"); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ ClassLoader jceClassLoader = new URLClassLoader(rsrcUrls, null); >+ Thread.currentThread().setContextClassLoader(jceClassLoader); >+ Class c = Class.forName(mi.rsrcMainClass, true, jceClassLoader); >+ Method main = c.getMethod("main", new Class[]{args.getClass()}); //$NON-NLS-1$ >+ main.invoke((Object)null, new Object[]{args}); >+ } >+ >+ private static ManifestInfo getManifestInfo() throws IOException { >+ Enumeration resEnum; >+ resEnum = Thread.currentThread().getContextClassLoader().getResources("META-INF/MANIFEST.MF"); //$NON-NLS-1$ >+ while (resEnum.hasMoreElements()) { >+ try { >+ URL url = (URL)resEnum.nextElement(); >+ InputStream is = url.openStream(); >+ if (is != null) { >+ ManifestInfo result = new ManifestInfo(); >+ Manifest manifest = new Manifest(is); >+ Attributes mainAttribs = manifest.getMainAttributes(); >+ result.rsrcMainClass = mainAttribs.getValue("Rsrc-Main-Class"); //$NON-NLS-1$ >+ String rsrcCP = mainAttribs.getValue("Rsrc-Class-Path"); //$NON-NLS-1$ >+ if (rsrcCP == null) >+ rsrcCP = ""; //$NON-NLS-1$ >+ result.rsrcClassPath = splitSpaces(rsrcCP); >+ if ((result.rsrcMainClass != null) && !result.rsrcMainClass.trim().equals("")) //$NON-NLS-1$ >+ return result; >+ } >+ } >+ catch (Exception e) { >+ // Silently ignore wrong manifests on classpath? >+ } >+ } >+ System.err.println("Missing attributes for RsrcLoader in Manifest (Rsrc-Main-Class, Rsrc-Class-Path)"); //$NON-NLS-1$ >+ return null; >+ } >+ >+ /** >+ * JDK 1.3.1 does not support String.split(), so we have to do it manually. Skip all spaces >+ * (tabs are not handled) >+ * >+ * @param line the line to split >+ * @return array of strings >+ */ >+ private static String[] splitSpaces(String line) { >+ if (line == null) >+ return null; >+ List result = new ArrayList(); >+ int firstPos = 0; >+ while (firstPos < line.length()) { >+ int lastPos = line.indexOf(' ', firstPos); >+ if (lastPos == -1) >+ lastPos = line.length(); >+ if (lastPos > firstPos) { >+ result.add(line.substring(firstPos, lastPos)); >+ } >+ firstPos = lastPos+1; >+ } >+ return (String[]) result.toArray(new String[result.size()]); >+ } >+ >+} >Index: .externalToolBuilders/Build Jar in Jar Loader.launch >=================================================================== >RCS file: .externalToolBuilders/Build Jar in Jar Loader.launch >diff -N .externalToolBuilders/Build Jar in Jar Loader.launch >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .externalToolBuilders/Build Jar in Jar Loader.launch 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+<?xml version="1.0" encoding="UTF-8" standalone="no"?> >+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> >+<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> >+<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> >+<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet editPageId="org.eclipse.ui.resourceWorkingSetPage" factoryID="org.eclipse.ui.internal.WorkingSetFactory" label="workingSet" name="workingSet"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/org.eclipse.jdt.ui" type="4"/> </launchConfigurationWorkingSet>}"/> >+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> >+<listEntry value="/org.eclipse.jdt.ui/scripts/build_jar-in-jar-loader.xml"/> >+</listAttribute> >+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> >+<listEntry value="1"/> >+</listAttribute> >+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> >+<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="true"/> >+<booleanAttribute key="org.eclipse.debug.ui.ATTR_RUN_IN_BACKGROUND" value="false"/> >+<stringAttribute key="org.eclipse.debug.ui.target_run_perspective" value="perspective_none"/> >+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> >+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> >+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet editPageId="org.eclipse.ui.resourceWorkingSetPage" factoryID="org.eclipse.ui.internal.WorkingSetFactory" label="workingSet" name="workingSet"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/org.eclipse.jdt.ui/jar in jar loader" type="2"/> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/org.eclipse.jdt.ui/scripts/buildExtraJAR.xml" type="1"/> </launchConfigurationWorkingSet>}"/> >+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.jdt.ui/scripts/build_jar-in-jar-loader.xml}"/> >+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/> >+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> >+</launchConfiguration>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 262746
:
124472
|
124743
|
126044