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;
}
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();
}
}
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());
}
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);
}
}
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);
}
};
}
Aggregations