From 17d3929b0fd78f3f4eac64d0da11e6f3318f7511 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 25 Feb 2019 18:40:05 +0100 Subject: [PATCH] further fixing of #229: Fix org.objectweb.asm version collision Faster bundle lookup via recursion. --- .../IntegrityClasspathContainer.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/classpath/IntegrityClasspathContainer.java b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/classpath/IntegrityClasspathContainer.java index b833d1bcc..6d3c696af 100644 --- a/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/classpath/IntegrityClasspathContainer.java +++ b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/classpath/IntegrityClasspathContainer.java @@ -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()]; @@ -102,13 +105,29 @@ public IClasspathEntry[] getClasspathEntries() { * bundles that are part of a single combination) */ private void addToList(List 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 aList, String[][] someBundleNames, boolean aRecursiveFlag) { StringBuffer tempBuffer = new StringBuffer(); for (String[] tempBundleNames : someBundleNames) { StringBuffer tempInnerBuffer = new StringBuffer(); List tempList = new ArrayList(); 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 { @@ -136,8 +155,9 @@ private void addToList(List 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 someSeenBundles) { @@ -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)) { @@ -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);