Attempt to fix the tests for symlinks src.zip

This commit is contained in:
BoykoAlex
2018-11-07 20:07:45 -05:00
parent 2e6238a2b7
commit d3faadef7b
2 changed files with 25 additions and 33 deletions

View File

@@ -55,39 +55,30 @@ public class BootProjectUtil {
}
public static Path jreSources(Path libJar) {
System.out.println("LIB JAR: " + libJar);
Path home = javaHomeFromLibJar(libJar);
if (home != null) {
System.out.println("Trying java-home " + home);
// Path sources = home.resolve("src.zip");
try {
Files.list(home).forEach(p -> System.out.println("entry=" + p + " exists=" + Files.exists(p) + " readable=" + Files.isReadable(p) + " symbolicLink=" + Files.isSymbolicLink(p)));
} catch (IOException e) {
e.printStackTrace();
Path sources = sourceZip(home);
if (sources == null) {
sources = sourceZip(home.resolve("lib"));
}
try {
return Files.list(home).filter(p -> p.endsWith("src.zip")).findFirst().orElseGet(() -> {
try {
return Files.list(home.resolve("lib")).filter(p -> p.endsWith("src.zip")).findFirst().orElse(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// if (Files.isReadable(sources)) {
// return sources;
// }
// sources = home.resolve("lib/src.zip");
// if (Files.isReadable(sources)) {
// return sources;
// }
return sources;
}
return null;
}
private static Path sourceZip(Path containerFolder) {
Path sourcesZip = containerFolder.resolve("src.zip");
if (Files.isReadable(sourcesZip)) {
return sourcesZip;
} else if (Files.isSymbolicLink(sourcesZip)) {
try {
Path realPath = sourcesZip.toRealPath();
System.out.println("Symlink points to -> " + realPath);
return realPath;
} catch (IOException e) {
log.error("", e);
}
}
return null;
}
}

View File

@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.maven.java;
import java.io.File;
import java.net.URL;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
@@ -87,14 +88,14 @@ public class MavenProjectClasspath implements IClasspath {
if (javaVersion == null) {
javaVersion = "8";
}
// try {
cpe.setSourceContainerUrl(BootProjectUtil.jreSources(path).toUri().toURL());
// } catch (Throwable t) {
// t.printStackTrace();
// }
cpe.setJavadocContainerUrl(new URL("https://docs.oracle.com/javase/" + javaVersion + "/docs/api/"));
cpe.setSystem(true);
entries.add(cpe);
// Add at the end, not critical if throws exception, but the CPE needs to be around regardless if the below throws
Path sources = BootProjectUtil.jreSources(path);
if (sources != null) {
cpe.setSourceContainerUrl(sources.toUri().toURL());
}
})));
//Add jar dependencies...
for (Artifact a : projectDependencies(project)) {