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

jreleaser / jreleaser / #477

04 Apr 2025 05:53PM UTC coverage: 35.124% (-5.1%) from 40.183%
#477

push

github

aalmiray
fix(deploy): Add missing Forgejo messages

Related to #1842

18210 of 51845 relevant lines covered (35.12%)

0.35 hits per line

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

0.0
/core/jreleaser-model-impl/src/main/java/org/jreleaser/model/spi/deploy/maven/Deployable.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.model.spi.deploy.maven;
19

20
import org.jreleaser.mustache.TemplateContext;
21

22
import java.nio.file.Path;
23
import java.nio.file.Paths;
24
import java.util.Objects;
25
import java.util.Set;
26

27
import static org.jreleaser.util.CollectionUtils.setOf;
28
import static org.jreleaser.util.StringUtils.isNotBlank;
29

30
/**
31
 * @author Andres Almiray
32
 * @since 1.4.0
33
 */
34
public class Deployable implements Comparable<Deployable> {
35
    public static final String PACKAGING_AAR = "aar";
36
    public static final String PACKAGING_JAR = "jar";
37
    public static final String PACKAGING_WAR = "war";
38
    public static final String PACKAGING_POM = "pom";
39
    public static final String PACKAGING_NBM = "nbm";
40
    public static final String PACKAGING_ZIP = "zip";
41
    public static final String PACKAGING_MAVEN_ARCHETYPE = "maven-archetype";
42
    public static final String MAVEN_METADATA_XML = "maven-metadata.xml";
43
    public static final String EXT_JAR = ".jar";
44
    public static final String EXT_WAR = ".war";
45
    public static final String EXT_POM = ".pom";
46
    public static final String EXT_ASC = ".asc";
47
    public static final String EXT_MODULE = ".module";
48
    public static final String EXT_XML = ".xml";
49
    public static final String EXT_JSON = ".json";
50

51
    private static final String[] EXT_CHECKSUMS = {".md5", ".sha1", ".sha256", ".sha512"};
×
52

53
    private static final Set<String> JAR_EXCLUSIONS = setOf(
×
54
        PACKAGING_POM,
55
        PACKAGING_AAR,
56
        PACKAGING_WAR,
57
        PACKAGING_ZIP
58
    );
59

60
    private static final Set<String> SOURCE_EXCLUSIONS = setOf(
×
61
        PACKAGING_POM,
62
        PACKAGING_NBM,
63
        PACKAGING_AAR
64
    );
65

66
    private static final Set<String> JAVADOC_EXCLUSIONS = setOf(
×
67
        PACKAGING_POM,
68
        PACKAGING_NBM,
69
        PACKAGING_MAVEN_ARCHETYPE,
70
        PACKAGING_AAR
71
    );
72

73
    private final String stagingRepository;
74
    private final String path;
75
    private final String filename;
76
    private final String groupId;
77
    private final String artifactId;
78
    private final String version;
79
    private final String classifier;
80
    private final String extension;
81
    private final String packaging;
82
    private final boolean relocated;
83

84
    public Deployable(String stagingRepository, String path, String packaging, String filename, boolean relocated) {
×
85
        this.stagingRepository = stagingRepository;
×
86
        this.path = path;
×
87
        this.filename = filename;
×
88
        this.packaging = packaging;
×
89
        this.relocated = relocated;
×
90

91
        if (!MAVEN_METADATA_XML.equals(filename)) {
×
92
            Path p = Paths.get(path);
×
93
            this.version = p.getFileName().toString();
×
94
            p = p.getParent();
×
95
            this.artifactId = p.getFileName().toString();
×
96
            p = p.getParent();
×
97
            String gid = p.toString()
×
98
                .replace("/", ".")
×
99
                .replace("\\", ".");
×
100
            if (gid.startsWith(".")) {
×
101
                gid = gid.substring(1);
×
102
            }
103
            this.groupId = gid;
×
104

105
            String str = filename.substring(filename.indexOf(version) + version.length() + 1);
×
106
            if (filename.charAt(filename.indexOf(version) + version.length()) == '-') {
×
107
                this.classifier = str.substring(0, str.indexOf('.'));
×
108
            } else {
109
                this.classifier = "";
×
110
            }
111

112
            int dot = filename.lastIndexOf('.');
×
113
            if (dot > -1) {
×
114
                this.extension = filename.substring(dot + 1);
×
115
            } else {
116
                this.extension = "";
×
117
            }
118
        } else {
×
119
            this.version = "";
×
120
            this.artifactId = "";
×
121
            this.groupId = "";
×
122
            this.classifier = "";
×
123
            this.extension = "";
×
124
        }
125
    }
×
126

127
    public TemplateContext props() {
128
        TemplateContext props = new TemplateContext();
×
129
        props.set("groupId", groupId);
×
130
        props.set("artifactId", artifactId);
×
131
        props.set("version", version);
×
132
        props.set("filename", filename);
×
133
        props.set("path", getDeployPath());
×
134
        return props;
×
135
    }
136

137
    public boolean requiresJar() {
138
        return isNotBlank(packaging) && !JAR_EXCLUSIONS.contains(packaging);
×
139
    }
140

141
    public boolean requiresWar() {
142
        return isNotBlank(packaging) && PACKAGING_WAR.equalsIgnoreCase(packaging);
×
143
    }
144

145
    public boolean requiresSourcesJar() {
146
        return isNotBlank(packaging) && !SOURCE_EXCLUSIONS.contains(packaging);
×
147
    }
148

149
    public boolean requiresJavadocJar() {
150
        return isNotBlank(packaging) && !JAVADOC_EXCLUSIONS.contains(packaging);
×
151
    }
152

153
    public String getGav() {
154
        return groupId + ":" + artifactId + ":" + version;
×
155
    }
156

157
    public String getStagingRepository() {
158
        return stagingRepository;
×
159
    }
160

161
    public String getPath() {
162
        return path;
×
163
    }
164

165
    public String getFullDeployPath() {
166
        return getDeployPath() + "/" + getFilename();
×
167
    }
168

169
    public String getDeployPath() {
170
        return path.replace("\\", "/").substring(1);
×
171
    }
172

173
    public String getFilename() {
174
        return filename;
×
175
    }
176

177
    public String getGroupId() {
178
        return groupId;
×
179
    }
180

181
    public String getArtifactId() {
182
        return artifactId;
×
183
    }
184

185
    public String getVersion() {
186
        return version;
×
187
    }
188

189
    public String getClassifier() {
190
        return classifier;
×
191
    }
192

193
    public String getExtension() {
194
        return extension;
×
195
    }
196

197
    public Path getLocalPath() {
198
        return Paths.get(stagingRepository, path, filename);
×
199
    }
200

201
    public boolean isRelocated() {
202
        return relocated;
×
203
    }
204

205
    public Deployable deriveByFilename(String filename) {
206
        return new Deployable(stagingRepository, path, packaging, filename, false);
×
207
    }
208

209
    public Deployable deriveByFilename(String packaging, String filename) {
210
        return new Deployable(stagingRepository, path, packaging, filename, false);
×
211
    }
212

213
    @Override
214
    public boolean equals(Object o) {
215
        if (this == o) return true;
×
216
        if (null == o || getClass() != o.getClass()) return false;
×
217
        Deployable that = (Deployable) o;
×
218
        return stagingRepository.equals(that.stagingRepository) &&
×
219
            path.equals(that.path) &&
×
220
            filename.equals(that.filename);
×
221
    }
222

223
    @Override
224
    public int hashCode() {
225
        return Objects.hash(stagingRepository, path, filename);
×
226
    }
227

228
    @Override
229
    public int compareTo(Deployable o) {
230
        if (null == o) return -1;
×
231
        return getFullDeployPath().compareTo(o.getFullDeployPath());
×
232
    }
233

234
    public boolean isArtifact() {
235
        return !isPom() &&
×
236
            !isSignature() &&
×
237
            !isChecksum() &&
×
238
            !isJson() &&
×
239
            !isXml() &&
×
240
            !isGradleMetadata() &&
×
241
            !isMavenMetadata();
×
242
    }
243

244
    public boolean isPom() {
245
        return filename.endsWith(EXT_POM);
×
246
    }
247

248
    public boolean isSignature() {
249
        return filename.endsWith(EXT_ASC);
×
250
    }
251

252
    public boolean isChecksum() {
253
        for (String ext : EXT_CHECKSUMS) {
×
254
            if (filename.endsWith(ext)) return true;
×
255
        }
256
        return false;
×
257
    }
258

259
    public boolean isJson() {
260
        return filename.endsWith(EXT_JSON);
×
261
    }
262

263
    public boolean isXml() {
264
        return filename.endsWith(EXT_XML);
×
265
    }
266

267
    public boolean isGradleMetadata() {
268
        return filename.endsWith(EXT_MODULE);
×
269
    }
270

271
    public boolean isMavenMetadata() {
272
        return filename.endsWith(MAVEN_METADATA_XML);
×
273
    }
274
}
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