Search in sources :

Example 16 with JReleaserContext

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

the class Release method createContext.

@Override
protected JReleaserContext createContext() {
    JReleaserContext context = super.createContext();
    if (null != composite) {
        context.setIncludedDistributions(collectEntries(composite.includedDistributions()));
        context.setIncludedUploaderTypes(collectEntries(composite.includedUploaderTypes(), true));
        context.setIncludedUploaderNames(collectEntries(composite.includedUploaderNames()));
        context.setExcludedDistributions(collectEntries(composite.excludedDistributions()));
        context.setExcludedUploaderTypes(collectEntries(composite.excludedUploaderTypes(), true));
        context.setExcludedUploaderNames(collectEntries(composite.excludedUploaderNames()));
    }
    return context;
}
Also used : JReleaserContext(org.jreleaser.model.JReleaserContext)

Example 17 with JReleaserContext

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

the class Release method execute.

protected void execute() {
    if (composite == null || !composite.autoConfig()) {
        super.execute();
        return;
    }
    basedir();
    initLogger();
    JReleaserContext context = ModelAutoConfigurer.builder().logger(logger).basedir(actualBasedir).outputDirectory(getOutputDirectory()).dryrun(dryrun()).gitRootSearch(gitRootSearch).projectName(composite.autoConfig.projectName).projectVersion(composite.autoConfig.projectVersion).projectVersionPattern(composite.autoConfig.projectVersionPattern).projectSnapshotPattern(composite.autoConfig.projectSnapshotPattern).projectSnapshotLabel(composite.autoConfig.projectSnapshotLabel).projectSnapshotFullChangelog(composite.autoConfig.projectSnapshotFullChangelog).tagName(composite.autoConfig.tagName).previousTagName(composite.autoConfig.previousTagName).releaseName(composite.autoConfig.releaseName).milestoneName(composite.autoConfig.milestoneName).branch(composite.autoConfig.branch).prerelease(composite.autoConfig.prerelease).prereleasePattern(composite.autoConfig.prereleasePattern).draft(composite.autoConfig.draft).overwrite(composite.autoConfig.overwrite).update(composite.autoConfig.update).updateSections(collectUpdateSections()).skipTag(composite.autoConfig.skipTag).skipRelease(composite.autoConfig.skipRelease).changelog(composite.autoConfig.changelog).changelogFormatted(composite.autoConfig.changelogFormatted).username(composite.autoConfig.username).commitAuthorName(composite.autoConfig.commitAuthorName).commitAuthorEmail(composite.autoConfig.commitAuthorEmail).signing(composite.autoConfig.signing).armored(composite.autoConfig.armored).files(collectEntries(composite.autoConfig.files)).globs(collectEntries(composite.autoConfig.globs)).selectedPlatforms(collectSelectedPlatforms()).autoConfigure();
    doExecute(context);
}
Also used : JReleaserContext(org.jreleaser.model.JReleaserContext)

Example 18 with JReleaserContext

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

the class DistributionsValidator method validateArtifactPlatforms.

