use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class XSLTProcess method process.
/**
* 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);
}
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class Mapper method getImplementation.
/**
* Returns a fully configured FileNameMapper implementation.
* @return a FileNameMapper object to be configured
* @throws BuildException on error
*/
public FileNameMapper getImplementation() throws BuildException {
if (isReference()) {
dieOnCircularReference();
Reference r = getRefid();
Object o = r.getReferencedObject(getProject());
if (o instanceof FileNameMapper) {
return (FileNameMapper) o;
}
if (o instanceof Mapper) {
return ((Mapper) o).getImplementation();
}
String od = o == null ? "null" : o.getClass().getName();
throw new BuildException(od + " at reference '" + r.getRefId() + "' is not a valid mapper reference.");
}
if (type == null && classname == null && container == null) {
throw new BuildException("nested mapper or " + "one of the attributes type or classname is required");
}
if (container != null) {
return container;
}
if (type != null && classname != null) {
throw new BuildException("must not specify both type and classname attribute");
}
try {
FileNameMapper m = getImplementationClass().newInstance();
final Project p = getProject();
if (p != null) {
p.setProjectReference(m);
}
m.setFrom(from);
m.setTo(to);
return m;
} catch (BuildException be) {
throw be;
} catch (Throwable t) {
throw new BuildException(t);
}
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class PropertySet method getPropertyMap.
/**
* @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 query the PropertyHelper for property value to grab potentially shadowed values?
if (value != null) {
// 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;
}
use of org.apache.tools.ant.util.FileNameMapper in project ant-ivy by apache.
the class IvyRetrieve method add.
/**
* Add a nested filenamemapper.
*
* @param fileNameMapper
* the mapper to add.
*/
public void add(FileNameMapper fileNameMapper) {
Mapper m = new Mapper(getProject());
m.add(fileNameMapper);
addMapper(m);
}
Aggregations