Search in sources :

Example 1 with Project

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

the class ChangelogGeneratorUnitTest method doNecessaryMock.

private LogCommand doNecessaryMock(String effectiveTagName, String configuredTagName, ObjectId headId, boolean isSnapshot, List<Ref> tagRefs) throws GitAPIException, IOException {
    ListTagCommand listTagCommand = mock(ListTagCommand.class);
    JReleaserModel model = mock(JReleaserModel.class);
    when(context.getModel()).thenReturn(model);
    Project project = mock(Project.class);
    when(model.getProject()).thenReturn(project);
    Release release = mock(Release.class);
    when(model.getRelease()).thenReturn(release);
    VersionPattern versionPattern = mock(VersionPattern.class);
    when(versionPattern.getType()).thenReturn(VersionPattern.Type.SEMVER);
    when(project.versionPattern()).thenReturn(versionPattern);
    LogCommand logCommand = mock(LogCommand.class, RETURNS_DEEP_STUBS);
    when(git.log()).thenReturn(logCommand);
    when(listTagCommand.call()).thenReturn(tagRefs);
    when(git.tagList()).thenReturn(listTagCommand);
    GitService gitService = mock(GitService.class, RETURNS_DEEP_STUBS);
    when(release.getGitService()).thenReturn(gitService);
    when(gitService.getEffectiveTagName(any())).thenReturn(effectiveTagName);
    when(gitService.getConfiguredTagName()).thenReturn(configuredTagName);
    when(git.getRepository().resolve(Constants.HEAD)).thenReturn(headId);
    doReturn(SemVer.of(effectiveTagName)).when(project).version();
    when(context.getModel().getProject().isSnapshot()).thenReturn(isSnapshot);
    return logCommand;
}
Also used : Project(org.jreleaser.model.Project) VersionPattern(org.jreleaser.model.VersionPattern) LogCommand(org.eclipse.jgit.api.LogCommand) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) ListTagCommand(org.eclipse.jgit.api.ListTagCommand) Release(org.jreleaser.model.Release)

Example 2 with Project

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

the class DockerValidator method validateDocker.

public static void validateDocker(JReleaserContext context, Distribution distribution, Docker packager, Errors errors) {
    JReleaserModel model = context.getModel();
    Project project = model.getProject();
    Docker parentPackager = model.getPackagers().getDocker();
    if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
        packager.setActive(parentPackager.getActive());
    }
    if (!packager.resolveEnabled(context.getModel().getProject(), distribution))
        return;
    String element = "distribution." + distribution.getName() + ".docker";
    context.getLogger().debug(element);
    List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
    if (candidateArtifacts.size() == 0) {
        packager.setActive(Active.NEVER);
        packager.disable();
        return;
    }
    // check specs for active status
    for (DockerSpec spec : packager.getSpecs().values()) {
        if (!spec.isActiveSet() && packager.isActiveSet()) {
            spec.setActive(packager.getActive());
        }
        spec.resolveEnabled(context.getModel().getProject(), distribution);
    }
    validateTemplate(context, distribution, packager, parentPackager, errors);
    validateCommitAuthor(packager, parentPackager);
    Docker.DockerRepository repository = packager.getRepository();
    repository.resolveEnabled(model.getProject());
    if (!repository.isVersionedSubfoldersSet()) {
        repository.setVersionedSubfolders(parentPackager.getRepository().isVersionedSubfolders());
    }
    if (isBlank(repository.getName())) {
        repository.setName(project.getName() + "-docker");
    }
    validateTap(context, distribution, repository, parentPackager.getRepository(), "docker.repository");
    mergeExtraProperties(packager, parentPackager);
    validateContinueOnError(packager, parentPackager);
    if (isBlank(packager.getDownloadUrl())) {
        packager.setDownloadUrl(parentPackager.getDownloadUrl());
    }
    if (isBlank(packager.getBaseImage())) {
        packager.setBaseImage(parentPackager.getBaseImage());
    }
    validateBaseImage(distribution, packager);
    if (packager.getImageNames().isEmpty()) {
        packager.setImageNames(parentPackager.getImageNames());
    }
    if (packager.getImageNames().isEmpty()) {
        packager.addImageName("{{repoOwner}}/{{distributionName}}:{{tagName}}");
    }
    if (context.getModel().getProject().isSnapshot()) {
        // find the 1st image that ends with :{{tagName}}
        Optional<String> imageName = packager.getImageNames().stream().filter(n -> n.endsWith(":{{tagName}}") || n.endsWith(":{{ tagName }}")).findFirst();
        packager.setImageNames(singleton(imageName.orElse("{{repoOwner}}/{{distributionName}}:{{tagName}}")));
    }
    validateCommands(packager, parentPackager);
    Map<String, String> labels = new LinkedHashMap<>();
    labels.putAll(parentPackager.getLabels());
    labels.putAll(packager.getLabels());
    packager.setLabels(labels);
    if (!packager.getLabels().containsKey(LABEL_OCI_IMAGE_TITLE)) {
        packager.getLabels().put(LABEL_OCI_IMAGE_TITLE, "{{distributionName}}");
    }
    validateLabels(packager);
    validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
    validateRegistries(context, packager, parentPackager, errors, element);
    if (!packager.isUseLocalArtifactSet() && parentPackager.isUseLocalArtifactSet()) {
        packager.setUseLocalArtifact(parentPackager.isUseLocalArtifact());
    }
    if (distribution.getType() == Distribution.DistributionType.SINGLE_JAR) {
        packager.setUseLocalArtifact(true);
    }
    for (Map.Entry<String, DockerSpec> e : packager.getSpecs().entrySet()) {
        DockerSpec spec = e.getValue();
        if (isBlank(spec.getName())) {
            spec.setName(e.getKey());
        }
        validateDockerSpec(context, distribution, spec, packager, errors);
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) DockerSpec(org.jreleaser.model.DockerSpec) DockerConfiguration(org.jreleaser.model.DockerConfiguration) LABEL_OCI_IMAGE_TITLE(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_TITLE) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Active(org.jreleaser.model.Active) Errors(org.jreleaser.util.Errors) Collections.singleton(java.util.Collections.singleton) LABEL_OCI_IMAGE_DESCRIPTION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_DESCRIPTION) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Env(org.jreleaser.util.Env) DistributionsValidator.validateArtifactPlatforms(org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) Distribution(org.jreleaser.model.Distribution) LinkedHashSet(java.util.LinkedHashSet) LABEL_OCI_IMAGE_URL(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_URL) LABEL_OCI_IMAGE_REVISION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_REVISION) LABEL_OCI_IMAGE_VERSION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_VERSION) Set(java.util.Set) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) ExtraPropertiesValidator.mergeExtraProperties(org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties) Project(org.jreleaser.model.Project) List(java.util.List) Registry(org.jreleaser.model.Registry) LABEL_OCI_IMAGE_LICENSES(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_LICENSES) Docker(org.jreleaser.model.Docker) Optional(java.util.Optional) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) Artifact(org.jreleaser.model.Artifact) LinkedHashMap(java.util.LinkedHashMap) Project(org.jreleaser.model.Project) Docker(org.jreleaser.model.Docker) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DockerSpec(org.jreleaser.model.DockerSpec)

