org.apache.brooklyn.util.os.Os类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.apache.brooklyn.util.os.Os类的一些代码示例,展示了Os类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Os类的具体详情如下:
包路径:org.apache.brooklyn.util.os.Os
类名称:Os

Os介绍

暂无

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

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;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static void deleteCompletely(File d) {
    DeletionResult result = Os.deleteRecursively(d);
    if (!result.wasSuccessful())
      log.warn("Unable to delete persistence dir "+d);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public ToolAbstractAsyncExecScript(Map<String,?> props) {
  super(props);
  stdoutPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stdout");
  stderrPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stderr");
  exitStatusPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".exitstatus");
  pidPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".pid");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** like {@link #deleteOnExitRecursively(File)} followed by {@link #deleteOnExitEmptyParentsUpTo(File, File)} */
public static void deleteOnExitRecursivelyAndEmptyParentsUpTo(File directoryToCleanOrFile, File highestAncestorToDelete) {
  deleteOnExitRecursively(directoryToCleanOrFile);
  deleteOnExitEmptyParentsUpTo(directoryToCleanOrFile, highestAncestorToDelete);
}

代码示例来源:origin: io.cloudsoft.brooklyn.tosca/brooklyn-tosca-transformer

@Inject
public Alien4CloudFacade(ICSARRepositorySearchService repositorySearchService, TopologyTreeBuilderService treeBuilder, ICsarRepositry csarFileRepository, TopologyServiceCore topologyService, TopologyTemplateVersionService topologyTemplateVersionService, DeploymentTopologyService deploymentTopologyService, ApplicationService applicationService) {
  this.repositorySearchService = repositorySearchService;
  this.treeBuilder = treeBuilder;
  this.csarFileRepository = csarFileRepository;
  this.topologyService = topologyService;
  this.topologyTemplateVersionService = topologyTemplateVersionService;
  this.deploymentTopologyService = deploymentTopologyService;
  this.applicationService = applicationService;
  tmpRoot = Os.newTempDir("brooklyn-a4c");
  Os.deleteOnExitRecursively(tmpRoot);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

@Test(groups = "Integration")
public void testStartsInDifferentRunAndInstallSpecifiedDirectories() throws Exception {
  String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
  String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
  app.config().set(BrooklynConfigKeys.INSTALL_DIR, dir1);
  app.config().set(BrooklynConfigKeys.RUN_DIR, dir2);
  doTestSpecifiedDirectory(dir1, dir2);
  Os.deleteRecursively(dir1);
  Os.deleteRecursively(dir2);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private void assertSubFilesEqual(File parentDir, Map<String, String> files) throws Exception {
    for (Map.Entry<String, String> entry : archiveContents.entrySet()) {
      File subFile = new File(Os.mergePaths(parentDir.getAbsolutePath(), entry.getKey()));
      assertEquals(Joiner.on("\n").join(Files.readLines(subFile, Charsets.UTF_8)), entry.getValue());
    }
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** @deprecated since 0.7.0; use method {@link Os#tidyPath(String)} */ @Deprecated
public static String tidyFilePath(String path) {
  return Os.tidyPath(path);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testDeleteRecursivelyNonExistantDir() throws Exception {
  DeletionResult result = Os.deleteRecursively(Os.mergePaths(Os.tmp(), Identifiers.makeRandomId(8)));
  assertTrue(result.wasSuccessful());
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testDeleteRecursivelyEmptyDir() throws Exception {
  File dir = Os.newTempDir(OsTest.class);
  DeletionResult result = Os.deleteRecursively(dir);
  assertTrue(result.wasSuccessful());
  assertFalse(dir.exists());
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private File newZip(Map<String, String> files) throws Exception {
  File parentDir = Os.newTempDir(getClass().getSimpleName()+"-archive");
  for (Map.Entry<String, String> entry : files.entrySet()) {
    File subFile = new File(Os.mergePaths(parentDir.getAbsolutePath(), entry.getKey()));
    subFile.getParentFile().mkdirs();
    Files.write(entry.getValue(), subFile, Charsets.UTF_8);
  }
  return ArchiveBuilder.zip().addDirContentsAt(parentDir, ".").create();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test(groups = {"Integration"})
public void testOutputAsExpected() throws Exception {
  final String CONTENTS = "hello world\n"
    + "bye bye\n";
  execCommands("cat > "+Os.mergePaths(Os.tmp(), "test1")+" << X\n"
    + CONTENTS
    + "X\n");
  String read = execCommands("echo START_FOO", "cat "+Os.mergePaths(Os.tmp(), "test1"), "echo END_FOO");
  log.debug("read back data written, as:\n"+read);
  String contents = Strings.getFragmentBetween(read, "START_FOO", "END_FOO");
  Assert.assertEquals(CONTENTS.trim(), contents.trim());
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@BeforeMethod
public void setUp() {
  mementoDir = Os.newTempDir(getClass());
  managementContextForTermination = new ArrayList<>();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** as {@link #newTempFile(String, String)} using the class as the basis for a prefix */
public static File newTempFile(Class<?> clazz, String ext) {
  return newTempFile(JavaClassNames.cleanSimpleClassName(clazz), ext);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

@Test(groups = "Integration")
public void testStartsInAppSpecifiedDirectoryUnderHome() throws Exception {
  String dir = Os.mergePathsUnix("~/.brooklyn-test-"+Strings.makeRandomId(4));
  try {
    app.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
    doTestSpecifiedDirectory(dir, dir);
  } finally {
    Os.deleteRecursively(dir);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** allow the temp dir where ssh temporary files on the brooklyn server side are placed */
public static void setLocalTempDir(Map<String,?> source, ConfigBag target) {
  // TODO better would be to use BrooklynServerConfig, requiring management passed in
  String brooklynDataDir = (String) source.get(BrooklynServerConfig.getMgmtBaseDir(source));
  if (brooklynDataDir != null && brooklynDataDir.length() > 0) {
    String tempDir = Os.mergePaths(brooklynDataDir, "tmp", "ssh");
    target.putIfAbsentAndNotNull(SshTool.PROP_LOCAL_TEMP_DIR, tempDir);
    Os.deleteOnExitEmptyParentsUpTo(new File(tempDir), new File(brooklynDataDir));
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

@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())));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@BeforeClass
public void createTmpDirAndFiles() throws IOException {
  parentDir = Os.newTempDir(getClass().getSimpleName());
  Os.deleteOnExitRecursively(parentDir);
  tmpDir = new File(parentDir, Identifiers.makeRandomId(4));
  Os.mkdirs(tmpDir);
  Files.write("abcdef", new File(tmpDir, "data01.txt"), Charsets.US_ASCII);
  Files.write("123456", new File(tmpDir, "data02.txt"), Charsets.US_ASCII);
  Files.write("qqqqqq", new File(tmpDir, "data03.txt"), Charsets.US_ASCII);
  
  tmpDir2 = new File(parentDir, Identifiers.makeRandomId(4));
  Os.mkdirs(tmpDir2);
  Files.write("zzzzzz", new File(tmpDir2, "data04.txt"), Charsets.US_ASCII);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static File getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) {
  File cacheDirF = getOsgiCacheDir(mgmt);
  boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF);
  log.debug("OSGi cache dir computed as "+cacheDirF.getAbsolutePath()+" ("+
    (cacheDirF.exists() ? "already exists" : "does not exist")+", "+
    (clean ? "cleaning now (and on exit)" : "cleaning not requested"));
  if (clean) {
    Os.deleteRecursively(cacheDirF);
    Os.deleteOnExitRecursively(cacheDirF);
  }
  
  return cacheDirF;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** @deprecated since 0.7.0; use same method in {@link Os} */ @Deprecated
public static File writeToTempFile(InputStream is, String prefix, String suffix) {
  return Os.writeToTempFile(is, prefix, suffix);
}

相关文章