aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/installer/EclipseFinder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/installer/EclipseFinder.java')
-rw-r--r--src/lombok/installer/EclipseFinder.java132
1 files changed, 112 insertions, 20 deletions
diff --git a/src/lombok/installer/EclipseFinder.java b/src/lombok/installer/EclipseFinder.java
index 1ca82440..3c966359 100644
--- a/src/lombok/installer/EclipseFinder.java
+++ b/src/lombok/installer/EclipseFinder.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * 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.installer;
import static java.util.Arrays.asList;
@@ -18,8 +39,17 @@ import java.util.regex.Pattern;
import lombok.Lombok;
-public class EclipseFinder {
- public static File findOurJar() {
+/** Utility class for doing various OS-specific operations related to finding eclipse installations. */
+class EclipseFinder {
+ private EclipseFinder() {
+ //Prevent instantiation.
+ }
+
+ /**
+ * Returns a File object pointing to our own jar file. Will obviously fail if the installer was started via
+ * a jar that wasn't accessed via the file-system, or if its started via e.g. unpacking the jar.
+ */
+ static File findOurJar() {
try {
URI uri = EclipseFinder.class.getResource("/" + EclipseFinder.class.getName().replace('.', '/') + ".class").toURI();
Pattern p = Pattern.compile("^jar:file:([^\\!]+)\\!.*\\.class$");
@@ -33,7 +63,15 @@ public class EclipseFinder {
}
}
- public static List<String> getDrivesOnWindows() throws IOException {
+ /**
+ * Returns all drive letters on windows, regardless of what kind of drive is represented.
+ *
+ * Relies on the 'fsutil.exe' program. I have no idea if you can call it without triggering a gazillion
+ * security warnings on Vista. I did a cursory test on an out-of-the-box Windows XP and that seems to work.
+ *
+ * @return A List of drive letters, such as ["A", "C", "D", "X"].
+ */
+ static List<String> getDrivesOnWindows() throws IOException {
ProcessBuilder builder = new ProcessBuilder("c:\\windows\\system32\\fsutil.exe", "fsinfo", "drives");
builder.redirectErrorStream(true);
Process process = builder.start();
@@ -58,7 +96,12 @@ public class EclipseFinder {
return drives;
}
- public static boolean isLocalDriveOnWindows(String driveLetter) {
+ /**
+ * @return true if the letter represents a local fixed disk, false if its a disk drive, optical drive,
+ * USB stick, network drive, or any other kind of drive. Substed (virtual) drives that are an alias to
+ * a directory on a local disk cause a 'return true', but this is intentional.
+ */
+ static boolean isLocalDriveOnWindows(String driveLetter) {
if ( driveLetter == null || driveLetter.length() == 0 ) return false;
try {
ProcessBuilder builder = new ProcessBuilder("c:\\windows\\system32\\fsutil.exe", "fsinfo", "drivetype", driveLetter + ":");
@@ -78,7 +121,19 @@ public class EclipseFinder {
}
}
- public static List<String> findEclipseOnWindows() {
+ /**
+ * 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*
+ *
+ * Where 'X' is tried for all local disk drives, unless there's a problem calling fsutil, in which case only
+ * C: is tried.
+ *
+ * @return A List of directories that contain 'eclipse.exe'.
+ */
+ static List<String> findEclipseOnWindows() {
List<String> eclipses = new ArrayList<String>();
List<String> driveLetters = asList("C");
@@ -109,34 +164,71 @@ public class EclipseFinder {
return eclipses;
}
+ /** Checks if the provided directory contains 'eclipse.exe', and if so, returns the directory, otherwise null. */
private static String findEclipseOnWindows1(File dir) {
- if ( new File(dir, "eclipse.exe").isFile() ) return dir.toString();
+ if ( new File(dir, "eclipse.exe").isFile() ) return dir.getAbsolutePath();
return null;
}
- public static void main(String[] args) throws Exception {
- System.out.println(findEclipses());
+ /**
+ * Calls the OS-dependent 'find eclipse' routine. If the local OS doesn't have a routine written for it,
+ * null is returned.
+ *
+ * @return List of directories that contain the eclipse executable.
+ */
+ static List<String> findEclipses() {
+ switch ( getOS() ) {
+ case WINDOWS:
+ return findEclipseOnWindows();
+ case MAC_OS_X:
+ return findEclipseOnMac();
+ default:
+ case UNIX:
+ return null;
+ }
}
- public static List<String> findEclipses() {
- String prop = System.getProperty("os.name", "");
- if ( prop.equalsIgnoreCase("Mac OS X") ) return findEclipseOnMac();
- if ( prop.equalsIgnoreCase("Windows XP") ) return findEclipseOnWindows();
-
- return null;
+ static enum OS {
+ MAC_OS_X, WINDOWS, UNIX;
}
- public static String getEclipseExecutableName() {
- String prop = System.getProperty("os.name", "");
- if ( prop.equalsIgnoreCase("Mac OS X") ) return "Eclipse.app";
- if ( prop.equalsIgnoreCase("Windows XP") ) return "eclipse.exe";
+ static OS getOS() {
+ String prop = System.getProperty("os.name", "").toLowerCase();
+ if ( prop.matches("^.*\\bmac\\b.*$") ) return OS.MAC_OS_X;
+ if ( prop.matches("^.*\\bwin(dows)\\b.*$") ) return OS.WINDOWS;
- return "eclipse";
+ return OS.UNIX;
}
- public static List<String> findEclipseOnMac() {
+ /**
+ * Returns the proper name of the executable for the local OS.
+ *
+ * @return 'Eclipse.app' on OS X, 'eclipse.exe' on Windows, and 'eclipse' on other OSes.
+ */
+ static String getEclipseExecutableName() {
+ switch ( getOS() ) {
+ case WINDOWS:
+ return "eclipse.exe";
+ case MAC_OS_X:
+ return "Eclipse.app";
+ default:
+ case UNIX:
+ return "eclipse";
+ }
+ }
+
+ /**
+ * Scans /Applications for any folder named 'Eclipse'
+ */
+ static List<String> findEclipseOnMac() {
List<String> eclipses = new ArrayList<String>();
for ( File dir : new File("/Applications").listFiles() ) {
+ if ( !dir.isDirectory() ) continue;
+ if ( dir.getName().toLowerCase().equals("eclipse.app") ) {
+ //This would be kind of an unorthodox eclipse installation, but if eclipse ever
+ //moves to this more maclike installation concept, our installer can still handle it.
+ eclipses.add("/Applications");
+ }
if ( dir.getName().toLowerCase().contains("eclipse") ) {
if ( new File(dir, "Eclipse.app").exists() ) eclipses.add(dir.toString());
}