Search in sources :

Example 1 with PackagerProcessingException

use of org.jreleaser.model.packager.spi.PackagerProcessingException in project jreleaser by jreleaser.

the class Distributions method processPackager.

private static void processPackager(JReleaserContext context, Distribution distribution, String packagerName, PackagerProcessingFunction function) {
    context.getLogger().increaseIndent();
    context.getLogger().setPrefix(packagerName);
    try {
        DistributionProcessor processor = createDistributionProcessor(context, distribution, packagerName);
        function.consume(processor);
    } catch (PackagerProcessingException e) {
        throw new JReleaserException(RB.$("ERROR_unexpected_error"), e);
    }
    context.getLogger().restorePrefix();
    context.getLogger().decreaseIndent();
}
Also used : PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with PackagerProcessingException

use of org.jreleaser.model.packager.spi.PackagerProcessingException in project jreleaser by jreleaser.

the class AbstractTemplatePackagerProcessor method doPackageDistribution.

protected void doPackageDistribution(Distribution distribution, Map<String, Object> props, Path packageDirectory) throws PackagerProcessingException {
    try {
        // cleanup from previous session
        FileUtils.deleteFiles(packageDirectory);
        Files.createDirectories(packageDirectory);
    } catch (IOException e) {
        throw new PackagerProcessingException(e);
    }
}
Also used : PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) IOException(java.io.IOException)

Example 3 with PackagerProcessingException

use of org.jreleaser.model.packager.spi.PackagerProcessingException in project jreleaser by jreleaser.

the class AbstractTemplatePackagerProcessor method writeFile.

protected void writeFile(Reader reader, Path outputFile) throws PackagerProcessingException {
    try {
        createDirectoriesWithFullAccess(outputFile.getParent());
        Scanner scanner = new Scanner(reader);
        scanner.useDelimiter("\\Z");
        Files.write(outputFile, scanner.next().getBytes(), CREATE, WRITE, TRUNCATE_EXISTING);
        scanner.close();
        grantFullAccess(outputFile);
    } catch (IOException e) {
        throw new PackagerProcessingException(RB.$("ERROR_unexpected_error_writing_file", outputFile.toAbsolutePath()), e);
    }
}
Also used : Scanner(java.util.Scanner) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) IOException(java.io.IOException)

Example 4 with PackagerProcessingException

use of org.jreleaser.model.packager.spi.PackagerProcessingException in project jreleaser by jreleaser.

the class BrewPackagerProcessor method fillPackagerProperties.

