Search in sources :

Example 1 with ZipArchiver

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));
}
Also used : LangFileExport(org.metaborg.core.config.LangFileExport) IExportConfig(org.metaborg.core.config.IExportConfig) FileSelector(org.apache.commons.vfs2.FileSelector) DirectoryModifiedStamper(org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper) IOException(java.io.IOException) ZipArchiver(org.metaborg.util.resource.ZipArchiver) IExportVisitor(org.metaborg.core.config.IExportVisitor) ResourceExport(org.metaborg.core.config.ResourceExport) LangDirExport(org.metaborg.core.config.LangDirExport) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

IOException (java.io.IOException)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSelector (org.apache.commons.vfs2.FileSelector)1 IExportConfig (org.metaborg.core.config.IExportConfig)1 IExportVisitor (org.metaborg.core.config.IExportVisitor)1 LangDirExport (org.metaborg.core.config.LangDirExport)1 LangFileExport (org.metaborg.core.config.LangFileExport)1 ResourceExport (org.metaborg.core.config.ResourceExport)1 DirectoryModifiedStamper (org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper)1 ZipArchiver (org.metaborg.util.resource.ZipArchiver)1