Search in sources :

Example 1 with GitService

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

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

the class ModelConfigurer method autoConfigureGitlab.

private static void autoConfigureGitlab(JReleaserContext context, Repository repository) {
    GitService service = context.getModel().getRelease().getGitService();
    if (service != null) {
        if (!(service instanceof Gitlab)) {
            context.getModel().getRelease().getGitService().setMatch(false);
            context.getModel().getRelease().getGitService().setSkipTag(true);
            context.getLogger().warn(RB.$("ERROR_context_configurer_detected_git"), "gitlab", service.getServiceName());
        }
    } else {
        context.getModel().getRelease().setGitlab(new Gitlab());
    }
    fillGitProperties(context.getModel().getRelease().getGitService(), repository, context.getModel().getCommit());
}
Also used : GitService(org.jreleaser.model.GitService) Gitlab(org.jreleaser.model.Gitlab)

Example 3 with GitService

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

the class ModelConfigurer method autoConfigureGithub.

private static void autoConfigureGithub(JReleaserContext context, Repository repository) {
    GitService service = context.getModel().getRelease().getGitService();
    if (service != null) {
        if (!(service instanceof Github)) {
            context.getModel().getRelease().getGitService().setMatch(false);
            context.getModel().getRelease().getGitService().setSkipTag(true);
            context.getLogger().warn(RB.$("ERROR_context_configurer_detected_git"), "github", service.getServiceName());
        }
    } else {
        context.getModel().getRelease().setGithub(new Github());
    }
    fillGitProperties(context.getModel().getRelease().getGitService(), repository, context.getModel().getCommit());
}
Also used : Github(org.jreleaser.model.Github) GitService(org.jreleaser.model.GitService)

Example 4 with GitService

use of org.jreleaser.model.GitService 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 5 with GitService

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

Aggregations

GitService (org.jreleaser.model.GitService)34 JReleaserModel (org.jreleaser.model.JReleaserModel)12 Artifact (org.jreleaser.model.Artifact)10 IOException (java.io.IOException)6 Project (org.jreleaser.model.Project)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Git (org.eclipse.jgit.api.Git)5 List (java.util.List)4 Gitlab (org.jreleaser.model.Gitlab)4 JReleaserContext (org.jreleaser.model.JReleaserContext)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RB (org.jreleaser.bundle.RB)3 Changelog (org.jreleaser.model.Changelog)3 Github (org.jreleaser.model.Github)3