Search in sources :

Example 6 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class SpringIndexer method updateDocument.

public CompletableFuture<Void> updateDocument(String docURI, String content) {
    synchronized (this) {
        if (docURI.endsWith(".java") && lastInitializeItem != null) {
            try {
                Optional<IJavaProject> maybeProject = projectFinder.find(new TextDocumentIdentifier(docURI));
                if (maybeProject.isPresent()) {
                    String[] classpathEntries = getClasspathEntries(maybeProject.get());
                    UpdateItem updateItem = new UpdateItem(docURI, content, classpathEntries);
                    updateQueue.put(updateItem);
                    return updateItem.getFuture();
                }
            } catch (Exception e) {
                log.error("{}", e);
            }
        }
    }
    return null;
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject)

Example 7 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class SpringIndexer method scanFiles.

private void scanFiles(WorkspaceFolder directory) {
    try {
        Map<Optional<IJavaProject>, List<String>> projects = Files.walk(Paths.get(new URI(directory.getUri()))).filter(path -> path.getFileName().toString().endsWith(".java")).filter(Files::isRegularFile).map(path -> path.toAbsolutePath().toString()).collect(Collectors.groupingBy((javaFile) -> projectFinder.find(new TextDocumentIdentifier(new File(javaFile).toURI().toString()))));
        projects.forEach((maybeProject, files) -> maybeProject.ifPresent(project -> scanProject(project, files.toArray(new String[0]))));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Arrays(java.util.Arrays) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SymbolProvider(org.springframework.ide.vscode.boot.java.handlers.SymbolProvider) LoggerFactory(org.slf4j.LoggerFactory) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FileASTRequestor(org.eclipse.jdt.core.dom.FileASTRequestor) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) AnnotationHierarchyAwareLookup(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup) URI(java.net.URI) Path(java.nio.file.Path) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) Predicate(java.util.function.Predicate) SymbolAddOnInformation(org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) List(java.util.List) Stream(java.util.stream.Stream) ASTParser(org.eclipse.jdt.core.dom.ASTParser) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) AST(org.eclipse.jdt.core.dom.AST) Optional(java.util.Optional) SimpleWorkspaceService(org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) MarkerAnnotation(org.eclipse.jdt.core.dom.MarkerAnnotation) JavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder) SymbolKind(org.eclipse.lsp4j.SymbolKind) BootLanguageServerParams(org.springframework.ide.vscode.boot.BootLanguageServerParams) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) ProjectObserver(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) ImmutableList(com.google.common.collect.ImmutableList) Annotation(org.eclipse.jdt.core.dom.Annotation) AnnotationHierarchies(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies) UriUtil(org.springframework.ide.vscode.commons.util.UriUtil) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) LanguageId(org.springframework.ide.vscode.commons.util.text.LanguageId) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) Logger(org.slf4j.Logger) Files(java.nio.file.Files) JavaCore(org.eclipse.jdt.core.JavaCore) Futures(org.springframework.ide.vscode.commons.util.Futures) FileUtils(org.apache.commons.io.FileUtils) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) File(java.io.File) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) Paths(java.nio.file.Paths) Collections(java.util.Collections) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Optional(java.util.Optional) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Files(java.nio.file.Files) URI(java.net.URI) File(java.io.File)

Example 8 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class GradleProjectTest method findGradleProjectWithStandardBuildFile.

@Test
public void findGradleProjectWithStandardBuildFile() throws Exception {
    GradleProjectFinder finder = new GradleProjectFinder(new GradleProjectCache(server, GradleCore.getDefault(), false, null));
    File sourceFile = new File(GradleProjectTest.class.getResource("/test-app-1/src/main/java/Library.java").toURI());
    Optional<IJavaProject> project = finder.find(sourceFile);
    assertTrue(project.isPresent());
    assertTrue(project.get() instanceof GradleJavaProject);
    GradleJavaProject gradleProject = (GradleJavaProject) project.get();
    assertEquals(new File(GradleProjectTest.class.getResource("/test-app-1").toURI()), gradleProject.getLocation());
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) File(java.io.File) Test(org.junit.Test)

Example 9 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class GradleProjectTest method testGradleFileChanges.

