Search in sources :

Example 1 with AssemblerProcessingException

use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.

the class Assemblers method assemble.

private static void assemble(JReleaserContext context, Assembler assembler) {
    try {
        context.getLogger().increaseIndent();
        context.getLogger().setPrefix(assembler.getType());
        DistributionAssembler processor = createDistributionAssembler(context, assembler);
        processor.assemble();
        context.getLogger().restorePrefix();
        context.getLogger().decreaseIndent();
    } catch (AssemblerProcessingException e) {
        throw new JReleaserException(e.getMessage(), e);
    }
}
Also used : AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with AssemblerProcessingException

use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.

the class AbstractJavaAssemblerProcessor method copyFiles.

protected Set<Path> copyFiles(JReleaserContext context, Path destination) throws AssemblerProcessingException {
    Set<Path> paths = new LinkedHashSet<>();
    // resolve all first
    for (Glob glob : assembler.getFiles()) {
        glob.getResolvedArtifacts(context).stream().map(artifact -> artifact.getResolvedPath(context, assembler)).forEach(paths::add);
    }
    // copy all next
    try {
        Files.createDirectories(destination);
        for (Path path : paths) {
            context.getLogger().debug(RB.$("assembler.copying"), path.getFileName());
            Files.copy(path, destination.resolve(path.getFileName()), REPLACE_EXISTING);
        }
    } catch (IOException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_assembler_copying_files"), e);
    }
    return paths;
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) Constants(org.jreleaser.util.Constants) JavaAssembler(org.jreleaser.model.JavaAssembler) Files(java.nio.file.Files) MustacheUtils.applyTemplate(org.jreleaser.util.MustacheUtils.applyTemplate) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) Glob(org.jreleaser.model.Glob) Project(org.jreleaser.model.Project) TemplateUtils.resolveAndMergeTemplates(org.jreleaser.templates.TemplateUtils.resolveAndMergeTemplates) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) RB(org.jreleaser.bundle.RB) Path(java.nio.file.Path) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) LinkedHashSet(java.util.LinkedHashSet) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) Glob(org.jreleaser.model.Glob) IOException(java.io.IOException)

Example 3 with AssemblerProcessingException

use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.

the class AbstractJavaAssemblerProcessor method assemble.

@Override
public void assemble(Map<String, Object> props) throws AssemblerProcessingException {
    try {
        context.getLogger().debug(RB.$("packager.create.properties"), assembler.getType(), assembler.getName());
        Map<String, Object> newProps = fillProps(props);
        context.getLogger().debug(RB.$("packager.resolve.templates"), assembler.getType(), assembler.getName());
        Map<String, Reader> templates = resolveAndMergeTemplates(context.getLogger(), assembler.getType(), assembler.getType(), context.getModel().getProject().isSnapshot(), context.getBasedir().resolve(getAssembler().getTemplateDirectory()));
        for (Map.Entry<String, Reader> entry : templates.entrySet()) {
            context.getLogger().debug(RB.$("packager.evaluate.template"), entry.getKey(), assembler.getName(), assembler.getType());
            String content = applyTemplate(entry.getValue(), newProps, entry.getKey());
            context.getLogger().debug(RB.$("packager.write.template"), entry.getKey(), assembler.getName(), assembler.getType());
            writeFile(context.getModel().getProject(), content, newProps, entry.getKey());
        }
        Path assembleDirectory = (Path) props.get(Constants.KEY_DISTRIBUTION_ASSEMBLE_DIRECTORY);
        Files.createDirectories(assembleDirectory);
        doAssemble(newProps);
    } catch (IllegalArgumentException | IOException e) {
        throw new AssemblerProcessingException(e);
    }
}
Also used : Path(java.nio.file.Path) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) Reader(java.io.Reader) IOException(java.io.IOException) Map(java.util.Map)

Example 4 with AssemblerProcessingException

use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.

the class AssemblerUtils method copyJars.

