@Override
protected List<FilePath> run() throws Exception {
// where to copy artifacts from?
Run r = build; // TODO consider an option to override this (but in what format?)
ArtifactManager am = r.getArtifactManager();
List<FilePath> files = new ArrayList<FilePath>();
if (step.mapping == null)
throw new AbortException("'mapping' has not been defined for this 'unarchive' step");
for (Entry<String, String> e : step.mapping.entrySet()) {
FilePath dst = new FilePath(ws,e.getValue());
String src = e.getKey();
String[] all = am.root().list(src);
if (all.length == 0) {
throw new AbortException("no artifacts to unarchive in " + src);
} else if (all.length == 1 && all[0].equals(src)) {
// the source is a file
if (dst.isDirectory())
dst = dst.child(getFileName(all[0]));
files.add(copy(am.root().child(all[0]), dst));
} else {
// copy into a directory
for (String path : all) {
files.add(copy(am.root().child(path), dst.child(path)));
}
}
}
return files;