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

jreleaser / jreleaser / #524

01 Aug 2025 02:16PM UTC coverage: 48.454% (-0.9%) from 49.315%
#524

push

github

aalmiray
fix(hooks): Inherit matrix and environment from named groups

Relates to #1947

56 of 125 new or added lines in 5 files covered. (44.8%)

450 existing lines in 37 files now uncovered.

25680 of 52999 relevant lines covered (48.45%)

0.48 hits per line

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

81.44
/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"};
1✔
52

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

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

66
    private static final Set<String> JAVADOC_EXCLUSIONS = setOf(
1✔
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
    private final boolean snapshot;
84

85
    public Deployable(boolean snapshot, String stagingRepository, String path, String packaging, String filename, boolean relocated) {
1✔
86
        this.snapshot = snapshot;
1✔
87
        this.stagingRepository = stagingRepository;
1✔
88
        this.path = path;
1✔
89
        this.filename = filename;
1✔
90
        this.packaging = packaging;
1✔
91
        this.relocated = relocated;
1✔
92

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

107
            String v = version;
1✔
108
            int l = version.length();
1✔
109
            if (snapshot) {
1✔
110
                // SNAPSHOT replaced with YYYYMMDD.HHmmSS-#
111
                v = version.substring(0, version.length() - "SNAPSHOT".length());
×
112
                l = v.length() + 17;
×
113
            }
114

115
            if (filename.contains(v)) {
1✔
116
                String str = filename.substring(filename.indexOf(v) + l + 1);
1✔
117
                if (filename.charAt(filename.indexOf(v) + l) == '-') {
1✔
118
                    this.classifier = str.substring(0, str.indexOf('.'));
1✔
119
                } else {
120
                    this.classifier = "";
1✔
121
                }
122
            } else {
1✔
123
                this.classifier = "";
×
124
            }
125

126
            int dot = filename.lastIndexOf('.');
1✔
127
            if (dot > -1) {
1✔
128
                this.extension = filename.substring(dot + 1);
1✔
129
            } else {
130
                this.extension = "";
×
131
            }
132
        } else {
1✔
133
            this.version = "";
×
134
            this.artifactId = "";
×
135
            this.groupId = "";
×
136
            this.classifier = "";
×
137
            this.extension = "";
×
138
        }
139
    }
1✔
140

141
    public TemplateContext props() {
142
        TemplateContext props = new TemplateContext();
1✔
143
        props.set("groupId", groupId);
1✔
144
        props.set("artifactId", artifactId);
1✔
145
        props.set("version", version);
1✔
146
        props.set("filename", filename);
1✔
147
        props.set("path", getDeployPath());
1✔
148
        return props;
1✔
149
    }
150

151
    public boolean requiresJar() {
152
        return isNotBlank(packaging) && !JAR_EXCLUSIONS.contains(packaging);
1✔
153
    }
154

155
    public boolean requiresWar() {
156
        return isNotBlank(packaging) && PACKAGING_WAR.equalsIgnoreCase(packaging);
1✔
157
    }
158

159
    public boolean requiresSourcesJar() {
160
        return isNotBlank(packaging) && !SOURCE_EXCLUSIONS.contains(packaging);
1✔
161
    }
162

163
    public boolean requiresJavadocJar() {
164
        return isNotBlank(packaging) && !JAVADOC_EXCLUSIONS.contains(packaging);
1✔
165
    }
166

167
    public String getGav() {
168
        return groupId + ":" + artifactId + ":" + version;
×
169
    }
170

171
    public String getStagingRepository() {
172
        return stagingRepository;
1✔
173
    }
174

175
    public String getPath() {
176
        return path;
1✔
177
    }
178

179
    public String getFullDeployPath() {
180
        return getDeployPath() + "/" + getFilename();
1✔
181
    }
182

183
    public String getDeployPath() {
184
        return path.replace("\\", "/").substring(1);
1✔
185
    }
186

187
    public String getFilename() {
188
        return filename;
1✔
189
    }
190

191
    public String getGroupId() {
192
        return groupId;
1✔
193
    }
194

195
    public String getArtifactId() {
196
        return artifactId;
1✔
197
    }
198

199
    public String getVersion() {
200
        return version;
1✔
201
    }
202

203
    public String getClassifier() {
204
        return classifier;
×
205
    }
206

207
    public String getExtension() {
208
        return extension;
×
209
    }
210

211
    public Path getLocalPath() {
212
        return Paths.get(stagingRepository, path, filename);
1✔
213
    }
214

215
    public boolean isRelocated() {
216
        return relocated;
1✔
217
    }
218

219
    public Deployable deriveByFilename(String filename) {
220
        return new Deployable(snapshot, stagingRepository, path, packaging, filename, false);
1✔
221
    }
222

223
    public Deployable deriveByFilename(String packaging, String filename) {
224
        return new Deployable(snapshot, stagingRepository, path, packaging, filename, false);
1✔
225
    }
226

227
    @Override
228
    public boolean equals(Object o) {
UNCOV
229
        if (this == o) return true;
×
UNCOV
230
        if (null == o || getClass() != o.getClass()) return false;
×
UNCOV
231
        Deployable that = (Deployable) o;
×
UNCOV
232
        return stagingRepository.equals(that.stagingRepository) &&
×
UNCOV
233
            path.equals(that.path) &&
×
UNCOV
234
            filename.equals(that.filename);
×
235
    }
236

237
    @Override
238
    public int hashCode() {
239
        return Objects.hash(stagingRepository, path, filename);
1✔
240
    }
241

242
    @Override
243
    public int compareTo(Deployable o) {
244
        if (null == o) return -1;
1✔
245
        return getFullDeployPath().compareTo(o.getFullDeployPath());
1✔
246
    }
247

248
    public boolean isArtifact() {
249
        return !isPom() &&
1✔
250
            !isSignature() &&
1✔
251
            !isChecksum() &&
1✔
252
            !isJson() &&
1✔
253
            !isXml() &&
1✔
254
            !isGradleMetadata() &&
1✔
255
            !isMavenMetadata();
1✔
256
    }
257

258
    public boolean isPom() {
259
        return filename.endsWith(EXT_POM);
1✔
260
    }
261

262
    public boolean isSignature() {
263
        return filename.endsWith(EXT_ASC);
1✔
264
    }
265

266
    public boolean isChecksum() {
267
        for (String ext : EXT_CHECKSUMS) {
1✔
268
            if (filename.endsWith(ext)) return true;
1✔
269
        }
270
        return false;
1✔
271
    }
272

273
    public boolean isJson() {
274
        return filename.endsWith(EXT_JSON);
1✔
275
    }
276

277
    public boolean isXml() {
278
        return filename.endsWith(EXT_XML);
1✔
279
    }
280

281
    public boolean isGradleMetadata() {
282
        return filename.endsWith(EXT_MODULE);
1✔
283
    }
284

285
    public boolean isMavenMetadata() {
286
        return filename.endsWith(MAVEN_METADATA_XML);
1✔
287
    }
288
}
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