Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -86,12 +86,9 @@ public class MavenCore {
|
||||
try {
|
||||
return new JandexIndex(getJreLibs(), jarFile -> findIndexFile(jarFile), (classpathResource) -> {
|
||||
try {
|
||||
String javaVersion = "8";
|
||||
try {
|
||||
String fullVersion = getJavaRuntimeVersion();
|
||||
javaVersion = fullVersion.substring(fullVersion.indexOf('.') + 1, fullVersion.lastIndexOf('.'));
|
||||
} catch (MavenException e) {
|
||||
Log.log("Cannot determine Java runtime version. Defaulting to version 8", e);
|
||||
String javaVersion = getJavaRuntimeMinorVersion();
|
||||
if (javaVersion == null) {
|
||||
javaVersion = "8";
|
||||
}
|
||||
URL javadocUrl = new URL("http://docs.oracle.com/javase/" + javaVersion + "/docs/api/");
|
||||
return new HtmlJavadocProvider((type) -> SourceUrlProviderFromSourceContainer.JAVADOC_FOLDER_URL_SUPPLIER.sourceUrl(javadocUrl, type));
|
||||
@@ -260,10 +257,25 @@ public class MavenCore {
|
||||
return Arrays.stream(s.split(File.pathSeparator)).map(File::new).filter(f -> f.canRead()).map(f -> Paths.get(f.toURI()));
|
||||
}
|
||||
|
||||
private String getJavaRuntimeVersion() throws MavenException {
|
||||
public String getJavaRuntimeVersion() throws MavenException {
|
||||
return maven.createExecutionRequest().getSystemProperties().getProperty(JAVA_RUNTIME_VERSION);
|
||||
}
|
||||
|
||||
public String getJavaRuntimeMinorVersion() {
|
||||
try {
|
||||
String fullVersion = getJavaRuntimeVersion();
|
||||
String[] tokenized = fullVersion.split("\\.");
|
||||
if (tokenized.length > 1) {
|
||||
return tokenized[1];
|
||||
} else {
|
||||
Log.log("Cannot determine minor version for the Java Runtime Version: " + fullVersion);
|
||||
}
|
||||
} catch (MavenException e) {
|
||||
Log.log("Cannot determine Java runtime version. Defaulting to version 8", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getJavaHome() throws MavenException {
|
||||
return maven.createExecutionRequest().getSystemProperties().getProperty(JAVA_HOME);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
@@ -52,6 +53,15 @@ public class JavaIndexTest {
|
||||
return new MavenJavaProject(projectPath.resolve(MavenCore.POM_XML).toFile());
|
||||
}
|
||||
|
||||
private static boolean javaVersionHigherThan(int version) {
|
||||
String versionStr = MavenCore.getInstance().getJavaRuntimeMinorVersion();
|
||||
try {
|
||||
return versionStr != null && Integer.valueOf(versionStr) > version;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findClassInJar() throws Exception {
|
||||
MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
|
||||
@@ -278,6 +288,7 @@ public class JavaIndexTest {
|
||||
|
||||
@Test
|
||||
public void html_testClassJavadoc() throws Exception {
|
||||
Assume.assumeTrue(javaVersionHigherThan(6));
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.HTML;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
@@ -295,6 +306,7 @@ public class JavaIndexTest {
|
||||
|
||||
@Test
|
||||
public void html_testNestedClassJavadoc() throws Exception {
|
||||
Assume.assumeTrue(javaVersionHigherThan(6));
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.HTML;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
@@ -311,6 +323,7 @@ public class JavaIndexTest {
|
||||
|
||||
@Test
|
||||
public void html_testMethodJavadoc() throws Exception {
|
||||
Assume.assumeTrue(javaVersionHigherThan(6));
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.HTML;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
@@ -332,6 +345,8 @@ public class JavaIndexTest {
|
||||
|
||||
@Test
|
||||
public void html_testConstructorJavadoc() throws Exception {
|
||||
Assume.assumeTrue(javaVersionHigherThan(6));
|
||||
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.HTML;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
|
||||
Reference in New Issue
Block a user