@Test
public void testGradleFileChanges() throws Exception {
    Path testProjectPath = Paths.get(GradleProjectTest.class.getResource("/empty-gradle-project").toURI());
    File gradleFile = testProjectPath.resolve(GradleCore.GRADLE_BUILD_FILE).toFile();
    String gradelFileContents = Files.contentOf(gradleFile, Charset.defaultCharset());
    try {
        GradleProjectCache manager = new GradleProjectCache(server, GradleCore.getDefault(), false, null);
        IJavaProject[] projectChanged = new IJavaProject[] { null };
        IJavaProject[] projectDeleted = new IJavaProject[] { null };
        manager.addListener(new Listener() {

            @Override
            public void created(IJavaProject project) {
            }

            @Override
            public void changed(IJavaProject project) {
                projectChanged[0] = project;
            }

            @Override
            public void deleted(IJavaProject project) {
                projectDeleted[0] = project;
            }
        });
        // Get the project from cache
        GradleJavaProject cachedProject = manager.project(gradleFile);
        assertNotNull(cachedProject);
        ImmutableList<Path> calculatedClassPath = cachedProject.getClasspath().getClasspathEntries();
        assertEquals(48, calculatedClassPath.size());
        fileObserver.notifyFileChanged(gradleFile.toURI().toString());
        assertNull(projectChanged[0]);
        writeContent(gradleFile, Files.contentOf(testProjectPath.resolve("build.newgradle").toFile(), Charset.defaultCharset()));
        fileObserver.notifyFileChanged(gradleFile.toURI().toString());
        assertNotNull(projectChanged[0]);
        assertEquals(cachedProject, projectChanged[0]);
        calculatedClassPath = cachedProject.getClasspath().getClasspathEntries();
        assertEquals(49, calculatedClassPath.size());
        fileObserver.notifyFileDeleted(gradleFile.toURI().toString());
        assertEquals(cachedProject, projectDeleted[0]);
    } finally {
        writeContent(gradleFile, gradelFileContents);
    }
}
Also used : Path(java.nio.file.Path) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) File(java.io.File) Test(org.junit.Test)

Example 10 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class BootLanguageServerParams method createFallbackProjectCache.

private static JavaProjectsService createFallbackProjectCache(SimpleLanguageServer server) {
    CompositeJavaProjectFinder javaProjectFinder = new CompositeJavaProjectFinder();
    MavenProjectCache mavenProjectCache = new MavenProjectCache(server, MavenCore.getDefault(), true, Paths.get(IJavaProject.PROJECT_CACHE_FOLDER));
    javaProjectFinder.addJavaProjectFinder(new MavenProjectFinder(mavenProjectCache));
    GradleProjectCache gradleProjectCache = new GradleProjectCache(server, GradleCore.getDefault(), true, Paths.get(IJavaProject.PROJECT_CACHE_FOLDER));
    javaProjectFinder.addJavaProjectFinder(new GradleProjectFinder(gradleProjectCache));
    CompositeProjectOvserver projectObserver = new CompositeProjectOvserver(Arrays.asList(mavenProjectCache, gradleProjectCache));
    return new JavaProjectsService() {

        @Override
        public void removeListener(Listener listener) {
            projectObserver.removeListener(listener);
        }

        @Override
        public void addListener(Listener listener) {
            projectObserver.addListener(listener);
        }

        @Override
        public Optional<IJavaProject> find(TextDocumentIdentifier doc) {
            return javaProjectFinder.find(doc);
        }
    };
}
Also used : GradleProjectCache(org.springframework.ide.vscode.commons.gradle.GradleProjectCache) MavenProjectCache(org.springframework.ide.vscode.commons.maven.java.MavenProjectCache) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CompositeJavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.CompositeJavaProjectFinder) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) CompositeProjectOvserver(org.springframework.ide.vscode.commons.languageserver.java.CompositeProjectOvserver) MavenProjectFinder(org.springframework.ide.vscode.commons.maven.java.MavenProjectFinder) JavaProjectsService(org.springframework.ide.vscode.boot.jdt.ls.JavaProjectsService) GradleProjectFinder(org.springframework.ide.vscode.commons.gradle.GradleProjectFinder)

Aggregations

IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)63 Test (org.junit.Test)52 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)35 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)24 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)8 Ignore (org.junit.Ignore)8 IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)7 File (java.io.File)6 Path (java.nio.file.Path)6 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)6 URI (java.net.URI)5 Map (java.util.Map)5 Listener (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener)5 Stream (java.util.stream.Stream)4 JavaCore (org.eclipse.jdt.core.JavaCore)4 AST (org.eclipse.jdt.core.dom.AST)4 ASTParser (org.eclipse.jdt.core.dom.ASTParser)4 JavaProjectFinder (org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder)4 List (java.util.List)3