diff --git a/bndtools.builder/src/org/bndtools/builder/classpath/BndContainer.java b/bndtools.builder/src/org/bndtools/builder/classpath/BndContainer.java index a2fee640a03..e389796967b 100644 --- a/bndtools.builder/src/org/bndtools/builder/classpath/BndContainer.java +++ b/bndtools.builder/src/org/bndtools/builder/classpath/BndContainer.java @@ -88,7 +88,7 @@ void refresh() throws CoreException { resources = null; } - private static final IClasspathAttribute TEST = JavaCore.newClasspathAttribute("test", + static final IClasspathAttribute TEST = JavaCore.newClasspathAttribute("test", Boolean.TRUE.toString()); private static final IClasspathAttribute PROJECT = JavaCore.newClasspathAttribute(Constants.VERSION_ATTRIBUTE, Constants.VERSION_ATTR_PROJECT); @@ -146,7 +146,7 @@ IRuntimeClasspathEntry[] getRuntimeClasspathEntries() throws JavaModelException return runtime.toArray(EMPTY_RUNTIMEENTRIES); } - private static boolean hasAttribute(IClasspathEntry cpe, IClasspathAttribute attr) { + static boolean hasAttribute(IClasspathEntry cpe, IClasspathAttribute attr) { return Arrays.stream(cpe.getExtraAttributes()) .anyMatch(attr::equals); } diff --git a/bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java b/bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java index 0ebc8d7a69b..8d893326f23 100644 --- a/bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java +++ b/bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java @@ -1,6 +1,8 @@ package org.bndtools.builder.classpath; import static java.util.stream.Collectors.toList; +import static org.bndtools.builder.classpath.BndContainer.TEST; +import static org.bndtools.builder.classpath.BndContainer.hasAttribute; import java.io.File; import java.io.IOException; @@ -10,6 +12,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.WeakHashMap; import java.util.jar.Manifest; @@ -200,13 +203,9 @@ private static File getContainerFile(IProject p) { private static class Updater { private static final IAccessRule DISCOURAGED = JavaCore.newAccessRule(new Path("**"), IAccessRule.K_DISCOURAGED | IAccessRule.IGNORE_IF_BETTER); - private static final IAccessRule NON_ACCESSIBLE = JavaCore.newAccessRule(new Path("**"), - IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); private static final IClasspathAttribute EMPTY_INDEX = JavaCore.newClasspathAttribute( IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, "platform:/plugin/" + BndtoolsBuilder.PLUGIN_ID + "/org/bndtools/builder/classpath/empty.index"); - private static final IClasspathAttribute TEST = JavaCore.newClasspathAttribute("test", - Boolean.TRUE.toString()); private static final IClasspathAttribute WITHOUT_TEST_CODE = JavaCore .newClasspathAttribute("without_test_code", Boolean.TRUE.toString()); private static final Pattern packagePattern = Pattern.compile("(?<=^|\\.)\\*(?=\\.|$)|\\."); @@ -302,7 +301,7 @@ static void setClasspathContainer(IJavaProject javaProject, BndContainer contain }, null); } - private Void calculateProjectClasspath() { + private Void calculateProjectClasspath() throws CoreException { if (!project.isOpen()) { return null; } @@ -326,17 +325,11 @@ private Void calculateProjectClasspath() { return null; } - private void calculateContainersClasspath(String instruction, Collection containers) { - boolean testattr = false; - if (instruction.equals(Constants.TESTPATH)) { - try { - testattr = Arrays.stream(javaProject.getRawClasspath()) - .filter(cpe -> cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) - .map(IClasspathEntry::getExtraAttributes) - .flatMap(Arrays::stream) - .anyMatch(TEST::equals); - } catch (JavaModelException e) {} - } + private void calculateContainersClasspath(String instruction, Collection containers) + throws CoreException { + boolean testattr = instruction.equals(Constants.TESTPATH) && Arrays.stream(javaProject.getRawClasspath()) + .filter(cpe -> cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) + .anyMatch(cpe -> hasAttribute(cpe, TEST)); for (Container c : containers) { File file = c.getFile(); assert file.isAbsolute(); @@ -383,21 +376,37 @@ private void calculateContainersClasspath(String instruction, Collection projectAccessRules = Objects.equals(source, "project") ? accessRules + : Collections.emptyList(); + addProjectEntry(otherProject.getFullPath(), projectAccessRules, extraAttrs); /* * Supply an empty index for the generated JAR of a * workspace project dependency. This prevents the @@ -405,17 +414,44 @@ private void calculateContainersClasspath(String instruction, Collection accessRules, List extraAttrs) { + private void addProjectEntry(IPath path, List accessRules, + List extraAttrs) { List classpath = builder.entries(); for (int i = 0; i < classpath.size(); i++) { IClasspathEntry entry = classpath.get(i); @@ -441,13 +477,15 @@ private void addProjectEntry(IPath path, List accessRules, List accessRules, - List extraAttrs) { - IPath sourceAttachmentPath = calculateSourceAttachmentPath(path, file); - builder.entry(JavaCore.newLibraryEntry(path, sourceAttachmentPath, null, toAccessRulesArray(accessRules), - toClasspathAttributesArray(extraAttrs), false)); + List extraAttrs, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath) { + IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, + sourceAttachmentRootPath, + toAccessRulesArray(accessRules), + toClasspathAttributesArray(extraAttrs), false); + builder.entry(libraryEntry); builder.updateLastModified(file.lastModified()); }