Skip to content

Commit

Permalink
further fixing of #229: Fix org.objectweb.asm version collision
Browse files Browse the repository at this point in the history
Faster bundle lookup via recursion.
  • Loading branch information
S1artie committed Feb 25, 2019
1 parent 08d118f commit 17d3929
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public IClasspathEntry[] getClasspathEntries() {
addToList(tempEntryList, new String[][] { new String[] { "org.eclipse.xtext.common.types" } });
addToList(tempEntryList, new String[][] { new String[] { "org.jdom" }, new String[] { "org.jdom_jaxen" } });

addToList(tempEntryList, new String[][] { new String[] { "org.objectweb.asm" } });
// Recursion is necessary for org.objectweb.asm because xtext 2.16.x depends on 7.0.0 of that bundle, but
// Eclipse itself just uses 6.2.1, so we must recursively search the entire bundle tree in order to find all
// bundles.
addToList(tempEntryList, new String[][] { new String[] { "org.objectweb.asm" } }, true);

// convert the list to an array and return it
IClasspathEntry[] tempEntryArray = new IClasspathEntry[tempEntryList.size()];
Expand All @@ -102,13 +105,29 @@ public IClasspathEntry[] getClasspathEntries() {
* bundles that are part of a single combination)
*/
private void addToList(List<IClasspathEntry> aList, String[][] someBundleNames) {
addToList(aList, someBundleNames, false);
}

/**
* Finds one of the provided combination of bundles and adds it to the classpath. If no combination is found, an
* error is logged.
*
* @param aList
* the classpath
* @param someBundleNames
* an array of combinations of bundle names (outer array contains combinations, inner array contains the
* bundles that are part of a single combination)
* @param aRecursiveFlag
* whether to recursively search the contexts of bundles
*/
private void addToList(List<IClasspathEntry> aList, String[][] someBundleNames, boolean aRecursiveFlag) {
StringBuffer tempBuffer = new StringBuffer();
for (String[] tempBundleNames : someBundleNames) {
StringBuffer tempInnerBuffer = new StringBuffer();
List<IClasspathEntry> tempList = new ArrayList<IClasspathEntry>();
boolean tempFoundAll = true;
for (String tempBundleName : tempBundleNames) {
IClasspathEntry tempEntry = getPluginEntry(findBundle(tempBundleName));
IClasspathEntry tempEntry = getPluginEntry(findBundle(tempBundleName, aRecursiveFlag));
if (tempEntry != null) {
tempList.add(tempEntry);
} else {
Expand Down Expand Up @@ -136,8 +155,9 @@ private void addToList(List<IClasspathEntry> aList, String[][] someBundleNames)
+ tempBuffer + "' to add it to a projects' classpath!"));
}

private Bundle findBundle(String aSymbolicName) {
return findBundleRecursive(aSymbolicName, FrameworkUtil.getBundle(JavaCore.class), new HashSet<>());
private Bundle findBundle(String aSymbolicName, boolean aRecursiveFlag) {
return findBundleRecursive(aSymbolicName, FrameworkUtil.getBundle(JavaCore.class),
aRecursiveFlag ? new HashSet<>() : null);
}

private Bundle findBundleRecursive(String aSymbolicName, Bundle aRootBundle, Set<Bundle> someSeenBundles) {
Expand All @@ -148,10 +168,12 @@ private Bundle findBundleRecursive(String aSymbolicName, Bundle aRootBundle, Set
}

for (Bundle tempBundleCandidate : aRootBundle.getBundleContext().getBundles()) {
if (someSeenBundles.contains(tempBundleCandidate)) {
continue;
} else {
someSeenBundles.add(tempBundleCandidate);
if (someSeenBundles != null) {
if (someSeenBundles.contains(tempBundleCandidate)) {
continue;
} else {
someSeenBundles.add(tempBundleCandidate);
}
}

if (tempBundleCandidate.getSymbolicName().equals(aSymbolicName)) {
Expand All @@ -163,7 +185,7 @@ private Bundle findBundleRecursive(String aSymbolicName, Bundle aRootBundle, Set
}

tempBundleMatch = tempBundleCandidate;
} else {
} else if (someSeenBundles != null) {
Bundle tempRecursionCandidate
= findBundleRecursive(aSymbolicName, tempBundleCandidate, someSeenBundles);

Expand Down

0 comments on commit 17d3929

Please sign in to comment.