Search in sources :

Example 1 with Artifact

use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.

the class Signer method collectArtifacts.

private static List<FilePair> collectArtifacts(JReleaserContext context, boolean forceSign, Function<FilePair, Boolean> validator) {
    List<FilePair> files = new ArrayList<>();
    Signing signing = context.getModel().getSigning();
    Path signaturesDirectory = context.getSignaturesDirectory();
    String extension = ".sig";
    if (signing.getMode() != Signing.Mode.COSIGN) {
        extension = signing.isArmored() ? ".asc" : ".sig";
    }
    if (signing.isFiles()) {
        for (Artifact artifact : Artifacts.resolveFiles(context)) {
            if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING))
                continue;
            Path input = artifact.getEffectivePath(context);
            Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
            FilePair pair = new FilePair(input, output);
            if (!forceSign)
                pair.setValid(validator.apply(pair));
            files.add(pair);
        }
    }
    if (signing.isArtifacts()) {
        for (Distribution distribution : context.getModel().getActiveDistributions()) {
            if (distribution.extraPropertyIsTrue(KEY_SKIP_SIGNING))
                continue;
            for (Artifact artifact : distribution.getArtifacts()) {
                if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING))
                    continue;
                Path input = artifact.getEffectivePath(context, distribution);
                Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
                FilePair pair = new FilePair(input, output);
                if (!forceSign)
                    pair.setValid(validator.apply(pair));
                files.add(pair);
            }
        }
    }
    if (signing.isChecksums()) {
        for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
            Path checksums = context.getChecksumsDirectory().resolve(context.getModel().getChecksum().getResolvedName(context, algorithm));
            if (Files.exists(checksums)) {
                Path output = signaturesDirectory.resolve(checksums.getFileName().toString().concat(extension));
                FilePair pair = new FilePair(checksums, output);
                if (!forceSign)
                    pair.setValid(validator.apply(pair));
                files.add(pair);
            }
        }
    }
    return files;
}
Also used : Path(java.nio.file.Path) Signing(org.jreleaser.model.Signing) Distribution(org.jreleaser.model.Distribution) ArrayList(java.util.ArrayList) Algorithm(org.jreleaser.util.Algorithm) Artifact(org.jreleaser.model.Artifact)

Example 2 with Artifact

use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.

the class SdkmanHelper method collectArtifacts.

public static void collectArtifacts(JReleaserContext context, Distribution distribution, Map<String, String> platforms) {
    for (Artifact artifact : distribution.getArtifacts()) {
        if (!artifact.isActive())
            continue;
        // only zips are supported
        if (!artifact.getPath().endsWith(ZIP.extension())) {
            context.getLogger().debug(RB.$("sdkman.no.artifacts.match"), artifact.getEffectivePath(context, distribution).getFileName());
            continue;
        }
        if (isTrue(artifact.getExtraProperties().get(Sdkman.SKIP_SDKMAN))) {
            context.getLogger().debug(RB.$("sdkman.artifact.explicit.skip"), artifact.getEffectivePath(context, distribution).getFileName());
            continue;
        }
        String platform = mapPlatform(artifact.getPlatform());
        if (isBlank(platform)) {
            context.getLogger().warn(RB.$("sdkman.platform.unsupported"), artifact.getPlatform());
            continue;
        }
        String url = artifactUrl(context, distribution, artifact);
        if (platforms.containsKey(platform)) {
            context.getLogger().warn(RB.$("sdkman.platform.replacement"), platform, url, platforms.get(platform));
        }
        platforms.put(platform, url);
    }
}
Also used : Artifact(org.jreleaser.model.Artifact)

Example 3 with Artifact

use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.

the class ArchiveResolver method resolveArchiveOutputs.

