diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-07-05 00:49:54 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-07-05 00:49:54 +0200 |
commit | e7492d444cace44a39d94853512c31a9b95d930d (patch) | |
tree | c245e78ba3b328f255c1584f0702c04251d6dd4f /src/lombok/installer/EclipseFinder.java | |
parent | 938d4bb9f231722b2f55b71a05ecf9c3878119aa (diff) | |
download | lombok-e7492d444cace44a39d94853512c31a9b95d930d.tar.gz lombok-e7492d444cace44a39d94853512c31a9b95d930d.tar.bz2 lombok-e7492d444cace44a39d94853512c31a9b95d930d.zip |
W00t - written an installer that should work on linux (sort of), windows, and Mac OS X. Bumped the version number to celebrate, and changed build to roll the agent.jar into the main jar, and
change the executable class from the minimal help that was there to the installer. That minimal help thing (ShowUserHelp.java) is now gone.
Diffstat (limited to 'src/lombok/installer/EclipseFinder.java')
-rw-r--r-- | src/lombok/installer/EclipseFinder.java | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/src/lombok/installer/EclipseFinder.java b/src/lombok/installer/EclipseFinder.java new file mode 100644 index 00000000..1ca82440 --- /dev/null +++ b/src/lombok/installer/EclipseFinder.java @@ -0,0 +1,146 @@ +package lombok.installer; + +import static java.util.Arrays.asList; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import lombok.Lombok; + +public class EclipseFinder { + public static File findOurJar() { + try { + URI uri = EclipseFinder.class.getResource("/" + EclipseFinder.class.getName().replace('.', '/') + ".class").toURI(); + Pattern p = Pattern.compile("^jar:file:([^\\!]+)\\!.*\\.class$"); + System.out.println(uri.toString()); + Matcher m = p.matcher(uri.toString()); + if ( !m.matches() ) return new File("lombok.jar"); + String rawUri = m.group(1); + return new File(URLDecoder.decode(rawUri, Charset.defaultCharset().name())); + } catch ( Exception e ) { + throw Lombok.sneakyThrow(e); + } + } + + public static List<String> getDrivesOnWindows() throws IOException { + ProcessBuilder builder = new ProcessBuilder("c:\\windows\\system32\\fsutil.exe", "fsinfo", "drives"); + builder.redirectErrorStream(true); + Process process = builder.start(); + InputStream in = process.getInputStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + + List<String> drives = new ArrayList<String>(); + + String line; + while ( (line = br.readLine()) != null ) { + if ( line.startsWith("Drives: ") ) { + line = line.substring(8); + for ( String driveLetter : line.split("\\:\\\\\\s*") ) drives.add(driveLetter.trim()); + } + } + + Iterator<String> it = drives.iterator(); + while ( it.hasNext() ) { + if ( !isLocalDriveOnWindows(it.next()) ) it.remove(); + } + + return drives; + } + + public 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 + ":"); + builder.redirectErrorStream(true); + Process process = builder.start(); + InputStream in = process.getInputStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); + + String line; + while ( (line = br.readLine()) != null ) { + if ( line.substring(5).equalsIgnoreCase("Fixed Drive") ) return true; + } + + return false; + } catch ( Exception e ) { + return false; + } + } + + public static List<String> findEclipseOnWindows() { + List<String> eclipses = new ArrayList<String>(); + List<String> driveLetters = asList("C"); + + try { + driveLetters = getDrivesOnWindows(); + } catch ( IOException ignore ) {} + + for ( String letter : driveLetters ) { + File f = new File(letter + ":\\"); + for ( File dir : f.listFiles() ) { + if ( !dir.isDirectory() ) continue; + if ( dir.getName().toLowerCase().contains("eclipse") ) { + String eclipseLocation = findEclipseOnWindows1(dir); + if ( eclipseLocation != null ) eclipses.add(eclipseLocation); + } + if ( dir.getName().toLowerCase().contains("program files") ) { + for ( File dir2 : dir.listFiles() ) { + if ( !dir2.isDirectory() ) continue; + if ( dir.getName().toLowerCase().contains("eclipse") ) { + String eclipseLocation = findEclipseOnWindows1(dir); + if ( eclipseLocation != null ) eclipses.add(eclipseLocation); + } + } + } + } + } + + return eclipses; + } + + private static String findEclipseOnWindows1(File dir) { + if ( new File(dir, "eclipse.exe").isFile() ) return dir.toString(); + return null; + } + + public static void main(String[] args) throws Exception { + System.out.println(findEclipses()); + } + + 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; + } + + 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"; + + return "eclipse"; + } + + public static List<String> findEclipseOnMac() { + List<String> eclipses = new ArrayList<String>(); + for ( File dir : new File("/Applications").listFiles() ) { + if ( dir.getName().toLowerCase().contains("eclipse") ) { + if ( new File(dir, "Eclipse.app").exists() ) eclipses.add(dir.toString()); + } + } + return eclipses; + } +} |