@Override
protected void fillPackagerProperties(Map<String, Object> props, Distribution distribution) throws PackagerProcessingException {
    GitService gitService = context.getModel().getRelease().getGitService();
    props.put(KEY_BREW_FORMULA_NAME, packager.getResolvedFormulaName(props));
    props.put(KEY_HOMEBREW_TAP_REPO_URL, gitService.getResolvedRepoUrl(context.getModel(), packager.getTap().getOwner(), packager.getTap().getResolvedName()));
    props.put(KEY_HOMEBREW_TAP_REPO_CLONE_URL, gitService.getResolvedRepoCloneUrl(context.getModel(), packager.getTap().getOwner(), packager.getTap().getResolvedName()));
    props.put(KEY_BREW_HAS_LIVECHECK, packager.hasLivecheck());
    if (packager.hasLivecheck()) {
        props.put(KEY_BREW_LIVECHECK, packager.getLivecheck().stream().map(line -> resolveTemplate(line, props)).map(MustacheUtils::passThrough).collect(Collectors.toList()));
    }
    Brew.Cask cask = packager.getCask();
    if (cask.isEnabled()) {
        boolean hasPkg = isNotBlank(cask.getPkgName());
        boolean hasApp = isNotBlank(cask.getAppName());
        props.put(KEY_BREW_CASK_NAME, cask.getResolvedCaskName(props));
        props.put(KEY_BREW_CASK_DISPLAY_NAME, cask.getResolvedDisplayName(props));
        props.put(KEY_BREW_CASK_HAS_UNINSTALL, !cask.getUninstallItems().isEmpty());
        props.put(KEY_BREW_CASK_HAS_PKG, hasPkg);
        if (hasPkg) {
            props.put(KEY_BREW_CASK_PKG, cask.getResolvedPkgName(props));
        }
        props.put(KEY_BREW_CASK_HAS_APP, hasApp);
        if (hasApp) {
            props.put(KEY_BREW_CASK_APP, cask.getResolvedAppName(props));
        }
        props.put(KEY_BREW_CASK_UNINSTALL, cask.getUninstallItems());
        props.put(KEY_BREW_CASK_HAS_ZAP, !cask.getZapItems().isEmpty());
        props.put(KEY_BREW_CASK_ZAP, cask.getZapItems());
        String appcast = cask.getResolvedAppcast(props);
        props.put(KEY_BREW_CASK_HAS_APPCAST, isNotBlank(appcast));
        props.put(KEY_BREW_CASK_APPCAST, appcast);
        if (!hasApp && !hasPkg) {
            for (Artifact artifact : collectArtifacts(distribution)) {
                if (artifact.getPath().endsWith(ZIP.extension())) {
                    props.put(KEY_DISTRIBUTION_URL, resolveArtifactUrl(props, distribution, artifact));
                    props.put(KEY_BREW_CASK_HAS_BINARY, true);
                    break;
                }
            }
        }
    } else if (packager.isMultiPlatform()) {
        List<String> multiPlatforms = new ArrayList<>();
        for (Artifact artifact : collectArtifacts(distribution)) {
            if (!artifact.getPath().endsWith(ZIP.extension()) || isBlank(artifact.getPlatform()))
                continue;
            String template = null;
            String artifactUrl = resolveArtifactUrl(props, distribution, artifact);
            if (PlatformUtils.isMac(artifact.getPlatform())) {
                if (PlatformUtils.isArm(artifact.getPlatform())) {
                    template = TPL_MAC_ARM;
                } else {
                    template = TPL_MAC_INTEL;
                }
            } else if (PlatformUtils.isLinux(artifact.getPlatform())) {
                if (PlatformUtils.isArm(artifact.getPlatform())) {
                    template = TPL_LINUX_ARM;
                } else {
                    template = TPL_LINUX_INTEL;
                }
            }
            if (isNotBlank(template)) {
                Map<String, Object> newProps = new LinkedHashMap<>(props);
                newProps.put(KEY_DISTRIBUTION_URL, artifactUrl);
                newProps.put(KEY_DISTRIBUTION_CHECKSUM_SHA_256, artifact.getHash(Algorithm.SHA_256));
                multiPlatforms.add(resolveTemplate(template, newProps));
            }
        }
        if (multiPlatforms.isEmpty()) {
            throw new PackagerProcessingException(org.jreleaser.bundle.RB.$("ERROR_brew_multiplatform_artifacts"));
        }
        props.put(KEY_BREW_MULTIPLATFORM, passThrough(String.join(System.lineSeparator() + "  ", multiPlatforms)));
    } else if ((distribution.getType() == Distribution.DistributionType.JAVA_BINARY || distribution.getType() == Distribution.DistributionType.SINGLE_JAR) && !isTrue(packager.getExtraProperties().get(SKIP_JAVA))) {
        packager.addDependency("openjdk@" + props.get(KEY_DISTRIBUTION_JAVA_VERSION));
    }
    props.put(KEY_BREW_DEPENDENCIES, packager.getDependenciesAsList().stream().map(dependency -> passThrough(dependency.toString())).collect(Collectors.toList()));
}
Also used : TemplateUtils.trimTplExtension(org.jreleaser.templates.TemplateUtils.trimTplExtension) MustacheUtils.passThrough(org.jreleaser.util.MustacheUtils.passThrough) KEY_BREW_MULTIPLATFORM(org.jreleaser.util.Constants.KEY_BREW_MULTIPLATFORM) Artifact(org.jreleaser.model.Artifact) KEY_BREW_FORMULA_NAME(org.jreleaser.util.Constants.KEY_BREW_FORMULA_NAME) StringUtils.isTrue(org.jreleaser.util.StringUtils.isTrue) KEY_DISTRIBUTION_URL(org.jreleaser.util.Constants.KEY_DISTRIBUTION_URL) KEY_BREW_CASK_HAS_PKG(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_PKG) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) KEY_BREW_CASK_APPCAST(org.jreleaser.util.Constants.KEY_BREW_CASK_APPCAST) KEY_BREW_DEPENDENCIES(org.jreleaser.util.Constants.KEY_BREW_DEPENDENCIES) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) KEY_BREW_CASK_UNINSTALL(org.jreleaser.util.Constants.KEY_BREW_CASK_UNINSTALL) KEY_BREW_CASK_HAS_BINARY(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_BINARY) KEY_BREW_CASK_DISPLAY_NAME(org.jreleaser.util.Constants.KEY_BREW_CASK_DISPLAY_NAME) KEY_BREW_HAS_LIVECHECK(org.jreleaser.util.Constants.KEY_BREW_HAS_LIVECHECK) ZIP(org.jreleaser.util.FileType.ZIP) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Distribution(org.jreleaser.model.Distribution) Path(java.nio.file.Path) KEY_BREW_LIVECHECK(org.jreleaser.util.Constants.KEY_BREW_LIVECHECK) KEY_BREW_CASK_PKG(org.jreleaser.util.Constants.KEY_BREW_CASK_PKG) Templates.resolveTemplate(org.jreleaser.util.Templates.resolveTemplate) KEY_DISTRIBUTION_JAVA_VERSION(org.jreleaser.util.Constants.KEY_DISTRIBUTION_JAVA_VERSION) Algorithm(org.jreleaser.util.Algorithm) KEY_BREW_CASK_HAS_ZAP(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_ZAP) Brew(org.jreleaser.model.Brew) KEY_BREW_CASK_APP(org.jreleaser.util.Constants.KEY_BREW_CASK_APP) KEY_BREW_CASK_HAS_APPCAST(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_APPCAST) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) Project(org.jreleaser.model.Project) KEY_HOMEBREW_TAP_REPO_URL(org.jreleaser.util.Constants.KEY_HOMEBREW_TAP_REPO_URL) List(java.util.List) KEY_BREW_CASK_ZAP(org.jreleaser.util.Constants.KEY_BREW_CASK_ZAP) MustacheUtils(org.jreleaser.util.MustacheUtils) GitService(org.jreleaser.model.GitService) KEY_BREW_CASK_HAS_UNINSTALL(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_UNINSTALL) KEY_BREW_CASK_HAS_APP(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_APP) KEY_HOMEBREW_TAP_REPO_CLONE_URL(org.jreleaser.util.Constants.KEY_HOMEBREW_TAP_REPO_CLONE_URL) Artifacts(org.jreleaser.model.util.Artifacts) KEY_BREW_CASK_NAME(org.jreleaser.util.Constants.KEY_BREW_CASK_NAME) MustacheUtils(org.jreleaser.util.MustacheUtils) Artifact(org.jreleaser.model.Artifact) GitService(org.jreleaser.model.GitService) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) Brew(org.jreleaser.model.Brew) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with PackagerProcessingException

use of org.jreleaser.model.packager.spi.PackagerProcessingException 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)

Aggregations

PackagerProcessingException (org.jreleaser.model.packager.spi.PackagerProcessingException)18 IOException (java.io.IOException)8 Path (java.nio.file.Path)7 Distribution (org.jreleaser.model.Distribution)7 List (java.util.List)4 Map (java.util.Map)4 Artifact (org.jreleaser.model.Artifact)4 JReleaserContext (org.jreleaser.model.JReleaserContext)4 Packager (org.jreleaser.model.Packager)4 LinkedHashMap (java.util.LinkedHashMap)3 Project (org.jreleaser.model.Project)3 Artifacts (org.jreleaser.model.util.Artifacts)3 TemplateUtils.trimTplExtension (org.jreleaser.templates.TemplateUtils.trimTplExtension)3 Algorithm (org.jreleaser.util.Algorithm)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 GitService (org.jreleaser.model.GitService)2 MustacheUtils.passThrough (org.jreleaser.util.MustacheUtils.passThrough)2 PlatformUtils (org.jreleaser.util.PlatformUtils)2 StringUtils.getFilename (org.jreleaser.util.StringUtils.getFilename)2