/**
* @see org.apache.tools.ant.Task#execute()
*/
@Override
public void execute() {
final ProcessorFactory processorFactory = new JavaEEProcessorFactory();
try {
final File temp = File.createTempFile("smaller-ant", ".dir");
try {
temp.delete();
temp.mkdirs();
log("Reading config-file: " + this.configFilePath);
final ConfigFile configFile = ConfigFile.read(this.configFilePath);
final List<String> includedFiles = new ArrayList<String>();
for (final String envName : configFile.getBuildServer()
.getEnvironments()) {
final Environment env = configFile.getEnvironments().get(envName);
for (final String dir : env.getFiles().getFolder()) {
copyFirstInputFile(env, dir, temp);
File base = new File(dir);
if (!base.isAbsolute()) {
base = new File(this.configFilePath.getParentFile(),
base.getPath());
}
final String[] included = scanIncludedFiles(base.getAbsolutePath(),
env.getFiles().getIncludes(), env.getFiles().getExcludes());
for (final String include : included) {
FileUtils.copyFile(new File(base, include), new File(temp,
include));
includedFiles.add(include);
}
}
}
final VFS vfs = new VFS();
try {
vfs.mount(vfs.find("/"), new JavaFile(temp));
final ResourceResolver resolver = new VFSResourceResolver(vfs);
final Manifest manifest = Manifest.fromConfigFile(configFile);
final Pipeline pipeline = new Pipeline(processorFactory);
pipeline.execute(Version.getCurrentVersion(), vfs, resolver,
manifest, this.target);
} finally {
vfs.dispose();
}
} finally {
FileUtils.deleteDirectory(temp);
}
} catch (final IOException e) {
log(Util.formatException(e), Project.MSG_ERR);
throw new BuildException("Failed execute embedded smaller", e);
} finally {
processorFactory.dispose();
}
}