Example 3 with Project

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

the class ChocolateyValidator method postValidateChocolatey.

public static void postValidateChocolatey(JReleaserContext context, Distribution distribution, Chocolatey packager, Errors errors) {
    if (!packager.isEnabled())
        return;
    context.getLogger().debug("distribution.{}.chocolatey", distribution.getName());
    Project project = context.getModel().getProject();
    if (isBlank(project.getLicenseUrl())) {
        errors.configuration(RB.$("ERROR_project_no_license_url"));
    }
}
Also used : Project(org.jreleaser.model.Project)

Example 4 with Project

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

the class JpackageValidator method validateJpackage.

private static void validateJpackage(JReleaserContext context, JReleaserContext.Mode mode, Jpackage jpackage, Errors errors) {
    context.getLogger().debug("jpackage.{}", jpackage.getName());
    if (!jpackage.isActiveSet()) {
        jpackage.setActive(Active.NEVER);
    }
    Project project = context.getModel().getProject();
    if (!jpackage.resolveEnabled(project))
        return;
    Jpackage.PlatformPackager packager = jpackage.getResolvedPlatformPackager();
    Jpackage.ApplicationPackage applicationPackage = jpackage.getApplicationPackage();
    packager.enable();
    if (isNotBlank(jpackage.getJlink())) {
        Jlink jlink = context.getModel().getAssemble().findJlink(jpackage.getJlink());
        Path baseOutputDirectory = context.getAssembleDirectory().resolve(jlink.getName()).resolve(jlink.getType());
        String imageName = jlink.getResolvedImageName(context);
        List<Artifact> candidateRuntimeImages = new ArrayList<>();
        for (Artifact targetJdk : jlink.getTargetJdks()) {
            if (!context.isPlatformSelected(targetJdk))
                continue;
            String platform = targetJdk.getPlatform();
            Path path = baseOutputDirectory.resolve("work-" + platform).resolve(imageName + "-" + platform).toAbsolutePath();
            candidateRuntimeImages.add(Artifact.of(path, platform));
        }
        if (jpackage.getRuntimeImages().size() > 0 && jpackage.getRuntimeImages().size() != candidateRuntimeImages.size()) {
            errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
        }
        int count = 0;
        for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
            Path rp = runtimeImage.getResolvedPath(context, jpackage);
            Path tp = runtimeImage.getResolvedTransform(context, jpackage);
            Path path = tp != null ? tp : rp;
            if (candidateRuntimeImages.stream().anyMatch(a -> a.getPath().equals(path.toString()))) {
                count++;
            }
        }
        if (jpackage.getRuntimeImages().size() > 0 && count != candidateRuntimeImages.size()) {
            errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
        }
        jpackage.setJava(jlink.getJava());
        jpackage.setMainJar(jlink.getMainJar());
        jpackage.setJars(jlink.getJars());
        packager.setJdk(jlink.getJdk());
        if (isBlank(jpackage.getExecutable())) {
            jpackage.setExecutable(jlink.getExecutable());
        }
        for (Artifact runtimeImage : candidateRuntimeImages) {
            runtimeImage.activate();
            jpackage.addRuntimeImage(runtimeImage);
        }
    }
    context.getLogger().debug("jpackage.{}.java", jpackage.getName());
    if (!validateJava(context, jpackage, errors)) {
        return;
    }
    if (isBlank(jpackage.getExecutable())) {
        jpackage.setExecutable(jpackage.getName());
    }
    if (jpackage.getRuntimeImages().size() == 0) {
        errors.configuration(RB.$("validation_jpackage_runtime_images_missing", jpackage.getName()));
        return;
    }
    int i = 0;
    for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
        validateRuntimeImage(context, mode, jpackage, runtimeImage, i++, errors);
    }
    // validate jdks.platform is unique
    Map<String, List<Artifact>> byPlatform = jpackage.getRuntimeImages().stream().collect(groupingBy(ri -> isBlank(ri.getPlatform()) ? "<nil>" : ri.getPlatform()));
    if (byPlatform.containsKey("<nil>")) {
        errors.configuration(RB.$("validation_jpackage_runtime_image_platform", jpackage.getName()));
    }
    // check platforms
    byPlatform.forEach((p, jdks) -> {
        if (jdks.size() > 1) {
            errors.configuration(RB.$("validation_jpackage_runtime_image_multiple_platforms", jpackage.getName(), p));
        }
    });
    if (isBlank(packager.getJdk().getPath())) {
        String javaHome = System.getProperty("java.home");
        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;
        }
        packager.getJdk().setPath(javaHome);
        packager.getJdk().setPlatform(PlatformUtils.getCurrentFull());
    }
    if (packager.getTypes().isEmpty()) {
        packager.setTypes(singletonList(packager.getValidTypes().get(0)));
    }
    if (isBlank(applicationPackage.getAppName())) {
        applicationPackage.setAppName(jpackage.getName());
    }
    if (isBlank(applicationPackage.getAppVersion())) {
        applicationPackage.setAppVersion(project.getResolvedVersion());
    }
    // validate appVersion
    String appVersion = applicationPackage.getResolvedAppVersion(context, jpackage);
    try {
        SemVer v = SemVer.of(appVersion);
        if (isNotBlank(v.getBuild()) && isNotBlank(v.getTag()) && v.getMajor() <= 0) {
            errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
        }
    } catch (IllegalArgumentException e) {
        // can't use this value
        errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
    }
    if (isBlank(applicationPackage.getVendor())) {
        applicationPackage.setVendor(project.getVendor());
    }
    if (isBlank(applicationPackage.getVendor())) {
        errors.configuration(RB.$("validation_jpackage_missing_vendor", jpackage.getName()));
    }
    if (isBlank(applicationPackage.getCopyright())) {
        applicationPackage.setCopyright(project.getCopyright());
    }
    if (mode == JReleaserContext.Mode.ASSEMBLE) {
        validateTemplate(context, jpackage, errors);
    }
    if (isBlank(packager.getAppName())) {
        packager.setAppName(jpackage.getApplicationPackage().getAppName());
    }
    if (packager instanceof Jpackage.Linux) {
        validateLinux(context, jpackage, (Jpackage.Linux) packager, errors);
    }
    if (packager instanceof Jpackage.Osx) {
        validateOsx(context, jpackage, (Jpackage.Osx) packager, errors);
    }
    if (packager instanceof Jpackage.Windows) {
        validateWindows(context, jpackage, (Jpackage.Windows) packager, errors);
    }
}
Also used : Jpackage(org.jreleaser.model.Jpackage) Path(java.nio.file.Path) Artifact(org.jreleaser.model.Artifact) 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) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) 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) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) SemVer(org.jreleaser.util.SemVer) Pattern(java.util.regex.Pattern) Jpackage(org.jreleaser.model.Jpackage) RB(org.jreleaser.bundle.RB) Path(java.nio.file.Path) Jlink(org.jreleaser.model.Jlink) ArrayList(java.util.ArrayList) SemVer(org.jreleaser.util.SemVer) Artifact(org.jreleaser.model.Artifact) Project(org.jreleaser.model.Project) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 5 with Project

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

