com.thoughtworks.go.util.FileUtil类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(161)

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

FileUtil介绍

暂无

代码示例

代码示例来源:origin: gocd/gocd

public static String join(File defaultWorkingDir, String actualFileToUse) {
  if (actualFileToUse == null) {
    LOGGER.trace("Using the default Directory->{}", defaultWorkingDir);
    return FilenameUtils.separatorsToUnix(defaultWorkingDir.getPath());
  }
  return applyBaseDirIfRelativeAndNormalize(defaultWorkingDir, new File(actualFileToUse));
}

代码示例来源:origin: gocd/gocd

public static boolean isChildOf(File parent, File subdirectory) throws IOException {
  File parentFile = parent.getCanonicalFile();
  File current = subdirectory.getCanonicalFile();
  return !current.equals(parentFile) && isSubdirectoryOf(parent, subdirectory);
}

代码示例来源:origin: gocd/gocd

File resolveRelativeDir(String... dirs) {
  if (dirs.length == 0) {
    return workingDir;
  }
  File result = new File(dirs[dirs.length - 1]);
  for (int i = dirs.length - 2; i >= 0; i--) {
    result = applyBaseDirIfRelative(new File(dirs[i]), result);
  }
  return applyBaseDirIfRelative(workingDir, result);
}

代码示例来源:origin: gocd/gocd

public static String removeLeadingPath(File leading, File path) {
  String l = normalize(leading.getAbsolutePath()).getAbsolutePath();
  String p = normalize(path.getAbsolutePath()).getAbsolutePath();
  if (l.equals(p)) {
    return "";
  }
  // ensure that l ends with a /
  // so we never think /foo was a parent directory of /foobar
  if (!l.endsWith(File.separator)) {
    l += File.separator;
  }
  return removeLeadingPath(l, p);
}

代码示例来源:origin: gocd/gocd

/**
 * From <code>base</code> traverse the filesystem in order to find
 * a file that matches the given name.
 *
 * @param base base File (dir).
 * @param path file path.
 * @param cs whether to scan case-sensitively.
 * @return File object that points to the file in question or null.
 *
 * @since Ant 1.6.3
 */
private File findFile(File base, String path, boolean cs) {
  if (FileUtil.isAbsolutePath(path)) {
    if (base == null) {
      String[] s = FileUtil.dissect(path);
      base = new File(s[0]);
      path = s[1];
    } else {
      File f = FileUtil.normalize(path);
      String s = FileUtil.removeLeadingPath(base, f);
      if (s.equals(f.getAbsolutePath())) {
        //removing base from path yields no change; path not child of base
        return null;
      }
      path = s;
    }
  }
  return findFile(base, SelectorUtils.tokenizePath(path), cs);
}

代码示例来源:origin: gocd/gocd

