From d3faadef7b9a223a632982395ec417c713bbde44 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Wed, 7 Nov 2018 20:07:45 -0500 Subject: [PATCH] Attempt to fix the tests for symlinks src.zip --- .../vscode/commons/java/BootProjectUtil.java | 47 ++++++++----------- .../maven/java/MavenProjectClasspath.java | 11 +++-- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/BootProjectUtil.java b/headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/BootProjectUtil.java index 8dc5cb4db..be276fb01 100644 --- a/headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/BootProjectUtil.java +++ b/headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/BootProjectUtil.java @@ -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; + } } diff --git a/headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/MavenProjectClasspath.java b/headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/MavenProjectClasspath.java index f735e467a..ee81afbfb 100644 --- a/headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/MavenProjectClasspath.java +++ b/headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/MavenProjectClasspath.java @@ -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)) {