Search in sources :

Example 1 with JReleaserModel

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

the class ModelAutoConfigurer method autoConfiguredModel.

private JReleaserModel autoConfiguredModel(Path basedir) {
    JReleaserModel model = new JReleaserModel();
    model.getProject().setName(projectName);
    model.getProject().setVersion(projectVersion);
    model.getProject().setVersionPattern(projectVersionPattern);
    model.getProject().getSnapshot().setPattern(projectSnapshotPattern);
    model.getProject().getSnapshot().setLabel(projectSnapshotLabel);
    model.getProject().getSnapshot().setFullChangelog(projectSnapshotFullChangelog);
    try {
        Repository repository = GitSdk.of(basedir, gitRootSearch).getRemote();
        GitService service = null;
        switch(repository.getKind()) {
            case GITHUB:
                service = new Github();
                model.getRelease().setGithub((Github) service);
                if (prerelease)
                    ((Github) service).getPrerelease().setEnabled(true);
                ((Github) service).getPrerelease().setPattern(prereleasePattern);
                ((Github) service).setDraft(draft);
                break;
            case GITLAB:
                service = new Gitlab();
                model.getRelease().setGitlab((Gitlab) service);
                break;
            case CODEBERG:
                service = new Codeberg();
                model.getRelease().setCodeberg((Codeberg) service);
                if (prerelease)
                    ((Codeberg) service).getPrerelease().setEnabled(true);
                ((Codeberg) service).getPrerelease().setPattern(prereleasePattern);
                ((Codeberg) service).setDraft(draft);
                break;
            default:
                throw new JReleaserException(RB.$("ERROR_context_configurer_unsupported_url", repository.getHttpUrl()));
        }
        service.setUsername(username);
        service.setTagName(tagName);
        service.setPreviousTagName(previousTagName);
        service.setReleaseName(releaseName);
        service.getMilestone().setName(milestoneName);
        service.setOverwrite(overwrite);
        service.getUpdate().setEnabled(update);
        if (!updateSections.isEmpty()) {
            if (!update) {
                throw new JReleaserException(RB.$("ERROR_context_configurer_update_not_set"));
            }
            service.getUpdate().setSections(updateSections);
        }
        service.setSkipTag(skipTag);
        service.setSkipRelease(skipRelease);
        if (isNotBlank(branch))
            service.setBranch(branch);
        if (isNotBlank(changelog))
            service.getChangelog().setExternal(changelog);
        if (isNotBlank(commitAuthorName))
            service.getCommitAuthor().setName(commitAuthorName);
        if (isNotBlank(commitAuthorEmail))
            service.getCommitAuthor().setEmail(commitAuthorEmail);
        if (changelogFormatted)
            service.getChangelog().setFormatted(Active.ALWAYS);
    } catch (IOException e) {
        throw new JReleaserException(e.getMessage());
    }
    if (signing) {
        model.getSigning().setActive(Active.ALWAYS);
        model.getSigning().setArmored(armored);
    }
    if (!files.isEmpty()) {
        for (String file : files) {
            model.getFiles().addArtifact(Artifact.of(basedir.resolve(file)));
        }
    }
    if (!globs.isEmpty()) {
        model.getFiles().addArtifacts(Artifacts.resolveFiles(logger, basedir, globs));
    }
    return model;
}
Also used : Codeberg(org.jreleaser.model.Codeberg) Repository(org.jreleaser.model.releaser.spi.Repository) Github(org.jreleaser.model.Github) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) IOException(java.io.IOException) Gitlab(org.jreleaser.model.Gitlab) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with JReleaserModel

use of org.jreleaser.model.JReleaserModel 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 3 with JReleaserModel

use of org.jreleaser.model.JReleaserModel 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 4 with JReleaserModel

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

the class DockerValidator method validateRegistries.

private static void validateRegistries(JReleaserContext context, DockerConfiguration self, DockerConfiguration other, Errors errors, String element) {
    JReleaserModel model = context.getModel();
    Set<Registry> registries = new LinkedHashSet<>();
    registries.addAll(self.getRegistries());
    registries.addAll(other.getRegistries());
    self.setRegistries(registries);
    if (registries.isEmpty()) {
        context.getLogger().warn(RB.$("validation_docker_no_registries", element));
        return;
    }
    for (Registry registry : registries) {
        GitService service = model.getRelease().getGitService();
        String serverName = registry.getServerName();
        registry.setUsername(checkProperty(context, "DOCKER_" + Env.toVar(serverName) + "_USERNAME", "registry." + Env.toVar(serverName) + ".username", registry.getUsername(), service.getResolvedUsername()));
        if (isBlank(registry.getRepositoryName())) {
            registry.setRepositoryName(service.getOwner());
        }
        if (isBlank(registry.getUsername())) {
            errors.configuration(RB.$("validation_must_not_be_blank", element + ".registry." + serverName + ".username"));
        }
        registry.setPassword(checkProperty(context, "DOCKER_" + Env.toVar(serverName) + "_PASSWORD", "registry." + Env.toVar(serverName) + ".password", registry.getPassword(), errors, context.isDryrun()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) Registry(org.jreleaser.model.Registry)

Example 5 with JReleaserModel

use of org.jreleaser.model.JReleaserModel 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)

Aggregations

JReleaserModel (org.jreleaser.model.JReleaserModel)18 GitService (org.jreleaser.model.GitService)13 Artifact (org.jreleaser.model.Artifact)9 Project (org.jreleaser.model.Project)5 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 RB (org.jreleaser.bundle.RB)2 Active (org.jreleaser.model.Active)2 Distribution (org.jreleaser.model.Distribution)2 JReleaserContext (org.jreleaser.model.JReleaserContext)2 Registry (org.jreleaser.model.Registry)2 DistributionsValidator.validateArtifactPlatforms (org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms)2 ExtraPropertiesValidator.mergeExtraProperties (org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties)2 Errors (org.jreleaser.util.Errors)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections.singleton (java.util.Collections.singleton)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1