Search in sources :

Example 1 with ProgressService

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

the class SpringPropertyIndexTest method testPropertiesIndexRefreshOnProjectChange.

@Test
public void testPropertiesIndexRefreshOnProjectChange() throws Exception {
    harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI()));
    propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServerWrapper().getComponents().getSpringPropertyIndexProvider();
    File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
    File javaFile = new File(directory, "/src/main/java/org/test/SimpleMappingClass.java");
    TextDocument doc = new TextDocument(javaFile.toURI().toString(), LanguageId.JAVA);
    // Not cached yet, hence progress service invoked
    ProgressService progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
    // Should be cached now, so progress service should not be touched
    progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, never()).progressEvent(anyObject(), anyObject());
    // Change POM file for the project
    harness.changeFile(new File(directory, MavenCore.POM_XML).toURI().toString());
    // POM has changed, hence project needs to be reloaded, cached value is cleared
    progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ProjectsHarness(org.springframework.ide.vscode.project.harness.ProjectsHarness) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) File(java.io.File) Test(org.junit.Test)

Example 2 with ProgressService

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

the class AbstractFileToProjectCache method performUpdate.

protected final void performUpdate(P project, boolean async, boolean notify) {
    final String taskId = getProgressId();
    final ProgressService progressService = server.getProgressService();
    if (progressService != null) {
        progressService.progressEvent(taskId, "Updating data for project `" + project.getElementName() + "'");
    }
    if (async) {
        CompletableFuture.supplyAsync(() -> update(project)).thenAccept((changed) -> afterUpdate(project, changed, notify, taskId));
    } else {
        boolean changed = update(project);
        afterUpdate(project, changed, notify, taskId);
    }
}
Also used : ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService)

Example 3 with ProgressService

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

the class SpringPropertiesIndexTest method testPropertiesIndexRefreshOnProjectChange.

@Test
public void testPropertiesIndexRefreshOnProjectChange() throws Exception {
    harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI()));
    propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServerWrapper().getComponents().get(BootPropertiesLanguageServerComponents.class).getPropertiesIndexProvider();
    File directory = new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI());
    File javaFile = new File(directory, "/src/main/java/demo/Application.java");
    TextDocument doc = new TextDocument(javaFile.toURI().toString(), LanguageId.JAVA);
    // Not cached yet, hence progress service invoked
    ProgressService progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
    // Should be cached now, so progress service should not be touched
    progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, never()).progressEvent(anyObject(), anyObject());
    // Change POM file for the project
    harness.changeFile(new File(directory, MavenCore.POM_XML).toURI().toString());
    // POM has changed, hence project needs to be reloaded, cached value is cleared
    progressService = mock(ProgressService.class);
    propertyIndexProvider.setProgressService(progressService);
    propertyIndexProvider.getIndex(doc);
    verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
}
Also used : BootPropertiesLanguageServerComponents(org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ProjectsHarness(org.springframework.ide.vscode.project.harness.ProjectsHarness) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) File(java.io.File) Test(org.junit.Test)

Example 4 with ProgressService

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

the class MavenProjectCacheTest method testClasspathCaching.

@Test
public void testClasspathCaching() throws Exception {
    Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/empty-boot-project-with-classpath-file").toURI());
    Path cacheFolder = testProjectPath.resolve(IJavaProject.PROJECT_CACHE_FOLDER);
    final File classpathCacheFile = cacheFolder.resolve(ClasspathFileBasedCache.CLASSPATH_DATA_CACHE_FILE).toFile();
    AtomicBoolean progressDone = new AtomicBoolean();
    ProgressService progressService = mock(ProgressService.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            progressDone.set(true);
            return null;
        }
    }).when(progressService).progressEvent(any(String.class), (String) isNull());
    when(server.getProgressService()).thenReturn(progressService);
    assertFalse(classpathCacheFile.exists());
    MavenProjectCache cache = new MavenProjectCache(server, MavenCore.getDefault(), true, cacheFolder);
    MavenJavaProject project = cache.project(pomFile);
    assertTrue(project.getClasspath().getClasspathEntries().isEmpty());
    CompletableFuture.runAsync(() -> {
        while (!progressDone.get()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).get(30, TimeUnit.SECONDS);
    assertTrue(classpathCacheFile.exists());
    assertEquals(48, project.getClasspath().getClasspathEntries().size());
    progressDone.set(false);
    // Reset the cache
    cache = new MavenProjectCache(server, MavenCore.getDefault(), true, cacheFolder);
    // Check loaded from cache file
    project = cache.project(pomFile);
    assertEquals(48, project.getClasspath().getClasspathEntries().size());
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProjectCache(org.springframework.ide.vscode.commons.maven.java.MavenProjectCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) File(java.io.File) Test(org.junit.Test)

Example 5 with ProgressService

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

the class MavenProjectCacheTest method testErrorLoadingProject.

@Test
public void testErrorLoadingProject() throws Exception {
    Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/empty-boot-project-with-classpath-file").toURI());
    Path cacheFolder = testProjectPath.resolve(IJavaProject.PROJECT_CACHE_FOLDER);
    AtomicBoolean progressDone = new AtomicBoolean();
    ProgressService progressService = mock(ProgressService.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            progressDone.set(true);
            return null;
        }
    }).when(progressService).progressEvent(any(String.class), (String) isNull());
    when(server.getProgressService()).thenReturn(progressService);
    DiagnosticService diagnosticService = mock(DiagnosticService.class);
    when(server.getDiagnosticService()).thenReturn(diagnosticService);
    MavenProjectCache cache = new MavenProjectCache(server, MavenCore.getDefault(), true, cacheFolder);
    MavenJavaProject project = cache.project(pomFile);
    assertTrue(project.getClasspath().getClasspathEntries().isEmpty());
    CompletableFuture.runAsync(() -> {
        while (!progressDone.get()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).get(30, TimeUnit.SECONDS);
    progressDone.set(false);
    verify(diagnosticService, never()).diagnosticEvent(any(ShowMessageException.class));
    writeContent(pomFile, "");
    fileObserver.notifyFileChanged(pomFile.toURI().toString());
    CompletableFuture.runAsync(() -> {
        while (!progressDone.get()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).get(30, TimeUnit.SECONDS);
    progressDone.set(false);
    verify(diagnosticService, times(1)).diagnosticEvent(any(ShowMessageException.class));
    assertTrue(project.getClasspath().getClasspathEntries().isEmpty());
    assertFalse(cacheFolder.resolve(ClasspathFileBasedCache.CLASSPATH_DATA_CACHE_FILE).toFile().exists());
}
Also used : Path(java.nio.file.Path) ShowMessageException(org.springframework.ide.vscode.commons.languageserver.util.ShowMessageException) DiagnosticService(org.springframework.ide.vscode.commons.languageserver.DiagnosticService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProjectCache(org.springframework.ide.vscode.commons.maven.java.MavenProjectCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) Test(org.junit.Test)

Aggregations

ProgressService (org.springframework.ide.vscode.commons.languageserver.ProgressService)5 Test (org.junit.Test)4 File (java.io.File)3 Path (java.nio.file.Path)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)2 MavenProjectCache (org.springframework.ide.vscode.commons.maven.java.MavenProjectCache)2 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 ProjectsHarness (org.springframework.ide.vscode.project.harness.ProjectsHarness)2 BootPropertiesLanguageServerComponents (org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents)1 DiagnosticService (org.springframework.ide.vscode.commons.languageserver.DiagnosticService)1 ShowMessageException (org.springframework.ide.vscode.commons.languageserver.util.ShowMessageException)1