private static void resolveArchiveOutputs(JReleaserContext context, Archive archive, Errors errors) {
    if (archive.isAttachPlatform() && !context.isPlatformSelected(PlatformUtils.getCurrentFull()))
        return;
    Path baseOutputDirectory = context.getAssembleDirectory().resolve(archive.getName()).resolve(archive.getType());
    String archiveName = archive.getResolvedArchiveName(context);
    for (Archive.Format format : archive.getFormats()) {
        Path path = baseOutputDirectory.resolve(archiveName + "." + format.extension()).toAbsolutePath();
        if (!Files.exists(path)) {
            errors.assembly(RB.$("validation_missing_assembly", archive.getType(), archive.getName(), archive.getName()));
        } else {
            Artifact artifact = Artifact.of(path, archive.isAttachPlatform() ? PlatformUtils.getCurrentFull() : "");
            artifact.setExtraProperties(archive.getExtraProperties());
            artifact.activate();
            archive.addOutput(artifact);
        }
    }
}
Also used : Path(java.nio.file.Path) Archive(org.jreleaser.model.Archive) Artifact(org.jreleaser.model.Artifact)

Example 4 with Artifact

use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.

the class BrewValidator method validateBrew.

public static void validateBrew(JReleaserContext context, Distribution distribution, Brew packager, Errors errors) {
    JReleaserModel model = context.getModel();
    Brew parentPackager = model.getPackagers().getBrew();
    if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
        packager.setActive(parentPackager.getActive());
    }
    if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) {
        packager.disable();
        packager.getCask().disable();
        return;
    }
    GitService service = model.getRelease().getGitService();
    if (!service.isReleaseSupported()) {
        packager.disable();
        packager.getCask().disable();
        return;
    }
    context.getLogger().debug("distribution.{}.brew", distribution.getName());
    Brew.Cask cask = preValidateCask(distribution, packager, parentPackager);
    if (!packager.isMultiPlatformSet() && parentPackager.isMultiPlatformSet()) {
        packager.setMultiPlatform(parentPackager.isMultiPlatform());
    }
    if (packager.isMultiPlatform() && (distribution.getType() == Distribution.DistributionType.SINGLE_JAR || distribution.getType() == Distribution.DistributionType.JAVA_BINARY || distribution.getType() == Distribution.DistributionType.NATIVE_PACKAGE)) {
        packager.setMultiPlatform(false);
    }
    if (packager.isMultiPlatform()) {
        packager.getCask().disable();
    }
    validateCask(context, distribution, packager, cask, errors);
    List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
    if (candidateArtifacts.size() == 0) {
        packager.setActive(Active.NEVER);
        packager.disable();
        return;
    }
    validateCommitAuthor(packager, parentPackager);
    Brew.HomebrewTap tap = packager.getTap();
    tap.resolveEnabled(model.getProject());
    validateTap(context, distribution, tap, parentPackager.getTap(), "brew.tap");
    validateTemplate(context, distribution, packager, parentPackager, errors);
    mergeExtraProperties(packager, parentPackager);
    validateContinueOnError(packager, parentPackager);
    if (isBlank(packager.getDownloadUrl())) {
        packager.setDownloadUrl(parentPackager.getDownloadUrl());
    }
    List<Brew.Dependency> dependencies = new ArrayList<>(parentPackager.getDependenciesAsList());
    dependencies.addAll(packager.getDependenciesAsList());
    packager.setDependenciesAsList(dependencies);
    if (isBlank(packager.getFormulaName())) {
        packager.setFormulaName(distribution.getName());
    }
    if (!cask.isEnabled()) {
        validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
    }
}
Also used : JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) ArrayList(java.util.ArrayList) Brew(org.jreleaser.model.Brew) Artifact(org.jreleaser.model.Artifact)

Example 5 with Artifact

use of org.jreleaser.model.Artifact in project jreleaser by jreleaser.

the class BrewValidator method validateCask.

