KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > builder > ClasspathComputer3_0


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.builder;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.*;
18 import org.eclipse.core.internal.boot.PlatformURLHandler;
19 import org.eclipse.core.internal.runtime.PlatformURLFragmentConnection;
20 import org.eclipse.core.internal.runtime.PlatformURLPluginConnection;
21 import org.eclipse.core.runtime.*;
22 import org.eclipse.osgi.service.resolver.*;
23 import org.eclipse.osgi.util.NLS;
24 import org.eclipse.pde.internal.build.*;
25 import org.eclipse.pde.internal.build.site.PDEState;
26 import org.eclipse.update.core.IPluginEntry;
27 import org.osgi.framework.Filter;
28
29 public class ClasspathComputer3_0 implements IClasspathComputer, IPDEBuildConstants, IXMLConstants, IBuildPropertiesConstants {
30     public static class ClasspathElement {
31         private String JavaDoc path;
32         private String JavaDoc accessRules;
33         
34         /**
35          * Create a ClasspathElement object
36          * @param path
37          * @param accessRules
38          * @throws NullPointerException if path is null
39          */

40         public ClasspathElement(String JavaDoc path, String JavaDoc accessRules){
41             this.path = path;
42             this.accessRules = accessRules;
43         }
44         public String JavaDoc toString() {
45             return path;
46         }
47         public String JavaDoc getPath() {
48             return path;
49         }
50         public String JavaDoc getAccessRules(){
51             return accessRules;
52         }
53         public void addRules(String JavaDoc newRule){
54             if (accessRules.equals("") || accessRules.equals(newRule)) //$NON-NLS-1$
55
return;
56             if (!newRule.equals("")) { //$NON-NLS-1$
57
String JavaDoc join = accessRules.substring(0, accessRules.length() - EXCLUDE_ALL_RULE.length() - 1);
58                 newRule = join + newRule.substring(1);
59             }
60             accessRules = newRule;
61             return;
62         }
63         /**
64          * ClasspathElement objects are equal if they have the same path.
65          * Access rules are not considered.
66          */

67         public boolean equals(Object JavaDoc obj) {
68             if (obj instanceof ClasspathElement) {
69                 ClasspathElement element = (ClasspathElement) obj;
70                 return (path != null && path.equals(element.getPath()));
71             }
72             return false;
73         }
74         public int hashCode() {
75             return path.hashCode();
76         }
77         
78         public static String JavaDoc normalize(String JavaDoc path) {
79             //always use '/' as a path separator to help with comparing paths in equals
80
return path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
81
}
82     }
83     
84     private static final String JavaDoc EXCLUDE_ALL_RULE = "?**/*"; //$NON-NLS-1$
85

86     private ModelBuildScriptGenerator generator;
87     private Map visiblePackages = null;
88     private Map pathElements = null;
89     
90     public ClasspathComputer3_0(ModelBuildScriptGenerator modelGenerator) {
91         this.generator = modelGenerator;
92     }
93
94     /**
95      * Compute the classpath for the given jar.
96      * The path returned conforms to Parent / Prerequisite / Self
97      *
98      * @param model the plugin containing the jar compiled
99      * @param jar the jar for which the classpath is being compiled
100      * @return String the classpath
101      * @throws CoreException
102      */

103     public List getClasspath(BundleDescription model, ModelBuildScriptGenerator.CompiledEntry jar) throws CoreException {
104         List classpath = new ArrayList(20);
105         List pluginChain = new ArrayList(10); //The list of plugins added to detect cycle
106
String JavaDoc location = generator.getLocation(model);
107         Set addedPlugins = new HashSet(10); //The set of all the plugins already added to the classpath (this allows for optimization)
108
pathElements = new HashMap();
109         visiblePackages = getVisiblePackages(model);
110
111         //PREREQUISITE
112
addPrerequisites(model, classpath, location, pluginChain, addedPlugins);
113
114         //SELF
115
addSelf(model, jar, classpath, location, pluginChain, addedPlugins);
116
117         return classpath;
118
119     }
120
121     private Map getVisiblePackages(BundleDescription model) {
122         Map packages = new HashMap(20);
123         StateHelper helper = Platform.getPlatformAdmin().getStateHelper();
124         addVisiblePackagesFromState(helper, model, packages);
125         if (model.getHost() != null)
126             addVisiblePackagesFromState(helper, (BundleDescription)model.getHost().getSupplier(), packages);
127         return packages;
128     }
129     
130     private void addVisiblePackagesFromState(StateHelper helper, BundleDescription model, Map packages) {
131         ExportPackageDescription[] exports = helper.getVisiblePackages(model);
132         for (int i = 0; i < exports.length; i++) {
133             BundleDescription exporter = exports[i].getExporter();
134             if (exporter == null)
135                 continue;
136             
137             boolean discouraged = helper.getAccessCode(model, exports[i]) == StateHelper.ACCESS_DISCOURAGED;
138             String JavaDoc pattern = exports[i].getName().replaceAll("\\.", "/") + "/*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
139
String JavaDoc rule = (discouraged ? '~' : '+') + pattern;
140             
141             String JavaDoc rules = (String JavaDoc) packages.get(exporter.getSymbolicName());
142             if (rules != null) {
143                 if (rules.indexOf(rule) == -1)
144                     rules = (rules != null) ? rules + File.pathSeparator + rule : rule;
145             } else {
146                 rules = rule;
147             }
148                 
149             packages.put(exporter.getSymbolicName(), rules);
150         }
151     }
152     /**
153      * Add the specified plugin (including its jars) and its fragments
154      * @param plugin
155      * @param classpath
156      * @param location
157      * @throws CoreException
158      */

159     private void addPlugin(BundleDescription plugin, List classpath, String JavaDoc location) throws CoreException {
160         boolean allFragments = true;
161         String JavaDoc patchInfo = (String JavaDoc) generator.getSite(false).getRegistry().getPatchData().get(new Long JavaDoc(plugin.getBundleId()));
162         if (patchInfo != null && plugin != generator.getModel()) {
163             addFragmentsLibraries(plugin, classpath, location, false, false);
164             allFragments = false;
165         }
166         addRuntimeLibraries(plugin, classpath, location);
167         addFragmentsLibraries(plugin, classpath, location, true, allFragments);
168     }
169
170     /**
171      * Add the runtime libraries for the specified plugin.
172      * @param model
173      * @param classpath
174      * @param baseLocation
175      * @throws CoreException
176      */

177     private void addRuntimeLibraries(BundleDescription model, List classpath, String JavaDoc baseLocation) throws CoreException {
178         String JavaDoc[] libraries = getClasspathEntries(model);
179         String JavaDoc root = generator.getLocation(model);
180         IPath base = Utils.makeRelative(new Path(root), new Path(baseLocation));
181         Properties modelProps = getBuildPropertiesFor(model);
182         ModelBuildScriptGenerator.specialDotProcessing(modelProps, libraries);
183         for (int i = 0; i < libraries.length; i++) {
184             addDevEntries(model, baseLocation, classpath, Utils.getArrayFromString(modelProps.getProperty(PROPERTY_OUTPUT_PREFIX + libraries[i])));
185             addPathAndCheck(model, base, libraries[i], modelProps, classpath);
186         }
187     }
188
189     /**
190      * Add all fragments of the given plugin
191      * @param plugin
192      * @param classpath
193      * @param baseLocation
194      * @throws CoreException
195      */

196     private void addFragmentsLibraries(BundleDescription plugin, List classpath, String JavaDoc baseLocation, boolean afterPlugin, boolean all) throws CoreException {
197         // if plugin is not a plugin, it's a fragment and there is no fragment for a fragment. So we return.
198
BundleDescription[] fragments = plugin.getFragments();
199         if (fragments == null)
200             return;
201
202         for (int i = 0; i < fragments.length; i++) {
203             if (fragments[i] == generator.getModel())
204                 continue;
205             if (matchFilter(fragments[i]) == false)
206                 continue;
207             if (! afterPlugin && isPatchFragment(fragments[i])) {
208                 addPluginLibrariesToFragmentLocations(plugin, fragments[i], classpath, baseLocation);
209                 addRuntimeLibraries(fragments[i], classpath, baseLocation);
210                 continue;
211             }
212             if ( (afterPlugin && !isPatchFragment(fragments[i])) || all) {
213                 addRuntimeLibraries(fragments[i], classpath, baseLocation);
214                 addPluginLibrariesToFragmentLocations(plugin, fragments[i], classpath, baseLocation);
215                 continue;
216             }
217         }
218     }
219
220     private boolean isPatchFragment(BundleDescription fragment) throws CoreException {
221         return generator.getSite(false).getRegistry().getPatchData().get(new Long JavaDoc(fragment.getBundleId())) != null;
222     }
223
224     /**
225      * There are cases where the plug-in only declares a library but the real JAR is under
226      * a fragment location. This method gets all the plugin libraries and place them in the
227      * possible fragment location.
228      *
229      * @param plugin
230      * @param fragment
231      * @param classpath
232      * @param baseLocation
233      * @throws CoreException
234      */

235     private void addPluginLibrariesToFragmentLocations(BundleDescription plugin, BundleDescription fragment, List classpath, String JavaDoc baseLocation) throws CoreException {
236         //TODO This methods causes the addition of a lot of useless entries. See bug #35544
237
//If we reintroduce the test below, we reintroduce the problem 35544
238
// if (fragment.getRuntime() != null)
239
// return;
240
String JavaDoc[] libraries = getClasspathEntries(plugin);
241
242         String JavaDoc root = generator.getLocation(fragment);
243         IPath base = Utils.makeRelative(new Path(root), new Path(baseLocation));
244         Properties modelProps = getBuildPropertiesFor(fragment);
245         for (int i = 0; i < libraries.length; i++) {
246             addPathAndCheck(fragment, base, libraries[i], modelProps, classpath);
247         }
248     }
249
250     private Properties getBuildPropertiesFor(BundleDescription bundle) {
251         try {
252             Properties bundleProperties = AbstractScriptGenerator.readProperties(generator.getLocation(bundle), PROPERTIES_FILE, IStatus.OK);
253             if (Utils.isStringIn(generator.getClasspathEntries(bundle), ModelBuildScriptGenerator.DOT) != -1) {
254                 String JavaDoc sourceFolder = bundleProperties.getProperty(PROPERTY_SOURCE_PREFIX + ModelBuildScriptGenerator.DOT);
255                 if (sourceFolder != null) {
256                     bundleProperties.setProperty(PROPERTY_SOURCE_PREFIX + ModelBuildScriptGenerator.EXPANDED_DOT, sourceFolder);
257                     bundleProperties.remove(PROPERTY_SOURCE_PREFIX + ModelBuildScriptGenerator.DOT);
258                 }
259                 String JavaDoc outputValue = bundleProperties.getProperty(PROPERTY_OUTPUT_PREFIX + ModelBuildScriptGenerator.DOT);
260                 if (outputValue != null) {
261                     bundleProperties.setProperty(PROPERTY_OUTPUT_PREFIX + ModelBuildScriptGenerator.EXPANDED_DOT, outputValue);
262                     bundleProperties.remove(PROPERTY_OUTPUT_PREFIX + ModelBuildScriptGenerator.DOT);
263                 }
264             }
265             return bundleProperties;
266         } catch (CoreException e) {
267             //ignore
268
}
269         return null;
270     }
271
272     // Add a path into the classpath for a given model
273
// pluginId the plugin we are adding to the classpath
274
// basePath : the relative path between the plugin from which we are adding the classpath and the plugin that is requiring this entry
275
// classpath : The classpath in which we want to add this path
276
private void addPathAndCheck(BundleDescription model, IPath basePath, String JavaDoc libraryName, Properties modelProperties, List classpath) {
277         String JavaDoc pluginId = model != null ? model.getSymbolicName() : null;
278         String JavaDoc rules = ""; //$NON-NLS-1$
279
//only add access rules to libraries that are not part of the current bundle
280
//and are not this bundle's host if we are a fragment
281
BundleDescription currentBundle = generator.getModel();
282         if (model != null && model != currentBundle && (currentBundle.getHost() == null || currentBundle.getHost().getSupplier() != model) ) {
283             String JavaDoc packageKey = pluginId;
284             if (model.isResolved() && model.getHost() != null) {
285                 packageKey = ((BundleDescription) model.getHost().getSupplier()).getSymbolicName();
286             }
287             if (visiblePackages.containsKey(packageKey)) {
288                 rules = "[" + (String JavaDoc) visiblePackages.get(packageKey) + File.pathSeparator + EXCLUDE_ALL_RULE + "]"; //$NON-NLS-1$ //$NON-NLS-2$
289
} else {
290                 rules = "[" + EXCLUDE_ALL_RULE + "]"; //$NON-NLS-1$//$NON-NLS-2$
291
}
292         }
293
294         String JavaDoc path = null;
295         if ("jar".equalsIgnoreCase(basePath.getFileExtension())) { //$NON-NLS-1$
296
path = basePath.toOSString();
297         } else {
298             Path libraryPath = new Path(libraryName);
299             if (libraryPath.isAbsolute())
300                 path = libraryPath.toOSString();
301             else
302                 path = basePath.append(libraryPath).toOSString();
303         }
304         path = generator.replaceVariables(path, pluginId == null ? false : generator.getCompiledElements().contains(pluginId));
305         String JavaDoc secondaryPath = null;
306         if (generator.getCompiledElements().contains(pluginId)) {
307             if (modelProperties == null || modelProperties.getProperty(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX + libraryName) != null)
308                 path = Utils.getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER) + '/' + path;
309             secondaryPath = Utils.getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER) + "/../" + model.getSymbolicName() + '_' + model.getVersion() + '/' + libraryName; //$NON-NLS-1$
310

311         }
312         
313         addClasspathElementWithRule(classpath, path, rules);
314         if (secondaryPath != null) {
315             addClasspathElementWithRule(classpath, secondaryPath, rules);
316         }
317     }
318
319     private void addClasspathElementWithRule(List classpath, String JavaDoc path, String JavaDoc rules) {
320         String JavaDoc normalizedPath = ClasspathElement.normalize(path);
321         ClasspathElement existing = (ClasspathElement) pathElements.get(normalizedPath);
322         if (existing != null){
323             existing.addRules( rules);
324         } else {
325             ClasspathElement element = new ClasspathElement(normalizedPath, rules);
326             classpath.add(element);
327             pathElements.put(normalizedPath, element);
328         }
329     }
330
331     private void addSelf(BundleDescription model, ModelBuildScriptGenerator.CompiledEntry jar, List classpath, String JavaDoc location, List pluginChain, Set addedPlugins) throws CoreException {
332         // If model is a fragment, we need to add in the classpath the plugin to which it is related
333
HostSpecification host = model.getHost();
334         if (host != null) {
335             BundleDescription[] hosts = host.getHosts();
336             for (int i = 0; i < hosts.length; i++)
337                 addPluginAndPrerequisites(hosts[i], classpath, location, pluginChain, addedPlugins);
338         }
339
340         // Add the libraries
341
Properties modelProperties = generator.getBuildProperties();
342         String JavaDoc jarOrder = (String JavaDoc) modelProperties.get(PROPERTY_JAR_ORDER);
343         if (jarOrder == null) {
344             // if no jar order was specified in build.properties, we add all the libraries but the current one
345
// based on the order specified by the plugin.xml. Both library that we compile and .jar provided are processed
346
String JavaDoc[] libraries = getClasspathEntries(model);
347             if (libraries != null) {
348                 for (int i = 0; i < libraries.length; i++) {
349                     String JavaDoc libraryName = libraries[i];
350                     if (jar.getName(false).equals(libraryName))
351                         continue;
352
353                     boolean isSource = (modelProperties.getProperty(PROPERTY_SOURCE_PREFIX + libraryName) != null);
354                     if (isSource) {
355                         addDevEntries(model, location, classpath, Utils.getArrayFromString(modelProperties.getProperty(PROPERTY_OUTPUT_PREFIX + libraryName)));
356                     }
357                     //Potential pb: here there maybe a nasty case where the libraries variable may refer to something which is part of the base
358
//but $xx$ will replace it by the $xx instead of $basexx. The solution is for the user to use the explicitly set the content
359
// of its build.property file
360
addPathAndCheck(model, Path.EMPTY, libraryName, modelProperties, classpath);
361                 }
362             }
363         } else {
364             // otherwise we add all the predecessor jars
365
String JavaDoc[] order = Utils.getArrayFromString(jarOrder);
366             for (int i = 0; i < order.length; i++) {
367                 if (order[i].equals(jar.getName(false)))
368                     break;
369                 addDevEntries(model, location, classpath, Utils.getArrayFromString((String JavaDoc) modelProperties.get(PROPERTY_OUTPUT_PREFIX + order[i])));
370                 addPathAndCheck(model, Path.EMPTY, order[i], modelProperties, classpath);
371             }
372             // Then we add all the "pure libraries" (the one that does not contain source)
373
String JavaDoc[] libraries = getClasspathEntries(model);
374             for (int i = 0; i < libraries.length; i++) {
375                 String JavaDoc libraryName = libraries[i];
376                 if (modelProperties.get(PROPERTY_SOURCE_PREFIX + libraryName) == null) {
377                     //Potential pb: if the pure library is something that is being compiled (which is supposetly not the case, but who knows...)
378
//the user will get $basexx instead of $ws
379
addPathAndCheck(model, Path.EMPTY, libraryName, modelProperties, classpath);
380                 }
381             }
382         }
383
384         // add extra classpath if it exists. this code is kept for backward compatibility
385
String JavaDoc extraClasspath = (String JavaDoc) modelProperties.get(PROPERTY_JAR_EXTRA_CLASSPATH);
386         if (extraClasspath != null) {
387             String JavaDoc[] extra = Utils.getArrayFromString(extraClasspath, ";,"); //$NON-NLS-1$
388

389             for (int i = 0; i < extra.length; i++) {
390                 //Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...)
391
//the user will get $basexx instead of $ws
392
String JavaDoc toAdd = computeExtraPath(extra[i], classpath, location);
393                 if (toAdd != null)
394                     addPathAndCheck(null, new Path(toAdd), "", modelProperties, classpath); //$NON-NLS-1$
395
}
396         }
397
398         // add extra classpath if it is specified for the given jar
399
String JavaDoc[] jarSpecificExtraClasspath = jar.getExtraClasspath();
400         for (int i = 0; i < jarSpecificExtraClasspath.length; i++) {
401             //Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...)
402
//the user will get $basexx instead of $ws
403
String JavaDoc toAdd = computeExtraPath(jarSpecificExtraClasspath[i], classpath, location);
404             if (toAdd != null)
405                 addPathAndCheck(null, new Path(toAdd), "", modelProperties, classpath); //$NON-NLS-1$
406
}
407     }
408
409     /**
410      * Convenience method that compute the relative classpath of extra.classpath entries
411      * @param url a url
412      * @param location location used as a base location to compute the relative path
413      * @return String the relative path
414      * @throws CoreException
415      */

