Skip to content

Commit

Permalink
Added support for installing/uninstalling eclipse support from all ec…
Browse files Browse the repository at this point in the history
…lipse locations that lombok is automatically able to find, from the command line without interaction (for mass deployment)
  • Loading branch information
Reinier Zwitserloot committed Nov 25, 2009
1 parent 66d4709 commit 6c22449
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 30 deletions.
19 changes: 12 additions & 7 deletions src/lombok/installer/EclipseFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ static List<String> getDrivesOnWindows() throws Throwable {

return drives;
}

/**
* Returns a list of paths of Eclipse installations.
* Eclipse installations are found by checking for the existence of 'eclipse.exe' in the following locations:
*
* X:\*Program Files*\*Eclipse*
* X:\*Eclipse*
* <ul>
* <li>X:\*Program Files*\*Eclipse*</li>
* <li>X:\*Eclipse*</li>
* </ul>
*
* Where 'X' is tried for all local disk drives, unless there's a problem calling fsutil, in which case only
* C: is tried.
Expand Down Expand Up @@ -204,9 +205,13 @@ private static String findEclipseOnWindows1(File dir) {
* Calls the OS-dependent 'find Eclipse' routine. If the local OS doesn't have a routine written for it,
* null is returned.
*
* @param locations List of valid eclipse locations - provide an empty list; this method will fill it.
* @param problems List of eclipse locations that seem to contain half-baked eclipses that can't be installed.
* Provide an empty list; this method will fill it.
* @param locations
* List of valid eclipse locations - provide an empty list; this
* method will fill it.
* @param problems
* List of eclipse locations that seem to contain half-baked
* eclipses that can't be installed. Provide an empty list; this
* method will fill it.
*/
static void findEclipses(List<EclipseLocation> locations, List<NotAnEclipseException> problems) {
switch (getOS()) {
Expand Down
24 changes: 14 additions & 10 deletions src/lombok/installer/EclipseLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ private EclipseLocation(String nameOfLocation, File pathToEclipseIni) throws Not
* Create a new EclipseLocation by pointing at either the directory contain the Eclipse executable, or the executable itself,
* or an eclipse.ini file.
*
* @throws NotAnEclipseException If this isn't an Eclipse executable or a directory with an Eclipse executable.
* @throws NotAnEclipseException
* If this isn't an Eclipse executable or a directory with an
* Eclipse executable.
*/
public static EclipseLocation create(String path) throws NotAnEclipseException {
if (path == null) throw new NullPointerException("path");
Expand Down Expand Up @@ -130,7 +132,6 @@ public static EclipseLocation create(String path) throws NotAnEclipseException {
}

private static EclipseLocation findEclipseIniFromExe(File exePath, int loopCounter) throws NotAnEclipseException {
System.out.println(exePath);
/* Try looking for eclipse.ini as sibling to the executable */ {
File ini = new File(exePath.getParentFile(), "eclipse.ini");
if (ini.isFile()) return new EclipseLocation(getFilePath(exePath), ini);
Expand All @@ -147,7 +148,7 @@ private static EclipseLocation findEclipseIniFromExe(File exePath, int loopCount
String oPath = exePath.getAbsolutePath();
String nPath = exePath.getCanonicalPath();
if (!oPath.equals(nPath)) try {
return findEclipseIniFromExe(new File(nPath), loopCounter +1);
return findEclipseIniFromExe(new File(nPath), loopCounter + 1);
} catch (NotAnEclipseException ignore) {
// Unlinking didn't help find an eclipse, so continue.
}
Expand Down Expand Up @@ -215,7 +216,7 @@ boolean hasLombok() {
"^\\-javaagent\\:.*lombok.*\\.jar$", Pattern.CASE_INSENSITIVE);

private final Pattern BOOTCLASSPATH_LINE_MATCHER = Pattern.compile(
"^\\-Xbootclasspath\\/a\\:(.*lombok.*\\.jar.*)$", Pattern.CASE_INSENSITIVE);
"^\\-Xbootclasspath\\/a\\:(.*lombok.*\\.jar.*)$", Pattern.CASE_INSENSITIVE);

private boolean checkForLombok(File iniFile) throws IOException {
if (!iniFile.exists()) return false;
Expand Down Expand Up @@ -257,8 +258,10 @@ private List<File> getUninstallDirs() {
* It's a no-op if lombok wasn't there in the first place,
* and it will remove a half-succeeded lombok installation as well.
*
* @throws UninstallException If there's an obvious I/O problem that is preventing installation.
* bugs in the uninstall code will probably throw other exceptions; this is intentional.
* @throws UninstallException
* If there's an obvious I/O problem that is preventing
* installation. bugs in the uninstall code will probably throw
* other exceptions; this is intentional.
*/
void uninstall() throws UninstallException {
for (File dir : getUninstallDirs()) {
Expand Down Expand Up @@ -319,8 +322,7 @@ void uninstall() throws UninstallException {
fos.close();
}
} catch (IOException e) {
throw new UninstallException("Cannot uninstall lombok from " + name +
generateWriteErrorMessage(), e);
throw new UninstallException("Cannot uninstall lombok from " + name + generateWriteErrorMessage(), e);
}
}
}
Expand Down Expand Up @@ -356,8 +358,10 @@ private static String generateWriteErrorMessage() {
* Install lombok into the Eclipse at this location.
* If lombok is already there, it is overwritten neatly (upgrade mode).
*
* @throws InstallException If there's an obvious I/O problem that is preventing installation.
* bugs in the install code will probably throw other exceptions; this is intentional.
* @throws InstallException
* If there's an obvious I/O problem that is preventing
* installation. bugs in the install code will probably throw
* other exceptions; this is intentional.
*/
void install() throws InstallException {
// For whatever reason, relative paths in your eclipse.ini file don't work on linux, but only for -javaagent.
Expand Down
52 changes: 39 additions & 13 deletions src/lombok/installer/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,57 @@ public class Installer {
private JButton installButton;

public static void main(String[] args) {
if (args.length > 0 && args[0].equals("install")) {
if (args.length > 0 && (args[0].equals("install") || args[0].equals("uninstall"))) {
boolean uninstall = args[0].equals("uninstall");
if (args.length < 3 || !args[1].equals("eclipse")) {
System.err.println("Run java -jar lombok.jar install eclipse path/to/eclipse/executable");
System.err.printf("Run java -jar lombok.jar %1$s eclipse path/to/eclipse/executable (or 'auto' to %1$s to all auto-discovered eclipse locations)\n", uninstall ? "uninstall" : "install");
System.exit(1);
}
String path = args[2];
try {
EclipseLocation loc = EclipseLocation.create(path);
loc.install();
System.out.println("Installed to: " + loc.getName());
final List<EclipseLocation> locations = new ArrayList<EclipseLocation>();
final List<NotAnEclipseException> problems = new ArrayList<NotAnEclipseException>();
if (path.equals("auto")) {
EclipseFinder.findEclipses(locations, problems);
} else {
locations.add(EclipseLocation.create(path));
}
int validLocations = locations.size();
for (EclipseLocation loc : locations) {
try {
if (uninstall) {
loc.uninstall();
} else {
loc.install();
}
System.out.printf("Lombok %s %s: %s\n", uninstall ? "uninstalled" : "installed", uninstall ? "from" : "to", loc.getName());
} catch (InstallException e) {
System.err.printf("Installation at %s failed:\n", loc.getName());
System.err.println(e.getMessage());
validLocations--;
} catch (UninstallException e) {
System.err.printf("Uninstall at %s failed:\n", loc.getName());
System.err.println(e.getMessage());
validLocations--;
}
}
for (NotAnEclipseException problem : problems) {
System.err.println("WARNING: " + problem.getMessage());
}
if (validLocations == 0) {
System.err.println("WARNING: Zero valid locations found; so nothing was done.");
}
System.exit(0);
} catch (NotAnEclipseException e) {
System.err.println("Not a valid eclipse location:");
System.err.println(e.getMessage());
System.exit(2);
} catch (InstallException e) {
System.err.println("Installation failed:");
System.err.println(e.getMessage());
System.exit(1);
}
}

if (args.length > 0 && args[0].equals("uninstall")) {
if (args.length < 3 || !args[1].equals("eclipse")) {
System.err.println("Run java -jar lombok.jar uninstall eclipse path/to/eclipse/executable");
System.err.println("Run java -jar lombok.jar uninstall eclipse path/to/eclipse/executable (or 'auto' to uninstall all auto-discovered eclipse locations)");
System.exit(1);
}
String path = args[2];
Expand Down Expand Up @@ -732,15 +758,15 @@ private void buildChrome(Container appWindowContainer) {
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(8, 8, 8, 8);
appWindowContainer.add(leftGraphic,constraints);
appWindowContainer.add(leftGraphic, constraints);
constraints.insets = new Insets(0, 0, 0, 0);

constraints.gridx++;
constraints.gridy++;
constraints.gridheight = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.ipadx = 16;
constraints.ipady = 14 ;
constraints.ipady = 14;
appWindowContainer.add(javacArea, constraints);

constraints.gridy++;
Expand Down Expand Up @@ -789,7 +815,7 @@ private void buildChrome(Container appWindowContainer) {
rt.exec(cmd);
break;
case MAC_OS_X:
rt.exec( "open " + ABOUT_LOMBOK_URL.toString());
rt.exec("open " + ABOUT_LOMBOK_URL.toString());
break;
default:
case UNIX:
Expand Down

0 comments on commit 6c22449

Please sign in to comment.