public static void validateArtifactPlatforms(JReleaserContext context, Distribution distribution, Packager packager, List<Artifact> candidateArtifacts, Errors errors) {
    // validate distribution type
    if (distribution.getType() == Distribution.DistributionType.BINARY || distribution.getType() == Distribution.DistributionType.JLINK || distribution.getType() == Distribution.DistributionType.NATIVE_IMAGE || distribution.getType() == Distribution.DistributionType.NATIVE_PACKAGE) {
        // ensure all artifacts define a platform
        AtomicBoolean universal = new AtomicBoolean();
        String noPlatform = "<nil>";
        Map<String, List<Artifact>> byPlatform = candidateArtifacts.stream().peek(artifact -> {
            if (distribution.getType() == Distribution.DistributionType.BINARY && artifact.extraPropertyIsTrue("universal")) {
                universal.compareAndSet(false, true);
            }
        }).collect(groupingBy(artifact -> isBlank(artifact.getPlatform()) ? noPlatform : artifact.getPlatform()));
        if (byPlatform.containsKey(noPlatform) && !universal.get()) {
            errors.configuration(RB.$("validation_distributions_platform_check", distribution.getName(), distribution.getType(), packager.getType()));
        }
        if (byPlatform.keySet().stream().noneMatch(packager::supportsPlatform) && !universal.get()) {
            context.getLogger().warn(RB.$("validation_distributions_disable", distribution.getName(), packager.getType()));
            packager.disable();
        }
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) ChocolateyValidator.validateChocolatey(org.jreleaser.model.validation.ChocolateyValidator.validateChocolatey) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScoopValidator.validateScoop(org.jreleaser.model.validation.ScoopValidator.validateScoop) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) ArrayList(java.util.ArrayList) Active(org.jreleaser.model.Active) JbangValidator.validateJbang(org.jreleaser.model.validation.JbangValidator.validateJbang) Errors(org.jreleaser.util.Errors) JbangValidator.postValidateJBang(org.jreleaser.model.validation.JbangValidator.postValidateJBang) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) BrewValidator.validateBrew(org.jreleaser.model.validation.BrewValidator.validateBrew) Distribution(org.jreleaser.model.Distribution) ChocolateyValidator.postValidateChocolatey(org.jreleaser.model.validation.ChocolateyValidator.postValidateChocolatey) FileType(org.jreleaser.util.FileType) BrewValidator.postValidateBrew(org.jreleaser.model.validation.BrewValidator.postValidateBrew) KEY_SKIP_RELEASE_SIGNATURES(org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES) DockerValidator.validateDocker(org.jreleaser.model.validation.DockerValidator.validateDocker) Packager(org.jreleaser.model.Packager) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) SdkmanValidator.postValidateSdkman(org.jreleaser.model.validation.SdkmanValidator.postValidateSdkman) Project(org.jreleaser.model.Project) List(java.util.List) GofishValidator.validateGofish(org.jreleaser.model.validation.GofishValidator.validateGofish) SdkmanValidator.validateSdkman(org.jreleaser.model.validation.SdkmanValidator.validateSdkman) MacportsValidator.validateMacports(org.jreleaser.model.validation.MacportsValidator.validateMacports) SpecValidator.validateSpec(org.jreleaser.model.validation.SpecValidator.validateSpec) RB(org.jreleaser.bundle.RB) SnapValidator.validateSnap(org.jreleaser.model.validation.SnapValidator.validateSnap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with JReleaserContext

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

the class GofishValidator method validateGofish.

public static void validateGofish(JReleaserContext context, Distribution distribution, Gofish packager, Errors errors) {
    JReleaserModel model = context.getModel();
    Gofish parentPackager = model.getPackagers().getGofish();
    if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
        packager.setActive(parentPackager.getActive());
    }
    if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) {
        packager.disable();
        return;
    }
    GitService service = model.getRelease().getGitService();
    if (!service.isReleaseSupported()) {
        packager.disable();
        return;
    }
    context.getLogger().debug("distribution.{}.gofish", distribution.getName());
    List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
    if (candidateArtifacts.size() == 0) {
        packager.setActive(Active.NEVER);
        packager.disable();
        return;
    } else if (candidateArtifacts.stream().filter(artifact -> isBlank(artifact.getPlatform())).count() > 1) {
        errors.configuration(RB.$("validation_packager_multiple_artifacts", "distribution." + distribution.getName() + ".gofish"));
        packager.disable();
        return;
    }
    validateCommitAuthor(packager, parentPackager);
    Gofish.GofishRepository repository = packager.getRepository();
    repository.resolveEnabled(model.getProject());
    validateTap(context, distribution, repository, parentPackager.getRepository(), "gofish.repository");
    validateTemplate(context, distribution, packager, parentPackager, errors);
    mergeExtraProperties(packager, parentPackager);
    validateContinueOnError(packager, parentPackager);
    if (isBlank(packager.getDownloadUrl())) {
        packager.setDownloadUrl(parentPackager.getDownloadUrl());
    }
    validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
}
Also used : Artifact(org.jreleaser.model.Artifact) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) JReleaserModel(org.jreleaser.model.JReleaserModel) ExtraPropertiesValidator.mergeExtraProperties(org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties) Active(org.jreleaser.model.Active) List(java.util.List) Errors(org.jreleaser.util.Errors) Gofish(org.jreleaser.model.Gofish) JReleaserContext(org.jreleaser.model.JReleaserContext) DistributionsValidator.validateArtifactPlatforms(org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) Distribution(org.jreleaser.model.Distribution) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) Gofish(org.jreleaser.model.Gofish) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) Artifact(org.jreleaser.model.Artifact)

Example 20 with JReleaserContext

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

the class JlinkValidator method validateJlink.

