public static String fromHome(String path) { return new File(Os.home(), path).getAbsolutePath(); }
public Builder resetGlobalFiles() { defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties"); globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties"); return this; }
public Builder resetGlobalFiles() { defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties"); globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties"); return this; }
/** fails if the dir is not "safe" for deletion, currently length <= 2 or the home directory */ protected static void checkSafe(File dir) throws IOException { String dp = dir.getAbsolutePath(); dp = Strings.removeFromEnd(dp, "/"); if (dp.length()<=2) throw new IOException("Refusing instruction to delete "+dir+": name too short"); if (Os.home().equals(dp)) throw new IOException("Refusing instruction to delete "+dir+": it's the home directory"); }
/** * Tidy up a file path. * <p> * Removes duplicate or trailing path separators (Unix style forward * slashes only), replaces initial {@literal ~} with the * value of {@link #home()} and folds out use of {@literal ..} and * {@literal .} path segments. * * @see com.google.common.io.Files#simplifyPath(String) */ public static String tidyPath(String path) { Preconditions.checkNotNull(path, "path"); Iterable<String> segments = Splitter.on("/").split(Files.simplifyPath(path)); if (Iterables.get(segments, 0).equals("~")) { // Always at least one segment after simplifyPath segments = Iterables.concat(ImmutableSet.of(Os.home()), Iterables.skip(segments, 1)); } String result = Joiner.on("/").join(segments); if (log.isTraceEnabled() && !result.equals(path)) log.trace("Quietly changing '{}' to '{}'", path, result); return result; }
if (matcher.matches()) { File home = new File(Os.home()); File file = new File(home, matcher.group(1)); out = file.toURI();
protected synchronized boolean find() { if (isFound()) return true; String customtmp = System.getProperty(BROOKLYN_OS_TMPDIR_PROPERTY); if (customtmp!=null) { if (checkAndSet(customtmp)) return true; log.warn("TmpDirFinder: Custom tmp directory '"+customtmp+"' in "+BROOKLYN_OS_TMPDIR_PROPERTY+" is not a valid tmp dir; ignoring"); } String systmp = System.getProperty("java.io.tmpdir"); boolean systmpWeird = (systmp.contains("/var/") || systmp.startsWith("/private")); if (!systmpWeird) if (checkAndSet(systmp)) return true; if (checkAndSet(File.separator+"tmp")) return true; if (systmpWeird) if (checkAndSet(systmp)) return true; try { String hometmp = mergePaths(home(), ".tmp"); File hometmpF = new File(hometmp); hometmpF.mkdirs(); if (checkAndSet(hometmp)) return true; } catch (Exception e) { log.debug("TmpDirFinder: Cannot create tmp dir in user's home dir: "+e); } return false; }
@Test(groups="Integration") public void testMachine127InHome() throws Exception { MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)); app.start(ImmutableList.of(machine127)); String installDir = entity.getAttribute(SoftwareProcess.INSTALL_DIR); assertTrue(installDir.startsWith(Os.home()+"/brooklyn-managed-processes/installs/"), "installed in "+installDir); }
@Test(groups="Integration") public void testWebServerTempDirRespectsDataDirConfig() throws Exception { String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4); String dataDir = "~/"+dataDirName; launcher = newLauncherForTests(true) .brooklynProperties(BrooklynServerConfig.MGMT_BASE_DIR, dataDir) .start(); ManagementContext managementContext = launcher.getServerDetails().getManagementContext(); String expectedTempDir = Os.mergePaths(Os.home(), dataDirName, "planes", managementContext.getManagementNodeId(), "jetty"); File webappTempDir = launcher.getServerDetails().getWebServer().getWebappTempDir(); assertEquals(webappTempDir.getAbsolutePath(), expectedTempDir); }
@Test public void testInstallDirAndRunDirUsingTilde() throws Exception { String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4); String dataDir = "~/"+dataDirName; String resolvedDataDir = Os.mergePaths(Os.home(), dataDirName); MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, dataDir)); entity.start(ImmutableList.of(loc)); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.INSTALL_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "installs/MyService"))); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.RUN_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "apps/"+entity.getApplicationId()+"/entities/MyService_"+entity.getId()))); }