Lines 10-23
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.pde.internal.core; |
11 |
package org.eclipse.pde.internal.core; |
12 |
|
12 |
|
13 |
import java.io.File; |
13 |
import java.io.*; |
14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
15 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
|
|
16 |
import java.util.jar.JarFile; |
16 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.runtime.*; |
18 |
import org.eclipse.core.runtime.*; |
18 |
import org.eclipse.jdt.core.*; |
19 |
import org.eclipse.jdt.core.*; |
19 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
20 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
20 |
import org.eclipse.pde.core.plugin.*; |
21 |
import org.eclipse.pde.core.plugin.*; |
|
|
22 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
21 |
|
23 |
|
22 |
public class PDEClasspathContainer { |
24 |
public class PDEClasspathContainer { |
23 |
|
25 |
|
Lines 41-46
Link Here
|
41 |
|
43 |
|
42 |
private static final IAccessRule EXCLUDE_ALL_RULE = JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); //$NON-NLS-1$ |
44 |
private static final IAccessRule EXCLUDE_ALL_RULE = JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); //$NON-NLS-1$ |
43 |
|
45 |
|
|
|
46 |
private static final String LIB_CACHE_DIR = ".libcache"; //$NON-NLS-1$ |
47 |
|
44 |
protected void addProjectEntry(IProject project, Rule[] rules, ArrayList entries) throws CoreException { |
48 |
protected void addProjectEntry(IProject project, Rule[] rules, ArrayList entries) throws CoreException { |
45 |
if (project.hasNature(JavaCore.NATURE_ID)) { |
49 |
if (project.hasNature(JavaCore.NATURE_ID)) { |
46 |
IClasspathEntry entry = null; |
50 |
IClasspathEntry entry = null; |
Lines 67-72
Link Here
|
67 |
if (srcPath == null) |
71 |
if (srcPath == null) |
68 |
srcPath = new Path(model.getInstallLocation()); |
72 |
srcPath = new Path(model.getInstallLocation()); |
69 |
addLibraryEntry(new Path(model.getInstallLocation()), srcPath, rules, getClasspathAttributes(model), entries); |
73 |
addLibraryEntry(new Path(model.getInstallLocation()), srcPath, rules, getClasspathAttributes(model), entries); |
|
|
74 |
// add wrapped and referenced JARs |
75 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
76 |
for (int i = 0; i < libraries.length; i++) { |
77 |
if (!".".equals(libraries[i].getName())) { //$NON-NLS-1$ |
78 |
File f = cacheLibrary(new File(model.getInstallLocation()), libraries[i]); |
79 |
Path path = new Path(f.getAbsolutePath()); |
80 |
addLibraryEntry(path, path, rules, getClasspathAttributes(model), entries); |
81 |
} |
82 |
} |
70 |
} else { |
83 |
} else { |
71 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
84 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
72 |
for (int i = 0; i < libraries.length; i++) { |
85 |
for (int i = 0; i < libraries.length; i++) { |
Lines 147-150
Link Here
|
147 |
return null; |
160 |
return null; |
148 |
} |
161 |
} |
149 |
|
162 |
|
|
|
163 |
private static File cacheLibrary(File bundleJar, IPluginLibrary lib) { |
164 |
// get the PDE config directory |
165 |
IPath path = PDECore.getDefault().getStateLocation(); |
166 |
|
167 |
File fDir = new File(path.toFile(), LIB_CACHE_DIR); |
168 |
|
169 |
// create a subdirectory for the exact bundle version |
170 |
BundleDescription desc = lib.getPluginModel().getBundleDescription(); |
171 |
String bundleName = desc.getSymbolicName() + "_" + desc.getVersion().toString(); //$NON-NLS-1$ |
172 |
|
173 |
fDir = new File(fDir, bundleName); |
174 |
if (!fDir.isDirectory() && !fDir.mkdirs()) |
175 |
return null; |
176 |
|
177 |
// extract file from JAR |
178 |
String libName = lib.getName(); |
179 |
|
180 |
if (libName.indexOf('/') > -1) |
181 |
libName = libName.substring(libName.lastIndexOf('/') + 1); |
182 |
|
183 |
try { |
184 |
File fTarget = new File(fDir, libName); |
185 |
if (!fTarget.isFile()) |
186 |
extractJar(bundleJar, lib.getName(), fTarget); |
187 |
return fTarget; |
188 |
} catch (IOException e) { |
189 |
// TODO log? |
190 |
return null; |
191 |
} |
192 |
} |
193 |
|
194 |
private static void extractJar(File jarFile, String libName, File targetFile) throws IOException { |
195 |
JarFile f = new JarFile(jarFile); |
196 |
InputStream in = null; |
197 |
try { |
198 |
in = f.getInputStream(f.getEntry(libName)); |
199 |
if (in == null) |
200 |
throw new IOException(); |
201 |
|
202 |
CoreUtility.readFile(in, targetFile); |
203 |
} finally { |
204 |
try { |
205 |
f.close(); |
206 |
} catch (Exception e) { |
207 |
} |
208 |
try { |
209 |
in.close(); |
210 |
} catch (Exception e) { |
211 |
} |
212 |
} |
213 |
} |
214 |
|
150 |
} |
215 |
} |