private static void validateJlink(JReleaserContext context, JReleaserContext.Mode mode, Jlink jlink, Errors errors) {
    context.getLogger().debug("jlink.{}", jlink.getName());
    if (!jlink.isActiveSet()) {
        jlink.setActive(Active.NEVER);
    }
    if (!jlink.resolveEnabled(context.getModel().getProject()))
        return;
    if (isBlank(jlink.getName())) {
        errors.configuration(RB.$("validation_must_not_be_blank", "jlink.name"));
        return;
    }
    context.getLogger().debug("jlink.{}.java", jlink.getName());
    if (!validateJava(context, jlink, errors)) {
        return;
    }
    Platform platform = jlink.getPlatform().merge(context.getModel().getPlatform());
    jlink.setPlatform(platform);
    if (isBlank(jlink.getImageName())) {
        jlink.setImageName(jlink.getJava().getGroupId() + "." + jlink.getJava().getArtifactId() + "-" + context.getModel().getProject().getResolvedVersion());
    }
    if (isBlank(jlink.getExecutable())) {
        jlink.setExecutable(jlink.getName());
    }
    int i = 0;
    for (Artifact targetJdk : jlink.getTargetJdks()) {
        validateJdk(context, mode, jlink, targetJdk, i++, errors);
    }
    // validate jdks.platform is unique
    Map<String, List<Artifact>> byPlatform = jlink.getTargetJdks().stream().collect(groupingBy(jdk -> isBlank(jdk.getPlatform()) ? "<nil>" : jdk.getPlatform()));
    if (byPlatform.containsKey("<nil>")) {
        errors.configuration(RB.$("validation_jlink_jdk_platform", jlink.getName()));
    }
    // check platforms
    byPlatform.forEach((p, jdks) -> {
        if (jdks.size() > 1) {
            errors.configuration(RB.$("validation_jlink_jdk_multiple_platforms", jlink.getName(), p));
        }
    });
    if (isBlank(jlink.getJdk().getPath())) {
        String currentPlatform = PlatformUtils.getCurrentFull();
        String javaHome = System.getProperty("java.home");
        if (jlink.getTargetJdks().isEmpty()) {
            if (isBlank(javaHome)) {
                // Can only happen when running as native-image, fail for now
                // TODO: native-image
                errors.configuration(RB.$("validation_java_home_missing"));
                return;
            }
            // Use current
            jlink.getJdk().setPath(javaHome);
            jlink.getJdk().setPlatform(currentPlatform);
            jlink.addTargetJdk(jlink.getJdk());
        } else {
            // find a compatible JDK in targets
            Optional<Artifact> jdk = jlink.getTargetJdks().stream().filter(j -> PlatformUtils.isCompatible(currentPlatform, j.getPlatform())).findFirst();
            if (jdk.isPresent()) {
                jlink.setJdk(jdk.get());
            } else {
                if (isBlank(javaHome)) {
                    // Can only happen when running as native-image, fail for now
                    // TODO: native-image
                    errors.configuration(RB.$("validation_java_home_missing"));
                    return;
                }
                // Can't tell if the current JDK will work but might as well use it
                jlink.getJdk().setPath(javaHome);
                jlink.getJdk().setPlatform(currentPlatform);
            }
        }
    }
    if (jlink.getArgs().isEmpty()) {
        jlink.getArgs().add("--no-header-files");
        jlink.getArgs().add("--no-man-pages");
        jlink.getArgs().add("--compress=2");
        jlink.getArgs().add("--strip-debug");
    }
    if (null == jlink.getMainJar()) {
        errors.configuration(RB.$("validation_is_null", "jlink." + jlink.getName() + ".mainJar"));
        return;
    }
    if (isBlank(jlink.getMainJar().getPath())) {
        errors.configuration(RB.$("validation_must_not_be_null", "jlink." + jlink.getName() + ".mainJar.path"));
    }
    validateGlobs(context, jlink.getJars(), "jlink." + jlink.getName() + ".jars", errors);
    if (mode == JReleaserContext.Mode.ASSEMBLE) {
        validateTemplate(context, jlink, errors);
    }
    if (!jlink.getFileSets().isEmpty()) {
        i = 0;
        for (FileSet fileSet : jlink.getFileSets()) {
            validateFileSet(context, mode, jlink, fileSet, i++, errors);
        }
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) FileSet(org.jreleaser.model.FileSet) Jlink(org.jreleaser.model.Jlink) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) PlatformUtils(org.jreleaser.util.PlatformUtils) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) Platform(org.jreleaser.model.Platform) Project(org.jreleaser.model.Project) Active(org.jreleaser.model.Active) List(java.util.List) Errors(org.jreleaser.util.Errors) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Optional(java.util.Optional) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) RB(org.jreleaser.bundle.RB) Platform(org.jreleaser.model.Platform) FileSet(org.jreleaser.model.FileSet) List(java.util.List) Artifact(org.jreleaser.model.Artifact)

Aggregations

JReleaserContext (org.jreleaser.model.JReleaserContext)29 RB (org.jreleaser.bundle.RB)13 Map (java.util.Map)11 List (java.util.List)10 Project (org.jreleaser.model.Project)8 StringUtils.isBlank (org.jreleaser.util.StringUtils.isBlank)8 StringUtils.isNotBlank (org.jreleaser.util.StringUtils.isNotBlank)8 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)7 Active (org.jreleaser.model.Active)7 Artifact (org.jreleaser.model.Artifact)7 Errors (org.jreleaser.util.Errors)7 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Optional (java.util.Optional)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 TemplateValidator.validateTemplate (org.jreleaser.model.validation.TemplateValidator.validateTemplate)5 PlatformUtils (org.jreleaser.util.PlatformUtils)5 IOException (java.io.IOException)4 Distribution (org.jreleaser.model.Distribution)4