Search in sources :

Example 1 with DirectoryModifiedStamper

use of org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper in project spoofax by metaborg.

the class CopyPattern method build.

@Override
public None build(Input input) throws IOException {
    requireBuild(input.origin);
    require(input.srcDir, new DirectoryModifiedStamper());
    final Collection<File> files = FileUtils.listFiles(input.srcDir, new RegexFileFilter(input.pattern), FalseFileFilter.INSTANCE);
    for (File file : files) {
        require(file);
        final File dstFile = new File(input.dstDir, file.getName());
        FileUtils.copyFile(file, dstFile);
        provide(dstFile);
    }
    return None.val;
}
Also used : DirectoryModifiedStamper(org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File)

Example 2 with DirectoryModifiedStamper

use of org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper 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)

Example 3 with DirectoryModifiedStamper

use of org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper in project spoofax by metaborg.

the class PackageBuilder method jar.

public Origin jar(File jarFile, File baseDir, @Nullable Origin origin, @Nullable File depPath, Iterable<File> paths) throws IOException {
    final Collection<JarBuilder.Entry> fileEntries = Lists.newLinkedList();
    for (File path : paths) {
        require(path, new DirectoryModifiedStamper());
        final Collection<File> files = findFiles(path);
        for (final File classFile : files) {
            final String relative = relativize(classFile, baseDir);
            // Ignore files that are not relative to the base directory.
            if (relative != null) {
                // Convert \ to / on Windows; ZIP/JAR files must use / for paths.
                // HACK: this should be fixed in the JarBuilder.
                final String forwardslashRelative = relative.replace('\\', '/');
                fileEntries.add(new JarBuilder.Entry(forwardslashRelative, classFile));
            }
        }
    }
    final BuildRequest<?, ?, ?, ?> buildRequest = new BuildRequest<>(JarBuilder.factory, new JarBuilder.Input(jarFile, fileEntries, origin, depPath));
    final Origin jarOrigin = Origin.from(buildRequest);
    requireBuild(jarOrigin);
    return jarOrigin;
}
Also used : Origin(build.pluto.dependency.Origin) DirectoryModifiedStamper(org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper) JarBuilder(build.pluto.buildjava.JarBuilder) BuildRequest(build.pluto.builder.BuildRequest) File(java.io.File)

Aggregations

DirectoryModifiedStamper (org.metaborg.spoofax.meta.core.pluto.stamp.DirectoryModifiedStamper)3 File (java.io.File)2 BuildRequest (build.pluto.builder.BuildRequest)1 JarBuilder (build.pluto.buildjava.JarBuilder)1 Origin (build.pluto.dependency.Origin)1 IOException (java.io.IOException)1 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)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 ZipArchiver (org.metaborg.util.resource.ZipArchiver)1