Skip to content

Commit

Permalink
[FIXUP] Set test attribute for name-matching test plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Sep 20, 2023
1 parent d2c8b53 commit 9e42a61
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

public class ClasspathComputer {

private record ClasspathConfiguration(IPluginModelBase model, IJavaProject javaProject, boolean isTestPlugin,
private record ClasspathConfiguration(IPluginModelBase model, IJavaProject javaProject,
IClasspathAttribute[] defaultAttrs, Map<IPath, IClasspathEntry> originalByPath,
List<IClasspathEntry> reloaded) {
}
Expand All @@ -74,8 +74,8 @@ public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase
IJavaProject javaProject = JavaCore.create(project);
List<IClasspathEntry> originalClasspath = clear ? List.of() : Arrays.asList(javaProject.getRawClasspath());
ClasspathConfiguration context = new ClasspathConfiguration(model, javaProject,
hasTestPluginName(project), getClasspathAttributes(project, model),
mapFirstSeenByPath(originalClasspath.stream()), new ArrayList<>());
getClasspathAttributes(project, model), mapFirstSeenByPath(originalClasspath.stream()),
new ArrayList<>());

// add JRE and set compliance options
String ee = getExecutionEnvironment(model.getBundleDescription());
Expand All @@ -88,7 +88,8 @@ public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase
// add own libraries/source
addSourceAndLibraries(sourceLibraryMap != null ? sourceLibraryMap : Collections.emptyMap(), context);

IClasspathEntry[] entries = collectInOriginalOrder(originalClasspath, context.reloaded);
boolean isTestPlugin = hasTestPluginName(project);
IClasspathEntry[] entries = collectInOriginalOrder(originalClasspath, context.reloaded, isTestPlugin);
IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation());
if (!validation.isOK()) {
PDECore.logErrorMessage(validation.getMessage());
Expand All @@ -98,7 +99,7 @@ public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase
}

private static IClasspathEntry[] collectInOriginalOrder(List<IClasspathEntry> originalClasspath,
List<IClasspathEntry> reloaded) {
List<IClasspathEntry> reloaded, boolean isTestPlugin) {
// preserve original entries which eventually weren't reloaded
Map<IPath, IClasspathEntry> resultingReloadedByPath = mapFirstSeenByPath(reloaded.stream());
List<IClasspathEntry> result = new ArrayList<>(originalClasspath);
Expand All @@ -108,6 +109,10 @@ private static IClasspathEntry[] collectInOriginalOrder(List<IClasspathEntry> or
});
// using the order of reloading, append new entries (in the map still)
result.addAll(resultingReloadedByPath.values());
if (isTestPlugin) {
// don't remove existing TEST attributes, but set if advised
result.replaceAll(e -> updateTestAttribute(true, e));
}
return result.toArray(IClasspathEntry[]::new);
}

Expand Down Expand Up @@ -236,12 +241,7 @@ private static void addSourceFolders(IBuildEntry buildEntry, ClasspathConfigurat
continue;
}
}
if (context.isTestPlugin) {
context.reloaded.add(JavaCore.newSourceEntry(path, null, null, null, new IClasspathAttribute[] {
JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") })); //$NON-NLS-1$
} else {
context.reloaded.add(JavaCore.newSourceEntry(path));
}
context.reloaded.add(JavaCore.newSourceEntry(path));
}
}

Expand Down

0 comments on commit 9e42a61

Please sign in to comment.