Skip to content
Open
Show file tree
Hide file tree
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 @@ -816,9 +816,13 @@ public String getProjectUri() {

private class GradleCompatibilityInfo {

@SuppressWarnings("unused")
private String projectUri;
@SuppressWarnings("unused")
private String message;
@SuppressWarnings("unused")
private String highestJavaVersion;
@SuppressWarnings("unused")
private String recommendedGradleVersion;

public GradleCompatibilityInfo(String projectPath, String message, String highestJavaVersion, String recommendedGradleVersion) {
Expand All @@ -830,8 +834,11 @@ public GradleCompatibilityInfo(String projectPath, String message, String highes
}

private class UpgradeGradleWrapperInfo {
@SuppressWarnings("unused")
private String projectUri;
@SuppressWarnings("unused")
private String message;
@SuppressWarnings("unused")
private String recommendedGradleVersion;

public UpgradeGradleWrapperInfo(String projectUri, String message, String recommendedGradleVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -26,6 +25,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -55,17 +55,18 @@
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;

import com.google.common.collect.ImmutableSet;

/**
* @author snjeza
*
*/
public class ScalaGradleSupport {

public static final Path CONTAINER_PATH = new Path("org.eclipse.buildship.core.gradleclasspathcontainer");
public static String[] EXCLUSIONS_PATTERNS = { "**" };

// Gradle Tooling API removes several scala libraries and adds the Scala builder and container that aren't recognized by Java LS.
// See https://github.com/gradle/gradle/blob/b3c5d40e82439da4627b38b4ced93121e551b0eb/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/eclipse/EclipsePlugin.java#L375-L377
public static final Set<String> SCALA_LIBRARIES = ImmutableSet.of("scala-library", "scala-swing", "scala-dbc");
public void cleanScalaProjects(IProgressMonitor monitor) {
PreferenceManager preferenceManager = JavaLanguageServerPlugin.getPreferencesManager();
if (preferenceManager == null || !preferenceManager.getPreferences().isScalaSupportEnabled()) {
Expand Down Expand Up @@ -149,16 +150,7 @@ private void checkSourcePaths(IProject project, IProgressMonitor monitor) {
if (Boolean.getBoolean("jdt.ls.debug")) {
JavaLanguageServerPlugin.logException(e);
}
} finally {
if (initScript != null) {
try {
Files.delete(initScript.toPath());
} catch (IOException e) {
JavaLanguageServerPlugin.logException(e);
}
}
}
return;
}

private File getInitScript() throws IOException {
Expand Down Expand Up @@ -258,39 +250,23 @@ private static void configureClasspath(IJavaProject javaProject, List<String> to
}
}
// @formatter:off
IClasspathEntry[] newClasspath = Stream.concat(Arrays
.stream(classpath), entries.stream())
.distinct()
.toArray(IClasspathEntry[]::new);
// @formatter:on
for (int i = 0; i < newClasspath.length; i++) {
IClasspathEntry entry = newClasspath[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
Optional<String> optional = resources.stream().filter(r -> Objects.equals(entry.getPath().removeFirstSegments(1), new Path(r).makeRelativeTo(javaProject.getProject().getLocation()))).findFirst();
if (optional.isPresent()) {
IPath[] exclusions = entry.getExclusionPatterns();
if (exclusions == null) {
exclusions = new IPath[0];
}
List<IPath> currentExclusions = new ArrayList<>(Arrays.asList(exclusions));
for (String ext : EXCLUSIONS_PATTERNS) {
IPath newPath = new Path(ext);
boolean exists = currentExclusions.stream().anyMatch(existingPath -> existingPath.toString().equals(ext));
if (!exists) {
currentExclusions.add(newPath);
}
}
IClasspathEntry newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), currentExclusions.toArray(new IPath[0]), entry.getOutputLocation(), entry.getExtraAttributes());
newClasspath[i] = newEntry;
}
}
}
IClasspathEntry[] newClasspath = Stream.concat(Arrays
.stream(classpath), entries.stream())
.distinct()
.toArray(IClasspathEntry[]::new);
// @formatter:on
javaProject.setRawClasspath(newClasspath, monitor);
}

private static List<String> getMissingPaths(IJavaProject javaProject, List<String> paths) {
List<String> toAdd = new ArrayList<>();
for (String path : paths) {
// @formatter:off
List<String> scalaLibs = paths
.stream()
.filter(s -> SCALA_LIBRARIES.stream().anyMatch(s::contains))
.collect(Collectors.toList());
// @formatter:on
for (String path : scalaLibs) {
try {
IClasspathContainer container = JavaCore.getClasspathContainer(CONTAINER_PATH, javaProject);
if (container != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,32 @@ public void testScalaSupportEnabled() throws Exception {
}
}

// https://github.com/redhat-developer/vscode-java/issues/4393#top
@Test
public void testResources() throws Exception {
boolean oldScalaSupported = this.preferences.isScalaSupportEnabled();
try {
this.preferences.setScalaSupportEnabled(true);
importGradleProject("scala");
waitForOtherLangs();
IProject project = ProjectUtils.getProject("app");
assertTrue(ProjectUtils.isGradleProject(project));
assertNoErrors(project);
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (IClasspathEntry entry : classpath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && "/app/src/main/resources".equals(entry.getPath().toString())) {
IPath[] exclusions = entry.getExclusionPatterns();
if (exclusions != null && exclusions.length > 0) {
fail("src/main/resources is excluded from classpath");
}
}
}
} finally {
this.preferences.setScalaSupportEnabled(oldScalaSupported);
}
}

@Test
public void testScalaSupportDisabled() throws Exception {
boolean oldScalaSupported = this.preferences.isScalaSupportEnabled();
Expand Down