Fixed netbeans 7.4RC1 issue (JavaCompiler.version() was returning bogus values, so we now work around that javac bug).

This commit is contained in:
Reinier Zwitserloot committed 2013-09-24 01:11:13 +02:00
1 parent b81d5ef65c
commit 7ee868659f
4 files changed
+88 -9

No files matched your search

@@ -82,7 +82,7 @@ public class DebugSnapshotStore {
}
try {
File logFile = new File(System.getProperty("user.home", "."), String.format("lombok164-%d.err", System.currentTimeMillis()));
File logFile = new File(System.getProperty("user.home", "."), String.format("lombokdss-%d.err", System.currentTimeMillis()));
OutputStream stream = new FileOutputStream(logFile);
try {
stream.write(out.toString().getBytes("UTF-8"));
@@ -84,7 +84,7 @@ public class DelombokApp extends LombokApp {
return null;
}
@SuppressWarnings("resource") final JarFile toolsJarFile = new JarFile(toolsJar);
@SuppressWarnings({"resource", "all"}) final JarFile toolsJarFile = new JarFile(toolsJar);
ClassLoader loader = new ClassLoader() {
private Class<?> loadStreamAsClass(String name, boolean resolve, InputStream in) throws ClassNotFoundException {
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok.core.debug;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
public class FileLog {
private static FileOutputStream fos;
public static void log(String message) {
log(message, null);
}
public synchronized static void log(String message, Throwable t) {
try {
if (fos == null) {
fos = new FileOutputStream(new File(System.getProperty("user.home"), "LOMBOK-DEBUG-OUT.txt"));
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
fos.close();
} catch (Throwable ignore) {}
}
});
}
fos.write(message.getBytes("UTF-8"));
fos.write('\n');
if (t != null) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
fos.write(sw.toString().getBytes("UTF-8"));
fos.write('\n');
}
fos.flush();
} catch (IOException e) {
throw new IllegalStateException("Internal lombok file-based debugging not possible", e);
}
}
}
+25 -7
View File
@@ -39,6 +39,7 @@ import javax.lang.model.type.TypeVisitor;
import lombok.javac.JavacTreeMaker.TreeTag;
import lombok.javac.JavacTreeMaker.TypeTag;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.tree.JCTree;
@@ -62,6 +63,7 @@ public class Javac {
private static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile("^(boolean|byte|short|int|long|float|double|char)$");
private static final Pattern VERSION_PARSER = Pattern.compile("^(\\d{1,6})\\.(\\d{1,6}).*$");
private static final Pattern SOURCE_PARSER = Pattern.compile("^JDK(\\d{1,6})_(\\d{1,6}).*$");
private static final AtomicInteger compilerVersion = new AtomicInteger(-1);
@@ -71,13 +73,29 @@ public class Javac {
public static int getJavaCompilerVersion() {
int cv = compilerVersion.get();
if (cv != -1) return cv;
Matcher m = VERSION_PARSER.matcher(JavaCompiler.version());
if (m.matches()) {
int major = Integer.parseInt(m.group(1));
int minor = Integer.parseInt(m.group(2));
if (major == 1) {
compilerVersion.set(minor);
return minor;
/* Main algorithm: Use JavaCompiler's intended method to do this */ {
Matcher m = VERSION_PARSER.matcher(JavaCompiler.version());
if (m.matches()) {
int major = Integer.parseInt(m.group(1));
int minor = Integer.parseInt(m.group(2));
if (major == 1) {
compilerVersion.set(minor);
return minor;
}
}
}
/* Fallback algorithm one: Check Source's values. Lets hope oracle never releases a javac that recognizes future versions for -source */ {
String name = Source.values()[Source.values().length - 1].name();
Matcher m = SOURCE_PARSER.matcher(name);
if (m.matches()) {
int major = Integer.parseInt(m.group(1));
int minor = Integer.parseInt(m.group(2));
if (major == 1) {
compilerVersion.set(minor);
return minor;
}
}
}