### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.core Index: src/org/eclipse/pde/internal/core/PDEClasspathContainer.java =================================================================== RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEClasspathContainer.java,v retrieving revision 1.28 diff -u -r1.28 PDEClasspathContainer.java --- src/org/eclipse/pde/internal/core/PDEClasspathContainer.java 27 May 2009 20:25:20 -0000 1.28 +++ src/org/eclipse/pde/internal/core/PDEClasspathContainer.java 10 Mar 2011 13:52:06 -0000 @@ -10,14 +10,16 @@ *******************************************************************************/ package org.eclipse.pde.internal.core; -import java.io.File; +import java.io.*; import java.util.ArrayList; import java.util.HashMap; +import java.util.jar.JarFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.*; import org.eclipse.jdt.core.*; import org.eclipse.osgi.service.resolver.BundleDescription; import org.eclipse.pde.core.plugin.*; +import org.eclipse.pde.internal.core.util.CoreUtility; public class PDEClasspathContainer { @@ -41,6 +43,8 @@ private static final IAccessRule EXCLUDE_ALL_RULE = JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); //$NON-NLS-1$ + private static final String LIB_CACHE_DIR = ".libcache"; //$NON-NLS-1$ + protected void addProjectEntry(IProject project, Rule[] rules, ArrayList entries) throws CoreException { if (project.hasNature(JavaCore.NATURE_ID)) { IClasspathEntry entry = null; @@ -67,6 +71,15 @@ if (srcPath == null) srcPath = new Path(model.getInstallLocation()); addLibraryEntry(new Path(model.getInstallLocation()), srcPath, rules, getClasspathAttributes(model), entries); + // add wrapped and referenced JARs + IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); + for (int i = 0; i < libraries.length; i++) { + if (!".".equals(libraries[i].getName())) { //$NON-NLS-1$ + File f = cacheLibrary(new File(model.getInstallLocation()), libraries[i]); + Path path = new Path(f.getAbsolutePath()); + addLibraryEntry(path, path, rules, getClasspathAttributes(model), entries); + } + } } else { IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); for (int i = 0; i < libraries.length; i++) { @@ -147,4 +160,56 @@ return null; } + private static File cacheLibrary(File bundleJar, IPluginLibrary lib) { + // get the PDE config directory + IPath path = PDECore.getDefault().getStateLocation(); + + File fDir = new File(path.toFile(), LIB_CACHE_DIR); + + // create a subdirectory for the exact bundle version + BundleDescription desc = lib.getPluginModel().getBundleDescription(); + String bundleName = desc.getSymbolicName() + "_" + desc.getVersion().toString(); //$NON-NLS-1$ + + fDir = new File(fDir, bundleName); + if (!fDir.isDirectory() && !fDir.mkdirs()) + return null; + + // extract file from JAR + String libName = lib.getName(); + + if (libName.indexOf('/') > -1) + libName = libName.substring(libName.lastIndexOf('/') + 1); + + try { + File fTarget = new File(fDir, libName); + if (!fTarget.isFile()) + extractJar(bundleJar, lib.getName(), fTarget); + return fTarget; + } catch (IOException e) { + // TODO log? + return null; + } + } + + private static void extractJar(File jarFile, String libName, File targetFile) throws IOException { + JarFile f = new JarFile(jarFile); + InputStream in = null; + try { + in = f.getInputStream(f.getEntry(libName)); + if (in == null) + throw new IOException(); + + CoreUtility.readFile(in, targetFile); + } finally { + try { + f.close(); + } catch (Exception e) { + } + try { + in.close(); + } catch (Exception e) { + } + } + } + }