• 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/FlatpakPackagerProcessor.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.apache.commons.lang3.StringUtils;
21
import org.jreleaser.bundle.RB;
22
import org.jreleaser.engine.release.Releasers;
23
import org.jreleaser.model.Stereotype;
24
import org.jreleaser.model.internal.JReleaserContext;
25
import org.jreleaser.model.internal.common.Artifact;
26
import org.jreleaser.model.internal.common.Screenshot;
27
import org.jreleaser.model.internal.distributions.Distribution;
28
import org.jreleaser.model.internal.packagers.FlatpakPackager;
29
import org.jreleaser.model.internal.release.BaseReleaser;
30
import org.jreleaser.model.internal.release.GithubReleaser;
31
import org.jreleaser.model.internal.release.Releaser;
32
import org.jreleaser.model.spi.packagers.PackagerProcessingException;
33
import org.jreleaser.mustache.MustacheUtils;
34
import org.jreleaser.mustache.TemplateContext;
35
import org.jreleaser.util.FileUtils;
36

37
import java.io.IOException;
38
import java.nio.file.Path;
39
import java.util.Optional;
40

41
import static java.util.Collections.emptyList;
42
import static java.util.Collections.singletonList;
43
import static java.util.stream.Collectors.toList;
44
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_ARTIFACT;
45
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_CLASS;
46
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_MODULE;
47
import static org.jreleaser.model.Constants.KEY_FLATPACK_ICONS;
48
import static org.jreleaser.model.Constants.KEY_FLATPAK_BINARIES;
49
import static org.jreleaser.model.Constants.KEY_FLATPAK_CATEGORIES;
50
import static org.jreleaser.model.Constants.KEY_FLATPAK_CATEGORIES_BY_COMMA;
51
import static org.jreleaser.model.Constants.KEY_FLATPAK_CATEGORIES_BY_SEMICOLON;
52
import static org.jreleaser.model.Constants.KEY_FLATPAK_COMPONENT_ID;
53
import static org.jreleaser.model.Constants.KEY_FLATPAK_DEVELOPER_NAME;
54
import static org.jreleaser.model.Constants.KEY_FLATPAK_DIRECTORIES;
55
import static org.jreleaser.model.Constants.KEY_FLATPAK_FILES;
56
import static org.jreleaser.model.Constants.KEY_FLATPAK_HAS_SDK_EXTENSIONS;
57
import static org.jreleaser.model.Constants.KEY_FLATPAK_HAS_SDK_FINISH_ARGS;
58
import static org.jreleaser.model.Constants.KEY_FLATPAK_INCLUDE_OPENJDK;
59
import static org.jreleaser.model.Constants.KEY_FLATPAK_RELEASES;
60
import static org.jreleaser.model.Constants.KEY_FLATPAK_REPOSITORY_NAME;
61
import static org.jreleaser.model.Constants.KEY_FLATPAK_REPOSITORY_OWNER;
62
import static org.jreleaser.model.Constants.KEY_FLATPAK_REPO_NAME;
63
import static org.jreleaser.model.Constants.KEY_FLATPAK_REPO_OWNER;
64
import static org.jreleaser.model.Constants.KEY_FLATPAK_RUNTIME;
65
import static org.jreleaser.model.Constants.KEY_FLATPAK_RUNTIME_VERSION;
66
import static org.jreleaser.model.Constants.KEY_FLATPAK_SCREENSHOTS;
67
import static org.jreleaser.model.Constants.KEY_FLATPAK_SDK;
68
import static org.jreleaser.model.Constants.KEY_FLATPAK_SDK_EXTENSIONS;
69
import static org.jreleaser.model.Constants.KEY_FLATPAK_SDK_FINISH_ARGS;
70
import static org.jreleaser.model.Constants.KEY_FLATPAK_URLS;
71
import static org.jreleaser.model.Constants.KEY_PROJECT_AUTHORS;
72
import static org.jreleaser.model.Constants.KEY_SPEC_BINARIES;
73
import static org.jreleaser.model.Constants.KEY_SPEC_DIRECTORIES;
74
import static org.jreleaser.model.Constants.KEY_SPEC_FILES;
75
import static org.jreleaser.model.Constants.SKIP_OPENJDK;
76
import static org.jreleaser.packagers.AppdataUtils.isReleaseIncluded;
77
import static org.jreleaser.packagers.AppdataUtils.resolveIcons;
78
import static org.jreleaser.templates.TemplateUtils.trimTplExtension;
79
import static org.jreleaser.util.StringUtils.isFalse;
80

