com.thoughtworks.go.util.FileUtil.removeLeadingPath()方法的使用及代码示例

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

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

FileUtil.removeLeadingPath介绍

暂无

代码示例

代码示例来源: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

@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

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

代码示例来源: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

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;

相关文章