private static void validateCask(JReleaserContext context, Distribution distribution, Brew packager, Brew.Cask cask, Errors errors) {
    if (cask == null || (cask.isEnabledSet() && !cask.isEnabled())) {
        return;
    }
    context.getLogger().debug("distribution.{}.brew.cask", distribution.getName());
    // look for a .dmg, .pkg. or .zip
    int dmgFound = 0;
    int pkgFound = 0;
    int zipFound = 0;
    String pkgName = "";
    for (Artifact artifact : distribution.getArtifacts()) {
        if (!artifact.isActive() || !PlatformUtils.isMac(artifact.getPlatform()))
            continue;
        if (artifact.getPath().endsWith(".dmg") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
            dmgFound++;
        } else if (artifact.getPath().endsWith(".pkg") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
            pkgFound++;
            pkgName = artifact.getEffectivePath(context).getFileName().toString();
        } else if (artifact.getPath().endsWith(".zip") && !isTrue(artifact.getExtraProperties().get(SKIP_BREW))) {
            zipFound++;
        }
    }
    if (dmgFound == 0 && pkgFound == 0 && zipFound == 0) {
        // no artifacts found, disable cask
        cask.disable();
        return;
    } else if (dmgFound > 1) {
        errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".dmg"));
        cask.disable();
        return;
    } else if (pkgFound > 1) {
        errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".pkg"));
        cask.disable();
        return;
    } else if (zipFound > 1) {
        errors.configuration(RB.$("validation_brew_multiple_artifact", "distribution." + distribution.getName() + ".brew", ".zip"));
        cask.disable();
        return;
    } else if (dmgFound + pkgFound + zipFound > 1) {
        errors.configuration(RB.$("validation_brew_single_artifact", "distribution." + distribution.getName() + ".brew"));
        cask.disable();
        return;
    }
    if (zipFound == 1 && !cask.isEnabled()) {
        // https://github.com/jreleaser/jreleaser/issues/337
        return;
    }
    cask.enable();
    if (isBlank(cask.getPkgName()) && isNotBlank(pkgName)) {
        cask.setPkgName(pkgName);
    }
    if (isNotBlank(cask.getPkgName())) {
        if (!cask.getPkgName().endsWith(".pkg")) {
            cask.setPkgName(cask.getPkgName() + ".pkg");
        }
    } else if (isBlank(cask.getAppName())) {
        cask.setAppName(packager.getResolvedFormulaName(context) + ".app");
    } else if (!cask.getAppName().endsWith(".app")) {
        cask.setAppName(cask.getAppName() + ".app");
    }
    if (zipFound > 0) {
        cask.setAppName("");
        cask.setPkgName("");
    }
    if (isBlank(cask.getName())) {
        cask.setName(packager.getResolvedFormulaName(context).toLowerCase());
    }
    if (isBlank(cask.getDisplayName())) {
        cask.setDisplayName(packager.getResolvedFormulaName(context));
    }
}
Also used : Artifact(org.jreleaser.model.Artifact)

Aggregations

Artifact (org.jreleaser.model.Artifact)43 Path (java.nio.file.Path)24 Distribution (org.jreleaser.model.Distribution)14 List (java.util.List)13 Map (java.util.Map)12 GitService (org.jreleaser.model.GitService)12 JReleaserContext (org.jreleaser.model.JReleaserContext)12 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 JReleaserModel (org.jreleaser.model.JReleaserModel)10 Project (org.jreleaser.model.Project)10 StringUtils.isBlank (org.jreleaser.util.StringUtils.isBlank)10 RB (org.jreleaser.bundle.RB)9 PlatformUtils (org.jreleaser.util.PlatformUtils)9 LinkedHashMap (java.util.LinkedHashMap)8 Active (org.jreleaser.model.Active)8 Errors (org.jreleaser.util.Errors)8 StringUtils.isNotBlank (org.jreleaser.util.StringUtils.isNotBlank)8 Algorithm (org.jreleaser.util.Algorithm)7 Collectors (java.util.stream.Collectors)6