aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2017-01-20 00:38:10 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2017-01-20 00:38:10 +0100
commitce9fa7fb06fda7c459e381022f38564c31b41744 (patch)
tree87bd0cf8593b008e37a5b152c698e1f3c0ebfea1 /src
parent00ce9a72e6625f685da485b3338a9f52ce4227e5 (diff)
parentac2bedb8f31c73a9b92793611c9199ba95f904af (diff)
downloadlombok-ce9fa7fb06fda7c459e381022f38564c31b41744.tar.gz
lombok-ce9fa7fb06fda7c459e381022f38564c31b41744.tar.bz2
lombok-ce9fa7fb06fda7c459e381022f38564c31b41744.zip
Merge remote-tracking branch 'origin/master' into playNiceWithOtherAP
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/ConfigurationKeys.java25
-rw-r--r--src/core/lombok/core/configuration/ConfigurationApp.java2
-rw-r--r--src/core/lombok/core/handlers/HandlerUtil.java8
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java24
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java17
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java20
-rw-r--r--src/eclipseAgent/lombok/launch/PatchFixesHider.java46
-rw-r--r--src/installer/lombok/installer/IdeLocation.java7
-rw-r--r--src/installer/lombok/installer/IdeLocationProvider.java22
-rw-r--r--src/installer/lombok/installer/Installer.java17
-rw-r--r--src/installer/lombok/installer/InstallerGUI.java10
-rw-r--r--src/installer/lombok/installer/OsUtils.java (renamed from src/installer/lombok/installer/IdeFinder.java)21
-rw-r--r--src/installer/lombok/installer/eclipse/EclipseLocationProvider.java149
-rw-r--r--src/installer/lombok/installer/eclipse/EclipseProductDescriptor.java (renamed from src/installer/lombok/installer/eclipse/STSLocation.java)38
-rw-r--r--src/installer/lombok/installer/eclipse/EclipseProductLocation.java (renamed from src/installer/lombok/installer/eclipse/EclipseLocation.java)55
-rw-r--r--src/installer/lombok/installer/eclipse/EclipseProductLocationProvider.java (renamed from src/installer/lombok/installer/eclipse/EclipseFinder.java)256
-rw-r--r--src/installer/lombok/installer/eclipse/JbdsFinder.java70
-rw-r--r--src/installer/lombok/installer/eclipse/JbdsLocation.java45
-rw-r--r--src/installer/lombok/installer/eclipse/JbdsLocationProvider.java49
-rw-r--r--src/installer/lombok/installer/eclipse/MyEclipseFinder.java69
-rw-r--r--src/installer/lombok/installer/eclipse/MyEclipseLocation.java45
-rw-r--r--src/installer/lombok/installer/eclipse/MyEclipseLocationProvider.java52
-rw-r--r--src/installer/lombok/installer/eclipse/RhdsFinder.java70
-rw-r--r--src/installer/lombok/installer/eclipse/RhdsLocation.java45
-rw-r--r--src/installer/lombok/installer/eclipse/RhdsLocationProvider.java49
-rw-r--r--src/installer/lombok/installer/eclipse/STSFinder.java70
-rw-r--r--src/installer/lombok/installer/eclipse/STSLocationProvider.java48
-rw-r--r--src/installer/lombok/installer/eclipse/StandardProductDescriptor.java158
28 files changed, 591 insertions, 896 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java
index 132bde8d..ff17ca09 100644
--- a/src/core/lombok/ConfigurationKeys.java
+++ b/src/core/lombok/ConfigurationKeys.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2014 The Project Lombok Authors.
+ * Copyright (C) 2013-2017 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
@@ -41,11 +41,32 @@ public class ConfigurationKeys {
/**
* lombok configuration: {@code lombok.addGeneratedAnnotation} = {@code true} | {@code false}.
*
- * If unset or {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated.
+ * If unset or {@code true}, lombok generates various annotations to mark generated code like {@code @javax.annotation.Generated("lombok")} and {@code @lombok.Generated}.
+ *
+ * @see ConfigurationKeys#ADD_JAVAX_GENERATED_ANNOTATIONS
+ * @see ConfigurationKeys#ADD_LOMBOK_GENERATED_ANNOTATIONS
*/
public static final ConfigurationKey<Boolean> ADD_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: true).") {};
/**
+ * lombok configuration: {@code lombok.addJavaxGeneratedAnnotation} = {@code true} | {@code false}.
+ *
+ * If unset or {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated, unless {@code lombok.addGeneratedAnnotation} is set to {@code false}.
+ *
+ * @see ConfigurationKeys#ADD_GENERATED_ANNOTATIONS
+ */
+ public static final ConfigurationKey<Boolean> ADD_JAVAX_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addJavaxGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: follow lombok.addGeneratedAnnotation).") {};
+
+ /**
+ * lombok configuration: {@code lombok.addLombokGeneratedAnnotation} = {@code true} | {@code false}.
+ *
+ * If unset or {@code true}, lombok generates {@code @lombok.Generated} on all fields, methods, and types that are generated, unless {@code lombok.addGeneratedAnnotation} is set to {@code false}.
+ *
+ * @see ConfigurationKeys#ADD_GENERATED_ANNOTATIONS
+ */
+ public static final ConfigurationKey<Boolean> ADD_LOMBOK_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addLombokGeneratedAnnotation", "Generate @lombok.Generated on all generated code (default: follow lombok.addGeneratedAnnotation).") {};
+
+ /**
* lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}.
*
* If {@code true}, lombok generates {@code edu.umd.cs.findbugs.annotations.SuppressFBWarnings} on all fields, methods, and types that are generated.
diff --git a/src/core/lombok/core/configuration/ConfigurationApp.java b/src/core/lombok/core/configuration/ConfigurationApp.java
index e441b4de..efe57e38 100644
--- a/src/core/lombok/core/configuration/ConfigurationApp.java
+++ b/src/core/lombok/core/configuration/ConfigurationApp.java
@@ -198,7 +198,7 @@ public class ConfigurationApp extends LombokApp {
if (paths.size() == 1) {
if (!(argsPaths.size() == 1)) out.printf("Configuration for '%s'.%n%n", paths.iterator().next());
} else {
- out.printf("Configuration for:%n", paths.iterator().next());
+ out.printf("Configuration for:%n");
for (String path : paths) out.printf("- %s%n", path);
out.println();
}
diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java
index ef4ac7d6..a05578d4 100644
--- a/src/core/lombok/core/handlers/HandlerUtil.java
+++ b/src/core/lombok/core/handlers/HandlerUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2015 The Project Lombok Authors.
+ * Copyright (C) 2013-2017 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
@@ -109,6 +109,12 @@ public class HandlerUtil {
}
}
+ public static boolean shouldAddGenerated(LombokNode<?, ?, ?> node, ConfigurationKey<Boolean> key) {
+ Boolean add = node.getAst().readConfiguration(key);
+ if (add != null) return add;
+ return !Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS));
+ }
+
public static void handleExperimentalFlagUsage(LombokNode<?, ?, ?> node, ConfigurationKey<FlagUsageType> key, String featureName) {
handleFlagUsage(node, key, featureName, ConfigurationKeys.EXPERIMENTAL_FLAG_USAGE, "any lombok.experimental feature");
}
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 76251225..f822e095 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-2017 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
@@ -1329,6 +1329,7 @@ public class EclipseHandlerUtil {
private static final char[] GENERATED_CODE = "generated code".toCharArray();
private static final char[] LOMBOK = "lombok".toCharArray();
private static final char[][] JAVAX_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("javax.annotation.Generated");
+ private static final char[][] LOMBOK_GENERATED = Eclipse.fromQualifiedName("lombok.Generated");
private static final char[][] EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS = Eclipse.fromQualifiedName("edu.umd.cs.findbugs.annotations.SuppressFBWarnings");
public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
@@ -1343,24 +1344,29 @@ public class EclipseHandlerUtil {
}
public static Annotation[] addGenerated(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
- if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) return originalAnnotationArray;
- return addAnnotation(source, originalAnnotationArray, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0));
+ Annotation[] result = originalAnnotationArray;
+ if (HandlerUtil.shouldAddGenerated(node, ConfigurationKeys.ADD_JAVAX_GENERATED_ANNOTATIONS)) {
+ result = addAnnotation(source, result, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0));
+ }
+ if (HandlerUtil.shouldAddGenerated(node, ConfigurationKeys.ADD_LOMBOK_GENERATED_ANNOTATIONS)) {
+ result = addAnnotation(source, result, LOMBOK_GENERATED, null);
+ }
+ return result;
}
private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, ASTNode arg) {
char[] simpleName = annotationTypeFqn[annotationTypeFqn.length - 1];
if (originalAnnotationArray != null) for (Annotation ann : originalAnnotationArray) {
- char[] lastToken = null;
-
if (ann.type instanceof QualifiedTypeReference) {
char[][] t = ((QualifiedTypeReference) ann.type).tokens;
- lastToken = t[t.length - 1];
- } else if (ann.type instanceof SingleTypeReference) {
- lastToken = ((SingleTypeReference) ann.type).token;
+ if (Arrays.deepEquals(t, annotationTypeFqn)) return originalAnnotationArray;
}
- if (lastToken != null && Arrays.equals(simpleName, lastToken)) return originalAnnotationArray;
+ if (ann.type instanceof SingleTypeReference) {
+ char[] lastToken = ((SingleTypeReference) ann.type).token;
+ if (Arrays.equals(lastToken, simpleName)) return originalAnnotationArray;
+ }
}
int pS = source.sourceStart, pE = source.sourceEnd;
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index af6bb48f..0b4e839d 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -1025,9 +1025,12 @@ public class JavacHandlerUtil {
public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) {
if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateGenerated()) return;
- if (!Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) {
+ if (HandlerUtil.shouldAddGenerated(node, ConfigurationKeys.ADD_JAVAX_GENERATED_ANNOTATIONS)) {
addAnnotation(mods, node, pos, source, context, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok"));
}
+ if (HandlerUtil.shouldAddGenerated(node, ConfigurationKeys.ADD_LOMBOK_GENERATED_ANNOTATIONS)) {
+ addAnnotation(mods, node, pos, source, context, "lombok.Generated", null);
+ }
}
private static void addAnnotation(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context, String annotationTypeFqn, JCExpression arg) {
@@ -1041,12 +1044,16 @@ public class JavacHandlerUtil {
for (JCAnnotation ann : mods.annotations) {
JCTree annType = ann.getAnnotationType();
- Name lastPart = null;
- if (annType instanceof JCIdent) lastPart = ((JCIdent) annType).name;
- else if (annType instanceof JCFieldAccess) lastPart = ((JCFieldAccess) annType).name;
+ if (annType instanceof JCIdent) {
+ Name lastPart = ((JCIdent) annType).name;
+ if (lastPart.contentEquals(simpleName)) return;
+ }
- if (lastPart != null && lastPart.contentEquals(simpleName)) return;
+ if (annType instanceof JCFieldAccess) {
+ if (annType.toString().equals(annotationTypeFqn)) return;
+ }
}
+
JavacTreeMaker maker = node.getTreeMaker();
JCExpression annType = isJavaLangBased ? genJavaLangTypeRef(node, simpleName) : chainDotsString(node, annotationTypeFqn);
annType.pos = pos;
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index 4b18dc0f..77f615b5 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -30,6 +30,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
+
import lombok.core.AgentLauncher;
import lombok.patcher.Filter;
import lombok.patcher.Hook;
@@ -120,10 +122,28 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
patchLombokizeAST(sm);
patchEcjTransformers(sm, ecjOnly);
patchExtensionMethod(sm, ecjOnly);
+ patchRenameField(sm);
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
+ private static void patchRenameField(ScriptManager sm) {
+ /* RefactoringSearchEngine.search will not return results when renaming field and Data Annotation is present. Return a fake Element to make checks pass */
+ sm.addScript(ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor", "checkAccessorDeclarations", "org.eclipse.ltk.core.refactoring.RefactoringStatus", "org.eclipse.core.runtime.IProgressMonitor", "org.eclipse.jdt.core.IMethod"))
+ .methodToWrap(new Hook("org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine", "search", "org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup[]", "org.eclipse.jdt.core.search.SearchPattern","org.eclipse.jdt.core.search.IJavaSearchScope","org.eclipse.core.runtime.IProgressMonitor","org.eclipse.ltk.core.refactoring.RefactoringStatus"))
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "createFakeSearchResult", "org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup[]", "org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup[]", "java.lang.Object"))
+ .requestExtra(StackRequest.THIS)
+ .transplant().build());
+
+ /* Filter search results which are Generated and based on Fields, e.g. Generated getters/setters */
+ sm.addScript(ScriptBuilder.wrapMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor", "addAccessorOccurrences", "void", "org.eclipse.core.runtime.IProgressMonitor", "org.eclipse.jdt.core.IMethod", "java.lang.String","java.lang.String","org.eclipse.ltk.core.refactoring.RefactoringStatus"))
+ .methodToWrap(new Hook("org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup", "getSearchResults", "org.eclipse.jdt.core.search.SearchMatch[]"))
+ .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGenerated", "org.eclipse.jdt.core.search.SearchMatch[]", "org.eclipse.jdt.core.search.SearchMatch[]"))
+ .transplant().build());
+ }
+
private static void patchExtractInterface(ScriptManager sm) {
/* Fix sourceEnding for generated nodes to avoid null pointer */
sm.addScript(ScriptBuilder.wrapMethodCall()
diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index fae06900..b1d73352 100644
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -36,11 +36,13 @@ import lombok.eclipse.EclipseAugments;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
@@ -55,9 +57,11 @@ import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
+import org.eclipse.jdt.internal.core.SourceField;
import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent;
import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent;
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
+import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
/** These contain a mix of the following:
@@ -565,6 +569,48 @@ final class PatchFixesHider {
return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]);
}
+ public static SearchMatch[] removeGenerated(SearchMatch[] returnValue) {
+ List<SearchMatch> result = new ArrayList<SearchMatch>();
+ for (int j = 0; j < returnValue.length; j++) {
+ SearchMatch searchResult = returnValue[j];
+ if (searchResult.getElement() instanceof IField) {
+ IField field = (IField) searchResult.getElement();
+
+ // can not check for value=lombok because annotation is
+ // not fully resolved
+ IAnnotation annotation = field.getAnnotation("Generated");
+ if (annotation != null) {
+ // Method generated at field location, skip
+ continue;
+ }
+
+ }
+ result.add(searchResult);
+ }
+ return result.toArray(new SearchMatch[result.size()]);
+ }
+
+ public static SearchResultGroup[] createFakeSearchResult(SearchResultGroup[] returnValue,
+ Object/*
+ * org.eclipse.jdt.internal.corext.refactoring.rename.
+ * RenameFieldProcessor
+ */ processor) throws Exception {
+ if (returnValue == null || returnValue.length == 0) {
+ // if no matches were found, check if Data annotation is present on the class
+ Field declaredField = processor.getClass().getDeclaredField("fField");
+ if (declaredField != null) {
+ declaredField.setAccessible(true);
+ SourceField fField = (SourceField) declaredField.get(processor);
+ IAnnotation dataAnnotation = fField.getDeclaringType().getAnnotation("Data");
+ if (dataAnnotation != null) {
+ // add fake item, to make refactoring checks pass
+ return new SearchResultGroup[] {new SearchResultGroup(null, new SearchMatch[1])};
+ }
+ }
+ }
+ return returnValue;
+ }
+
public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception {
Field f = SimpleName.class.getField("$isGenerated");
diff --git a/src/installer/lombok/installer/IdeLocation.java b/src/installer/lombok/installer/IdeLocation.java
index 4e3a7e41..c3853867 100644
--- a/src/installer/lombok/installer/IdeLocation.java
+++ b/src/installer/lombok/installer/IdeLocation.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -25,7 +25,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
-import lombok.installer.eclipse.EclipseFinder;
import lombok.patcher.ClassRootFinder;
/**
@@ -46,7 +45,7 @@ public abstract class IdeLocation {
* a jar that wasn't accessed via the file-system, or if its started via e.g. unpacking the jar.
*/
public static File findOurJar() {
- return new File(ClassRootFinder.findClassRootOfClass(IdeFinder.class));
+ return new File(ClassRootFinder.findClassRootOfClass(OsUtils.class));
}
@Override public String toString() {
@@ -70,7 +69,7 @@ public abstract class IdeLocation {
private static final String LEGAL_PATH_CHARS_WINDOWS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/:\\ ";
public static String escapePath(String path) {
StringBuilder out = new StringBuilder();
- String legalChars = IdeFinder.getOS() == EclipseFinder.OS.UNIX ? LEGAL_PATH_CHARS : LEGAL_PATH_CHARS_WINDOWS;
+ String legalChars = OsUtils.getOS() == OsUtils.OS.UNIX ? LEGAL_PATH_CHARS : LEGAL_PATH_CHARS_WINDOWS;
for (char c : path.toCharArray()) {
if (legalChars.indexOf(c) == -1) out.append('\\');
out.append(c);
diff --git a/src/installer/lombok/installer/IdeLocationProvider.java b/src/installer/lombok/installer/IdeLocationProvider.java
index 933a5989..c4b64141 100644
--- a/src/installer/lombok/installer/IdeLocationProvider.java
+++ b/src/installer/lombok/installer/IdeLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -21,20 +21,30 @@
*/
package lombok.installer;
+import java.util.List;
import java.util.regex.Pattern;
-import lombok.installer.IdeFinder.OS;
-
public interface IdeLocationProvider {
/**
* @throws CorruptedIdeLocationException
* Only throw this exception if the location seems like a proper installation except there's something wrong with it.
* Do not throw it (just return {@code null}) if there's nothing there or it looks absolutely nothing like your IDE.
*/
- public abstract IdeLocation create(String path) throws CorruptedIdeLocationException;
+ IdeLocation create(String path) throws CorruptedIdeLocationException;
+
+ /**
+ * Return the usual name of the IDE executable or other obvious marker of an IDE installation on the current platform.
+ */
+ Pattern getLocationSelectors();
/**
- * Return the usual name of the IDE executable or other obvious marker of an IDE installation on the provided platform.
+ * Look for installations of your IDE in the usual places.
+ *
+ * @param locations Add to this list any valid locations that you found.
+ * @param problems
+ * Add to this list any locations that look like installations,
+ * but have problems that prevent you from installing/uninstalling from them. DONT add to this list
+ * any common locations that have no installation at all - only add near misses.
*/
- public abstract Pattern getLocationSelectors(OS os);
+ void findIdes(List<IdeLocation> locations, List<CorruptedIdeLocationException> problems);
}
diff --git a/src/installer/lombok/installer/Installer.java b/src/installer/lombok/installer/Installer.java
index 7ae01d7a..94cc1a45 100644
--- a/src/installer/lombok/installer/Installer.java
+++ b/src/installer/lombok/installer/Installer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -38,7 +38,7 @@ import lombok.Lombok;
import lombok.core.LombokApp;
import lombok.core.SpiLoadUtil;
import lombok.core.Version;
-import lombok.installer.IdeFinder.OS;
+import lombok.installer.OsUtils.OS;
import lombok.patcher.ClassRootFinder;
import org.mangosdk.spi.ProviderFor;
@@ -72,10 +72,9 @@ public class Installer {
}
static List<Pattern> getIdeExecutableNames() {
- OS os = IdeFinder.getOS();
List<Pattern> list = new ArrayList<Pattern>();
for (IdeLocationProvider provider : locationProviders) {
- Pattern p = provider.getLocationSelectors(os);
+ Pattern p = provider.getLocationSelectors();
if (p != null) list.add(p);
}
return list;
@@ -91,12 +90,8 @@ public class Installer {
}
static void autoDiscover(List<IdeLocation> locations, List<CorruptedIdeLocationException> problems) {
- try {
- for (IdeFinder finder : SpiLoadUtil.findServices(IdeFinder.class)) {
- finder.findIdes(locations, problems);
- }
- } catch (IOException e) {
- throw Lombok.sneakyThrow(e);
+ for (IdeLocationProvider provider : locationProviders) {
+ provider.findIdes(locations, problems);
}
}
@@ -160,7 +155,7 @@ public class Installer {
}
private static int guiInstaller() {
- if (IdeFinder.getOS() == OS.MAC_OS_X) {
+ if (OsUtils.getOS() == OS.MAC_OS_X) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Lombok Installer");
System.setProperty("com.apple.macos.use-file-dialog-packages", "true");
}
diff --git a/src/installer/lombok/installer/InstallerGUI.java b/src/installer/lombok/installer/InstallerGUI.java
index 6b8a58ab..ebdf2035 100644
--- a/src/installer/lombok/installer/InstallerGUI.java
+++ b/src/installer/lombok/installer/InstallerGUI.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -67,7 +67,7 @@ import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
import lombok.core.Version;
-import lombok.installer.IdeFinder.OS;
+import lombok.installer.OsUtils.OS;
/**
* The lombok GUI installer.
@@ -313,7 +313,7 @@ public class InstallerGUI {
final List<Pattern> exeNames = Installer.getIdeExecutableNames();
String file = null;
- if (IdeFinder.getOS() == OS.MAC_OS_X) {
+ if (OsUtils.getOS() == OS.MAC_OS_X) {
FileDialog chooser = new FileDialog(appWindow);
chooser.setMode(FileDialog.LOAD);
@@ -740,7 +740,7 @@ public class InstallerGUI {
} catch (Exception e) {
Runtime rt = Runtime.getRuntime();
try {
- switch (IdeFinder.getOS()) {
+ switch (OsUtils.getOS()) {
case WINDOWS:
String[] cmd = new String[4];
cmd[0] = "cmd.exe";
@@ -781,7 +781,7 @@ public class InstallerGUI {
*/
public void show() {
appWindow.setVisible(true);
- if (IdeFinder.getOS() == OS.MAC_OS_X) {
+ if (OsUtils.getOS() == OS.MAC_OS_X) {
try {
AppleNativeLook.go();
} catch (Throwable ignore) {
diff --git a/src/installer/lombok/installer/IdeFinder.java b/src/installer/lombok/installer/OsUtils.java
index f68a0e4c..2da7de09 100644
--- a/src/installer/lombok/installer/IdeFinder.java
+++ b/src/installer/lombok/installer/OsUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -34,9 +34,13 @@ import lombok.core.Version;
/**
* Implement and provide this class to add auto-finding a certain brand of IDEs to the lombok installer.
*/
-public abstract class IdeFinder {
+public final class OsUtils {
private static final AtomicBoolean windowsDriveInfoLibLoaded = new AtomicBoolean(false);
+ private OsUtils() {
+ // Prevent instantiation
+ }
+
private static void loadWindowsDriveInfoLib() throws IOException {
if (!windowsDriveInfoLibLoaded.compareAndSet(false, true)) return;
@@ -63,7 +67,7 @@ public abstract class IdeFinder {
}
private static boolean unpackDLL(String dllName, File target) throws IOException {
- InputStream in = IdeFinder.class.getResourceAsStream(dllName);
+ InputStream in = OsUtils.class.getResourceAsStream(dllName);
try {
try {
FileOutputStream out = new FileOutputStream(target);
@@ -130,15 +134,4 @@ public abstract class IdeFinder {
return OS.UNIX;
}
-
- /**
- * Look for installations of your IDE in the usual places.
- *
- * @param locations Add to this list any valid locations that you found.
- * @param problems
- * Add to this list any locations that look like installations,
- * but have problems that prevent you from installing/uninstalling from them. DONT add to this list
- * any common locations that have no installation at all - only add near misses.
- */
- public abstract void findIdes(List<IdeLocation> locations, List<CorruptedIdeLocationException> problems);
}
diff --git a/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java b/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java
index 29716a1f..fa2ce958 100644
--- a/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java
+++ b/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 The Project Lombok Authors.
+ * Copyright (C) 2009-2016 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
@@ -21,145 +21,24 @@
*/
package lombok.installer.eclipse;
-import static lombok.installer.IdeLocation.canonical;
+import java.util.Collections;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import lombok.installer.IdeLocation;
import lombok.installer.IdeLocationProvider;
-import lombok.installer.CorruptedIdeLocationException;
-import lombok.installer.IdeFinder.OS;
import org.mangosdk.spi.ProviderFor;
@ProviderFor(IdeLocationProvider.class)
-public class EclipseLocationProvider implements IdeLocationProvider {
- @Override public IdeLocation create(String path) throws CorruptedIdeLocationException {
- return create0(path);
- }
-
- protected List<String> getEclipseExecutableNames() {
- return Arrays.asList("eclipse.app", "eclipse.exe", "eclipse");
- }
-
- protected String getIniName() {
- return "eclipse.ini";
- }
-
- protected IdeLocation makeLocation(String name, File ini) throws CorruptedIdeLocationException {
- return new EclipseLocation(name, ini);
- }
-
- protected String getMacAppName() {
- return "Eclipse.app";
- }
-
- protected String getUnixAppName() {
- return "eclipse";
- }
-
- /**
- * Create a new EclipseLocation by pointing at either the directory contains the Eclipse executable, or the executable itself,
- * or an eclipse.ini file.
- *
- * @throws NotAnIdeLocationException
- * If this isn't an Eclipse executable or a directory with an
- * Eclipse executable.
- */
- protected IdeLocation create0(String path) throws CorruptedIdeLocationException {
- if (path == null) throw new NullPoint