416     private String JavaDoc computeExtraPath(String JavaDoc url, List classpath, String JavaDoc location) throws CoreException {
417         String JavaDoc relativePath = null;
418
419         String JavaDoc[] urlfragments = Utils.getArrayFromString(url, "/"); //$NON-NLS-1$
420

421         // A valid platform url for a plugin has a leat 3 segments.
422
if (urlfragments.length > 2 && urlfragments[0].equals(PlatformURLHandler.PROTOCOL + PlatformURLHandler.PROTOCOL_SEPARATOR)) {
423             String JavaDoc modelLocation = null;
424             BundleDescription bundle = null;
425             if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN) || urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
426                 bundle = generator.getSite(false).getRegistry().getResolvedBundle(urlfragments[2]);
427
428             if (urlfragments.length == 3) {
429                 addPlugin(bundle, classpath, location);
430                 return null;
431             }
432
433             modelLocation = generator.getLocation(bundle);
434
435             if (urlfragments[1].equalsIgnoreCase("resource")) { //$NON-NLS-1$
436
String JavaDoc message = NLS.bind(Messages.exception_url, generator.getPropertiesFileName() + "::" + url); //$NON-NLS-1$
437
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_MALFORMED_URL, message, null));
438             }
439             if (modelLocation != null) {
440                 for (int i = 3; i < urlfragments.length; i++) {
441                     modelLocation += '/' + urlfragments[i];
442                 }
443                 return relativePath = Utils.makeRelative(new Path(modelLocation), new Path(location)).toOSString();
444             }
445         }
446
447         // Then it's just a regular URL, or just something that will be added at the end of the classpath for backward compatibility.......
448
try {
449             URL JavaDoc extraURL = new URL JavaDoc(url);
450             try {
451                 relativePath = Utils.makeRelative(new Path(Platform.resolve(extraURL).getFile()), new Path(location)).toOSString();
452             } catch (IOException JavaDoc e) {
453                 String JavaDoc message = NLS.bind(Messages.exception_url, generator.getPropertiesFileName() + "::" + url); //$NON-NLS-1$
454
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_MALFORMED_URL, message, e));
455             }
456         } catch (MalformedURLException JavaDoc e) {
457             relativePath = url;
458             //TODO remove this backward compatibility support for as soon as we go to 2.2 and put back the exception
459
// String message = Policy.bind("exception.url", PROPERTIES_FILE + "::"+url); //$NON-NLS-1$ //$NON-NLS-2$
460
// throw new CoreException(new Status(IStatus.ERROR,PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_MALFORMED_URL, message,e));
461
}
462         return relativePath;
463     }
464
465     //Add the prerequisite of a given plugin (target)
466
private void addPrerequisites(BundleDescription target, List classpath, String JavaDoc baseLocation, List pluginChain, Set addedPlugins) throws CoreException {
467         if (pluginChain.contains(target)) {
468             String JavaDoc cycleString = ""; //$NON-NLS-1$
469
for (Iterator iter = pluginChain.iterator(); iter.hasNext();)
470                 cycleString += iter.next().toString() + ", "; //$NON-NLS-1$
471
cycleString += target.toString();
472             String JavaDoc message = NLS.bind(Messages.error_pluginCycle, cycleString);
473             throw new CoreException(new Status(IStatus.ERROR, IPDEBuildConstants.PI_PDEBUILD, EXCEPTION_CLASSPATH_CYCLE, message, null));
474         }
475         if (addedPlugins.contains(target)) //the plugin we are considering has already been added
476
return;
477
478         // add libraries from pre-requisite plug-ins. Don't worry about the export flag
479
// as all required plugins may be required for compilation.
480
BundleDescription[] requires = PDEState.getDependentBundles(target);
481         pluginChain.add(target);
482         for (int i = 0; i < requires.length; i++) {
483             addPluginAndPrerequisites(requires[i], classpath, baseLocation, pluginChain, addedPlugins);
484         }
485         pluginChain.remove(target);
486         addedPlugins.add(target);
487     }
488
489     /**
490      * The pluginChain parameter is used to keep track of possible cycles. If prerequisite is already
491      * present in the chain it is not included in the classpath.
492      *
493      * @param target : the plugin for which we are going to introduce
494      * @param classpath
495      * @param baseLocation
496      * @param pluginChain
497      * @param addedPlugins
498      * @throws CoreException
499      */

