|
Lines 25-32
Link Here
|
| 25 |
import org.osgi.framework.Filter; |
25 |
import org.osgi.framework.Filter; |
| 26 |
|
26 |
|
| 27 |
public class ClasspathComputer3_0 implements IClasspathComputer, IPDEBuildConstants, IXMLConstants, IBuildPropertiesConstants { |
27 |
public class ClasspathComputer3_0 implements IClasspathComputer, IPDEBuildConstants, IXMLConstants, IBuildPropertiesConstants { |
| 28 |
public static class ClasspathElement { |
28 |
public class ClasspathElement { |
| 29 |
private final String path; |
29 |
private final String path; |
|
|
30 |
private final String subPath; |
| 30 |
private String accessRules; |
31 |
private String accessRules; |
| 31 |
|
32 |
|
| 32 |
/** |
33 |
/** |
|
Lines 35-42
Link Here
|
| 35 |
* @param accessRules |
36 |
* @param accessRules |
| 36 |
* @throws NullPointerException if path is null |
37 |
* @throws NullPointerException if path is null |
| 37 |
*/ |
38 |
*/ |
| 38 |
public ClasspathElement(String path, String accessRules) { |
39 |
protected ClasspathElement(String path, String subPath, String accessRules) { |
|
|
40 |
if (path == null) |
| 41 |
throw new NullPointerException(); |
| 39 |
this.path = path; |
42 |
this.path = path; |
|
|
43 |
this.subPath = subPath; |
| 40 |
this.accessRules = accessRules; |
44 |
this.accessRules = accessRules; |
| 41 |
} |
45 |
} |
| 42 |
|
46 |
|
|
Lines 48-57
Link Here
|
| 48 |
return path; |
52 |
return path; |
| 49 |
} |
53 |
} |
| 50 |
|
54 |
|
|
|
55 |
public String getSubPath() { |
| 56 |
return subPath; |
| 57 |
} |
| 58 |
|
| 51 |
public String getAccessRules() { |
59 |
public String getAccessRules() { |
| 52 |
return accessRules; |
60 |
return accessRules; |
| 53 |
} |
61 |
} |
| 54 |
|
62 |
|
|
|
63 |
public String getAbsolutePath() { |
| 64 |
if (new File(path).isAbsolute()) |
| 65 |
return path; |
| 66 |
|
| 67 |
return modelLocation + '/' + path; |
| 68 |
} |
| 69 |
|
| 55 |
public void addRules(String newRule) { |
70 |
public void addRules(String newRule) { |
| 56 |
if (accessRules.equals("") || accessRules.equals(newRule)) //$NON-NLS-1$ |
71 |
if (accessRules.equals("") || accessRules.equals(newRule)) //$NON-NLS-1$ |
| 57 |
return; |
72 |
return; |
|
Lines 70-88
Link Here
|
| 70 |
public boolean equals(Object obj) { |
85 |
public boolean equals(Object obj) { |
| 71 |
if (obj instanceof ClasspathElement) { |
86 |
if (obj instanceof ClasspathElement) { |
| 72 |
ClasspathElement element = (ClasspathElement) obj; |
87 |
ClasspathElement element = (ClasspathElement) obj; |
| 73 |
return (path != null && path.equals(element.getPath())); |
88 |
if (!path.equals(element.getPath())) |
|
|
89 |
return false; |
| 90 |
if (subPath != null && subPath.equals(element.getSubPath())) |
| 91 |
return false; |
| 92 |
return true; |
| 74 |
} |
93 |
} |
| 75 |
return false; |
94 |
return false; |
| 76 |
} |
95 |
} |
| 77 |
|
96 |
|
| 78 |
public int hashCode() { |
97 |
public int hashCode() { |
| 79 |
return path.hashCode(); |
98 |
int result = path.hashCode(); |
|
|
99 |
return 13 * result + ((subPath == null) ? 0 : subPath.hashCode()); |
| 80 |
} |
100 |
} |
| 81 |
|
101 |
|
| 82 |
public static String normalize(String path) { |
102 |
} |
| 83 |
//always use '/' as a path separator to help with comparing paths in equals |
103 |
private static String normalize(String path) { |
| 84 |
return path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ |
104 |
if (path == null) |
| 85 |
} |
105 |
return null; |
|
|
106 |
//always use '/' as a path separator to help with comparing paths in equals |
| 107 |
return path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 86 |
} |
108 |
} |
| 87 |
|
109 |
|
| 88 |
private static final String EXCLUDE_ALL_RULE = "?**/*"; //$NON-NLS-1$ |
110 |
private static final String EXCLUDE_ALL_RULE = "?**/*"; //$NON-NLS-1$ |
|
Lines 92-97
Link Here
|
| 92 |
private Map pathElements = null; |
114 |
private Map pathElements = null; |
| 93 |
private boolean allowBinaryCycles = false; |
115 |
private boolean allowBinaryCycles = false; |
| 94 |
private Set requiredIds = null; |
116 |
private Set requiredIds = null; |
|
|
117 |
protected String modelLocation = null; |
| 95 |
|
118 |
|
| 96 |
public ClasspathComputer3_0(ModelBuildScriptGenerator modelGenerator) { |
119 |
public ClasspathComputer3_0(ModelBuildScriptGenerator modelGenerator) { |
| 97 |
this.generator = modelGenerator; |
120 |
this.generator = modelGenerator; |
|
Lines 109-115
Link Here
|
| 109 |
public List getClasspath(BundleDescription model, ModelBuildScriptGenerator.CompiledEntry jar) throws CoreException { |
132 |
public List getClasspath(BundleDescription model, ModelBuildScriptGenerator.CompiledEntry jar) throws CoreException { |
| 110 |
List classpath = new ArrayList(20); |
133 |
List classpath = new ArrayList(20); |
| 111 |
List pluginChain = new ArrayList(10); //The list of plugins added to detect cycle |
134 |
List pluginChain = new ArrayList(10); //The list of plugins added to detect cycle |
| 112 |
String location = generator.getLocation(model); |
135 |
modelLocation = generator.getLocation(model); |
| 113 |
Set addedPlugins = new HashSet(10); //The set of all the plugins already added to the classpath (this allows for optimization) |
136 |
Set addedPlugins = new HashSet(10); //The set of all the plugins already added to the classpath (this allows for optimization) |
| 114 |
pathElements = new HashMap(); |
137 |
pathElements = new HashMap(); |
| 115 |
visiblePackages = getVisiblePackages(model); |
138 |
visiblePackages = getVisiblePackages(model); |
|
Lines 117-126
Link Here
|
| 117 |
allowBinaryCycles = AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_ALLOW_BINARY_CYCLES); |
140 |
allowBinaryCycles = AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_ALLOW_BINARY_CYCLES); |
| 118 |
|
141 |
|
| 119 |
//PREREQUISITE |
142 |
//PREREQUISITE |
| 120 |
addPrerequisites(model, classpath, location, pluginChain, addedPlugins); |
143 |
addPrerequisites(model, classpath, modelLocation, pluginChain, addedPlugins); |
| 121 |
|
144 |
|
| 122 |
//SELF |
145 |
//SELF |
| 123 |
addSelf(model, jar, classpath, location, pluginChain, addedPlugins); |
146 |
addSelf(model, jar, classpath, modelLocation, pluginChain, addedPlugins); |
| 124 |
|
147 |
|
| 125 |
recordRequiredIds(model); |
148 |
recordRequiredIds(model); |
| 126 |
|
149 |
|
|
Lines 327-340
Link Here
|
| 327 |
} |
350 |
} |
| 328 |
|
351 |
|
| 329 |
String path = null; |
352 |
String path = null; |
| 330 |
if ("jar".equalsIgnoreCase(basePath.getFileExtension())) { //$NON-NLS-1$ |
353 |
String subPath = null; |
|
|
354 |
Path libraryPath = new Path(libraryName); |
| 355 |
if (libraryPath.isAbsolute()) { |
| 356 |
path = libraryPath.toOSString(); |
| 357 |
} else if ("jar".equalsIgnoreCase(basePath.getFileExtension())) { //$NON-NLS-1$ |
| 358 |
if ("jar".equalsIgnoreCase(libraryPath.getFileExtension())) //$NON-NLS-1$ |
| 359 |
subPath = libraryPath.toOSString(); |
| 331 |
path = basePath.toOSString(); |
360 |
path = basePath.toOSString(); |
| 332 |
} else { |
361 |
} else { |
| 333 |
Path libraryPath = new Path(libraryName); |
362 |
path = basePath.append(libraryPath).toOSString(); |
| 334 |
if (libraryPath.isAbsolute()) |
|
|
| 335 |
path = libraryPath.toOSString(); |
| 336 |
else |
| 337 |
path = basePath.append(libraryPath).toOSString(); |
| 338 |
} |
363 |
} |
| 339 |
path = ModelBuildScriptGenerator.replaceVariables(path, pluginKey == null ? false : generator.getCompiledElements().contains(pluginKey)); |
364 |
path = ModelBuildScriptGenerator.replaceVariables(path, pluginKey == null ? false : generator.getCompiledElements().contains(pluginKey)); |
| 340 |
String secondaryPath = null; |
365 |
String secondaryPath = null; |
|
Lines 345-365
Link Here
|
| 345 |
|
370 |
|
| 346 |
} |
371 |
} |
| 347 |
|
372 |
|
| 348 |
addClasspathElementWithRule(classpath, path, rules); |
373 |
addClasspathElementWithRule(classpath, path, subPath, rules); |
| 349 |
if (secondaryPath != null) { |
374 |
if (secondaryPath != null) { |
| 350 |
addClasspathElementWithRule(classpath, secondaryPath, rules); |
375 |
addClasspathElementWithRule(classpath, secondaryPath, null, rules); |
| 351 |
} |
376 |
} |
| 352 |
} |
377 |
} |
| 353 |
|
378 |
|
| 354 |
private void addClasspathElementWithRule(List classpath, String path, String rules) { |
379 |
private void addClasspathElementWithRule(List classpath, String path, String subPath, String rules) { |
| 355 |
String normalizedPath = ClasspathElement.normalize(path); |
380 |
path = normalize(path); |
| 356 |
ClasspathElement existing = (ClasspathElement) pathElements.get(normalizedPath); |
381 |
subPath = normalize(subPath); |
|
|
382 |
|
| 383 |
String elementsKey = subPath != null ? path + '/' + subPath : path; |
| 384 |
ClasspathElement existing = (ClasspathElement) pathElements.get(elementsKey); |
| 357 |
if (existing != null) { |
385 |
if (existing != null) { |
| 358 |
existing.addRules(rules); |
386 |
existing.addRules(rules); |
| 359 |
} else { |
387 |
} else { |
| 360 |
ClasspathElement element = new ClasspathElement(normalizedPath, rules); |
388 |
ClasspathElement element = new ClasspathElement(path, subPath, rules); |
| 361 |
classpath.add(element); |
389 |
classpath.add(element); |
| 362 |
pathElements.put(normalizedPath, element); |
390 |
pathElements.put(elementsKey, element); |
| 363 |
} |
391 |
} |
| 364 |
} |
392 |
} |
| 365 |
|
393 |
|
|
Lines 424-432
Link Here
|
| 424 |
for (int i = 0; i < extra.length; i++) { |
452 |
for (int i = 0; i < extra.length; i++) { |
| 425 |
//Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...) |
453 |
//Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...) |
| 426 |
//the user will get $basexx instead of $ws |
454 |
//the user will get $basexx instead of $ws |
| 427 |
String toAdd = computeExtraPath(extra[i], classpath, location); |
455 |
String[] toAdd = computeExtraPath(extra[i], classpath, location); |
| 428 |
if (toAdd != null) |
456 |
if (toAdd != null && toAdd.length == 2) |
| 429 |
addPathAndCheck(null, new Path(toAdd), "", modelProperties, classpath); //$NON-NLS-1$ |
457 |
addPathAndCheck(null, new Path(toAdd[0]), toAdd[1], modelProperties, classpath); |
| 430 |
} |
458 |
} |
| 431 |
} |
459 |
} |
| 432 |
|
460 |
|
|
Lines 435-443
Link Here
|
| 435 |
for (int i = 0; i < jarSpecificExtraClasspath.length; i++) { |
463 |
for (int i = 0; i < jarSpecificExtraClasspath.length; i++) { |
| 436 |
//Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...) |
464 |
//Potential pb: if the path refers to something that is being compiled (which is supposetly not the case, but who knows...) |
| 437 |
//the user will get $basexx instead of $ws |
465 |
//the user will get $basexx instead of $ws |
| 438 |
String toAdd = computeExtraPath(jarSpecificExtraClasspath[i], classpath, location); |
466 |
String[] toAdd = computeExtraPath(jarSpecificExtraClasspath[i], classpath, location); |
| 439 |
if (toAdd != null) |
467 |
if (toAdd != null && toAdd.length == 2) |
| 440 |
addPathAndCheck(null, new Path(toAdd), "", modelProperties, classpath); //$NON-NLS-1$ |
468 |
addPathAndCheck(null, new Path(toAdd[0]), toAdd[1], modelProperties, classpath); |
| 441 |
} |
469 |
} |
| 442 |
} |
470 |
} |
| 443 |
|
471 |
|
|
Lines 448-461
Link Here
|
| 448 |
* @return String the relative path |
476 |
* @return String the relative path |
| 449 |
* @throws CoreException |
477 |
* @throws CoreException |
| 450 |
*/ |
478 |
*/ |
| 451 |
private String computeExtraPath(String url, List classpath, String location) throws CoreException { |
479 |
private String[] computeExtraPath(String url, List classpath, String location) throws CoreException { |
| 452 |
String relativePath = null; |
480 |
String relativePath = null; |
| 453 |
|
481 |
|
| 454 |
String[] urlfragments = Utils.getArrayFromString(url, "/"); //$NON-NLS-1$ |
482 |
String[] urlfragments = Utils.getArrayFromString(url, "/"); //$NON-NLS-1$ |
| 455 |
|
483 |
|
| 456 |
// A valid platform url for a plugin has a leat 3 segments. |
484 |
// A valid platform url for a plugin has a leat 3 segments. |
| 457 |
if (urlfragments.length > 2 && urlfragments[0].equals(PlatformURLHandler.PROTOCOL + PlatformURLHandler.PROTOCOL_SEPARATOR)) { |
485 |
if (urlfragments.length > 2 && urlfragments[0].equals(PlatformURLHandler.PROTOCOL + PlatformURLHandler.PROTOCOL_SEPARATOR)) { |
| 458 |
String modelLocation = null; |
486 |
String bundleLocation = null; |
| 459 |
BundleDescription bundle = null; |
487 |
BundleDescription bundle = null; |
| 460 |
if (urlfragments[1].equalsIgnoreCase(PLUGIN) || urlfragments[1].equalsIgnoreCase(FRAGMENT)) { |
488 |
if (urlfragments[1].equalsIgnoreCase(PLUGIN) || urlfragments[1].equalsIgnoreCase(FRAGMENT)) { |
| 461 |
bundle = generator.getSite(false).getRegistry().getResolvedBundle(urlfragments[2]); |
489 |
bundle = generator.getSite(false).getRegistry().getResolvedBundle(urlfragments[2]); |
|
Lines 472-483
Link Here
|
| 472 |
return null; |
500 |
return null; |
| 473 |
} |
501 |
} |
| 474 |
|
502 |
|
| 475 |
modelLocation = generator.getLocation(bundle); |
503 |
bundleLocation = generator.getLocation(bundle); |
| 476 |
if (modelLocation != null) { |
504 |
if (bundleLocation != null) { |
| 477 |
for (int i = 3; i < urlfragments.length; i++) { |
505 |
String entry = urlfragments[3]; |
| 478 |
modelLocation += '/' + urlfragments[i]; |
506 |
for (int i = 4; i < urlfragments.length; i++) { |
|
|
507 |
entry += '/' + urlfragments[i]; |
| 479 |
} |
508 |
} |
| 480 |
return Utils.makeRelative(new Path(modelLocation), new Path(location)).toOSString(); |
509 |
return new String[] {Utils.makeRelative(new Path(bundleLocation), new Path(location)).toOSString(), entry}; |
| 481 |
} |
510 |
} |
| 482 |
} else if (urlfragments[1].equalsIgnoreCase("resource")) { //$NON-NLS-1$ |
511 |
} else if (urlfragments[1].equalsIgnoreCase("resource")) { //$NON-NLS-1$ |
| 483 |
String message = NLS.bind(Messages.exception_url, generator.getModel().getSymbolicName() + '/' + generator.getPropertiesFileName() + ": " + url); //$NON-NLS-1$ |
512 |
String message = NLS.bind(Messages.exception_url, generator.getModel().getSymbolicName() + '/' + generator.getPropertiesFileName() + ": " + url); //$NON-NLS-1$ |
|
Lines 500-506
Link Here
|
| 500 |
// String message = Policy.bind("exception.url", PROPERTIES_FILE + "::"+url); //$NON-NLS-1$ //$NON-NLS-2$ |
529 |
// String message = Policy.bind("exception.url", PROPERTIES_FILE + "::"+url); //$NON-NLS-1$ //$NON-NLS-2$ |
| 501 |
// throw new CoreException(new Status(IStatus.ERROR,PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_MALFORMED_URL, message,e)); |
530 |
// throw new CoreException(new Status(IStatus.ERROR,PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_MALFORMED_URL, message,e)); |
| 502 |
} |
531 |
} |
| 503 |
return relativePath; |
532 |
return new String[] {relativePath, ""}; //$NON-NLS-1$ |
| 504 |
} |
533 |
} |
| 505 |
|
534 |
|
| 506 |
//Add the prerequisite of a given plugin (target) |
535 |
//Add the prerequisite of a given plugin (target) |