Search in sources :

Example 1 with Listener

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

the class MavenProjectCacheTest method testPomFileChanges.

@Test
public void testPomFileChanges() throws Exception {
    MavenProjectCache cache = new MavenProjectCache(server, MavenCore.getDefault(), false, null);
    IJavaProject[] projectChanged = new IJavaProject[] { null };
    IJavaProject[] projectDeleted = new IJavaProject[] { null };
    cache.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
    MavenJavaProject cachedProject = cache.project(pomFile);
    assertNotNull(cachedProject);
    ImmutableList<Path> calculatedClassPath = cachedProject.getClasspath().getClasspathEntries();
    assertEquals(48, calculatedClassPath.size());
    fileObserver.notifyFileChanged(pomFile.toURI().toString());
    assertNull(projectChanged[0]);
    writeContent(pomFile, new String(Files.readAllBytes(testProjectPath.resolve("pom.newxml")), Charset.defaultCharset()));
    fileObserver.notifyFileChanged(pomFile.toURI().toString());
    assertNotNull(projectChanged[0]);
    assertEquals(cachedProject, projectChanged[0]);
    calculatedClassPath = cachedProject.getClasspath().getClasspathEntries();
    assertEquals(49, calculatedClassPath.size());
    fileObserver.notifyFileDeleted(pomFile.toURI().toString());
    assertEquals(cachedProject, projectDeleted[0]);
}
Also used : Path(java.nio.file.Path) MavenProjectCache(org.springframework.ide.vscode.commons.maven.java.MavenProjectCache) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) Test(org.junit.Test)

Example 2 with Listener

use of org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener 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 3 with Listener

use of org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener 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)3 Listener (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener)3 Path (java.nio.file.Path)2 Test (org.junit.Test)2 MavenProjectCache (org.springframework.ide.vscode.commons.maven.java.MavenProjectCache)2 File (java.io.File)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 JavaProjectsService (org.springframework.ide.vscode.boot.jdt.ls.JavaProjectsService)1 GradleProjectCache (org.springframework.ide.vscode.commons.gradle.GradleProjectCache)1 GradleProjectFinder (org.springframework.ide.vscode.commons.gradle.GradleProjectFinder)1 CompositeJavaProjectFinder (org.springframework.ide.vscode.commons.languageserver.java.CompositeJavaProjectFinder)1 CompositeProjectOvserver (org.springframework.ide.vscode.commons.languageserver.java.CompositeProjectOvserver)1 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)1 MavenProjectFinder (org.springframework.ide.vscode.commons.maven.java.MavenProjectFinder)1