81
/**
82
 * @author Andres Almiray
83
 * @since 1.2.0
84
 */
85
public class FlatpakPackagerProcessor extends AbstractRepositoryPackagerProcessor<FlatpakPackager> {
86
    public FlatpakPackagerProcessor(JReleaserContext context) {
UNCOV
87
        super(context);
×
UNCOV
88
    }
×
89

90
    @Override
91
    protected void doPrepareDistribution(Distribution distribution, TemplateContext props) throws PackagerProcessingException {
UNCOV
92
        setupPrepare(distribution, props);
×
UNCOV
93
        super.doPrepareDistribution(distribution, props);
×
UNCOV
94
    }
×
95

96
    private void setupPrepare(Distribution distribution, TemplateContext props) throws PackagerProcessingException {
UNCOV
97
        Artifact artifact = props.get(KEY_DISTRIBUTION_ARTIFACT);
×
UNCOV
98
        Path artifactPath = artifact.getResolvedPath(context, distribution);
×
99

UNCOV
100
        if (distribution.getType() == org.jreleaser.model.Distribution.DistributionType.FLAT_BINARY) {
×
101
            props.set(KEY_SPEC_DIRECTORIES, emptyList());
×
102
            props.set(KEY_SPEC_BINARIES, singletonList(distribution.getExecutable().resolveExecutable("linux")));
×
103
            props.set(KEY_SPEC_FILES, emptyList());
×
104
        } else {
105
            try {
UNCOV
106
                FileUtils.CategorizedArchive categorizedArchive = FileUtils.categorizeUnixArchive(
×
UNCOV
107
                    distribution.getExecutable().resolveWindowsExtension(),
×
108
                    artifactPath);
109

UNCOV
110
                props.set(KEY_FLATPAK_DIRECTORIES, categorizedArchive.getDirectories());
×
UNCOV
111
                props.set(KEY_FLATPAK_BINARIES, categorizedArchive.getBinaries());
×
UNCOV
112
                props.set(KEY_FLATPAK_FILES, categorizedArchive.getFiles());
×
113
            } catch (IOException e) {
×
114
                throw new PackagerProcessingException("ERROR", e);
×
UNCOV
115
            }
×
116
        }
117

UNCOV
118
        BaseReleaser<?, ?> releaser = context.getModel().getRelease().getReleaser();
×
119

120
        try {
UNCOV
121
            props.set(KEY_FLATPAK_RELEASES, Releasers.releaserFor(context)
×
UNCOV
122
                .listReleases(releaser.getOwner(), releaser.getName()).stream()
×
UNCOV
123
                .filter(r -> isReleaseIncluded(packager.getSkipReleases(), r.getVersion().toString()))
×
UNCOV
124
                .map(r -> AppdataUtils.Release.of(r.getUrl(), r.getVersion().toString(), r.getPublishedAt()))
×
UNCOV
125
                .collect(toList()));
×
126
        } catch (IOException e) {
×
127
            throw new PackagerProcessingException(RB.$("ERROR_unexpected_error"), e);
×
UNCOV
128
        }
×
129

UNCOV
130
        props.set(KEY_FLATPAK_SCREENSHOTS, packager.getScreenshots().stream()
×
UNCOV
131
            .map(Screenshot::asScreenshotTemplate)
×
UNCOV
132
            .collect(toList()));
×
133

UNCOV
134
        context.getLogger().debug(RB.$("packager.fetch.icons"));
×
UNCOV
135
        props.set(KEY_FLATPACK_ICONS, packager.getIcons());
×
UNCOV
136
        resolveIcons(context, packager, distribution, props, packager.getIcons());
×
UNCOV
137
    }
×
138

139
    @Override
140
    protected void doPackageDistribution(Distribution distribution, TemplateContext props, Path packageDirectory) throws PackagerProcessingException {
UNCOV
141
        super.doPackageDistribution(distribution, props, packageDirectory);
×
UNCOV
142
        copyPreparedFiles(props);
×
UNCOV
143
    }
×
144

145
    @Override
146
    protected void fillPackagerProperties(TemplateContext props, Distribution distribution) {
UNCOV
147
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_CLASS, distribution.getJava().getMainClass());
×
UNCOV
148
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_MODULE, distribution.getJava().getMainModule());
×
UNCOV
149
        props.set(KEY_PROJECT_AUTHORS, context.getModel().getProject().getAuthors());
×
UNCOV
150
        props.set(KEY_FLATPAK_URLS, context.getModel().getProject().getLinks().asLinkTemplates(true));
