• 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/SpecPackagerProcessor.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.SpecPackager;
24
import org.jreleaser.model.internal.release.BaseReleaser;
25
import org.jreleaser.model.spi.packagers.PackagerProcessingException;
26
import org.jreleaser.mustache.TemplateContext;
27
import org.jreleaser.util.FileUtils;
28

29
import java.io.IOException;
30
import java.nio.file.Path;
31

32
import static java.util.Collections.emptyList;
33
import static java.util.Collections.singletonList;
34
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_ARTIFACT;
35
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_CLASS;
36
import static org.jreleaser.model.Constants.KEY_DISTRIBUTION_JAVA_MAIN_MODULE;
37
import static org.jreleaser.model.Constants.KEY_PROJECT_VERSION;
38
import static org.jreleaser.model.Constants.KEY_SPEC_BINARIES;
39
import static org.jreleaser.model.Constants.KEY_SPEC_DIRECTORIES;
40
import static org.jreleaser.model.Constants.KEY_SPEC_FILES;
41
import static org.jreleaser.model.Constants.KEY_SPEC_PACKAGE_NAME;
42
import static org.jreleaser.model.Constants.KEY_SPEC_RELEASE;
43
import static org.jreleaser.model.Constants.KEY_SPEC_REPOSITORY_CLONE_URL;
44
import static org.jreleaser.model.Constants.KEY_SPEC_REPOSITORY_URL;
45
import static org.jreleaser.model.Constants.KEY_SPEC_REQUIRES;
46
import static org.jreleaser.templates.TemplateUtils.trimTplExtension;
47

48
/**
49
 * @author Andres Almiray
50
 * @since 0.9.1
51
 */
52
public class SpecPackagerProcessor extends AbstractRepositoryPackagerProcessor<SpecPackager> {
53
    public SpecPackagerProcessor(JReleaserContext context) {
UNCOV
54
        super(context);
×
UNCOV
55
    }
×
56

57
    @Override
58
    protected void doPrepareDistribution(Distribution distribution, TemplateContext props) throws PackagerProcessingException {
UNCOV
59
        setupFiles(distribution, props);
×
UNCOV
60
        super.doPrepareDistribution(distribution, props);
×
UNCOV
61
    }
×
62

63
    private void setupFiles(Distribution distribution, TemplateContext props) throws PackagerProcessingException {
UNCOV
64
        Artifact artifact = props.get(KEY_DISTRIBUTION_ARTIFACT);
×
UNCOV
65
        Path artifactPath = artifact.getResolvedPath(context, distribution);
×
66

UNCOV
67
        if (distribution.getType() == org.jreleaser.model.Distribution.DistributionType.FLAT_BINARY) {
×
68
            props.set(KEY_PROJECT_VERSION, context.getModel().getProject().version().toRpmVersion());
×
69
            props.set(KEY_SPEC_DIRECTORIES, emptyList());
×
70
            props.set(KEY_SPEC_BINARIES, singletonList(distribution.getExecutable().resolveExecutable("linux")));
×
71
            props.set(KEY_SPEC_FILES, emptyList());
×
72
            return;
×
73
        }
74

75
        try {
UNCOV
76
            FileUtils.CategorizedArchive categorizedArchive = FileUtils.categorizeUnixArchive(
×
UNCOV
77
                distribution.getExecutable().resolveWindowsExtension(),
×
78
                artifactPath);
79

UNCOV
80
            props.set(KEY_SPEC_DIRECTORIES, categorizedArchive.getDirectories());
×
UNCOV
81
            props.set(KEY_SPEC_BINARIES, categorizedArchive.getBinaries());
×
UNCOV
82
            props.set(KEY_SPEC_FILES, categorizedArchive.getFiles());
×
UNCOV
83
            props.set(KEY_PROJECT_VERSION, context.getModel().getProject().version().toRpmVersion());
×
84
        } catch (IOException e) {
×
85
            throw new PackagerProcessingException("ERROR", e);
×
UNCOV
86
        }
×
UNCOV
87
    }
×
88

89
    @Override
90
    protected void doPackageDistribution(Distribution distribution, TemplateContext props, Path packageDirectory) throws PackagerProcessingException {
UNCOV
91
        super.doPackageDistribution(distribution, props, packageDirectory);
×
UNCOV
92
        copyPreparedFiles(props);
×
UNCOV
93
    }
×
94

95
    @Override
96
    protected void fillPackagerProperties(TemplateContext props, Distribution distribution) {
UNCOV
97
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_CLASS, distribution.getJava().getMainClass());
×
UNCOV
98
        props.set(KEY_DISTRIBUTION_JAVA_MAIN_MODULE, distribution.getJava().getMainModule());
×
UNCOV
99
        props.set(KEY_SPEC_PACKAGE_NAME, packager.getPackageName());
×
UNCOV
100
        props.set(KEY_SPEC_RELEASE, packager.getRelease());
×
UNCOV
101
        props.set(KEY_SPEC_REQUIRES, packager.getRequires());
×
102

UNCOV
103
        BaseReleaser<?, ?> releaser = context.getModel().getRelease().getReleaser();
×
UNCOV
104
        props.set(KEY_SPEC_REPOSITORY_URL,
×
UNCOV
105
            releaser.getResolvedRepoUrl(context.getModel(), packager.getRepository().getOwner(), packager.getRepository().getResolvedName()));
×
UNCOV
106
        props.set(KEY_SPEC_REPOSITORY_CLONE_URL,
×
UNCOV
107
            releaser.getResolvedRepoCloneUrl(context.getModel(), packager.getRepository().getOwner(), packager.getRepository().getResolvedName()));
×
UNCOV
108
    }
×
109

110
    @Override
111
    protected void writeFile(Distribution distribution,
112
                             String content,
113
                             TemplateContext props,
114
                             Path outputDirectory,
115
                             String fileName) throws PackagerProcessingException {
UNCOV
116
        fileName = trimTplExtension(fileName);
×
117

UNCOV
118
        Path outputFile = "app.spec".equals(fileName) ?
×
UNCOV
119
            outputDirectory.resolve(packager.getPackageName().concat(".spec")) :
×
UNCOV
120
            outputDirectory.resolve(fileName);
×
121

UNCOV
122
        writeFile(content, outputFile);
×
UNCOV
123
    }
×
124
}
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