use of org.metaborg.util.resource.ZipArchiver in project spoofax by metaborg.
the class ArchiveBuilder method build.
@Override
protected OutputTransient<File> build(Input input) throws Throwable {
requireBuild(input.origin);
final ZipArchiver zipArchiver = new ZipArchiver();
final FileObject root = paths.root();
require(toFile(paths.iconsDir()), new DirectoryModifiedStamper());
zipArchiver.addFilesTo(root.getName(), paths.iconsDir(), FileSelectorUtils.all());
require(toFile(paths.targetMetaborgDir()), new DirectoryModifiedStamper());
zipArchiver.addFilesTo(root.getName(), paths.targetMetaborgDir(), FileSelectorUtils.not(FileSelectorUtils.ant("*.dep")));
zipArchiver.addFileTo(root.getName(), paths.mbComponentConfigFile());
for (IExportConfig export : input.exports) {
export.accept(new IExportVisitor() {
@Override
public void visit(ResourceExport export) {
addFiles(export, export.directory, export.includes, export.excludes);
}
@Override
public void visit(LangDirExport export) {
addFiles(export, export.directory, export.includes, export.excludes);
}
@Override
public void visit(LangFileExport export) {
try {
final FileObject file = paths.root().resolveFile(export.file);
zipArchiver.addFile(export.file, file);
} catch (IOException e) {
report("Unable to package export: " + export);
}
}
private void addFiles(IExportConfig export, String directory, Iterable<String> includes, Iterable<String> excludes) {
try {
final FileObject dir = paths.root().resolveFile(directory);
final FileSelector includesSelector;
if (Iterables.isEmpty(includes)) {
includesSelector = FileSelectorUtils.all();
} else {
includesSelector = FileSelectorUtils.ant(includes);
}
final FileSelector excludesSelector;
if (Iterables.isEmpty(excludes)) {
excludesSelector = FileSelectorUtils.none();
} else {
excludesSelector = FileSelectorUtils.ant(excludes);
}
zipArchiver.addFilesTo(paths.root().getName(), dir, FileSelectorUtils.includeExclude(includesSelector, excludesSelector));
} catch (IOException e) {
report("Unable to package export: " + export);
}
}
});
}
final FileObject spxArchiveFile = paths.spxArchiveFile(input.languageIdentifier.toFileString());
zipArchiver.build(spxArchiveFile, this);
return OutputTransient.of(toFile(spxArchiveFile));
}
Aggregations