×
UNCOV
151
        props.set(KEY_FLATPAK_COMPONENT_ID, getPackager().getComponentId());
×
UNCOV
152
        props.set(KEY_FLATPAK_CATEGORIES, getPackager().getCategories());
×
UNCOV
153
        props.set(KEY_FLATPAK_CATEGORIES_BY_COMMA, String.join(",", getPackager().getCategories()));
×
UNCOV
154
        props.set(KEY_FLATPAK_CATEGORIES_BY_SEMICOLON, String.join(";", getPackager().getCategories()) +
×
UNCOV
155
            (getPackager().getCategories().size() > 1 ? ";" : ""));
×
UNCOV
156
        props.set(KEY_FLATPAK_DEVELOPER_NAME, getPackager().getDeveloperName());
×
UNCOV
157
        props.set(KEY_FLATPAK_REPO_OWNER, packager.getRepository().getOwner());
×
UNCOV
158
        props.set(KEY_FLATPAK_REPO_NAME, packager.getRepository().getName());
×
UNCOV
159
        props.set(KEY_FLATPAK_REPOSITORY_OWNER, packager.getRepository().getOwner());
×
UNCOV
160
        props.set(KEY_FLATPAK_REPOSITORY_NAME, packager.getRepository().getName());
×
UNCOV
161
        props.set(KEY_FLATPAK_HAS_SDK_EXTENSIONS, !packager.getSdkExtensions().isEmpty());
×
UNCOV
162
        props.set(KEY_FLATPAK_SDK_EXTENSIONS, packager.getSdkExtensions());
×
UNCOV
163
        props.set(KEY_FLATPAK_HAS_SDK_FINISH_ARGS, !packager.getFinishArgs().isEmpty());
×
UNCOV
164
        props.set(KEY_FLATPAK_SDK_FINISH_ARGS, packager.getFinishArgs().stream()
×
UNCOV
165
            .map(MustacheUtils::passThrough)
×
UNCOV
166
            .collect(toList()));
×
UNCOV
167
        props.set(KEY_FLATPAK_RUNTIME, packager.getRuntime().runtime());
×
UNCOV
168
        props.set(KEY_FLATPAK_RUNTIME_VERSION, packager.getRuntimeVersion());
×
UNCOV
169
        props.set(KEY_FLATPAK_SDK, packager.getRuntime().sdk());
×
UNCOV
170
        props.set(KEY_FLATPAK_INCLUDE_OPENJDK, isFalse(packager.getExtraProperties().get(SKIP_OPENJDK)));
×
UNCOV
171
    }
×
172

173
    @Override
174
    protected void writeFile(Distribution distribution,
175
                             String content,
176
                             TemplateContext props,
177
                             Path outputDirectory,
178
                             String fileName) throws PackagerProcessingException {
UNCOV
179
        Releaser<?> gitService = context.getModel().getRelease().getReleaser();
×
UNCOV
180
        if (fileName.contains("github") && !(gitService instanceof GithubReleaser)) {
×
181
            // skip
182
            return;
×
UNCOV
183
        } else if (fileName.contains("-github")) {
×
184
            fileName = StringUtils.remove(fileName, "-github");
×
185
        }
186

UNCOV
187
        fileName = trimTplExtension(fileName);
×
UNCOV
188
        Optional<Stereotype> stereotype = resolveStereotype(fileName);
×
UNCOV
189
        if (stereotype.isPresent()) {
×
UNCOV
190
            if (distribution.getStereotype() == stereotype.get()) {
×
UNCOV
191
                fileName = fileName.substring(distribution.getStereotype().formatted().length() + 1);
×
192
            } else {
193
                // skip it
UNCOV
194
                return;
×
195
            }
196
        }
197

UNCOV
198
        Path outputFile = outputDirectory.resolve(fileName);
×
199

UNCOV
200
        if ("app.yml".equals(fileName)) {
×
UNCOV
201
            outputFile = outputDirectory.resolve(getPackager().getComponentId() + ".yml");
×
UNCOV
202
        } else if ("app.desktop".equals(fileName)) {
×
203
            outputFile = outputDirectory.resolve(getPackager().getComponentId() + ".desktop");
×
UNCOV
204
        } else if ("metainfo.xml".equals(fileName)) {
×
UNCOV
205
            outputFile = outputDirectory.resolve(getPackager().getComponentId() + ".metainfo.xml");
×
206
        }
207

UNCOV
208
        writeFile(content, outputFile);
×
UNCOV
209
    }
×
210
}
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