diff options
-rw-r--r-- | src/core/lombok/core/configuration/FileSystemSourceCache.java | 47 | ||||
-rw-r--r-- | src/core/lombok/eclipse/EclipseAST.java | 27 |
2 files changed, 63 insertions, 11 deletions
diff --git a/src/core/lombok/core/configuration/FileSystemSourceCache.java b/src/core/lombok/core/configuration/FileSystemSourceCache.java index d502a56b..12516557 100644 --- a/src/core/lombok/core/configuration/FileSystemSourceCache.java +++ b/src/core/lombok/core/configuration/FileSystemSourceCache.java @@ -24,6 +24,7 @@ package lombok.core.configuration; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.net.URI; import java.util.Collections; import java.util.Iterator; @@ -34,6 +35,10 @@ import java.util.concurrent.TimeUnit; import lombok.ConfigurationKeys; import lombok.core.configuration.ConfigurationSource.Result; +import lombok.eclipse.handlers.EclipseHandlerUtil; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; public class FileSystemSourceCache { private static String LOMBOK_CONFIG_FILENAME = "lombok.config"; @@ -47,9 +52,47 @@ public class FileSystemSourceCache { URI uri = javaFile.normalize(); if (!uri.isAbsolute()) { uri = new File(".").toURI().resolve(uri); + reporter.report(javaFile.toString(), "Somehow ended up with a relative path. This is a bug that the lombok authors cannot reproduce, so please help us out! Is this path: \"" + uri.toString() + "\" the correct absolute path for resource \"" + javaFile + "\"? If yes, or no, please report back to: https://code.google.com/p/projectlombok/issues/detail?id=683 and let us know. Thanks!", 0, ""); + } + try { + return sourcesForDirectory(new File(uri).getParentFile(), reporter); + } catch (Exception e) { + // possibly eclipse knows how to open this thing. Let's try! + int filesOpenedWithEclipse = 0; + String specialEclipseMessage = null; + try { + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri); + if (files == null) specialEclipseMessage = ".findFilesForLocationURI returned 'null'"; + for (IFile file : files) { + InputStream in = file.getContents(true); + if (in != null) { + filesOpenedWithEclipse++; + in.close(); + } + } + if (filesOpenedWithEclipse == 0) specialEclipseMessage = ".findFilesForLocationURI did work and returned " + files.length + " entries, but none of those resulted in readable contents."; + } catch (Throwable t) { + // That's unfortunate. + } + + StringBuilder sb = new StringBuilder(); + sb.append("Lombok is trying to find the directory on disk where source file \"").append(javaFile.toString()); + sb.append("\" is located. We're trying to turn this URL into a file: \"").append(uri.toString()); + sb.append("\" but that isn't working. Please help us out by going to "); + sb.append("https://code.google.com/p/projectlombok/issues/detail?id=683 and reporting this error. Thanks!\n\n"); + sb.append("Exception thrown: ").append(e.getClass().getName()).append("\nException msg: ").append(e.getMessage()); + if (specialEclipseMessage == null && filesOpenedWithEclipse > 0) { + sb.append("\n\n Alternate strategy to read this resource via eclipse DID WORK however!! files read: " + filesOpenedWithEclipse); + } else if (specialEclipseMessage != null) { + sb.append("\n\n Alternate strategy to read this resource via eclipse produced a noteworthy result: ").append(specialEclipseMessage).append(" files read: ").append(filesOpenedWithEclipse); + } + + reporter.report(javaFile.toString(), sb.toString(), 0, ""); + try { + EclipseHandlerUtil.warning(sb.toString(), null); + } catch (Throwable ignore) {} + return Collections.emptyList(); } - - return sourcesForDirectory(new File(uri).getParentFile(), reporter); } public Iterable<ConfigurationSource> sourcesForDirectory(URI directory, ConfigurationProblemReporter reporter) { diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index 74c60950..6e3f1847 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -34,6 +34,7 @@ import java.util.List; import lombok.Lombok; import lombok.core.AST; import lombok.core.LombokImmutableList; +import lombok.eclipse.handlers.EclipseHandlerUtil; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; @@ -88,18 +89,19 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { // * Either way there are sufficiently many WTF situations, that in case of error, as painful as this is, we should just carry on and not apply lombok.config, though at least if we don't recognize the scenario we should write a log file imploring the user to send us a bunch of feedback on the situation. // Relevant issues: Comment 2 on #683, all of #682 if (!skipEclipseWorkspaceBasedFileResolver) { - if (Boolean.TRUE) throw new IllegalArgumentException("Here's the alt strat result: " + getAlternativeAbsolutePath()); +// if (Boolean.FALSE) throw new IllegalArgumentException("Here's the alt strat result: " + getAlternativeAbsolutePathDEBUG()); try { /*if (fileName.startsWith("/") && fileName.indexOf('/', 1) > -1) */ try { return EclipseWorkspaceBasedFileResolver.resolve(fileName); } catch (IllegalArgumentException e) { - String msg = e.getMessage(); - if (msg != null && msg.startsWith("Path must include project and resource name")) { - // We shouldn't throw an exception at all, but we can't reproduce this so we need help from our users to figure this out. - // Let's bother them with an error that slows their eclipse down to a crawl and makes it unusable. - throw new IllegalArgumentException("Path resolution for lombok.config failed. Path: " + fileName + " -- package of this class: " + this.getPackageDeclaration()); - } else throw e; + EclipseHandlerUtil.warning("Finding 'lombok.config' file failed for '" + fileName + "'", e); +// String msg = e.getMessage(); +// if (msg != null && msg.startsWith("Path must include project and resource name")) { +// // We shouldn't throw an exception at all, but we can't reproduce this so we need help from our users to figure this out. +// // Let's bother them with an error that slows their eclipse down to a crawl and makes it unusable. +// throw new IllegalArgumentException("Path resolution for lombok.config failed. Path: " + fileName + " -- package of this class: " + this.getPackageDeclaration()); +// } else throw e; } } catch (NoClassDefFoundError e) { skipEclipseWorkspaceBasedFileResolver = true; @@ -108,10 +110,17 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { // Our fancy workspace based source file to absolute disk location algorithm only works in a fully fledged eclipse. // This fallback works when using 'ecj', which has a much simpler project/path system. For example, no 'linked' resources. - return new File(fileName).getAbsoluteFile().toURI(); + + try { + return new File(fileName).getAbsoluteFile().toURI(); + } catch (Exception e) { + // This is a temporary workaround while we try and gather all the various exotic shenanigans where lombok.config resolution is not going to work! + return null; + } } - private String getAlternativeAbsolutePath() { + /** This is ongoing research for issues with lombok.config resolution. */ + @SuppressWarnings("unused") private String getAlternativeAbsolutePathDEBUG() { try { ICompilationUnit cu = this.compilationUnitDeclaration.compilationResult.compilationUnit; |