use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class SignJar method execute.
/**
* sign the jar(s)
*
* @throws BuildException on errors
*/
@Override
public void execute() throws BuildException {
// validation logic
final boolean hasJar = jar != null;
final boolean hasSignedJar = signedjar != null;
final boolean hasDestDir = destDir != null;
final boolean hasMapper = mapper != null;
if (!hasJar && !hasResources()) {
throw new BuildException(ERROR_NO_SOURCE);
}
if (null == alias) {
throw new BuildException(ERROR_NO_ALIAS);
}
if (null == storepass) {
throw new BuildException(ERROR_NO_STOREPASS);
}
if (hasDestDir && hasSignedJar) {
throw new BuildException(ERROR_TODIR_AND_SIGNEDJAR);
}
if (hasResources() && hasSignedJar) {
throw new BuildException(ERROR_SIGNEDJAR_AND_PATHS);
}
// we can change implementation details later
if (!hasDestDir && hasMapper) {
throw new BuildException(ERROR_MAPPER_WITHOUT_DEST);
}
beginExecution();
try {
// special case single jar handling with signedjar attribute set
if (hasJar && hasSignedJar) {
// single jar processing
signOneJar(jar, signedjar);
// return here.
return;
}
// the rest of the method treats single jar like
// a nested path with one file
Path sources = createUnifiedSourcePath();
// set up our mapping policy
FileNameMapper destMapper = hasMapper ? mapper : new IdentityMapper();
// deal with the paths
for (Resource r : sources) {
FileResource fr = ResourceUtils.asFileResource(r.as(FileProvider.class));
// calculate our destination directory; it is either the destDir
// attribute, or the base dir of the fileset (for in situ updates)
File toDir = hasDestDir ? destDir : fr.getBaseDir();
// determine the destination filename via the mapper
String[] destFilenames = destMapper.mapFileName(fr.getName());
if (destFilenames == null || destFilenames.length != 1) {
// we only like simple mappers.
throw new BuildException(ERROR_BAD_MAP + fr.getFile());
}
File destFile = new File(toDir, destFilenames[0]);
signOneJar(fr.getFile(), destFile);
}
} finally {
endExecution();
}
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class Get method execute.
/**
* 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());
}
}
}
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class Rmic method scanDir.
/**
* Scans the directory looking for class files to be compiled.
* The result is returned in the class variable compileList.
* @param baseDir the base direction
* @param files the list of files to scan
* @param mapper the mapper of files to target files
*/
protected void scanDir(File baseDir, String[] files, FileNameMapper mapper) {
String[] newFiles = files;
if (idl) {
log("will leave uptodate test to rmic implementation in idl mode.", Project.MSG_VERBOSE);
} else if (iiop && iiopOpts != null && iiopOpts.contains("-always")) {
log("no uptodate test as -always option has been specified", Project.MSG_VERBOSE);
} else {
SourceFileScanner sfs = new SourceFileScanner(this);
newFiles = sfs.restrict(files, baseDir, getOutputDir(), mapper);
}
Stream.of(newFiles).map(s -> s.replace(File.separatorChar, '.')).map(s -> s.substring(0, s.lastIndexOf(".class"))).forEach(compileList::add);
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class PathConvert method add.
/**
* Add a nested filenamemapper.
* @param fileNameMapper the mapper to add.
* @since Ant 1.6.3
*/
public void add(FileNameMapper fileNameMapper) {
Mapper m = new Mapper(getProject());
m.add(fileNameMapper);
addMapper(m);
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class Image method execute.
/**
* Executes the Task.
* @throws BuildException on error.
*/
@Override
public void execute() throws BuildException {
validateAttributes();
try {
File dest = (destDir != null) ? destDir : srcDir;
int writeCount = 0;
// build mapper
final FileNameMapper mapper = mapperElement == null ? new IdentityMapper() : mapperElement.getImplementation();
// deal with specified srcDir
if (srcDir != null) {
writeCount += processDir(srcDir, super.getDirectoryScanner(srcDir).getIncludedFiles(), dest, mapper);
}
// deal with the filesets
for (FileSet fs : filesets) {
writeCount += processDir(fs.getDir(getProject()), fs.getDirectoryScanner(getProject()).getIncludedFiles(), dest, mapper);
}
if (writeCount > 0) {
log("Processed " + writeCount + (writeCount == 1 ? " image." : " images."));
}
} catch (Exception err) {
log(StringUtils.getStackTrace(err), Project.MSG_ERR);
throw new BuildException(err.getMessage());
}
}
Aggregations