500     private void addPluginAndPrerequisites(BundleDescription target, List classpath, String JavaDoc baseLocation, List pluginChain, Set addedPlugins) throws CoreException {
501         if (matchFilter(target) == false)
502             return;
503
504         addPlugin(target, classpath, baseLocation);
505         addPrerequisites(target, classpath, baseLocation, pluginChain, addedPlugins);
506     }
507
508     private boolean matchFilter(BundleDescription target) {
509         String JavaDoc filter = target.getPlatformFilter();
510         if (filter == null) //Target is platform independent, add it
511
return true;
512
513         IPluginEntry associatedEntry = generator.getAssociatedEntry();
514         if (associatedEntry == null)
515             return true;
516
517         String JavaDoc os = associatedEntry.getOS();
518         String JavaDoc ws = associatedEntry.getWS();
519         String JavaDoc arch = associatedEntry.getOSArch();
520         String JavaDoc nl = associatedEntry.getNL();
521         if (os == null && ws == null && arch == null && nl == null) //I'm a platform independent plugin
522
return true;
523
524         //The plugin for which we are generating the classpath and target are not platform independent
525
Filter f = BundleHelper.getDefault().createFilter(filter);
526         if (f == null)
527             return true;
528
529         Dictionary properties = new Hashtable(3);
530         if (os != null) {
531             properties.put(OSGI_OS, os);
532         } else {
533             properties.put(OSGI_OS, CatchAllValue.singleton);
534         }
535         if (ws != null)
536             properties.put(OSGI_WS, ws);
537         else
538             properties.put(OSGI_WS, CatchAllValue.singleton);
539
540         if (arch != null)
541             properties.put(OSGI_ARCH, arch);
542         else
543             properties.put(OSGI_ARCH, CatchAllValue.singleton);
544
545         if (arch != null)
546             properties.put(OSGI_NL, arch);
547         else
548             properties.put(OSGI_NL, CatchAllValue.singleton);
549
550         return f.match(properties);
551     }
552
553     /**
554      *
555      * @param model
556      * @param baseLocation
557      * @param classpath
558      */

559     private void addDevEntries(BundleDescription model, String JavaDoc baseLocation, List classpath, String JavaDoc[] jarSpecificEntries) {
560         if (generator.devEntries == null && (jarSpecificEntries == null || jarSpecificEntries.length == 0))
561             return;
562
563         String JavaDoc[] entries;
564         // if jarSpecificEntries is given, then it overrides devEntries
565
if (jarSpecificEntries != null && jarSpecificEntries.length > 0)
566             entries = jarSpecificEntries;
567         else
568             entries = generator.devEntries.getDevClassPath(model.getSymbolicName());
569
570         IPath root = Utils.makeRelative(new Path(generator.getLocation(model)), new Path(baseLocation));
571         for (int i = 0; i < entries.length; i++) {
572             addPathAndCheck(model, root, entries[i], null, classpath);
573         }
574     }
575
576     //Return the jar name from the classpath
577
private String JavaDoc[] getClasspathEntries(BundleDescription bundle) throws CoreException {
578         return generator.getClasspathEntries(bundle);
579     }
580 }
581
Popular Tags