Instead of mvn build use mvn project building + resolve. Refactorings
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -27,7 +28,6 @@ import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject.TypeFilter;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
@@ -244,11 +244,11 @@ public class JandexIndex {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, TypeFilter typeFilter) {
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
Flux<Tuple2<IType, Double>> flux = Flux.fromIterable(knownTypes.values())
|
||||
.publishOn(Schedulers.parallel())
|
||||
.flatMap(s -> Flux.fromIterable(s.get()))
|
||||
.filter(t -> typeFilter == null || typeFilter.accept(t.getT2()))
|
||||
.filter(t -> typeFilter == null || typeFilter.test(t.getT2()))
|
||||
.map(t -> Tuples.of(t.getT2(), FuzzyMatcher.matchScore(searchTerm, t.getT1())))
|
||||
.filter(t -> t.getT2() != 0.0);
|
||||
if (baseIndex == null) {
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
public interface IJavaProject extends IJavaElement {
|
||||
|
||||
/**
|
||||
* TypeFilter is deprecated. Should use java.util.funcion.Predicate<IType> instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@FunctionalInterface
|
||||
public static interface TypeFilter {
|
||||
boolean accept(IType type);
|
||||
}
|
||||
|
||||
IType findType(String fqName);
|
||||
|
||||
Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, TypeFilter typeFilter);
|
||||
Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter);
|
||||
|
||||
Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm);
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ public class MavenBuilder {
|
||||
|
||||
public MavenBuilder javadoc() {
|
||||
properties.add("javadoc:javadoc");
|
||||
properties.add("-Dshow=private");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ package org.springframework.ide.vscode.commons.maven.java;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
@@ -60,7 +60,7 @@ public class MavenJavaProject implements IJavaProject {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, TypeFilter typeFilter) {
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
return classpath.fuzzySearchType(searchTerm, typeFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,15 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.DirectoryScanner;
|
||||
import org.springframework.ide.vscode.commons.jandex.JandexIndex;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject.TypeFilter;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.parser.ParserJavadocProvider;
|
||||
@@ -72,14 +71,7 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
MavenProjectClasspath(File pom, MavenCore maven) {
|
||||
this.maven = maven;
|
||||
this.pom = pom;
|
||||
this.projectSupplier = Suppliers.memoize(() -> {
|
||||
try {
|
||||
return createMavenProject();
|
||||
} catch (MavenException e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
this.projectSupplier = Suppliers.memoize(() -> createMavenProject());
|
||||
this.javaIndex = Suppliers.memoize(() -> {
|
||||
Stream<Path> classpathEntries = Stream.empty();
|
||||
try {
|
||||
@@ -100,12 +92,20 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
});
|
||||
}
|
||||
|
||||
private final MavenProject createMavenProject() throws MavenException {
|
||||
MavenExecutionResult result = maven.build(pom);
|
||||
if (result.hasExceptions()) {
|
||||
result.getExceptions().forEach(Log::log);
|
||||
private final MavenProject createMavenProject() {
|
||||
try {
|
||||
// Read with resolved dependencies
|
||||
return maven.readProject(pom, true);
|
||||
} catch (MavenException e) {
|
||||
Log.log(e);
|
||||
try {
|
||||
// Try without resolving dependencies - just read the XML
|
||||
return maven.readProject(pom, false);
|
||||
} catch (MavenException e1) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result.getProject();
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
@@ -148,7 +148,7 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
return javaIndex.get().findType(fqName);
|
||||
}
|
||||
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchType(String searchTerm, TypeFilter typeFilter) {
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchType(String searchTerm, Predicate<IType> typeFilter) {
|
||||
return javaIndex.get().fuzzySearchTypes(searchTerm, typeFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.maven.java.classpathfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
@@ -59,7 +60,7 @@ public class JavaProjectWithClasspathFile implements IJavaProject {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, TypeFilter typeFilter) {
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
return Flux.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public class HtmlJavadocTest {
|
||||
try {
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.HTML;
|
||||
testProjectPath = Paths.get(HtmlJavadocTest.class.getResource("/gs-rest-service-cors-boot-1.4.1-with-classpath-file").toURI());
|
||||
MavenBuilder.newBuilder(testProjectPath).clean().pack().javadoc().skipTests().execute();
|
||||
return new MavenJavaProject(testProjectPath.resolve(MavenCore.POM_XML).toFile());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
||||
@@ -33,15 +33,12 @@ public class JavaIndexTest {
|
||||
@Override
|
||||
public MavenJavaProject load(String projectName) throws Exception {
|
||||
Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/" + projectName).toURI());
|
||||
return createMavenProject(testProjectPath);
|
||||
MavenBuilder.newBuilder(testProjectPath).clean().pack().javadoc().skipTests().execute();
|
||||
return new MavenJavaProject(testProjectPath.resolve(MavenCore.POM_XML).toFile());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
private static MavenJavaProject createMavenProject(Path projectPath) throws Exception {
|
||||
return new MavenJavaProject(projectPath.resolve(MavenCore.POM_XML).toFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fuzzySearchNoFilter() throws Exception {
|
||||
List<Tuple2<IType, Double>> results = MavenCore.getDefault().getJavaIndexForJreLibs()
|
||||
@@ -75,7 +72,7 @@ public class JavaIndexTest {
|
||||
@Test
|
||||
public void findClassInJar() throws Exception {
|
||||
MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
|
||||
IType type = project.findType("org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration");
|
||||
IType type = project.findType("org.springframework.test.web.client.ExpectedCount");
|
||||
assertNotNull(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ import com.google.common.collect.ImmutableList;
|
||||
public class BootPropertiesLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
public static final JavaProjectFinder DEFAULT_PROJECT_FINDER = new DefaultJavaProjectFinder(new IJavaProjectFinderStrategy[] {
|
||||
new JavaProjectWithClasspathFileFinderStrategy(),
|
||||
new MavenProjectFinderStrategy()
|
||||
new MavenProjectFinderStrategy(),
|
||||
new JavaProjectWithClasspathFileFinderStrategy()
|
||||
});
|
||||
|
||||
private static final String YML = ".yml";
|
||||
|
||||
@@ -50,6 +50,7 @@ public class ProjectsHarness {
|
||||
Path testProjectPath = getProjectPath(name);
|
||||
switch (type) {
|
||||
case MAVEN:
|
||||
MavenBuilder.newBuilder(testProjectPath).clean().pack().javadoc().skipTests().execute();
|
||||
return new MavenJavaProject(testProjectPath.resolve(MavenCore.POM_XML).toFile());
|
||||
case CLASSPATH_TXT:
|
||||
MavenBuilder.newBuilder(testProjectPath).clean().pack().skipTests().execute();
|
||||
|
||||
Reference in New Issue
Block a user