private static boolean canWrite(URL location) { if (location != null && "file".equals(location.getProtocol())) { // $NON-NLS-1$ File locationDir = new File(location.getFile()); if (!locationDir.exists()) locationDir.mkdirs(); if (locationDir.exists() && AdaptorUtil.canWrite(locationDir)) return true; } return false; }
private static File getMacOSEclipsoeHomeLocation(File launcherDir) { // TODO for now we go up three directories from the launcher dir as long as the parent dir is // named MacOS; is this always the case? // TODO not sure if case is important if (!launcherDir.getName().equalsIgnoreCase("macos")) // $NON-NLS-1$ return launcherDir; // don't do the up three stuff if not in macos directory String launcherParent = launcherDir.getParent(); if (launcherParent != null) launcherParent = new File(launcherParent).getParent(); if (launcherParent != null) launcherParent = new File(launcherParent).getParent(); return launcherParent == null ? null : new File(launcherParent); }
private static String computeDefaultUserAreaLocation(String pathAppendage) { // we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home> // is unique for each local user, and <application-id> is the one // defined in .eclipseproduct marker file. If .eclipseproduct does not // exist, use "eclipse" as the application-id. String installProperty = FrameworkProperties.getProperty(PROP_INSTALL_AREA); URL installURL = buildURL(installProperty, true); if (installURL == null) return null; File installDir = new File(installURL.getFile()); // compute an install dir hash to prevent configuration area collisions with other eclipse // installs int hashCode; try { hashCode = installDir.getCanonicalPath().hashCode(); } catch (IOException ioe) { // fall back to absolute path hashCode = installDir.getAbsolutePath().hashCode(); } if (hashCode < 0) hashCode = -(hashCode); String installDirHash = String.valueOf(hashCode); String appName = "." + ECLIPSE; // $NON-NLS-1$ File eclipseProduct = new File(installDir, PRODUCT_SITE_MARKER); if (eclipseProduct.exists()) { Properties props = new Properties(); try { props.load(new FileInputStream(eclipseProduct)); String appId = props.getProperty(PRODUCT_SITE_ID); if (appId == null || appId.trim().length() == 0) appId = ECLIPSE; String appVersion = props.getProperty(PRODUCT_SITE_VERSION); if (appVersion == null || appVersion.trim().length() == 0) appVersion = ""; // $NON-NLS-1$ appName += File.separator + appId + "_" + appVersion + "_" + installDirHash; //$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { // Do nothing if we get an exception. We will default to a standard location // in the user's home dir. // add the hash to help prevent collisions appName += File.separator + installDirHash; } } else { // add the hash to help prevent collisions appName += File.separator + installDirHash; } String userHome = FrameworkProperties.getProperty(PROP_USER_HOME); return new File(userHome, appName + "/" + pathAppendage).getAbsolutePath(); // $NON-NLS-1$ }
private static String computeDefaultConfigurationLocation() { // 1) We store the config state relative to the 'eclipse' directory if possible // 2) If this directory is read-only // we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home> // is unique for each local user, and <application-id> is the one // defined in .eclipseproduct marker file. If .eclipseproduct does not // exist, use "eclipse" as the application-id. URL installURL = computeInstallConfigurationLocation(); if (installURL != null && "file".equals(installURL.getProtocol())) { // $NON-NLS-1$ File installDir = new File(installURL.getFile()); File defaultConfigDir = new File(installDir, CONFIG_DIR); if (!defaultConfigDir.exists()) defaultConfigDir.mkdirs(); if (defaultConfigDir.exists() && AdaptorUtil.canWrite(defaultConfigDir)) return defaultConfigDir.getAbsolutePath(); } // We can't write in the eclipse install dir so try for some place in the user's home dir return computeDefaultUserAreaLocation(CONFIG_DIR); }
private static String getEclipseHomeLocation(String launcher) { if (launcher == null) return null; File launcherFile = new File(launcher); if (launcherFile.getParent() == null) return null; File launcherDir = new File(launcherFile.getParent()); // check for mac os; the os check is copied from EclipseEnvironmentInfo. String macosx = org.eclipse.osgi.service.environment.Constants.OS_MACOSX; if (macosx.equals(EclipseEnvironmentInfo.getDefault().getOS())) launcherDir = getMacOSEclipsoeHomeLocation(launcherDir); return (launcherDir.exists() && launcherDir.isDirectory()) ? launcherDir.getAbsolutePath() : null; }
/** * Returns a file from the configuration area that can be used by the framework * * @param filename the filename * @return a file from the configuration area */ public static File getConfigurationFile(String filename) { File dir = getOSGiConfigurationDir(); if (!dir.exists()) dir.mkdirs(); return new File(dir, filename); }