本文整理了Java中org.apache.tools.ant.util.FileUtils.getRelativePath()
方法的一些代码示例,展示了FileUtils.getRelativePath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.getRelativePath()
方法的具体详情如下:
包路径:org.apache.tools.ant.util.FileUtils
类名称:FileUtils
方法名:getRelativePath
[英]Calculates the relative path between two files.
Implementation note:
This function may throw an IOException if an I/O error occurs because its use of the canonical pathname may require filesystem queries.
[中]计算两个文件之间的相对路径。
实施说明:
如果发生I/O错误,此函数可能会引发IOException,因为它使用规范路径名可能需要文件系统查询。
代码示例来源:origin: org.apache.ant/ant
/**
* Sets file parameter(s) for directory and filename if the attribute
* 'filenameparameter' or 'filedirparameter' are set in the task.
*
* @param liaison to change parameters for
* @param inFile to get the additional file information from
* @throws Exception if an exception occurs on filename lookup
*
* @since Ant 1.7
*/
private void setLiaisonDynamicFileParameters(
final XSLTLiaison liaison, final File inFile) throws Exception { //NOSONAR
if (fileNameParameter != null) {
liaison.addParam(fileNameParameter, inFile.getName());
}
if (fileDirParameter != null) {
final String fileName = FileUtils.getRelativePath(baseDir, inFile);
final File file = new File(fileName);
// Give always a slash as file separator, so the stylesheet could be sure about that
// Use '.' so a dir + "/" + name would not result in an absolute path
liaison.addParam(fileDirParameter, file.getParent() != null ? file.getParent().replace(
'\\', '/') : ".");
}
}
代码示例来源:origin: org.apache.ant/ant
relPath = ".";
} else {
relPath = FileUtils.getRelativePath(dir, pathEntry);
代码示例来源:origin: org.apache.ant/ant
src.getName(),
FileUtils
.getRelativePath(dest
.getParentFile(),
src),
FileUtils
.getRelativePath(getProject()
.getBaseDir(),
src),
代码示例来源:origin: org.apache.ant/ant
: new File(untypedValue.toString());
File to = basedir != null ? basedir : getProject().getBaseDir();
String relPath = FileUtils.getRelativePath(to, from);
relPath = relPath.replace('/', File.separatorChar);
addProperty(name, relPath);
代码示例来源:origin: maven-nar/nar-maven-plugin
protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
//
// if there is an embedded space,
// must enclose in quotes
String relative="";
String inputFile;
try {
relative = FileUtils.getRelativePath(workDir, new File(filename));
} catch (Exception ex) {
}
if (relative.isEmpty()) {
inputFile = filename;
} else {
inputFile = relative;
}
if (inputFile.indexOf(' ') >= 0) {
final String buf = "\"" + inputFile +
"\"";
return buf;
}
return inputFile;
}
代码示例来源:origin: org.gradle/gradle-core
/**
* Returns a relative path from 'from' to 'to'
*
* @param from where to calculate from
* @param to where to calculate to
* @return The relative path
*/
public static String relativePath(File from, File to) {
try {
return org.apache.tools.ant.util.FileUtils.getRelativePath(from, to);
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
}
代码示例来源:origin: maven-nar/nar-maven-plugin
@Override
protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
if (index == 0) {
final String outputFileName = getOutputFileNames(filename, null)[0];
final String fullOutputName = new File(outputDir, outputFileName).toString();
return "/Fo" + fullOutputName;
}
String relative="";
try {
relative = FileUtils.getRelativePath(workDir, new File(filename));
} catch (Exception ex) {
}
if (relative.isEmpty()) {
return filename;
} else {
return relative;
}
}
代码示例来源:origin: maven-nar/nar-maven-plugin
@Override
protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
if (index == 0) {
final String outputFileName = getOutputFileNames(filename, null)[0];
final String objectName = new File(outputDir, outputFileName).toString();
return "-o" + objectName;
}
String relative="";
try {
relative = FileUtils.getRelativePath(workDir, new File(filename));
} catch (Exception ex) {
}
if (relative.isEmpty()) {
return filename;
} else {
return relative;
}
}
代码示例来源:origin: maven-nar/nar-maven-plugin
@Override
protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
switch (index) {
case 0:
return "-o";
case 1:
final String outputFileName = getOutputFileNames(filename, null)[0];
final String objectName = new File(outputDir, outputFileName).toString();
return objectName;
}
String relative="";
try {
relative = FileUtils.getRelativePath(workDir, new File(filename));
} catch (Exception ex) {
}
if (relative.isEmpty()) {
return filename;
} else {
return relative;
}
}
代码示例来源:origin: maven-nar/nar-maven-plugin
@Override
protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
switch (index) {
case 0:
return "-o";
case 1:
final String outputFileName = getOutputFileNames(filename, null)[0];
final String objectName = new File(outputDir, outputFileName).toString();
return objectName;
}
String relative = "";
if ( this.gccFileAbsolutePath) {
return filename;
} else {
try {
relative = FileUtils.getRelativePath(workDir, new File(filename));
} catch (Exception ex) {
}
}
if (relative.isEmpty()) {
return filename;
} else {
return relative;
}
}
代码示例来源:origin: org.codehaus.openxma/dsl-generator
public boolean hasVetoBeforeOpen(FileHandle fileHandle) {
try {
String relativePath = FileUtils.getRelativePath(new File(fileHandle.getOutlet().getPath()), fileHandle
.getTargetFile());
boolean fileExists = new File(this.checkPath + File.separatorChar + relativePath).exists();
if (fileExists) {
logger.warn("Skip generation of already existing java source '" + fileHandle.getTargetFile() + "'");
}
return fileExists;
} catch (Exception exception) {
logger.error("Error while testing existing file", exception);
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!