Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build server & resource attributes to classpath entry #1398

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public class GradleBuildServerBuildSupport implements IBuildSupport {
*/
private static final IClasspathAttribute modularAttribute = JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true");

/**
* Attribute to mark the entry is contributed by build server implementation.
*/
private static final IClasspathAttribute buildServerAttribute = JavaCore.newClasspathAttribute("gradle.buildServer", "true");

/**
* Attribute to mark whether the source root is a resource folder.
*/
private static final IClasspathAttribute resourceAttribute = JavaCore.newClasspathAttribute("resource", "true");

@Override
public boolean applies(IProject project) {
return Utils.isGradleBuildServerProject(project);
Expand Down Expand Up @@ -256,7 +266,13 @@ private List<IClasspathEntry> getProjectDependencyEntries(Set<BuildTargetIdentif
URI uri = Utils.getUriWithoutQuery(dependency.getUri());
IProject dependencyProject = ProjectUtils.getProjectFromUri(uri.toString());
if (dependencyProject != null) {
entries.add(JavaCore.newProjectEntry(dependencyProject.getFullPath()));
entries.add(JavaCore.newProjectEntry(
dependencyProject.getFullPath(),
ClasspathEntry.NO_ACCESS_RULES,
true,
new IClasspathAttribute[] { buildServerAttribute },
false
));
}
}
return entries;
Expand Down Expand Up @@ -329,6 +345,7 @@ private List<IClasspathEntry> getSourceEntries(IPath rootPath, IProject project,
if (!sourcePath.toFile().exists() || source.getGenerated() || isInBuildDir(sourceFullPath)) {
classpathAttributes.add(optionalAttribute);
}
classpathAttributes.add(buildServerAttribute);
sourceEntries.add(JavaCore.newSourceEntry(
sourceFullPath,
null,
Expand All @@ -354,6 +371,9 @@ private List<IClasspathEntry> getResourceEntries(IProject project, ResourcesResu
}
// resource folder may not exist.
classpathAttributes.add(optionalAttribute);

classpathAttributes.add(buildServerAttribute);
classpathAttributes.add(resourceAttribute);
resourceEntries.add(JavaCore.newSourceEntry(
resourceFullPath,
null,
Expand Down Expand Up @@ -439,10 +459,16 @@ private void setProjectJdk(Map<IPath, IClasspathEntry> classpathMap, List<BuildT
highestJavaVersion,
new File(new URI(jvmBuildTarget.getJavaHome())) // fallback jdk
);

List<IClasspathAttribute> classpathAttributes = new LinkedList<>();
if (isModular) {
classpathAttributes.add(modularAttribute);
}
classpathAttributes.add(buildServerAttribute);
IClasspathEntry jdkEntry = JavaCore.newContainerEntry(
JavaRuntime.newJREContainerPath(vm),
ClasspathEntry.NO_ACCESS_RULES,
isModular ? new IClasspathAttribute[] { modularAttribute } : ClasspathEntry.NO_EXTRA_ATTRIBUTES,
classpathAttributes.toArray(new IClasspathAttribute[0]),
false /*isExported*/
);
classpathMap.putIfAbsent(jdkEntry.getPath(), jdkEntry);
Expand Down Expand Up @@ -569,13 +595,14 @@ private List<IClasspathEntry> getDependencyJars(DependencyModulesResult dependen
if (!artifact.exists()) {
attributes.add(optionalAttribute);
}
attributes.add(buildServerAttribute);

dependencyEntries.add(JavaCore.newLibraryEntry(
new Path(artifact.getAbsolutePath()),
sourceArtifact == null ? null : new Path(sourceArtifact.getAbsolutePath()),
null,
ClasspathEntry.NO_ACCESS_RULES,
attributes.size() == 0 ? ClasspathEntry.NO_EXTRA_ATTRIBUTES : attributes.toArray(new IClasspathAttribute[attributes.size()]),
attributes.toArray(new IClasspathAttribute[0]),
false
));
}
Expand Down
Loading