public File archive(File source, File dest, Artifact artifact) throws //ArchiverException,
IOException {
String serverName = artifact.getArtifactId() + "-" + artifact.getVersion();
dest = new File(dest, serverName + "." + artifact.getType());
Project project = new Project();
MatchingTask archiver;
if ("tar.gz".equals(artifact.getType())) {
Tar tar = new Tar();
Tar.TarCompressionMethod tarCompressionMethod = new Tar.TarCompressionMethod();
tarCompressionMethod.setValue("gzip");
tar.setCompression(tarCompressionMethod);
Tar.TarLongFileMode fileMode = new Tar.TarLongFileMode();
fileMode.setValue(Tar.TarLongFileMode.GNU);
tar.setLongfile(fileMode);
tar.setDestFile(dest);
TarFileSet rc = new TarFileSet();
rc.setDir(source);
rc.setPrefix(serverName);
rc.setProject(project);
rc.setExcludes("bin/");
tar.add(rc);
rc = new TarFileSet();
rc.setDir(source);
rc.setPrefix(serverName);
rc.setProject(project);
rc.setIncludes("bin/");
rc.setExcludes("bin/*.bat");
rc.setFileMode("755");
tar.add(rc);
rc = new TarFileSet();
rc.setDir(source);
rc.setPrefix(serverName);
rc.setProject(project);
rc.setIncludes("bin/*.bat");
tar.add(rc);
for (Resource resource: this.project.getResources()) {
File resourceFile = new File(resource.getDirectory());
if (resourceFile.exists()) {
rc = new TarFileSet();
rc.setPrefix(serverName);
rc.setProject(project);
rc.setDir(resourceFile);
rc.appendIncludes(resource.getIncludes().toArray(new String[0]));
rc.appendExcludes(resource.getExcludes().toArray(new String[0]));
tar.add(rc);
}
}
archiver = tar;
} else if ("zip".equals(artifact.getType())) {
Zip zip = new Zip();
zip.setDestFile(dest);
ZipFileSet fs = new ZipFileSet();
fs.setDir(source);
fs.setPrefix(serverName);
fs.setProject(project);
fs.setExcludes("bin/");
zip.addFileset(fs);
fs = new ZipFileSet();
fs.setDir(source);
fs.setPrefix(serverName);
fs.setProject(project);
fs.setIncludes("bin/");
fs.setExcludes("bin/*.bat");
fs.setFileMode("755");
zip.add(fs);
fs = new ZipFileSet();
fs.setDir(source);
fs.setPrefix(serverName);
fs.setProject(project);
fs.setIncludes("bin/*.bat");
zip.add(fs);
for (Resource resource: this.project.getResources()) {
File resourceFile = new File(resource.getDirectory());
if (resourceFile.exists()) {
fs = new ZipFileSet();
fs.setPrefix(serverName);
fs.setProject(project);
fs.setDir(resourceFile);
fs.appendIncludes(resource.getIncludes().toArray(new String[0]));
fs.appendExcludes(resource.getExcludes().toArray(new String[0]));
zip.add(fs);
}
}
archiver = zip;
} else {
throw new IllegalArgumentException("Unknown target type: " + artifact.getType());
}
archiver.setProject(project);
archiver.execute();
return dest;
}