public static Set<Path> copyJars(JReleaserContext context, JavaAssembler assembler, Path jarsDirectory, String platform) throws AssemblerProcessingException {
    Set<Path> paths = new LinkedHashSet<>();
    // resolve all first
    if (isBlank(platform)) {
        paths.add(assembler.getMainJar().getEffectivePath(context, assembler));
    }
    for (Glob glob : assembler.getJars()) {
        if ((isBlank(platform) && isBlank(glob.getPlatform())) || (isNotBlank(platform) && PlatformUtils.isCompatible(platform, glob.getPlatform()))) {
            glob.getResolvedArtifacts(context).stream().map(artifact -> artifact.getResolvedPath(context, assembler)).forEach(paths::add);
        }
    }
    // copy all next
    try {
        Files.createDirectories(jarsDirectory);
        for (Path path : paths) {
            context.getLogger().debug(RB.$("assembler.copying"), path.getFileName());
            Files.copy(path, jarsDirectory.resolve(path.getFileName()), REPLACE_EXISTING);
        }
    } catch (IOException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_assembler_copying_jars"), e);
    }
    return paths;
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) JavaAssembler(org.jreleaser.model.JavaAssembler) Properties(java.util.Properties) Files(java.nio.file.Files) Set(java.util.Set) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) IOException(java.io.IOException) PlatformUtils(org.jreleaser.util.PlatformUtils) File(java.io.File) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) Glob(org.jreleaser.model.Glob) Paths(java.nio.file.Paths) JReleaserContext(org.jreleaser.model.JReleaserContext) RB(org.jreleaser.bundle.RB) Path(java.nio.file.Path) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) LinkedHashSet(java.util.LinkedHashSet) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) Glob(org.jreleaser.model.Glob) IOException(java.io.IOException)

Example 5 with AssemblerProcessingException

use of org.jreleaser.model.assembler.spi.AssemblerProcessingException in project jreleaser by jreleaser.

the class JlinkAssemblerProcessor method calculateJarPath.

private void calculateJarPath(Path jarsDirectory, String platform, Command cmd, boolean join) throws AssemblerProcessingException {
    try {
        if (join) {
            StringBuilder pathBuilder = new StringBuilder();
            String s = listFilesAndProcess(jarsDirectory.resolve("universal"), files -> files.map(jarsDirectory::relativize).map(Object::toString).collect(joining(File.pathSeparator)));
            pathBuilder.append(s);
            String platformSpecific = listFilesAndProcess(jarsDirectory.resolve(platform), files -> files.map(jarsDirectory::relativize).map(Object::toString).collect(joining(File.pathSeparator)));
            if (isNotBlank(platformSpecific)) {
                pathBuilder.append(File.pathSeparator).append(platformSpecific);
            }
            cmd.arg(pathBuilder.toString());
        } else {
            listFilesAndConsume(jarsDirectory.resolve("universal"), files -> files.map(jarsDirectory::relativize).map(Object::toString).forEach(cmd::arg));
            listFilesAndConsume(jarsDirectory.resolve(platform), files -> files.map(jarsDirectory::relativize).map(Object::toString).forEach(cmd::arg));
        }
    } catch (IOException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_assembler_jdeps_error", e.getMessage()));
    }
}
Also used : AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) IOException(java.io.IOException)

Aggregations

AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)23 IOException (java.io.IOException)18 Path (java.nio.file.Path)18 Command (org.jreleaser.util.command.Command)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Properties (java.util.Properties)3 Artifact (org.jreleaser.model.Artifact)3 Reader (java.io.Reader)2 Files (java.nio.file.Files)2 REPLACE_EXISTING (java.nio.file.StandardCopyOption.REPLACE_EXISTING)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 RB (org.jreleaser.bundle.RB)2 Archive (org.jreleaser.model.Archive)2 Glob (org.jreleaser.model.Glob)2 JReleaserContext (org.jreleaser.model.JReleaserContext)2 JavaAssembler (org.jreleaser.model.JavaAssembler)2 Jpackage (org.jreleaser.model.Jpackage)2 SemVer (org.jreleaser.util.SemVer)2