Merge branch 'master' of github.com:spring-projects/sts4

This commit is contained in:
Kris De Volder
2018-01-19 15:11:49 -08:00
5 changed files with 68 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -45,4 +45,9 @@ public class GradleProjectFinder extends FileBasedJavaProjectFinder {
public Optional<IJavaProject> find(File file) {
return FileUtils.findFile(file, PATH_MATCHERS, true).map(f -> cache.project(f));
}
@Override
protected Optional<IJavaProject> findProjectByName(String name) {
return cache.projectByName(name);
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.languageserver.java;
import java.util.Optional;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import org.springframework.ide.vscode.commons.java.IJavaProject;
@@ -62,6 +64,18 @@ public abstract class AbstractJavaProjectCache<K, P extends IJavaProject> implem
return null;
}
public Optional<IJavaProject> projectByName(String name) {
ConcurrentMap<K, P> map = cache.asMap();
for (P project : map.values()) {
if (project != null && project.getElementName().equals(name)) {
return Optional.of(project);
}
}
return Optional.empty();
}
abstract protected P createProject(K key) throws Exception;
protected void attachListeners(K key, P project) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,8 +11,10 @@
package org.springframework.ide.vscode.commons.languageserver.java;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.Optional;
import org.eclipse.lsp4j.TextDocumentIdentifier;
@@ -40,6 +42,20 @@ public abstract class FileBasedJavaProjectFinder implements JavaProjectFinder {
if (uri.getScheme().equalsIgnoreCase("file")) {
File file = new File(uri).getAbsoluteFile();
return find(file);
} else if (uri.getScheme().equalsIgnoreCase("jdt")) {
// Example of URI to be parsed (this is what we get from JDT):
// jdt://contents/spring-boot-autoconfigure-1.5.7.RELEASE.jar/org.springframework.boot.autoconfigure/SpringBootApplication.class?%3Ddemo%2F%5C%2FUsers%5C%2Fhomeuser%5C%2F.m2%5C%2Frepository%5C%2Forg%5C%2Fspringframework%5C%2Fboot%5C%2Fspring-boot-autoconfigure%5C%2F1.5.7.RELEASE%5C%2Fspring-boot-autoconfigure-1.5.7.RELEASE.jar%3Corg.springframework.boot.autoconfigure%28SpringBootApplication.class
String host = uri.getHost();
if ("contents".equals(host)) {
String query = uri.getQuery();
try {
String decoded = URLDecoder.decode(query, "UTF-8");
String projectName = getProjectName(decoded);
return findProjectByName(projectName);
} catch (UnsupportedEncodingException e) {
Log.log(e);
}
}
}
}
}
@@ -49,6 +65,24 @@ public abstract class FileBasedJavaProjectFinder implements JavaProjectFinder {
return Optional.empty();
}
private String getProjectName(String decodedQuery) {
// Example of decoded query to be parsed (this is what we get from JDT). Note that "demo" in the example below is the project name that we want to parse:
// =demo/\/Users\/homeuser\/.m2\/repository\/org\/springframework\/boot\/spring-boot-autoconfigure\/1.5.9.RELEASE\/spring-boot-autoconfigure-1.5.9.RELEASE.jar<org.springframework.boot.autoconfigure(SpringBootApplication.class
if (decodedQuery != null) {
String[] segs = decodedQuery.split("=");
if (segs.length > 1) {
String remaining = segs[1];
segs=remaining.split("\\/");
if (segs.length > 0) {
return segs[0];
}
}
}
return null;
}
protected abstract Optional<IJavaProject> findProjectByName(String name);
protected abstract Optional<IJavaProject> find(File file);
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -40,4 +40,9 @@ public class MavenProjectFinder extends FileBasedJavaProjectFinder {
}
return Optional.empty();
}
@Override
protected Optional<IJavaProject> findProjectByName(String name) {
return cache.projectByName(name);
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -42,4 +42,9 @@ public class JavaProjectWithClasspathFileFinder extends FileBasedJavaProjectFind
}
return Optional.empty();
}
@Override
protected Optional<IJavaProject> findProjectByName(String name) {
return cache.projectByName(name);
}
}