Search in sources :

Example 1 with Command

use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.

the class ChocolateyPackagerProcessor method publishChocolateyPackage.

private void publishChocolateyPackage(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
    Path packageDirectory = (Path) props.get(KEY_DISTRIBUTION_PACKAGE_DIRECTORY);
    Path execDirectory = packageDirectory.resolve(distribution.getName());
    Command cmd = new Command("choco").arg("apikey").arg("-k").arg(packager.getResolvedApiKey()).arg("-source").arg(packager.getSource());
    executeCommand(execDirectory, cmd);
    try {
        Optional<String> nuget = listFilesAndProcess(execDirectory, files -> files.map(Path::getFileName).map(Path::toString).filter(s -> s.endsWith(".nupkg")).findFirst());
        if (nuget.isPresent()) {
            cmd = new Command("choco").arg("push").arg(nuget.get()).arg("-s").arg(packager.getSource());
            context.getLogger().debug(String.join(" ", cmd.getArgs()));
            executeCommand(execDirectory, cmd);
        } else {
            throw new PackagerProcessingException(RB.$("ERROR_chocolatey_nuget_not_found", context.relativizeToBasedir(execDirectory)));
        }
    } catch (IOException e) {
        throw new PackagerProcessingException(RB.$("ERROR_unexpected_error"), e);
    }
}
Also used : Path(java.nio.file.Path) Command(org.jreleaser.util.command.Command) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) IOException(java.io.IOException)

Example 2 with Command

use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.

the class DockerPackagerProcessor method login.

private void login(Registry registry) throws PackagerProcessingException {
    Command cmd = createCommand("login");
    if (isNotBlank(registry.getServer())) {
        cmd.arg(registry.getServer());
    }
    cmd.arg("-u");
    cmd.arg(registry.getResolvedUsername());
    cmd.arg("-p");
    cmd.arg(registry.getResolvedPassword());
    ByteArrayInputStream in = new ByteArrayInputStream((registry.getResolvedPassword() + System.lineSeparator()).getBytes());
    context.getLogger().debug(RB.$("docker.login"), registry.getServerName(), (isNotBlank(registry.getServer()) ? " (" + registry.getServer() + ")" : ""));
    if (!context.isDryrun())
        executeCommandWithInput(cmd, in);
}
Also used : Command(org.jreleaser.util.command.Command) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with Command

use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.

the class DockerPackagerProcessor method packageDocker.

protected void packageDocker(Distribution distribution, Map<String, Object> props, Path packageDirectory, DockerConfiguration docker, List<Artifact> artifacts) throws PackagerProcessingException {
    super.doPackageDistribution(distribution, props, packageDirectory);
    try {
        // copy files
        Path workingDirectory = prepareAssembly(distribution, props, packageDirectory, artifacts);
        for (String imageName : docker.getImageNames()) {
            imageName = resolveTemplate(imageName, props);
            // command line
            Command cmd = createBuildCommand(props, docker);
            if (!cmd.hasArg("-q") && !cmd.hasArg("--quiet")) {
                cmd.arg("-q");
            }
            cmd.arg("-f");
            cmd.arg(workingDirectory.resolve("Dockerfile").toAbsolutePath().toString());
            cmd.arg("-t");
            cmd.arg(imageName);
            cmd.arg(workingDirectory.toAbsolutePath().toString());
            context.getLogger().debug(String.join(" ", cmd.getArgs()));
            context.getLogger().info(" - {}", imageName);
            // execute
            executeCommand(cmd);
        }
    } catch (IOException e) {
        throw new PackagerProcessingException(e);
    }
}
Also used : Path(java.nio.file.Path) Command(org.jreleaser.util.command.Command) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) IOException(java.io.IOException)

Example 4 with Command

use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.

the class SnapPackagerProcessor method push.

private void push(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
    Path packageDirectory = (Path) props.get(KEY_DISTRIBUTION_PACKAGE_DIRECTORY);
    String version = (String) props.get(KEY_PROJECT_EFFECTIVE_VERSION);
    String snapName = packager.getPackageName() + "-" + version + ".snap";
    Command cmd = new Command("snapcraft").arg("push").arg(snapName);
    executeCommand(packageDirectory, cmd);
}
Also used : Path(java.nio.file.Path) Command(org.jreleaser.util.command.Command)

Example 5 with Command

use of org.jreleaser.util.command.Command in project jreleaser by jreleaser.

the class JlinkAssemblerProcessor method jlink.

