Implement getSourceFolders in JdtLsClasspath
Also various refactoring and bug fixing
This commit is contained in:
@@ -267,7 +267,7 @@ public class BootJavaHoverProvider implements HoverHandler {
|
||||
try {
|
||||
IClasspath classpath = project.getClasspath();
|
||||
if (classpath!=null) {
|
||||
return classpath.getClasspathEntries().stream().anyMatch(cpe -> {
|
||||
return classpath.getClasspathEntryPaths().stream().anyMatch(cpe -> {
|
||||
String name = cpe.getFileName().toString();
|
||||
return name.startsWith("spring-boot-actuator-");
|
||||
});
|
||||
|
||||
@@ -125,7 +125,7 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
private String[] getClasspathEntries(IDocument doc) throws Exception {
|
||||
IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri())).get();
|
||||
IClasspath classpath = project.getClasspath();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntries().stream();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntryPaths().stream();
|
||||
return classpathEntries
|
||||
.filter(path -> path.toFile().exists())
|
||||
.map(path -> path.toAbsolutePath().toString()).toArray(String[]::new);
|
||||
|
||||
@@ -83,37 +83,34 @@ public abstract class AbstractSourceLinks implements SourceLinks {
|
||||
|
||||
private Optional<String> javaSourceLinkUrl(IJavaProject project, String fqName, File containerFolder) {
|
||||
IClasspath classpath = project.getClasspath();
|
||||
if (containerFolder.toPath().startsWith(classpath.getOutputFolder())) {
|
||||
return project.getClasspath().getSourceFolders().stream()
|
||||
.map(sourceFolder -> {
|
||||
try {
|
||||
return Paths.get(sourceFolder).toUri().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
LOG.get().warn("Failed to convert source folder " + sourceFolder + "to URI." + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.map(url -> {
|
||||
try {
|
||||
return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER.sourceUrl(url, fqName);
|
||||
} catch (Exception e) {
|
||||
LOG.get().warn("Failed to determine source URL from url=" + url + " fqName=" + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.map(url -> {
|
||||
try {
|
||||
return Paths.get(url.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
LOG.get().warn("Failed to convert URL " + url + " to path." + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(sourcePath -> sourcePath != null && Files.exists(sourcePath))
|
||||
.findFirst()
|
||||
.map(sourcePath -> javaSourceLinkUrl(project, sourcePath, fqName));
|
||||
}
|
||||
return Optional.empty();
|
||||
return project.getClasspath().getSourceFolders().stream()
|
||||
.map(sourceFolder -> {
|
||||
try {
|
||||
return Paths.get(sourceFolder).toUri().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
LOG.get().warn("Failed to convert source folder " + sourceFolder + "to URI." + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.map(url -> {
|
||||
try {
|
||||
return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER.sourceUrl(url, fqName);
|
||||
} catch (Exception e) {
|
||||
LOG.get().warn("Failed to determine source URL from url=" + url + " fqName=" + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.map(url -> {
|
||||
try {
|
||||
return Paths.get(url.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
LOG.get().warn("Failed to convert URL " + url + " to path." + fqName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(sourcePath -> sourcePath != null && Files.exists(sourcePath))
|
||||
.findFirst()
|
||||
.map(sourcePath -> javaSourceLinkUrl(project, sourcePath, fqName));
|
||||
}
|
||||
|
||||
private String javaSourceLinkUrl(IJavaProject project, Path sourcePath, String fqName) {
|
||||
|
||||
@@ -172,7 +172,7 @@ public final class CompilationUnitCache {
|
||||
return new String[0];
|
||||
} else {
|
||||
IClasspath classpath = project.getClasspath();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntries().stream();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntryPaths().stream();
|
||||
return classpathEntries
|
||||
.filter(path -> path.toFile().exists())
|
||||
.map(path -> path.toAbsolutePath().toString()).toArray(String[]::new);
|
||||
|
||||
@@ -619,7 +619,7 @@ public class SpringIndexer {
|
||||
|
||||
private String[] getClasspathEntries(IJavaProject project) throws Exception {
|
||||
IClasspath classpath = project.getClasspath();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntries().stream();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntryPaths().stream();
|
||||
return classpathEntries
|
||||
.filter(path -> path.toFile().exists())
|
||||
.map(path -> path.toAbsolutePath().toString()).toArray(String[]::new);
|
||||
|
||||
@@ -15,12 +15,14 @@ import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
@@ -31,6 +33,7 @@ import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListener;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
@@ -41,6 +44,7 @@ import org.springframework.ide.vscode.commons.util.UriUtil;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
|
||||
@@ -250,13 +254,8 @@ public class JdtLsProjectCache implements JavaProjectsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Path> getClasspathEntries() throws Exception {
|
||||
return classpath
|
||||
.getEntries()
|
||||
.stream()
|
||||
.filter(cpe -> cpe.getKind().equals(Classpath.ENTRY_KIND_BINARY))
|
||||
.map(cpe -> Paths.get(cpe.getPath()))
|
||||
.collect(CollectorUtil.toImmutableList());
|
||||
public Collection<CPE> getClasspathEntries() throws Exception {
|
||||
return classpath.getEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,8 +266,18 @@ public class JdtLsProjectCache implements JavaProjectsService {
|
||||
|
||||
@Override
|
||||
public ImmutableList<String> getSourceFolders() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
ImmutableList.Builder<String> sourceEntries = ImmutableList.builder();
|
||||
try {
|
||||
for (CPE e : getClasspathEntries()) {
|
||||
if (Classpath.isSource(e)) {
|
||||
sourceEntries.add(e.getPath());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return sourceEntries.build();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PropertiesLoader {
|
||||
|
||||
public ConfigurationMetadataRepository load(IClasspath classPath) {
|
||||
try {
|
||||
classPath.getClasspathEntries().forEach(entry -> {
|
||||
classPath.getClasspathEntryPaths().forEach(entry -> {
|
||||
//Log.info("Indexing "+entry);
|
||||
File fileEntry = entry.toFile();
|
||||
if (fileEntry.exists()) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
@@ -79,7 +80,7 @@ public class PropertiesIndexTest {
|
||||
assertEquals("port", propertyInfo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test @Ignore //ignore because classpath file is going to disapear and pieces already removed
|
||||
public void customPropertyPresent_ClasspathFile() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault(), null);
|
||||
@@ -91,7 +92,7 @@ public class PropertiesIndexTest {
|
||||
assertEquals("user", propertyInfo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test @Ignore //ignore because classpath file is going to disapear and pieces already removed
|
||||
public void propertyNotPresent_ClasspathFile() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault(), null);
|
||||
|
||||
Reference in New Issue
Block a user