public void build(DefaultGoPublisher publisher,
           EnvironmentVariableContext environmentVariableContext, TaskExtension taskExtension, ArtifactExtension artifactExtension, PluginRequestProcessorRegistry pluginRequestProcessorRegistry, String consoleLogCharset) throws CruiseControlException {
    try {
      FileUtil.createFilesByPath(buildWorkingDirectory, files);
    } catch (IOException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: gocd/gocd

protected static boolean isFileChanged(File file, String sha) {
  try {
    String currentHash = FileUtil.sha1Digest(file);
    return !currentHash.equals(sha);
  } catch (Exception e) {
    return true;
  }
}

代码示例来源:origin: gocd/gocd

public static String getRepoUrl(File repositoryRoot, String project) {
  String url = FileUtil.toFileURI(new File(repositoryRoot, project));
  return url.replaceAll(" ", "%20");
}

代码示例来源:origin: gocd/gocd

private OutputStream target(String targetFile) throws FileNotFoundException {
  return new FileOutputStream(testFolder.getAbsolutePath() + FileUtil.fileseparator() + targetFile);
}

代码示例来源:origin: gocd/gocd

private void mergeAndUploadTestResult(GoPublisher publisher, List<File> allFiles) {
  if (allFiles.size() > 0) {
    File tempFolder = null;
    try {
      tempFolder = FileUtil.createTempFolder();
      File testResultSource = new File(tempFolder, MERGED_TEST_RESULT_FOLDER);
      testResultSource.mkdirs();
      UnitTestReportGenerator generator = new UnitTestReportGenerator(publisher, testResultSource);
      generator.generate(allFiles.toArray(new File[allFiles.size()]), "testoutput");
      publisher.upload(testResultSource, "testoutput");
    } finally {
      if (tempFolder != null) {
        FileUtils.deleteQuietly(tempFolder);
      }
    }
  } else {
    String message = "No files were found in the Test Results folders";
    publisher.taggedConsumeLineWithPrefix(GoPublisher.PUBLISH_ERR, message);
    LOG.warn(message);
  }
}

代码示例来源:origin: gocd/gocd

if (FileUtil.isAbsolutePath(includes[i])) {
  String currentelement = (String) entry.getKey();
  if (basedir == null && !FileUtil.isAbsolutePath(currentelement)) {
    continue;
      String path = (basedir == null)
        ? myfile.getCanonicalPath()
        : FileUtil.removeLeadingPath(canonBase,
        myfile.getCanonicalFile());
      if (!path.equals(currentelement)) {
        myfile = findFile(basedir, currentelement, true);
        if (myfile != null && basedir != null) {
          currentelement = FileUtil.removeLeadingPath(
            basedir, myfile);
        : FileUtil.removeLeadingPath(basedir, f);
      myfile = f;

代码示例来源:origin: gocd/gocd

if (!isGitRepository(workingFolder) || isRepositoryChanged(gitCommand, workingFolder)) {
  LOG.debug("Invalid git working copy or repository changed. Delete folder: {}", workingFolder);
  deleteDirectoryNoisily(workingFolder);
createParentFolderIfNotExist(workingFolder);
if (!workingFolder.exists()) {
  TransactionSynchronizationManager txManager = new TransactionSynchronizationManager();

代码示例来源:origin: gocd/gocd

@Override
protected void handleFile(File file, int depth, Collection results) {
  String fileName = file.getName();
  if (!FilenameUtils.getExtension(fileName).equalsIgnoreCase(XML_EXTENSION)) {
    return;
  }
  String xmlContentOfFie = safeReadFileToString(file);
  if (xmlContentOfFie == null || !file.canRead()) {
    serverHealthService.update(ServerHealthState.warning("Command Repository", "Failed to access command snippet XML file located in Go Server Directory at " + file.getPath() +
        ". Go does not have sufficient permissions to access it.", HealthStateType.commandRepositoryAccessibilityIssue(), systemEnvironment.getCommandRepoWarningTimeout()));
    LOGGER.warn("[Command Repository] Failed to access command snippet XML file located in Go Server Directory at {}. Go does not have sufficient permissions to access it.", file.getAbsolutePath());
    return;
  }
  try {
    String relativeFilePath = FileUtil.removeLeadingPath(commandRepositoryBaseDirectory.get(), file.getAbsolutePath());
    results.add(commandSnippetXmlParser.parse(xmlContentOfFie, FilenameUtils.getBaseName(fileName), relativeFilePath));
  } catch (Exception e) {
    LOGGER.warn("Failed loading command snippet from {}", file.getAbsolutePath());
    LOGGER.debug(null, e);
  }
}

代码示例来源:origin: gocd/gocd

public void freshCheckout(ConsoleOutputStreamConsumer outputStreamConsumer, SubversionRevision revision,
             File workingFolder) {
  if (workingFolder.isDirectory()) {
    FileUtils.deleteQuietly(workingFolder);
  }
  LOGGER.trace("Checking out to revision {} in {}", revision, workingFolder);
  createParentFolderIfNotExist(workingFolder);
  svn().checkoutTo(outputStreamConsumer, workingFolder, revision);
}

代码示例来源:origin: gocd/gocd

@Test
public void testShouldSearchFileUnderTheSandBox() throws IOException {
  File file = new File(baseFolder, "another/another.xml");
  file.getParentFile().mkdirs();
  file.createNewFile();
  String[] data = {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml", "delta/delta.xml"};
  FileUtil.createFilesByPath(getBaseDir(), data);
  File sandbox = getBaseDir();
  ds.setBasedir(sandbox);
  ds.setIncludes(new String[]{new File(baseFolder, "another").getAbsolutePath() + "/**/*.xml"});
  ds.scan();
  compareFiles(ds, new String[]{}, new String[]{});
}

代码示例来源:origin: gocd/gocd

public String url(String remoteHost, String workingUrl) throws IOException {
  boolean fileExist = artifact.exists();
  LOG.debug("Requesting the file [{}], exist? [{}]", artifact.getAbsolutePath(), fileExist);
  if (fileExist && artifact.isFile()) {
    String sha1 = FileUtil.sha1Digest(artifact);
    return format("%s/%s/%s/%s?sha1=%s", remoteHost, "remoting", "files", workingUrl,
        URLEncoder.encode(sha1, "UTF-8"));
  } else {
    return format("%s/%s/%s/%s", remoteHost, "remoting", "files", workingUrl);
  }
}

代码示例来源:origin: gocd/gocd

public String projectRepositoryUrl() {
  return FileUtil.toFileURI(gitRepo);
}

代码示例来源:origin: gocd/gocd

private OutputStream target(String targetFile) throws FileNotFoundException {
  return new FileOutputStream(testFolder.getAbsolutePath() + FileUtil.fileseparator() + targetFile);
}

代码示例来源:origin: gocd/gocd

@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
  File workingDirectory = buildSession.resolveRelativeDir(command.getWorkingDirectory());
  String uploadPath = command.getStringArg("uploadPath");
  String[] sources = command.getArrayArg("srcs");
  ArrayList<File> allFiles = findMatchedSourceFiles(buildSession, workingDirectory, sources);
  if (allFiles.size() > 0) {
    File tempFolder = null;
    try {
      tempFolder = FileUtil.createTempFolder();
      File testResultSource = new File(tempFolder, "result");
      testResultSource.mkdirs();
      UnitTestReportGenerator generator = new UnitTestReportGenerator(buildSession.getPublisher(), testResultSource);
      generator.generate(allFiles.toArray(new File[allFiles.size()]), uploadPath);
    } finally {
      if (tempFolder != null) {
        FileUtils.deleteQuietly(tempFolder);
      }
    }
  } else {
    String message = "No files were found in the Test Results folders";
    buildSession.printlnWithPrefix(message);
    LOG.warn(message);
  }
  return true;
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldRemoveLeadingFilePathFromAFilePath() throws Exception {
  File file = new File("/var/command-repo/default/windows/echo.xml");
  File base = new File("/var/command-repo/default");
  assertThat(FileUtil.removeLeadingPath(base.getAbsolutePath(), file.getAbsolutePath()), isSameAsPath("/windows/echo.xml"));
  assertThat(FileUtil.removeLeadingPath(new File("/var/command-repo/default/").getAbsolutePath(), new File("/var/command-repo/default/windows/echo.xml").getAbsolutePath()), isSameAsPath("/windows/echo.xml"));
  assertThat(FileUtil.removeLeadingPath("/some/random/path", "/var/command-repo/default/windows/echo.xml"), is("/var/command-repo/default/windows/echo.xml"));
  assertThat(FileUtil.removeLeadingPath(new File("C:/blah").getAbsolutePath(), new File("C:/blah/abcd.txt").getAbsolutePath()), isSameAsPath("/abcd.txt"));
  assertThat(FileUtil.removeLeadingPath(new File("C:/blah/").getAbsolutePath(), new File("C:/blah/abcd.txt").getAbsolutePath()), isSameAsPath("/abcd.txt"));
  assertThat(FileUtil.removeLeadingPath(null, new File("/blah/abcd.txt").getAbsolutePath()), isSameAsPath(new File("/blah/abcd.txt").getAbsolutePath()));
  assertThat(FileUtil.removeLeadingPath("", new File("/blah/abcd.txt").getAbsolutePath()), isSameAsPath(new File("/blah/abcd.txt").getAbsolutePath()));
}

相关文章