• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jreleaser / jreleaser / #475

03 Apr 2025 10:50AM UTC coverage: 40.322% (-8.9%) from 49.193%
#475

push

github

aalmiray
feat(release): Support Forgejo as releaser

Closes #1842

Closes #1843

182 of 1099 new or added lines in 45 files covered. (16.56%)

4239 existing lines in 333 files now uncovered.

20797 of 51577 relevant lines covered (40.32%)

0.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.0
/sdks/jreleaser-gitlab-java-sdk/src/main/java/org/jreleaser/sdk/gitlab/GitlabMavenDeployer.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * Copyright 2020-2025 The JReleaser authors.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.jreleaser.sdk.gitlab;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.model.internal.JReleaserContext;
22
import org.jreleaser.model.spi.deploy.DeployException;
23
import org.jreleaser.model.spi.deploy.maven.Deployable;
24
import org.jreleaser.sdk.commons.AbstractMavenDeployer;
25
import org.jreleaser.sdk.gitlab.api.GlPackage;
26

27
import java.io.IOException;
28
import java.net.MalformedURLException;
29
import java.net.URI;
30
import java.net.URISyntaxException;
31
import java.net.URL;
32
import java.util.ArrayList;
33
import java.util.List;
34
import java.util.Optional;
35
import java.util.Set;
36

37
/**
38
 * @author Andres Almiray
39
 * @since 1.3.0
40
 */
41
public class GitlabMavenDeployer extends AbstractMavenDeployer<org.jreleaser.model.api.deploy.maven.GitlabMavenDeployer,
42
    org.jreleaser.model.internal.deploy.maven.GitlabMavenDeployer> {
43
    private org.jreleaser.model.internal.deploy.maven.GitlabMavenDeployer deployer;
44

45
    public GitlabMavenDeployer(JReleaserContext context) {
46
        super(context);
1✔
47
    }
1✔
48

49
    @Override
50
    public org.jreleaser.model.internal.deploy.maven.GitlabMavenDeployer getDeployer() {
UNCOV
51
        return deployer;
×
52
    }
53

54
    @Override
55
    public void setDeployer(org.jreleaser.model.internal.deploy.maven.GitlabMavenDeployer deployer) {
56
        this.deployer = deployer;
1✔
57
    }
1✔
58

59
    @Override
60
    public String getType() {
61
        return org.jreleaser.model.api.deploy.maven.GitlabMavenDeployer.TYPE;
×
62
    }
63

64
    @Override
65
    public void deploy(String name) throws DeployException {
UNCOV
66
        deployPackages();
×
UNCOV
67
    }
×
68

69
    @Override
70
    protected void deleteExistingPackages(String baseUrl, String token, Set<Deployable> deployables) throws DeployException {
UNCOV
71
        Gitlab api = createApi(baseUrl, token);
×
UNCOV
72
        List<GlPackage> glPackages = new ArrayList<>();
×
73

UNCOV
74
        if (!context.isDryrun()) {
×
75
            try {
76
                glPackages.addAll(api.listPackages(Integer.parseInt(deployer.getProjectIdentifier()), "maven"));
×
77
            } catch (IOException e) {
×
78
                context.getLogger().trace(e);
×
79
                throw new DeployException(RB.$("ERROR_unexpected_error"), e);
×
80
            }
×
81

82
            // delete existing packages (if any)
83
            for (Deployable deployable : deployables) {
×
84
                if (deployable.getFilename().endsWith(".pom")) {
×
85
                    deletePackage(api, deployable, glPackages);
×
86
                }
87
            }
×
88
        }
UNCOV
89
    }
×
90

91
    private Gitlab createApi(String baseUrl, String token) throws DeployException {
UNCOV
92
        URL url = null;
×
93

94
        try {
UNCOV
95
            url = new URI(baseUrl).toURL();
×
96
        } catch (URISyntaxException | MalformedURLException e) {
×
97
            context.getLogger().trace(e);
×
98
            throw new DeployException(RB.$("ERROR_unexpected_error"), e);
×
UNCOV
99
        }
×
100

UNCOV
101
        StringBuilder theUrl = new StringBuilder(url.getProtocol())
×
UNCOV
102
            .append("://")
×
UNCOV
103
            .append(url.getHost());
×
UNCOV
104
        if (url.getPort() != -1) {
×
105
            theUrl.append(url.getPort());
×
106
        }
107

108
        try {
UNCOV
109
            return new Gitlab(context.asImmutable(),
×
UNCOV
110
                theUrl.toString(),
×
111
                token,
UNCOV
112
                deployer.getConnectTimeout(),
×
UNCOV
113
                deployer.getReadTimeout());
×
114
        } catch (Exception e) {
×
115
            context.getLogger().trace(e);
×
116
            throw new DeployException(RB.$("ERROR_unexpected_error"), e);
×
117
        }
118
    }
119

120
    private void deletePackage(Gitlab api, Deployable deployable, List<GlPackage> glPackages) {
121
        try {
122
            String name = deployable.getGroupId().replace(".", "/") + "/" + deployable.getArtifactId();
×
123
            Optional<GlPackage> glPackage = glPackages.stream()
×
124
                .filter(p -> p.getName().equals(name) && p.getVersion().equals(deployable.getVersion()))
×
125
                .findFirst();
×
126

127
            glPackage.ifPresent(p -> api.deletePackage(Integer.parseInt(deployer.getProjectIdentifier()), p.getId()));
×
128
        } catch (Exception e) {
×
129
            context.getLogger().debug(RB.$("ERROR_gitlab_delete_package", deployer.getUsername(),
×
130
                "maven",
131
                deployable.getGroupId() + "-" + deployable.getArtifactId(),
×
132
                deployable.getVersion()));
×
133
        }
×
134
    }
×
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc