Search in sources :

Example 26 with MavenJavaProject

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

the class JavaIndexTest method voidMethodNoParams.

@Test
public void voidMethodNoParams() throws Exception {
    MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
    IType type = project.getClasspath().findType("java.util.ArrayList");
    assertNotNull(type);
    IMethod m = type.getMethod("clear", Stream.empty());
    assertEquals("clear", m.getElementName());
    assertEquals(IVoidType.DEFAULT, m.getReturnType());
    assertEquals(0, m.parameters().count());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IMethod(org.springframework.ide.vscode.commons.java.IMethod) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 27 with MavenJavaProject

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

the class JavaIndexTest method testFindJarResource.

@Test
public void testFindJarResource() throws Exception {
    MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
    Optional<File> jar = project.getClasspath().findClasspathResourceContainer("org.springframework.boot.autoconfigure.SpringBootApplication");
    assertTrue(jar.isPresent());
    assertEquals("spring-boot-autoconfigure-1.4.1.RELEASE.jar", jar.get().getName());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) File(java.io.File) Test(org.junit.Test)

Example 28 with MavenJavaProject

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

the class JavaIndexTest method testFindJavaResource.

@Test
public void testFindJavaResource() throws Exception {
    MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
    Optional<File> file = project.getClasspath().findClasspathResourceContainer("hello.GreetingController");
    assertTrue(file.isPresent());
    assertTrue(file.get().exists());
    assertEquals(project.getClasspath().getOutputFolder().toString(), file.get().toString());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) File(java.io.File) Test(org.junit.Test)

Example 29 with MavenJavaProject

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

the class JavaIndexTest method classNotFound.

@Test
public void classNotFound() throws Exception {
    MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
    IType type = project.getClasspath().findType("hello.NonExistentClass");
    assertNull(type);
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 30 with MavenJavaProject

use of org.springframework.ide.vscode.commons.maven.java.MavenJavaProject 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)

Aggregations

MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)31 Test (org.junit.Test)27 IType (org.springframework.ide.vscode.commons.java.IType)18 IMethod (org.springframework.ide.vscode.commons.java.IMethod)10 IJavadoc (org.springframework.ide.vscode.commons.javadoc.IJavadoc)10 Path (java.nio.file.Path)5 IField (org.springframework.ide.vscode.commons.java.IField)5 File (java.io.File)4 Before (org.junit.Before)4 MockRunningAppProvider (org.springframework.ide.vscode.project.harness.MockRunningAppProvider)4 VSCodeSourceLinks (org.springframework.ide.vscode.boot.java.links.VSCodeSourceLinks)3 MavenProjectCache (org.springframework.ide.vscode.commons.maven.java.MavenProjectCache)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ProgressService (org.springframework.ide.vscode.commons.languageserver.ProgressService)2 URI (java.net.URI)1 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)1 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)1 DiagnosticService (org.springframework.ide.vscode.commons.languageserver.DiagnosticService)1 Listener (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener)1