本文整理汇总了Java中org.apache.tools.ant.util.FileUtils.getFileUtils方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.getFileUtils方法的具体用法?Java FileUtils.getFileUtils怎么用?Java FileUtils.getFileUtils使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.util.FileUtils
的用法示例。
在下文中一共展示了FileUtils.getFileUtils方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFiles
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
protected void addFiles(File base, String[] files, Commandline cmdl)
{
FileUtils utils = FileUtils.getFileUtils();
if (spec == null)
{
for (int i = 0; i < files.length; i++)
{
cmdl.createArgument().setValue(utils.resolveFile(base, files[i]).getAbsolutePath());
}
}
else
{
for (int i = 0; i < files.length; i++)
{
cmdl.createArgument().setValue("-" + spec.getFullName() + equalString() +
utils.resolveFile(base, files[i]).getAbsolutePath());
}
}
}
示例2: addFiles
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
protected void addFiles(File base, String[] files, Commandline cmdl)
{
FileUtils utils = FileUtils.getFileUtils();
for (int i = 0; i < files.length; ++i)
{
File f = utils.resolveFile(base, files[i]);
String absolutePath = f.getAbsolutePath();
if( f.isFile() && !absolutePath.endsWith(".swc") && !absolutePath.endsWith(".ane") )
continue;
if (spec != null)
{
cmdl.createArgument().setValue("-" + spec.getFullName() + equalString() + absolutePath);
}
else
{
cmdl.createArgument().setValue(absolutePath);
}
}
}
示例3: collectFileListFromModulePath
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
private void collectFileListFromModulePath() {
final FileUtils fu = FileUtils.getFileUtils();
for (String pathElement : moduleSourcepath.list()) {
boolean valid = false;
for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement(
getProject().getBaseDir(), pathElement).entrySet()) {
final String moduleName = modules.getKey();
for (File srcDir : modules.getValue()) {
if (srcDir.exists()) {
valid = true;
final DirectoryScanner ds = getDirectoryScanner(srcDir);
final String[] files = ds.getIncludedFiles();
scanDir(srcDir, fu.resolveFile(destDir, moduleName), files);
}
}
}
if (!valid) {
throw new BuildException("modulesourcepath \""
+ pathElement
+ "\" does not exist!", getLocation());
}
}
}
示例4: findModules
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Finds modules in the expanded modulesourcepath entry.
* @param root the project root
* @param pathToModule the path to modules folder
* @param pathInModule the path in module to source folder
* @param collector the map to put modules into
* @since 1.9.7
*/
private static void findModules(
final File root,
final String pathToModule,
final String pathInModule,
final Map<String,Collection<File>> collector) {
final FileUtils fu = FileUtils.getFileUtils();
final File f = fu.resolveFile(root, pathToModule);
if (!f.isDirectory()) {
return;
}
for (File module : f.listFiles(File::isDirectory)) {
final String moduleName = module.getName();
final File moduleSourceRoot = pathInModule == null ?
module :
new File(module, pathInModule);
Collection<File> moduleRoots = collector.get(moduleName);
if (moduleRoots == null) {
moduleRoots = new ArrayList<>();
collector.put(moduleName, moduleRoots);
}
moduleRoots.add(moduleSourceRoot);
}
}
示例5: encodeDecode
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void encodeDecode() {
Random rand = new Random();
DummyDataSet.createDummyDataSet(context);
List<Data> datas = HelperFactory.getDataHelper(context).getDataObjects(0, 4);
for (Data data:datas) {
if (data.getFile() != null && !data.getFile().exists()) {
continue;
}
DataEncoder encoder = new StreamDataEncoder(data);
StreamDataDecoder decoder = new StreamDataDecoder(context, data.getSender().getNetworkingId());
while (encoder.available() > 0) {
byte[] bytes = new byte[rand.nextInt(encoder.available() + 1)];
int read = encoder.read(bytes, 0, bytes.length);
decoder.write(bytes, 0, read);
}
Data decodedData = decoder.getDecodedData();
assertNotNull("DecodedData should not be null", decodedData);
assertEquals("Text should be equal!", data.getText(), decodedData.getText());
assertEquals("sender should be equal!", data.getSender().getNetworkingId(), decodedData.getSender().getNetworkingId());
assertEquals("Chat network identifier should be equal (Data)!", data.getNetworkChatID(), decodedData.getNetworkChatID());
assertEquals("Chat network identifier should be equal (Decoder)!", data.getNetworkChatID(), decoder.getNetworkChatID());
if (data.getFile() != null && data.getFile().exists()) {
FileUtils fileUtils = FileUtils.getFileUtils();
try {
Assert.assertTrue("Send and received data should have the same file!", fileUtils.contentEquals(data.getFile(), decodedData.getFile()));
} catch (IOException e) {
Assert.assertTrue(e.getMessage(), false);
}
}
}
}
示例6: testPropertyResolution
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void testPropertyResolution() throws Exception {
FileUtils fu = FileUtils.getFileUtils();
File props = fu.createTempFile("propertyfilecli", ".properties",
null, true, true);
File build = fu.createTempFile("propertyfilecli", ".xml", null, true,
true);
File log = fu.createTempFile("propertyfilecli", ".log", null, true,
true);
FileWriter fw = null;
FileReader fr = null;
try {
fw = new FileWriter(props);
fw.write("w=world\nmessage=Hello, ${w}\n");
fw.close();
fw = new FileWriter(build);
fw.write("<project><echo>${message}</echo></project>");
fw.close();
fw = null;
Main m = new NoExitMain();
m.startAnt(new String[] {
"-propertyfile", props.getAbsolutePath(),
"-f", build.getAbsolutePath(),
"-l", log.getAbsolutePath()
}, null, null);
String l = FileUtils.safeReadFully(fr = new FileReader(log));
assertContains("Hello, world", l);
} finally {
FileUtils.close(fw);
FileUtils.close(fr);
}
}
示例7: tearDown
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@After
public void tearDown() {
if (f.exists()) {
FileUtils fu = FileUtils.getFileUtils();
fu.tryHardToDelete(f);
}
}
示例8: Copy
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Copy task constructor.
*/
public Copy() {
fileUtils = FileUtils.getFileUtils();
granularity = fileUtils.getFileTimestampGranularity();
}
示例9: execute
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Sets a property, which must not already exist, with a space
* separated list of files and directories relative to the jar
* file's parent directory.
*/
@Override
public void execute() {
if (name == null) {
throw new BuildException("Missing 'property' attribute!");
}
if (dir == null) {
throw new BuildException("Missing 'jarfile' attribute!");
}
if (getProject().getProperty(name) != null) {
throw new BuildException("Property '%s' already set!", name);
}
if (path == null) {
throw new BuildException("Missing nested <classpath>!");
}
StringBuilder tooLongSb = new StringBuilder();
for (int i = 0; i < maxParentLevels + 1; i++) {
tooLongSb.append("../");
}
final String tooLongPrefix = tooLongSb.toString();
// Normalize the reference directory (containing the jar)
final FileUtils fileUtils = FileUtils.getFileUtils();
dir = fileUtils.normalize(dir.getAbsolutePath());
String[] elements = path.list();
StringBuilder buffer = new StringBuilder();
for (String element : elements) {
// Normalize the current file
File pathEntry = new File(element);
String fullPath = pathEntry.getAbsolutePath();
pathEntry = fileUtils.normalize(fullPath);
String relPath = null;
String canonicalPath = null;
try {
if (dir.equals(pathEntry)) {
relPath = ".";
} else {
relPath = FileUtils.getRelativePath(dir, pathEntry);
}
canonicalPath = pathEntry.getCanonicalPath();
// getRelativePath always uses '/' as separator, adapt
if (File.separatorChar != '/') {
canonicalPath =
canonicalPath.replace(File.separatorChar, '/');
}
} catch (Exception e) {
throw new BuildException("error trying to get the relative path"
+ " from " + dir + " to " + fullPath,
e);
}
// No match, so bail out!
if (relPath.equals(canonicalPath)
|| relPath.startsWith(tooLongPrefix)) {
throw new BuildException(
"No suitable relative path from %s to %s", dir, fullPath);
}
if (pathEntry.isDirectory() && !relPath.endsWith("/")) {
relPath = relPath + '/';
}
relPath = Locator.encodeURI(relPath);
// Manifest's ClassPath: attribute always uses forward
// slashes '/', and is space-separated. Ant will properly
// format it on 72 columns with proper line continuation
buffer.append(relPath);
buffer.append(' ');
}
// Finally assign the property with the manifest classpath
getProject().setNewProperty(name, buffer.toString().trim());
}