• 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

0.0
/core/jreleaser-engine/src/main/java/org/jreleaser/packagers/GofishPackagerProcessor.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.packagers;
19

20
import org.jreleaser.model.internal.JReleaserContext;
21
import org.jreleaser.model.internal.common.Artifact;
22
import org.jreleaser.model.internal.distributions.Distribution;
23
import org.jreleaser.model.internal.packagers.GofishPackager;
24
import org.jreleaser.model.internal.util.Artifacts;
25
import org.jreleaser.model.spi.packagers.PackagerProcessingException;
26
import org.jreleaser.mustache.TemplateContext;
27
import org.jreleaser.util.Algorithm;
28
import org.jreleaser.util.FileType;
29
import org.jreleaser.util.PlatformUtils;
30

31
import java.nio.file.Path;
32
import java.util.List;
33
import java.util.Map;
34

35
import static java.util.stream.Collectors.toList;
36
import static org.jreleaser.model.Constants.KEY_GOFISH_PACKAGES;
37
import static org.jreleaser.mustache.MustacheUtils.passThrough;
38
import static org.jreleaser.templates.TemplateUtils.trimTplExtension;
39
import static org.jreleaser.util.StringUtils.capitalize;
40
import static org.jreleaser.util.StringUtils.getFilename;
41
import static org.jreleaser.util.StringUtils.isNotBlank;
42

43
/**
44
 * @author Andres Almiray
45
 * @since 0.9.1
46
 */
47
public class GofishPackagerProcessor extends AbstractRepositoryPackagerProcessor<GofishPackager> {
48
    public GofishPackagerProcessor(JReleaserContext context) {
UNCOV
49
        super(context);
×
UNCOV
50
    }
×
51

52
    @Override
53
    protected void doPackageDistribution(Distribution distribution, TemplateContext props, Path packageDirectory) throws PackagerProcessingException {
54
        super.doPackageDistribution(distribution, props, packageDirectory);
×
55
        copyPreparedFiles(props);
×
56
    }
×
57

58
    @Override
59
    protected void fillPackagerProperties(TemplateContext props, Distribution distribution) {
60
        List<Artifact> artifacts = collectArtifacts(distribution);
×
61

62
        List<GofishPackage> packages = artifacts.stream()
×
63
            .filter(artifact -> isNotBlank(artifact.getPlatform()))
×
64
            .map(artifact -> new GofishPackage(props, context, distribution, artifact))
×
65
            .collect(toList());
×
66

67
        if (packages.isEmpty()) {
×
68
            for (Artifact artifact : artifacts) {
×
69
                if (isNotBlank(artifact.getPlatform())) continue;
×
70
                for (String os : new String[]{"darwin", "linux", "windows"}) {
×
71
                    for (String arch : new String[]{"x86_64", "aarch64"}) {
×
72
                        Artifact copy = artifact.copy();
×
73
                        copy.setPlatform(os + "-" + arch);
×
74
                        packages.add(new GofishPackage(props, context, distribution, copy));
×
75
                    }
76
                }
77
            }
×
78
        }
79

80
        props.set(KEY_GOFISH_PACKAGES, packages);
×
81
    }
×
82

83
    @Override
84
    protected void writeFile(Distribution distribution,
85
                             String content,
86
                             TemplateContext props,
87
                             Path outputDirectory,
88
                             String fileName) throws PackagerProcessingException {
89
        fileName = trimTplExtension(fileName);
×
90

91
        Path outputFile = "food.lua".equals(fileName) ?
×
92
            outputDirectory.resolve("Food").resolve(distribution.getExecutable().getName().concat(".lua")) :
×
93
            outputDirectory.resolve(fileName);
×
94

95
        writeFile(content, outputFile);
×
96
    }
×
97

98
    private static class GofishPackage {
99
        private final boolean packageNotWindows;
100
        private final String packageOs;
101
        private final String packageArch;
102
        private final String packageUrl;
103
        private final String packageChecksum;
104
        private final String packagePath;
105
        private final String packageInstallPath;
106

107
        public GofishPackage(TemplateContext props, JReleaserContext context, Distribution distribution, Artifact artifact) {
×
108
            String platform = artifact.getPlatform();
×
109
            String artifactPlatform = isNotBlank(platform) ? capitalize(platform) : "";
×
110
            // add extra properties without clobbering existing keys
111
            Map<String, Object> artifactProps = artifact.resolvedExtraProperties("artifact" + artifactPlatform);
×
112
            artifactProps.keySet().stream()
×
113
                .filter(k -> !props.contains(k))
×
114
                .forEach(k -> props.set(k, artifactProps.get(k)));
×
115

116
            String artifactFile = artifact.getEffectivePath().getFileName().toString();
×
117
            String artifactFileName = getFilename(artifactFile, FileType.getSupportedExtensions());
×
118

119
            boolean windows = PlatformUtils.isWindows(platform);
×
120
            String executable = distribution.getExecutable().getName();
×
121
            String projectVersion = context.getModel().getProject().getVersion();
×
122

123
            String ps = windows ? "\\\\" : "/";
×
124
            String installPath = "\"bin" + ps + "\" .. name";
×
125
            String executablePath = artifactFileName.replace(executable, "name .. \"")
×
126
                .replace(projectVersion, "\" .. version .. \"")
×
127
                + ps + "bin" + ps + "\" .. name";
128

129
            if (windows) {
×
130
                executablePath += " .. \"" + distribution.getExecutable().resolveWindowsExtension() + "\"";
×
131
                installPath += " .. \"" + distribution.getExecutable().resolveWindowsExtension() + "\"";
×
132
            } else if (isNotBlank(distribution.getExecutable().getUnixExtension())) {
×
133
                executablePath += " .. \"" + distribution.getExecutable().resolveUnixExtension() + "\"";
×
134
                installPath += " .. \"" + distribution.getExecutable().resolveUnixExtension() + "\"";
×
135
            }
136
            packagePath = executablePath;
×
137
            packageInstallPath = installPath;
×
138

139
            String artifactOs = "";
×
140
            String artifactArch = "";
×
141
            if (isNotBlank(platform) && platform.contains("-")) {
×
142
                String[] parts = platform.split("-");
×
143
                artifactOs = parts[0];
×
144
                artifactArch = parts[1];
×
145
            }
146

147
            packageNotWindows = !PlatformUtils.isWindows(platform);
×
148
            packageOs = "osx".equals(artifactOs) ? "darwin" : artifactOs;
×
149
            packageArch = "x86_64".equals(artifactArch) ? "amd64" : "arm64";
×
150

151
            packageChecksum = artifact.getHash(Algorithm.SHA_256);
×
152

153
            String url = Artifacts.resolveDownloadUrl(context, org.jreleaser.model.api.packagers.GofishPackager.TYPE, distribution, artifact);
×
154
            packageUrl = url.replace(executable, "\" .. name .. \"")
×
155
                .replace(projectVersion, "\" .. version .. \"");
×
156
        }
×
157

158
        public boolean isPackageNotWindows() {
159
            return packageNotWindows;
×
160
        }
161

162
        public String getPackageOs() {
163
            return packageOs;
×
164
        }
165

166
        public String getPackageArch() {
167
            return packageArch;
×
168
        }
169

170
        public String getPackageUrl() {
171
            return passThrough(packageUrl);
×
172
        }
173

174
        public String getPackageChecksum() {
175
            return packageChecksum;
×
176
        }
177

178
        public String getPackagePath() {
179
            return passThrough(packagePath);
×
180
        }
181

182
        public String getPackageInstallPath() {
183
            return passThrough(packageInstallPath);
×
184
        }
185
    }
186
}
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