001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM - Initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.build.builder;
011:
012: import java.io.File;
013: import java.io.IOException;
014: import java.net.MalformedURLException;
015: import java.net.URL;
016: import java.util.*;
017: import org.eclipse.core.internal.boot.PlatformURLHandler;
018: import org.eclipse.core.internal.runtime.PlatformURLFragmentConnection;
019: import org.eclipse.core.internal.runtime.PlatformURLPluginConnection;
020: import org.eclipse.core.runtime.*;
021: import org.eclipse.osgi.service.resolver.*;
022: import org.eclipse.osgi.util.NLS;
023: import org.eclipse.pde.internal.build.*;
024: import org.eclipse.pde.internal.build.site.PDEState;
025: import org.eclipse.update.core.IPluginEntry;
026: import org.osgi.framework.Filter;
027:
028: public class ClasspathComputer3_0 implements IClasspathComputer,
029: IPDEBuildConstants, IXMLConstants, IBuildPropertiesConstants {
030: public static class ClasspathElement {
031: private String path;
032: private String accessRules;
033:
034: /**
035: * Create a ClasspathElement object
036: * @param path
037: * @param accessRules
038: * @throws NullPointerException if path is null
039: */
040: public ClasspathElement(String path, String accessRules) {
041: this .path = path;
042: this .accessRules = accessRules;
043: }
044:
045: public String toString() {
046: return path;
047: }
048:
049: public String getPath() {
050: return path;
051: }
052:
053: public String getAccessRules() {
054: return accessRules;
055: }
056:
057: public void addRules(String newRule) {
058: if (accessRules.equals("") || accessRules.equals(newRule)) //$NON-NLS-1$
059: return;
060: if (!newRule.equals("")) { //$NON-NLS-1$
061: String join = accessRules.substring(0, accessRules
062: .length()
063: - EXCLUDE_ALL_RULE.length() - 1);
064: newRule = join + newRule.substring(1);
065: }
066: accessRules = newRule;
067: return;
068: }
069:
070: /**
071: * ClasspathElement objects are equal if they have the same path.
072: * Access rules are not considered.
073: */
074: public boolean equals(Object obj) {
075: if (obj instanceof ClasspathElement) {
076: ClasspathElement element = (ClasspathElement) obj;
077: return (path != null && path.equals(element.getPath()));
078: }
079: return false;
080: }
081:
082: public int hashCode() {
083: return path.hashCode();
084: }
085:
086: public static String normalize(String path) {
087: //always use '/' as a path separator to help with comparing paths in equals
088: return path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
089: }
090: }
091:
092: private static final String EXCLUDE_ALL_RULE = "?**/*"; //$NON-NLS-1$
093:
094: private ModelBuildScriptGenerator generator;
095: private Map visiblePackages = null;
096: private Map pathElements = null;
097:
098: public ClasspathComputer3_0(ModelBuildScriptGenerator modelGenerator) {
099: this .generator = modelGenerator;
100: }
101:
102: /**
103: * Compute the classpath for the given jar.
104: * The path returned conforms to Parent / Prerequisite / Self
105: *
106: * @param model the plugin containing the jar compiled
107: * @param jar the jar for which the classpath is being compiled
108: * @return String the classpath
109: * @throws CoreException
110: */
111: public List getClasspath(BundleDescription model,
112: ModelBuildScriptGenerator.CompiledEntry jar)
113: throws CoreException {
114: List classpath = new ArrayList(20);
115: List pluginChain = new ArrayList(10); //The list of plugins added to detect cycle
116: String location = generator.getLocation(model);
117: Set addedPlugins = new HashSet(10); //The set of all the plugins already added to the classpath (this allows for optimization)
118: pathElements = new HashMap();
119: visiblePackages = getVisiblePackages(model);
120:
121: //PREREQUISITE
122: addPrerequisites(model, classpath, location, pluginChain,
123: addedPlugins);
124:
125: //SELF
126: addSelf(model, jar, classpath, location, pluginChain,
127: addedPlugins);
128:
129: return classpath;
130:
131: }
132:
133: private Map getVisiblePackages(BundleDescription model) {
134: Map packages = new HashMap(20);
135: StateHelper helper = Platform.getPlatformAdmin()
136: .getStateHelper();
137: addVisiblePackagesFromState(helper, model, packages);
138: if (model.getHost() != null)
139: addVisiblePackagesFromState(helper,
140: (BundleDescription) model.getHost().getSupplier(),
141: packages);
142: return packages;
143: }
144:
145: private void addVisiblePackagesFromState(StateHelper helper,
146: BundleDescription model, Map packages) {
147: ExportPackageDescription[] exports = helper
148: .getVisiblePackages(model);
149: for (int i = 0; i < exports.length; i++) {
150: BundleDescription exporter = exports[i].getExporter();
151: if (exporter == null)
152: continue;
153:
154: boolean discouraged = helper.getAccessCode(model,
155: exports[i]) == StateHelper.ACCESS_DISCOURAGED;
156: String pattern = exports[i].getName()
157: .replaceAll("\\.", "/") + "/*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
158: String rule = (discouraged ? '~' : '+') + pattern;
159:
160: String rules = (String) packages.get(exporter
161: .getSymbolicName());
162: if (rules != null) {
163: if (rules.indexOf(rule) == -1)
164: rules = (rules != null) ? rules
165: + File.pathSeparator + rule : rule;
166: } else {
167: rules = rule;
168: }
169:
170: packages.put(exporter.getSymbolicName(), rules);
171: }
172: }
173:
174: /**
175: * Add the specified plugin (including its jars) and its fragments
176: * @param plugin
177: * @param classpath
178: * @param location
179: * @throws CoreException
180: */
181: private void addPlugin(BundleDescription plugin, List classpath,
182: String location) throws CoreException {
183: boolean allFragments = true;
184: String patchInfo = (String) generator.getSite(false)
185: .getRegistry().getPatchData().get(
186: new Long(plugin.getBundleId()));
187: if (patchInfo != null && plugin != generator.getModel()) {
188: addFragmentsLibraries(plugin, classpath, location, false,
189: false);
190: allFragments = false;
191: }
192: addRuntimeLibraries(plugin, classpath, location);
193: addFragmentsLibraries(plugin, classpath, location, true,
194: allFragments);
195: }
196:
197: /**
198: * Add the runtime libraries for the specified plugin.
199: * @param model
200: * @param classpath
201: * @param baseLocation
202: * @throws CoreException
203: */
204: private void addRuntimeLibraries(BundleDescription model,
205: List classpath, String baseLocation) throws CoreException {
206: String[] libraries = getClasspathEntries(model);
207: String root = generator.getLocation(model);
208: IPath base = Utils.makeRelative(new Path(root), new Path(
209: baseLocation));
210: Properties modelProps = getBuildPropertiesFor(model);
211: ModelBuildScriptGenerator.specialDotProcessing(modelProps,
212: libraries);
213: for (int i = 0; i < libraries.length; i++) {
214: addDevEntries(model, baseLocation, classpath, Utils
215: .getArrayFromString(modelProps
216: .getProperty(PROPERTY_OUTPUT_PREFIX
217: + libraries[i])));
218: addPathAndCheck(model, base, libraries[i], modelProps,
219: classpath);
220: }
221: }
222:
223: /**
224: * Add all fragments of the given plugin
225: * @param plugin
226: * @param classpath
227: * @param baseLocation
228: * @throws CoreException
229: */
230: private void addFragmentsLibraries(BundleDescription plugin,
231: List classpath, String baseLocation, boolean afterPlugin,
232: boolean all) throws CoreException {
233: // if plugin is not a plugin, it's a fragment and there is no fragment for a fragment. So we return.
234: BundleDescription[] fragments = plugin.getFragments();
235: if (fragments == null)
236: return;
237:
238: for (int i = 0; i < fragments.length; i++) {
239: if (fragments[i] == generator.getModel())
240: continue;
241: if (matchFilter(fragments[i]) == false)
242: continue;
243: if (!afterPlugin && isPatchFragment(fragments[i])) {
244: addPluginLibrariesToFragmentLocations(plugin,
245: fragments[i], classpath, baseLocation);
246: addRuntimeLibraries(fragments[i], classpath,
247: baseLocation);
248: continue;
249: }
250: if ((afterPlugin && !isPatchFragment(fragments[i])) || all) {
251: addRuntimeLibraries(fragments[i], classpath,
252: baseLocation);
253: addPluginLibrariesToFragmentLocations(plugin,
254: fragments[i], classpath, baseLocation);
255: continue;
256: }
257: }
258: }
259:
260: private boolean isPatchFragment(BundleDescription fragment)
261: throws CoreException {
262: return generator.getSite(false).getRegistry().getPatchData()
263: .get(new Long(fragment.getBundleId())) != null;
264: }
265:
266: /**
267: * There are cases where the plug-in only declares a library but the real JAR is under
268: * a fragment location. This method gets all the plugin libraries and place them in the
269: * possible fragment location.
270: *
271: * @param plugin
272: * @param fragment
273: * @param classpath
274: * @param baseLocation
275: * @throws CoreException
276: */
277: private void addPluginLibrariesToFragmentLocations(
278: BundleDescription plugin, BundleDescription fragment,
279: List classpath, String baseLocation) throws CoreException {
280: //TODO This methods causes the addition of a lot of useless entries. See bug #35544
281: //If we reintroduce the test below, we reintroduce the problem 35544
282: // if (fragment.getRuntime() != null)
283: // return;
284: String[] libraries = getClasspathEntries(plugin);
285:
286: String root = generator.getLocation(fragment);
287: IPath base = Utils.makeRelative(new Path(root), new Path(
288: baseLocation));
289: Properties modelProps = getBuildPropertiesFor(fragment);
290: for (int i = 0; i < libraries.length; i++) {
291: addPathAndCheck(fragment, base, libraries[i], modelProps,
292: classpath);
293: }
294: }
295:
296: private Properties getBuildPropertiesFor(BundleDescription bundle) {
297: try {
298: Properties bundleProperties = AbstractScriptGenerator
299: .readProperties(generator.getLocation(bundle),
300: PROPERTIES_FILE, IStatus.OK);
301: if (Utils.isStringIn(generator.getClasspathEntries(bundle),
302: ModelBuildScriptGenerator.DOT) != -1) {
303: String sourceFolder = bundleProperties
304: .getProperty(PROPERTY_SOURCE_PREFIX
305: + ModelBuildScriptGenerator.DOT);
306: if (sourceFolder != null) {
307: bundleProperties.setProperty(PROPERTY_SOURCE_PREFIX
308: + ModelBuildScriptGenerator.EXPANDED_DOT,
309: sourceFolder);
310: bundleProperties.remove(PROPERTY_SOURCE_PREFIX
311: + ModelBuildScriptGenerator.DOT);
312: }
313: String outputValue = bundleProperties
314: .getProperty(PROPERTY_OUTPUT_PREFIX
315: + ModelBuildScriptGenerator.DOT);
316: if (outputValue != null) {
317: bundleProperties.setProperty(PROPERTY_OUTPUT_PREFIX
318: + ModelBuildScriptGenerator.EXPANDED_DOT,
319: outputValue);
320: bundleProperties.remove(PROPERTY_OUTPUT_PREFIX
321: + ModelBuildScriptGenerator.DOT);
322: }
323: }
324: return bundleProperties;
325: } catch (CoreException e) {
326: //ignore
327: }
328: return null;
329: }
330:
331: // Add a path into the classpath for a given model
332: // pluginId the plugin we are adding to the classpath
333: // basePath : the relative path between the plugin from which we are adding the classpath and the plugin that is requiring this entry
334: // classpath : The classpath in which we want to add this path
335: private void addPathAndCheck(BundleDescription model,
336: IPath basePath, String libraryName,
337: Properties modelProperties, List classpath) {
338: String pluginId = model != null ? model.getSymbolicName()
339: : null;
340: String rules = ""; //$NON-NLS-1$
341: //only add access rules to libraries that are not part of the current bundle
342: //and are not this bundle's host if we are a fragment
343: BundleDescription currentBundle = generator.getModel();
344: if (model != null
345: && model != currentBundle
346: && (currentBundle.getHost() == null || currentBundle
347: .getHost().getSupplier() != model)) {
348: String packageKey = pluginId;
349: if (model.isResolved() && model.getHost() != null) {
350: packageKey = ((BundleDescription) model.getHost()
351: .getSupplier()).getSymbolicName();
352: }
353: if (visiblePackages.containsKey(packageKey)) {
354: rules = "[" + (String) visiblePackages.get(packageKey) + File.pathSeparator + EXCLUDE_ALL_RULE + "]"; //$NON-NLS-1$ //$NON-NLS-2$
355: } else {
356: rules = "[" + EXCLUDE_ALL_RULE + "]"; //$NON-NLS-1$//$NON-NLS-2$
357: }
358: }
359:
360: String path = null;
361: if ("jar".equalsIgnoreCase(basePath.getFileExtension())) { //$NON-NLS-1$
362: path = basePath.toOSString();
363: } else {
364: Path libraryPath = new Path(libraryName);
365: if (libraryPath.isAbsolute())
366: path = libraryPath.toOSString();
367: else
368: path = basePath.append(libraryPath).toOSString();
369: }
370: path = generator.replaceVariables(path,
371: pluginId == null ? false : generator
372: .getCompiledElements().contains(pluginId));
373: String secondaryPath = null;
374: if (generator.getCompiledElements().contains(pluginId)) {
375: if (modelProperties == null
376: || modelProperties
377: .getProperty(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX
378: + libraryName) != null)
379: path = Utils
380: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER)
381: + '/' + path;
382: secondaryPath = Utils
383: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER)
384: + "/../" + model.getSymbolicName() + '_' + model.getVersion() + '/' + libraryName; //$NON-NLS-1$
385:
386: }
387:
388: addClasspathElementWithRule(classpath, path, rules);
389: if (secondaryPath != null) {
390: addClasspathElementWithRule(classpath, secondaryPath, rules);
391: }
392: }
393:
394: private void addClasspathElementWithRule(List classpath,
395: String path, String rules) {
396: String normalizedPath = ClasspathElement.normalize(path);
397: ClasspathElement existing = (ClasspathElement) pathElements
398: .get(normalizedPath);
399: if (existing != null) {
400: existing.addRules(rules);
401: } else {
402: ClasspathElement element = new ClasspathElement(
403: normalizedPath, rules);
404: classpath.add(element);
405: pathElements.put(normalizedPath, element);
406: }
407: }
408:
409: private void addSelf(BundleDescription model,
410: ModelBuildScriptGenerator.CompiledEntry jar,
411: List classpath, String location, List pluginChain,
412: Set addedPlugins) throws CoreException {
413: // If model is a fragment, we need to add in the classpath the plugin to which it is related
414: HostSpecification host = model.getHost();
415: if (host != null) {
416: BundleDescription[] hosts = host.getHosts();
417: for (int i = 0; i < hosts.length; i++)
418: addPluginAndPrerequisites(hosts[i], classpath,
419: location, pluginChain, addedPlugins);
420: }
421:
422: // Add the libraries
423: Properties modelProperties = generator.getBuildProperties();
424: String jarOrder = (String) modelProperties
425: .get(PROPERTY_JAR_ORDER);
426: if (jarOrder == null) {
427: // if no jar order was specified in build.properties, we add all the libraries but the current one
428: // based on the order specified by the plugin.xml. Both library that we compile and .jar provided are processed
429: String[] libraries = getClasspathEntries(model);
430: if (libraries != null) {
431: for (int i = 0; i < libraries.length; i++) {
432: String libraryName = libraries[i];
433: if (jar.getName(false).equals(libraryName))
434: continue;
435:
436: boolean isSource = (modelProperties
437: .getProperty(PROPERTY_SOURCE_PREFIX
438: + libraryName) != null);
439: if (isSource) {
440: addDevEntries(
441: model,
442: location,
443: classpath,
444: Utils
445: .getArrayFromString(modelProperties
446: .getProperty(PROPERTY_OUTPUT_PREFIX
447: + libraryName)));
448: }
449: //Potential pb: here there maybe a nasty case where the libraries variable may refer to something which is part of the base
450: //but $xx$ will replace it by the $xx instead of $basexx. The solution is for the user to use the explicitly set the content
451: // of its build.property file
452: addPathAndCheck(model, Path.EMPTY, libraryName,
453: modelProperties, classpath);
454: }
455: }
456: } else {
457: // otherwise we add all the predecessor jars
458: String[] order = Utils.getArrayFromString(jarOrder);
459: for (int i = 0; i < order.length; i++) {
460: if (order[i].equals(jar.getName(false)))
461: break;
462: addDevEntries(
463: model,
464: location,
465: classpath,
466: Utils
467: .getArrayFromString((String) modelProperties
468: .get(PROPERTY_OUTPUT_PREFIX
469: + order[i])));
470: addPathAndCheck(model, Path.EMPTY, order[i],
471: modelProperties, classpath);
472: }
473: // Then we add all the "pure libraries" (the one that does not contain source)
474: String[] libraries = getClasspathEntries(model);
475: for (int i = 0; i < libraries.length; i++) {
476: String libraryName = libraries[i];
477: if (modelProperties.get(PROPERTY_SOURCE_PREFIX
478: + libraryName) == null) {
479: //Potential pb: if the pure library is something that is being compiled (which is supposetly not the case, but who knows...)
480: //the user will get $basexx instead of $ws
481: addPathAndCheck(model, Path.EMPTY, libraryName,
482: modelProperties, classpath);
483: }
484: }
485: }
486:
487: // add extra classpath if it exists. this code is kept for backward compatibility
488: String extraClasspath = (String) modelProperties
489: .get(PROPERTY_JAR_EXTRA_CLASSPATH);
490: if (extraClasspath != null) {
491: String[] extra = Utils.getArrayFromString(extraClasspath,
492: ";,"); //$NON-NLS-1$
493:
494: for (int i = 0; i < extra.length; i++) {
495: //Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...)
496: //the user will get $basexx instead of $ws
497: String toAdd = computeExtraPath(extra[i], classpath,
498: location);
499: if (toAdd != null)
500: addPathAndCheck(null, new Path(toAdd),
501: "", modelProperties, classpath); //$NON-NLS-1$
502: }
503: }
504:
505: // add extra classpath if it is specified for the given jar
506: String[] jarSpecificExtraClasspath = jar.getExtraClasspath();
507: for (int i = 0; i < jarSpecificExtraClasspath.length; i++) {
508: //Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...)
509: //the user will get $basexx instead of $ws
510: String toAdd = computeExtraPath(
511: jarSpecificExtraClasspath[i], classpath, location);
512: if (toAdd != null)
513: addPathAndCheck(null, new Path(toAdd),
514: "", modelProperties, classpath); //$NON-NLS-1$
515: }
516: }
517:
518: /**
519: * Convenience method that compute the relative classpath of extra.classpath entries
520: * @param url a url
521: * @param location location used as a base location to compute the relative path
522: * @return String the relative path
523: * @throws CoreException
524: */
525: private String computeExtraPath(String url, List classpath,
526: String location) throws CoreException {
527: String relativePath = null;
528:
529: String[] urlfragments = Utils.getArrayFromString(url, "/"); //$NON-NLS-1$
530:
531: // A valid platform url for a plugin has a leat 3 segments.
532: if (urlfragments.length > 2
533: && urlfragments[0].equals(PlatformURLHandler.PROTOCOL
534: + PlatformURLHandler.PROTOCOL_SEPARATOR)) {
535: String modelLocation = null;
536: BundleDescription bundle = null;
537: if (urlfragments[1]
538: .equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN)
539: || urlfragments[1]
540: .equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
541: bundle = generator.getSite(false).getRegistry()
542: .getResolvedBundle(urlfragments[2]);
543:
544: if (urlfragments.length == 3) {
545: addPlugin(bundle, classpath, location);
546: return null;
547: }
548:
549: modelLocation = generator.getLocation(bundle);
550:
551: if (urlfragments[1].equalsIgnoreCase("resource")) { //$NON-NLS-1$
552: String message = NLS.bind(Messages.exception_url,
553: generator.getPropertiesFileName() + "::" + url); //$NON-NLS-1$
554: throw new CoreException(new Status(IStatus.ERROR,
555: PI_PDEBUILD, EXCEPTION_MALFORMED_URL, message,
556: null));
557: }
558: if (modelLocation != null) {
559: for (int i = 3; i < urlfragments.length; i++) {
560: modelLocation += '/' + urlfragments[i];
561: }
562: return relativePath = Utils.makeRelative(
563: new Path(modelLocation), new Path(location))
564: .toOSString();
565: }
566: }
567:
568: // Then it's just a regular URL, or just something that will be added at the end of the classpath for backward compatibility.......
569: try {
570: URL extraURL = new URL(url);
571: try {
572: relativePath = Utils.makeRelative(
573: new Path(Platform.resolve(extraURL).getFile()),
574: new Path(location)).toOSString();
575: } catch (IOException e) {
576: String message = NLS.bind(Messages.exception_url,
577: generator.getPropertiesFileName() + "::" + url); //$NON-NLS-1$
578: throw new CoreException(new Status(IStatus.ERROR,
579: PI_PDEBUILD, EXCEPTION_MALFORMED_URL, message,
580: e));
581: }
582: } catch (MalformedURLException e) {
583: relativePath = url;
584: //TODO remove this backward compatibility support for as soon as we go to 2.2 and put back the exception
585: // String message = Policy.bind("exception.url", PROPERTIES_FILE + "::"+url); //$NON-NLS-1$ //$NON-NLS-2$
586: // throw new CoreException(new Status(IStatus.ERROR,PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_MALFORMED_URL, message,e));
587: }
588: return relativePath;
589: }
590:
591: //Add the prerequisite of a given plugin (target)
592: private void addPrerequisites(BundleDescription target,
593: List classpath, String baseLocation, List pluginChain,
594: Set addedPlugins) throws CoreException {
595: if (pluginChain.contains(target)) {
596: String cycleString = ""; //$NON-NLS-1$
597: for (Iterator iter = pluginChain.iterator(); iter.hasNext();)
598: cycleString += iter.next().toString() + ", "; //$NON-NLS-1$
599: cycleString += target.toString();
600: String message = NLS.bind(Messages.error_pluginCycle,
601: cycleString);
602: throw new CoreException(new Status(IStatus.ERROR,
603: IPDEBuildConstants.PI_PDEBUILD,
604: EXCEPTION_CLASSPATH_CYCLE, message, null));
605: }
606: if (addedPlugins.contains(target)) //the plugin we are considering has already been added
607: return;
608:
609: // add libraries from pre-requisite plug-ins. Don't worry about the export flag
610: // as all required plugins may be required for compilation.
611: BundleDescription[] requires = PDEState
612: .getDependentBundles(target);
613: pluginChain.add(target);
614: for (int i = 0; i < requires.length; i++) {
615: addPluginAndPrerequisites(requires[i], classpath,
616: baseLocation, pluginChain, addedPlugins);
617: }
618: pluginChain.remove(target);
619: addedPlugins.add(target);
620: }
621:
622: /**
623: * The pluginChain parameter is used to keep track of possible cycles. If prerequisite is already
624: * present in the chain it is not included in the classpath.
625: *
626: * @param target : the plugin for which we are going to introduce
627: * @param classpath
628: * @param baseLocation
629: * @param pluginChain
630: * @param addedPlugins
631: * @throws CoreException
632: */
633: private void addPluginAndPrerequisites(BundleDescription target,
634: List classpath, String baseLocation, List pluginChain,
635: Set addedPlugins) throws CoreException {
636: if (matchFilter(target) == false)
637: return;
638:
639: addPlugin(target, classpath, baseLocation);
640: addPrerequisites(target, classpath, baseLocation, pluginChain,
641: addedPlugins);
642: }
643:
644: private boolean matchFilter(BundleDescription target) {
645: String filter = target.getPlatformFilter();
646: if (filter == null) //Target is platform independent, add it
647: return true;
648:
649: IPluginEntry associatedEntry = generator.getAssociatedEntry();
650: if (associatedEntry == null)
651: return true;
652:
653: String os = associatedEntry.getOS();
654: String ws = associatedEntry.getWS();
655: String arch = associatedEntry.getOSArch();
656: String nl = associatedEntry.getNL();
657: if (os == null && ws == null && arch == null && nl == null) //I'm a platform independent plugin
658: return true;
659:
660: //The plugin for which we are generating the classpath and target are not platform independent
661: Filter f = BundleHelper.getDefault().createFilter(filter);
662: if (f == null)
663: return true;
664:
665: Dictionary properties = new Hashtable(3);
666: if (os != null) {
667: properties.put(OSGI_OS, os);
668: } else {
669: properties.put(OSGI_OS, CatchAllValue.singleton);
670: }
671: if (ws != null)
672: properties.put(OSGI_WS, ws);
673: else
674: properties.put(OSGI_WS, CatchAllValue.singleton);
675:
676: if (arch != null)
677: properties.put(OSGI_ARCH, arch);
678: else
679: properties.put(OSGI_ARCH, CatchAllValue.singleton);
680:
681: if (arch != null)
682: properties.put(OSGI_NL, arch);
683: else
684: properties.put(OSGI_NL, CatchAllValue.singleton);
685:
686: return f.match(properties);
687: }
688:
689: /**
690: *
691: * @param model
692: * @param baseLocation
693: * @param classpath
694: */
695: private void addDevEntries(BundleDescription model,
696: String baseLocation, List classpath,
697: String[] jarSpecificEntries) {
698: if (generator.devEntries == null
699: && (jarSpecificEntries == null || jarSpecificEntries.length == 0))
700: return;
701:
702: String[] entries;
703: // if jarSpecificEntries is given, then it overrides devEntries
704: if (jarSpecificEntries != null && jarSpecificEntries.length > 0)
705: entries = jarSpecificEntries;
706: else
707: entries = generator.devEntries.getDevClassPath(model
708: .getSymbolicName());
709:
710: IPath root = Utils.makeRelative(new Path(generator
711: .getLocation(model)), new Path(baseLocation));
712: for (int i = 0; i < entries.length; i++) {
713: addPathAndCheck(model, root, entries[i], null, classpath);
714: }
715: }
716:
717: //Return the jar name from the classpath
718: private String[] getClasspathEntries(BundleDescription bundle)
719: throws CoreException {
720: return generator.getClasspathEntries(bundle);
721: }
722: }
|