the class PackagersValidator method validatePackagers.

public static void validatePackagers(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
    if (!mode.validateConfig()) {
        return;
    }
    context.getLogger().debug("packagers");
    JReleaserModel model = context.getModel();
    Packagers packagers = model.getPackagers();
    Project project = model.getProject();
    packagers.getBrew().resolveEnabled(project);
    packagers.getBrew().getTap().resolveEnabled(project);
    validatePackager(context, packagers.getBrew(), packagers.getBrew().getTap(), errors);
    packagers.getChocolatey().resolveEnabled(project);
    packagers.getChocolatey().getBucket().resolveEnabled(project);
    validatePackager(context, packagers.getChocolatey(), packagers.getChocolatey().getBucket(), errors);
    packagers.getDocker().resolveEnabled(project);
    packagers.getDocker().getRepository().resolveEnabled(project);
    validatePackager(context, packagers.getDocker(), packagers.getDocker().getRepository(), errors);
    if (!packagers.getDocker().getSpecs().isEmpty()) {
        errors.configuration(RB.$("validation_packagers_docker_specs"));
    }
    packagers.getGofish().resolveEnabled(project);
    packagers.getGofish().getRepository().resolveEnabled(project);
    validatePackager(context, packagers.getGofish(), packagers.getGofish().getRepository(), errors);
    if (isBlank(packagers.getGofish().getRepository().getName())) {
        packagers.getGofish().getRepository().setName(model.getRelease().getGitService().getOwner() + "-fish-food");
    }
    packagers.getGofish().getRepository().setTapName(model.getRelease().getGitService().getOwner() + "-fish-food");
    packagers.getJbang().resolveEnabled(project);
    packagers.getJbang().getCatalog().resolveEnabled(project);
    validatePackager(context, packagers.getJbang(), packagers.getJbang().getCatalog(), errors);
    packagers.getMacports().resolveEnabled(project);
    packagers.getMacports().getRepository().resolveEnabled(project);
    validatePackager(context, packagers.getMacports(), packagers.getMacports().getRepository(), errors);
    packagers.getScoop().resolveEnabled(project);
    packagers.getScoop().getBucket().resolveEnabled(project);
    validatePackager(context, packagers.getScoop(), packagers.getScoop().getBucket(), errors);
    if (isBlank(packagers.getScoop().getBucket().getName())) {
        packagers.getScoop().getBucket().setName("scoop-" + model.getRelease().getGitService().getOwner());
    }
    packagers.getScoop().getBucket().setTapName("scoop-" + model.getRelease().getGitService().getOwner());
    packagers.getSnap().resolveEnabled(project);
    packagers.getSnap().getSnap().resolveEnabled(project);
    validatePackager(context, packagers.getSnap(), packagers.getSnap().getSnap(), errors);
    packagers.getSpec().resolveEnabled(project);
    packagers.getSpec().getRepository().resolveEnabled(project);
    validatePackager(context, packagers.getSpec(), packagers.getSpec().getRepository(), errors);
    if (isBlank(packagers.getSpec().getRepository().getName())) {
        packagers.getSpec().getRepository().setName(model.getRelease().getGitService().getOwner() + "-spec");
    }
    packagers.getSpec().getRepository().setTapName(model.getRelease().getGitService().getOwner() + "-spec");
    validateSdkman(context, packagers.getSdkman(), errors);
}
Also used : Project(org.jreleaser.model.Project) JReleaserModel(org.jreleaser.model.JReleaserModel) Packagers(org.jreleaser.model.Packagers)

Aggregations

Project (org.jreleaser.model.Project)10 JReleaserModel (org.jreleaser.model.JReleaserModel)5 GitService (org.jreleaser.model.GitService)4 Artifact (org.jreleaser.model.Artifact)3 Errors (org.jreleaser.util.Errors)3 List (java.util.List)2 Map (java.util.Map)2 RB (org.jreleaser.bundle.RB)2 Active (org.jreleaser.model.Active)2 JReleaserContext (org.jreleaser.model.JReleaserContext)2 Jpackage (org.jreleaser.model.Jpackage)2 TemplateValidator.validateTemplate (org.jreleaser.model.validation.TemplateValidator.validateTemplate)2 PlatformUtils (org.jreleaser.util.PlatformUtils)2 StringUtils.isBlank (org.jreleaser.util.StringUtils.isBlank)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1