aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-09-24 01:11:13 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-09-24 01:11:13 +0200
commit7ee868659f4ff3cb286b676d649e8c57e9248d87 (patch)
tree49b83448191544bf19455ed01bb7b086a0b44fe6 /src/utils
parentb81d5ef65cbe25d120df8a456999ab04a5467d94 (diff)
downloadlombok-7ee868659f4ff3cb286b676d649e8c57e9248d87.tar.gz
lombok-7ee868659f4ff3cb286b676d649e8c57e9248d87.tar.bz2
lombok-7ee868659f4ff3cb286b676d649e8c57e9248d87.zip
Fixed netbeans 7.4RC1 issue (JavaCompiler.version() was returning bogus values, so we now work around that javac bug).
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/lombok/core/debug/FileLog.java61
-rw-r--r--src/utils/lombok/javac/Javac.java32
2 files changed, 86 insertions, 7 deletions
diff --git a/src/utils/lombok/core/debug/FileLog.java b/src/utils/lombok/core/debug/FileLog.java
new file mode 100644
index 00000000..dedec40e
--- /dev/null
+++ b/src/utils/lombok/core/debug/FileLog.java
@@ -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);
+ }
+ }
+}
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 2f3c9be4..554c778d 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -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;
+ }
}
}