本文整理汇总了Java中org.apache.tools.ant.util.FileNameMapper.mapFileName方法的典型用法代码示例。如果您正苦于以下问题:Java FileNameMapper.mapFileName方法的具体用法?Java FileNameMapper.mapFileName怎么用?Java FileNameMapper.mapFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.util.FileNameMapper
的用法示例。
在下文中一共展示了FileNameMapper.mapFileName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertyMap
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
*
* @return Map
* @since 1.9.0
*/
private Map<String, Object> getPropertyMap() {
if (isReference()) {
return getRef().getPropertyMap();
}
dieOnCircularReference();
final Mapper myMapper = getMapper();
final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation();
final Map<String, Object> effectiveProperties = getEffectiveProperties();
final Set<String> propertyNames = getPropertyNames(effectiveProperties);
final Map<String, Object> result = new HashMap<>();
//iterate through the names, get the matching values
for (String name : propertyNames) {
Object value = effectiveProperties.get(name);
// TODO should we include null properties?
// TODO should we query the PropertyHelper for property value to grab potentially shadowed values?
if (value != null) {
// may be null if a system property has been added
// after the project instance has been initialized
if (m != null) {
//map the names
String[] newname = m.mapFileName(name);
if (newname != null) {
name = newname[0];
}
}
result.put(name, value);
}
}
return result;
}
示例2: buildMap
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
* Add to a map of files/directories to copy.
*
* @param fromDir the source directory.
* @param toDir the destination directory.
* @param names a list of filenames.
* @param mapper a <code>FileNameMapper</code> value.
* @param map a map of source file to array of destination files.
*/
protected void buildMap(final File fromDir, final File toDir, final String[] names,
final FileNameMapper mapper, final Hashtable<String, String[]> map) {
String[] toCopy = null;
if (forceOverwrite) {
final Vector<String> v = new Vector<String>();
for (int i = 0; i < names.length; i++) {
if (mapper.mapFileName(names[i]) != null) {
v.addElement(names[i]);
}
}
toCopy = new String[v.size()];
v.copyInto(toCopy);
} else {
final SourceFileScanner ds = new SourceFileScanner(this);
toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
}
for (int i = 0; i < toCopy.length; i++) {
final File src = new File(fromDir, toCopy[i]);
final String[] mappedFiles = mapper.mapFileName(toCopy[i]);
if (!enableMultipleMappings) {
map.put(src.getAbsolutePath(),
new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
} else {
// reuse the array created by the mapper
for (int k = 0; k < mappedFiles.length; k++) {
mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
}
map.put(src.getAbsolutePath(), mappedFiles);
}
}
}
示例3: testNested
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
@Test
public void testNested() {
Mapper mapper1 = new Mapper(project);
Mapper.MapperType mt = new Mapper.MapperType();
mt.setValue("glob");
mapper1.setType(mt);
mapper1.setFrom("from*");
mapper1.setTo("to*");
//mix element types
FileNameMapper mapper2 = new FlatFileNameMapper();
FileNameMapper mapper3 = new MergingMapper();
mapper3.setTo("mergefile");
Mapper container = new Mapper(project);
container.addConfiguredMapper(mapper1);
container.add(mapper2);
container.add(mapper3);
FileNameMapper fileNameMapper = container.getImplementation();
String[] targets = fileNameMapper.mapFileName("fromfilename");
assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 3, targets.length);
List list = Arrays.asList(targets);
assertTrue("cannot find expected target \"tofilename\"",
list.contains("tofilename"));
assertTrue("cannot find expected target \"fromfilename\"",
list.contains("fromfilename"));
assertTrue("cannot find expected target \"mergefile\"",
list.contains("mergefile"));
}
示例4: execute
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
public void execute() throws BuildException {
if (list == null && currPath == null) {
throw new BuildException("You must have a list or path to iterate through");
}
if (param == null)
throw new BuildException("You must supply a property name to set on each iteration in param");
if (target == null)
throw new BuildException("You must supply a target to perform");
Vector values = new Vector();
// Take Care of the list attribute
if (list != null) {
StringTokenizer st = new StringTokenizer(list, delimiter);
while (st.hasMoreTokens()) {
String tok = st.nextToken();
if (trim)
tok = tok.trim();
values.addElement(tok);
}
}
String[] pathElements = new String[0];
if (currPath != null) {
pathElements = currPath.list();
}
for (int i = 0; i < pathElements.length; i++) {
if (mapper != null) {
FileNameMapper m = mapper.getImplementation();
String mapped[] = m.mapFileName(pathElements[i]);
for (int j = 0; j < mapped.length; j++)
values.addElement(mapped[j]);
} else {
values.addElement(new File(pathElements[i]));
}
}
Vector tasks = new Vector();
int sz = values.size();
CallTarget ct = null;
Object val = null;
Property p = null;
for (int i = 0; i < sz; i++) {
val = values.elementAt(i);
ct = createCallTarget();
p = ct.createParam();
p.setName(param);
if (val instanceof File)
p.setLocation((File) val);
else
p.setValue((String) val);
tasks.addElement(ct);
}
if (parallel && maxThreads > 1) {
executeParallel(tasks);
} else {
executeSequential(tasks);
}
}
示例5: processDir
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
* Executes all the chained ImageOperations on the files inside
* the directory.
* @param srcDir File
* @param srcNames String[]
* @param dstDir File
* @param mapper FileNameMapper
* @return int
* @since Ant 1.8.0
*/
public int processDir(final File srcDir, final String[] srcNames,
final File dstDir, final FileNameMapper mapper) {
int writeCount = 0;
for (int i = 0; i < srcNames.length; ++i) {
final String srcName = srcNames[i];
final File srcFile = new File(srcDir, srcName).getAbsoluteFile();
final String[] dstNames = mapper.mapFileName(srcName);
if (dstNames == null) {
log(srcFile + " skipped, don't know how to handle it",
Project.MSG_VERBOSE);
continue;
}
for (String dstName : dstNames) {
final File dstFile = new File(dstDir, dstName).getAbsoluteFile();
if (dstFile.exists()) {
// avoid overwriting unless necessary
if(!overwrite
&& srcFile.lastModified() <= dstFile.lastModified()) {
log(srcFile + " omitted as " + dstFile
+ " is up to date.", Project.MSG_VERBOSE);
// don't overwrite the file
continue;
}
// avoid extra work while overwriting
if (!srcFile.equals(dstFile)) {
dstFile.delete();
}
}
processFile(srcFile, dstFile);
++writeCount;
}
}
// run the garbage collector if wanted
if (garbage_collect) {
System.gc();
}
return writeCount;
}
示例6: execute
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
* Do the execution.
* @throws BuildException if something is invalid.
*/
@Override
public void execute() throws BuildException {
Resources savedPath = path;
String savedPathSep = pathSep; // may be altered in validateSetup
String savedDirSep = dirSep; // may be altered in validateSetup
try {
// If we are a reference, create a Path from the reference
if (isReference()) {
Object o = refid.getReferencedObject(getProject());
if (!(o instanceof ResourceCollection)) {
throw new BuildException(
"refid '%s' does not refer to a resource collection.",
refid.getRefId());
}
getPath().add((ResourceCollection) o);
}
validateSetup(); // validate our setup
// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows
// (with the exception for NetWare and OS/2 below)
// for NetWare and OS/2, piggy-back on Windows, since here and
// in the apply code, the same assumptions can be made as with
// windows - that \\ is an OK separator, and do comparisons
// case-insensitive.
String fromDirSep = onWindows ? "\\" : "/";
StringBuilder rslt = new StringBuilder();
ResourceCollection resources = isPreserveDuplicates() ? (ResourceCollection) path : new Union(path);
List<String> ret = new ArrayList<>();
FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
for (Resource r : resources) {
String[] mapped = mapperImpl.mapFileName(String.valueOf(r));
for (int m = 0; mapped != null && m < mapped.length; ++m) {
ret.add(mapped[m]);
}
}
boolean first = true;
for (String string : ret) {
String elem = mapElement(string); // Apply the path prefix map
// Now convert the path and file separator characters from the
// current os to the target os.
if (!first) {
rslt.append(pathSep);
}
first = false;
StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true);
while (stDirectory.hasMoreTokens()) {
String token = stDirectory.nextToken();
rslt.append(fromDirSep.equals(token) ? dirSep : token);
}
}
// Place the result into the specified property,
// unless setonempty == false
if (setonempty || rslt.length() > 0) {
String value = rslt.toString();
if (property == null) {
log(value);
} else {
log("Set property " + property + " = " + value, Project.MSG_VERBOSE);
getProject().setNewProperty(property, value);
}
}
} finally {
path = savedPath;
dirSep = savedDirSep;
pathSep = savedPathSep;
}
}
示例7: execute
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
* Does the work.
*
* @exception BuildException Thrown in unrecoverable error.
*/
@Override
public void execute() throws BuildException {
checkAttributes();
for (final Resource r : sources) {
final URLProvider up = r.as(URLProvider.class);
final URL source = up.getURL();
File dest = destination;
if (destination.isDirectory()) {
if (mapperElement == null) {
String path = source.getPath();
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
final int slash = path.lastIndexOf('/');
if (slash > -1) {
path = path.substring(slash + 1);
}
dest = new File(destination, path);
} else {
final FileNameMapper mapper = mapperElement.getImplementation();
final String[] d = mapper.mapFileName(source.toString());
if (d == null) {
log("skipping " + r + " - mapper can't handle it",
Project.MSG_WARN);
continue;
}
if (d.length == 0) {
log("skipping " + r + " - mapper returns no file name",
Project.MSG_WARN);
continue;
}
if (d.length > 1) {
log("skipping " + r + " - mapper returns multiple file"
+ " names", Project.MSG_WARN);
continue;
}
dest = new File(destination, d[0]);
}
}
//set up logging
final int logLevel = Project.MSG_INFO;
DownloadProgress progress = null;
if (verbose) {
progress = new VerboseProgress(System.out);
}
//execute the get
try {
doGet(source, dest, logLevel, progress);
} catch (final IOException ioe) {
log("Error getting " + source + " to " + dest);
if (!ignoreErrors) {
throw new BuildException(ioe, getLocation());
}
}
}
}
示例8: process
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
/**
* Processes the given input XML file and stores the result
* in the given resultFile.
*
* @param baseDir the base directory for resolving files.
* @param xmlFile the input file
* @param destDir the destination directory
* @param stylesheet the stylesheet to use.
* @exception BuildException if the processing fails.
*/
private void process(final File baseDir, final String xmlFile, final File destDir, final Resource stylesheet)
throws BuildException {
File outF = null;
try {
final long styleSheetLastModified = stylesheet.getLastModified();
File inF = new File(baseDir, xmlFile);
if (inF.isDirectory()) {
log("Skipping " + inF + " it is a directory.", Project.MSG_VERBOSE);
return;
}
FileNameMapper mapper = mapperElement == null ? new StyleMapper()
: mapperElement.getImplementation();
final String[] outFileName = mapper.mapFileName(xmlFile);
if (outFileName == null || outFileName.length == 0) {
log("Skipping " + inFile + " it cannot get mapped to output.", Project.MSG_VERBOSE);
return;
}
if (outFileName.length > 1) {
log("Skipping " + inFile + " its mapping is ambiguous.", Project.MSG_VERBOSE);
return;
}
outF = new File(destDir, outFileName[0]);
if (force || inF.lastModified() > outF.lastModified()
|| styleSheetLastModified > outF.lastModified()) {
ensureDirectoryFor(outF);
log("Processing " + inF + " to " + outF);
configureLiaison(stylesheet);
setLiaisonDynamicFileParameters(liaison, inF);
liaison.transform(inF, outF);
}
} catch (final Exception ex) {
// If failed to process document, must delete target document,
// or it will not attempt to process it the second time
log("Failed to process " + inFile, Project.MSG_INFO);
if (outF != null) {
outF.delete();
}
handleTransformationError(ex);
}
}
示例9: testChained
import org.apache.tools.ant.util.FileNameMapper; //导入方法依赖的package包/类
@Test
public void testChained() {
// a --> b --> c --- def
// \-- ghi
FileNameMapper mapperAB = new GlobPatternMapper();
mapperAB.setFrom("a");
mapperAB.setTo("b");
FileNameMapper mapperBC = new GlobPatternMapper();
mapperBC.setFrom("b");
mapperBC.setTo("c");
//implicit composite
Mapper mapperCX = new Mapper(project);
FileNameMapper mapperDEF = new GlobPatternMapper();
mapperDEF.setFrom("c");
mapperDEF.setTo("def");
FileNameMapper mapperGHI = new GlobPatternMapper();
mapperGHI.setFrom("c");
mapperGHI.setTo("ghi");
mapperCX.add(mapperDEF);
mapperCX.add(mapperGHI);
Mapper chained = new Mapper(project);
chained.setClassname(ChainedMapper.class.getName());
chained.add(mapperAB);
chained.add(mapperBC);
chained.addConfiguredMapper(mapperCX);
FileNameMapper fileNameMapper = chained.getImplementation();
String[] targets = fileNameMapper.mapFileName("a");
assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 2, targets.length);
List list = Arrays.asList(targets);
assertTrue("cannot find expected target \"def\"", list.contains("def"));
assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
}