private Artifact jlink(Path assembleDirectory, Path jdkPath, Artifact targetJdk, Set<String> moduleNames, String imageName, Archive.Format archiveFormat) throws AssemblerProcessingException {
    String platform = targetJdk.getPlatform();
    String platformReplaced = assembler.getPlatform().applyReplacements(platform);
    String finalImageName = imageName + "-" + platformReplaced;
    context.getLogger().info("- {}", finalImageName);
    Path inputsDirectory = assembleDirectory.resolve("inputs");
    Path jarsDirectory = inputsDirectory.resolve("jars");
    Path workDirectory = assembleDirectory.resolve("work-" + platform);
    Path imageDirectory = workDirectory.resolve(finalImageName).toAbsolutePath();
    try {
        FileUtils.deleteFiles(imageDirectory);
    } catch (IOException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_assembler_delete_image", finalImageName), e);
    }
    // jlink it
    String moduleName = assembler.getJava().getMainModule();
    String modulePath = maybeQuote(targetJdk.getEffectivePath(context, assembler).resolve("jmods").toAbsolutePath().toString());
    if (isNotBlank(moduleName) || assembler.isCopyJars()) {
        modulePath += File.pathSeparator + maybeQuote(jarsDirectory.resolve("universal").toAbsolutePath().toString());
        try {
            Path platformJarsDirectory = jarsDirectory.resolve(platform).toAbsolutePath();
            if (listFilesAndProcess(platformJarsDirectory, Stream::count) > 1) {
                modulePath += File.pathSeparator + maybeQuote(platformJarsDirectory.toString());
            }
        } catch (IOException e) {
            throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error", e));
        }
    }
    Path jlinkExecutable = jdkPath.resolve("bin").resolve(PlatformUtils.isWindows() ? "jlink.exe" : "jlink").toAbsolutePath();
    Command cmd = new Command(jlinkExecutable.toString(), true).args(assembler.getArgs()).arg("--module-path").arg(modulePath).arg("--add-modules").arg(String.join(",", moduleNames));
    if (isNotBlank(moduleName)) {
        cmd.arg("--launcher").arg(assembler.getExecutable() + "=" + moduleName + "/" + assembler.getJava().getMainClass());
    }
    cmd.arg("--output").arg(maybeQuote(imageDirectory.toString()));
    context.getLogger().debug(String.join(" ", cmd.getArgs()));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    executeCommandCapturing(cmd, out);
    if (isBlank(moduleName)) {
        if (assembler.isCopyJars()) {
            Path outputJarsDirectory = imageDirectory.resolve("jars");
            try {
                Files.createDirectory(outputJarsDirectory);
                FileUtils.copyFiles(context.getLogger(), jarsDirectory.resolve("universal"), outputJarsDirectory);
                FileUtils.copyFiles(context.getLogger(), jarsDirectory.resolve(platform), outputJarsDirectory);
            } catch (IOException e) {
                throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_jars", context.relativizeToBasedir(outputJarsDirectory)), e);
            }
        }
        try {
            if (PlatformUtils.isWindows(platform)) {
                Files.copy(inputsDirectory.resolve(assembler.getExecutable().concat(".bat")), imageDirectory.resolve("bin").resolve(assembler.getExecutable().concat(".bat")));
            } else {
                Path launcher = imageDirectory.resolve("bin").resolve(assembler.getExecutable());
                Files.copy(inputsDirectory.resolve(assembler.getExecutable()), launcher);
                FileUtils.grantExecutableAccess(launcher);
            }
        } catch (IOException e) {
            throw new AssemblerProcessingException(RB.$("ERROR_assembler_copy_launcher", context.relativizeToBasedir(imageDirectory.resolve("bin"))), e);
        }
    }
    try {
        Path imageArchive = assembleDirectory.resolve(finalImageName + "." + archiveFormat.extension());
        FileUtils.copyFiles(context.getLogger(), context.getBasedir(), imageDirectory, path -> path.getFileName().startsWith("LICENSE"));
        copyFiles(context, imageDirectory);
        copyFileSets(context, imageDirectory);
        switch(archiveFormat) {
            case ZIP:
                FileUtils.zip(workDirectory, imageArchive);
                break;
            case TAR:
                FileUtils.tar(workDirectory, imageArchive);
                break;
            case TGZ:
            case TAR_GZ:
                FileUtils.tgz(workDirectory, imageArchive);
                break;
            case TXZ:
            case TAR_XZ:
                FileUtils.xz(workDirectory, imageArchive);
                break;
            case TBZ2:
            case TAR_BZ2:
                FileUtils.bz2(workDirectory, imageArchive);
        }
        context.getLogger().debug("- {}", imageArchive.getFileName());
        return Artifact.of(imageArchive, platform);
    } catch (IOException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
    }
}
Also used : Path(java.nio.file.Path) Command(org.jreleaser.util.command.Command) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Command (org.jreleaser.util.command.Command)23 Path (java.nio.file.Path)12 IOException (java.io.IOException)6 CommandExecutor (org.jreleaser.util.command.CommandExecutor)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CommandException (org.jreleaser.util.command.CommandException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)4 SigningException (org.jreleaser.util.signing.SigningException)3 PackagerProcessingException (org.jreleaser.model.packager.spi.PackagerProcessingException)2 Pattern (java.util.regex.Pattern)1 Artifact (org.jreleaser.model.Artifact)1 Jpackage (org.jreleaser.model.Jpackage)1 NativeImage (org.jreleaser.model.NativeImage)1