• 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

43.68
/core/jreleaser-model-impl/src/main/java/org/jreleaser/model/internal/signing/Signing.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.internal.signing;
19

20
import com.fasterxml.jackson.annotation.JsonIgnore;
21
import org.jreleaser.model.Active;
22
import org.jreleaser.model.internal.JReleaserContext;
23
import org.jreleaser.model.internal.common.AbstractActivatable;
24
import org.jreleaser.model.internal.common.AbstractModelObject;
25
import org.jreleaser.model.internal.common.Domain;
26

27
import java.io.File;
28
import java.nio.file.Path;
29
import java.nio.file.Paths;
30
import java.util.ArrayList;
31
import java.util.Collections;
32
import java.util.LinkedHashMap;
33
import java.util.List;
34
import java.util.Map;
35

36
import static java.util.Collections.unmodifiableList;
37
import static org.jreleaser.model.Constants.HIDE;
38
import static org.jreleaser.model.Constants.UNSET;
39
import static org.jreleaser.util.StringUtils.isBlank;
40
import static org.jreleaser.util.StringUtils.isNotBlank;
41

42
/**
43
 * @author Andres Almiray
44
 * @since 0.1.0
45
 */
46
public final class Signing extends AbstractActivatable<Signing> implements Domain {
1✔
47
    private static final long serialVersionUID = -7440879442726925285L;
48

49
    private final Command command = new Command();
1✔
50
    private final Cosign cosign = new Cosign();
1✔
51

52
    private Boolean armored;
53
    private Boolean verify;
54
    private String publicKey;
55
    private String secretKey;
56
    private String passphrase;
57
    private org.jreleaser.model.Signing.Mode mode;
58
    private Boolean artifacts;
59
    private Boolean files;
60
    private Boolean checksums;
61
    private Boolean catalogs;
62

63
    @JsonIgnore
1✔
64
    private final org.jreleaser.model.api.signing.Signing immutable = new org.jreleaser.model.api.signing.Signing() {
1✔
65
        private static final long serialVersionUID = -3565614952776622685L;
66

67
        @Override
68
        public boolean isArmored() {
69
            return Signing.this.isArmored();
×
70
        }
71

72
        @Override
73
        public boolean isVerify() {
74
            return Signing.this.isVerify();
×
75
        }
76

77
        @Override
78
        public String getPublicKey() {
79
            return publicKey;
×
80
        }
81

82
        @Override
83
        public String getSecretKey() {
84
            return secretKey;
×
85
        }
86

87
        @Override
88
        public String getPassphrase() {
89
            return passphrase;
×
90
        }
91

92
        @Override
93
        public org.jreleaser.model.Signing.Mode getMode() {
94
            return mode;
×
95
        }
96

97
        @Override
98
        public boolean isArtifacts() {
99
            return Signing.this.isArtifacts();
×
100
        }
101

102
        @Override
103
        public boolean isFiles() {
104
            return Signing.this.isFiles();
×
105
        }
106

107
        @Override
108
        public boolean isChecksums() {
109
            return Signing.this.isChecksums();
×
110
        }
111

112
        @Override
113
        public boolean isCatalogs() {
114
            return Signing.this.isCatalogs();
×
115
        }
116

117
        @Override
118
        public Command getCommand() {
119
            return command.asImmutable();
×
120
        }
121

122
        @Override
123
        public Cosign getCosign() {
124
            return cosign.asImmutable();
×
125
        }
126

127
        @Override
128
        public Active getActive() {
129
            return Signing.this.getActive();
×
130
        }
131

132
        @Override
133
        public boolean isEnabled() {
134
            return Signing.this.isEnabled();
×
135
        }
136

137
        @Override
138
        public Map<String, Object> asMap(boolean full) {
139
            return Signing.this.asMap(full);
×
140
        }
141
    };
142

143
    public org.jreleaser.model.api.signing.Signing asImmutable() {
144
        return immutable;
×
145
    }
146

147
    @Override
148
    public void merge(Signing source) {
149
        super.merge(source);
1✔
150
        this.armored = merge(this.armored, source.armored);
1✔
151
        this.verify = merge(this.verify, source.verify);
1✔
152
        this.publicKey = merge(this.publicKey, source.publicKey);
1✔
153
        this.secretKey = merge(this.secretKey, source.secretKey);
1✔
154
        this.passphrase = merge(this.passphrase, source.passphrase);
1✔
155
        this.mode = merge(this.mode, source.mode);
1✔
156
        this.artifacts = merge(this.artifacts, source.artifacts);
1✔
157
        this.files = merge(this.files, source.files);
1✔
158
        this.checksums = merge(this.checksums, source.checksums);
1✔
159
        this.catalogs = merge(this.catalogs, source.catalogs);
1✔
160
        setCommand(source.command);
1✔
161
        setCosign(source.cosign);
1✔
162
    }
1✔
163

164
    public org.jreleaser.model.Signing.Mode resolveMode() {
165
        if (null == mode) {
1✔
166
            mode = org.jreleaser.model.Signing.Mode.MEMORY;
1✔
167
        }
168
        return mode;
1✔
169
    }
170

171
    public boolean isArmored() {
172
        return null != armored && armored;
1✔
173
    }
174

175
    public void setArmored(Boolean armored) {
176
        this.armored = armored;
1✔
177
    }
1✔
178

179
    public boolean isArmoredSet() {
180
        return null != armored;
1✔
181
    }
182

183
    public boolean isVerify() {
184
        return null == verify || verify;
1✔
185
    }
186

187
    public void setVerify(Boolean verify) {
188
        this.verify = verify;
×
189
    }
×
190

191
    public boolean isVerifySet() {
192
        return null != verify;
×
193
    }
194

195
    public String getPublicKey() {
196
        return publicKey;
1✔
197
    }
198

199
    public void setPublicKey(String publicKey) {
200
        this.publicKey = publicKey;
1✔
201
    }
1✔
202

203
    public String getSecretKey() {
204
        return secretKey;
1✔
205
    }
206

207
    public void setSecretKey(String secretKey) {
208
        this.secretKey = secretKey;
1✔
209
    }
1✔
210

211
    public String getPassphrase() {
212
        return passphrase;
1✔
213
    }
214

215
    public void setPassphrase(String passphrase) {
216
        this.passphrase = passphrase;
1✔
217
    }
1✔
218

219
    public org.jreleaser.model.Signing.Mode getMode() {
220
        return mode;
1✔
221
    }
222

223
    public void setMode(org.jreleaser.model.Signing.Mode mode) {
224
        this.mode = mode;
×
225
    }
×
226

227
    public void setMode(String str) {
228
        setMode(org.jreleaser.model.Signing.Mode.of(str));
×
229
    }
×
230

231
    public boolean isArtifactsSet() {
232
        return null != artifacts;
×
233
    }
234

235
    public boolean isArtifacts() {
236
        return null == artifacts || artifacts;
1✔
237
    }
238

239
    public void setArtifacts(Boolean artifacts) {
240
        this.artifacts = artifacts;
×
241
    }
×
242

243
    public boolean isFiles() {
244
        return null == files || files;
1✔
245
    }
246

247
    public void setFiles(Boolean files) {
248
        this.files = files;
×
249
    }
×
250

251
    public boolean isFilesSet() {
252
        return null != files;
×
253
    }
254

255
    public boolean isChecksumsSet() {
256
        return null != checksums;
×
257
    }
258

259
    public boolean isChecksums() {
260
        return null == checksums || checksums;
1✔
261
    }
262

263
    public void setChecksums(Boolean checksums) {
264
        this.checksums = checksums;
×
265
    }
×
266

267
    public boolean isCatalogsSet() {
268
        return null != catalogs;
×
269
    }
270

271
    public boolean isCatalogs() {
272
        return null == catalogs || catalogs;
1✔
273
    }
274

275
    public void setCatalogs(Boolean catalogs) {
276
        this.catalogs = catalogs;
×
277
    }
×
278

279
    public Command getCommand() {
280
        return command;
×
281
    }
282

283
    public void setCommand(Command command) {
284
        this.command.merge(command);
1✔
285
    }
1✔
286

287
    public Cosign getCosign() {
288
        return cosign;
×
289
    }
290

291
    public void setCosign(Cosign cosign) {
292
        this.cosign.merge(cosign);
1✔
293
    }
1✔
294

295
    @Override
296
    public Map<String, Object> asMap(boolean full) {
297
        if (!full && !isEnabled()) return Collections.emptyMap();
1✔
298

299
        Map<String, Object> props = new LinkedHashMap<>();
1✔
300
        props.put("enabled", isEnabled());
1✔
301
        props.put("active", getActive());
1✔
302
        props.put("armored", isArmored());
1✔
303
        props.put("verify", isVerify());
1✔
304
        props.put("mode", mode);
1✔
305
        props.put("artifacts", isArtifacts());
1✔
306
        props.put("files", isFiles());
1✔
307
        props.put("checksums", isChecksums());
1✔
308
        props.put("catalogs", isCatalogs());
1✔
309
        props.put("passphrase", isNotBlank(passphrase) ? HIDE : UNSET);
1✔
310

311
        if (mode == org.jreleaser.model.Signing.Mode.COMMAND) {
1✔
312
            props.put("command", command.asMap(full));
×
313
        } else if (mode == org.jreleaser.model.Signing.Mode.COSIGN) {
1✔
314
            props.put("cosign", cosign.asMap(full));
×
315
        } else {
316
            props.put("publicKey", isNotBlank(publicKey) ? HIDE : UNSET);
1✔
317
            props.put("secretKey", isNotBlank(secretKey) ? HIDE : UNSET);
1✔
318
        }
319

320
        return props;
1✔
321
    }
322

323
    public String getSignatureExtension() {
324
        String extension = ".sig";
×
325
        if (mode != org.jreleaser.model.Signing.Mode.COSIGN) {
×
326
            extension = isArmored() ? ".asc" : ".sig";
×
327
        }
328

329
        return extension;
×
330
    }
331

332
    public static class Command extends AbstractModelObject<Command> implements Domain {
1✔
333
        private static final long serialVersionUID = -6208172775388448492L;
334

335
        private final List<String> args = new ArrayList<>();
1✔
336

337
        private String executable;
338
        private String keyName;
339
        private String homeDir;
340
        private String publicKeyring;
341
        private Boolean defaultKeyring;
342

343
        @JsonIgnore
1✔
344
        private final org.jreleaser.model.api.signing.Signing.Command immutable = new org.jreleaser.model.api.signing.Signing.Command() {
1✔
345
            private static final long serialVersionUID = -8636071040086599491L;
346

347
            @Override
348
            public String getExecutable() {
349
                return executable;
×
350
            }
351

352
            @Override
353
            public String getKeyName() {
354
                return keyName;
×
355
            }
356

357
            @Override
358
            public String getHomeDir() {
359
                return homeDir;
×
360
            }
361

362
            @Override
363
            public String getPublicKeyring() {
364
                return publicKeyring;
×
365
            }
366

367
            @Override
368
            public boolean isDefaultKeyring() {
369
                return Command.this.isDefaultKeyring();
×
370
            }
371

372
            @Override
373
            public List<String> getArgs() {
374
                return unmodifiableList(args);
×
375
            }
376

377
            @Override
378
            public Map<String, Object> asMap(boolean full) {
379
                return Command.this.asMap(full);
×
380
            }
381
        };
382

383
        public org.jreleaser.model.api.signing.Signing.Command asImmutable() {
384
            return immutable;
×
385
        }
386

387
        @Override
388
        public void merge(Command source) {
389
            this.executable = merge(this.executable, source.executable);
1✔
390
            this.keyName = merge(this.keyName, source.keyName);
1✔
391
            this.homeDir = merge(this.homeDir, source.homeDir);
1✔
392
            this.publicKeyring = merge(this.publicKeyring, source.publicKeyring);
1✔
393
            this.defaultKeyring = merge(this.defaultKeyring, source.defaultKeyring);
1✔
394
            setArgs(merge(this.args, source.args));
1✔
395
        }
1✔
396

397
        public String getExecutable() {
398
            return executable;
×
399
        }
400

401
        public void setExecutable(String executable) {
402
            this.executable = executable;
×
403
        }
×
404

405
        public String getKeyName() {
406
            return keyName;
×
407
        }
408

409
        public void setKeyName(String keyName) {
410
            this.keyName = keyName;
×
411
        }
×
412

413
        public String getHomeDir() {
414
            return homeDir;
×
415
        }
416

417
        public void setHomeDir(String homeDir) {
418
            this.homeDir = homeDir;
×
419
        }
×
420

421
        public String getPublicKeyring() {
422
            return publicKeyring;
×
423
        }
424

425
        public void setPublicKeyring(String publicKeyring) {
426
            this.publicKeyring = publicKeyring;
×
427
        }
×
428

429
        public boolean isDefaultKeyringSet() {
430
            return null != defaultKeyring;
×
431
        }
432

433
        public boolean isDefaultKeyring() {
434
            return null == defaultKeyring || defaultKeyring;
×
435
        }
436

437
        public void setDefaultKeyring(Boolean defaultKeyring) {
438
            this.defaultKeyring = defaultKeyring;
×
439
        }
×
440

441
        public List<String> getArgs() {
442
            return args;
×
443
        }
444

445
        public void setArgs(List<String> args) {
446
            this.args.clear();
1✔
447
            this.args.addAll(args);
1✔
448
        }
1✔
449

450
        @Override
451
        public Map<String, Object> asMap(boolean full) {
452
            Map<String, Object> props = new LinkedHashMap<>();
×
453

454
            props.put("executable", executable);
×
455
            props.put("keyName", keyName);
×
456
            props.put("homeDir", homeDir);
×
457
            props.put("publicKeyring", publicKeyring);
×
458
            props.put("defaultKeyring", isDefaultKeyring());
×
459
            props.put("args", args);
×
460

461
            return props;
×
462
        }
463
    }
464

465
    public static class Cosign extends AbstractModelObject<Cosign> implements Domain {
1✔
466
        private static final long serialVersionUID = 5608123183696686008L;
467

468
        private String version;
469
        private String privateKeyFile;
470
        private String publicKeyFile;
471

472
        @JsonIgnore
1✔
473
        private final org.jreleaser.model.api.signing.Signing.Cosign immutable = new org.jreleaser.model.api.signing.Signing.Cosign() {
1✔
474
            private static final long serialVersionUID = 3675807300391748445L;
475

476
            @Override
477
            public String getVersion() {
478
                return version;
×
479
            }
480

481
            @Override
482
            public String getPrivateKeyFile() {
483
                return privateKeyFile;
×
484
            }
485

486
            @Override
487
            public String getPublicKeyFile() {
488
                return publicKeyFile;
×
489
            }
490

491
            @Override
492
            public Map<String, Object> asMap(boolean full) {
493
                return Cosign.this.asMap(full);
×
494
            }
495
        };
496

497
        public org.jreleaser.model.api.signing.Signing.Cosign asImmutable() {
498
            return immutable;
×
499
        }
500

501
        @Override
502
        public void merge(Cosign source) {
503
            this.version = merge(this.version, source.version);
1✔
504
            this.privateKeyFile = merge(this.privateKeyFile, source.privateKeyFile);
1✔
505
            this.publicKeyFile = merge(this.publicKeyFile, source.publicKeyFile);
1✔
506
        }
1✔
507

508
        public String getVersion() {
509
            return version;
×
510
        }
511

512
        public void setVersion(String version) {
513
            this.version = version;
×
514
        }
×
515

516
        public String getPrivateKeyFile() {
517
            return privateKeyFile;
×
518
        }
519

520
        public void setPrivateKeyFile(String privateKeyFile) {
521
            this.privateKeyFile = privateKeyFile;
×
522
        }
×
523

524
        public String getPublicKeyFile() {
525
            return publicKeyFile;
×
526
        }
527

528
        public void setPublicKeyFile(String publicKeyFile) {
529
            this.publicKeyFile = publicKeyFile;
×
530
        }
×
531

532
        @Override
533
        public Map<String, Object> asMap(boolean full) {
534
            Map<String, Object> props = new LinkedHashMap<>();
×
535

536
            props.put("version", version);
×
537
            props.put("privateKeyFile", null != privateKeyFile ? HIDE : UNSET);
×
538
            props.put("publicKeyFile", publicKeyFile);
×
539

540
            return props;
×
541
        }
542

543
        public Path getResolvedPrivateKeyFilePath(JReleaserContext context) {
544
            String privateKey = getPrivateKeyFile();
×
545

546
            if (isNotBlank(privateKey)) {
×
547
                return context.getBasedir().resolve(privateKey);
×
548
            }
549

550
            return resolveJReleaserHomeDir().resolve("cosign.key");
×
551
        }
552

553
        public Path getResolvedPublicKeyFilePath(JReleaserContext context) {
554
            String publicKey = getPublicKeyFile();
×
555

556
            if (isNotBlank(publicKey)) {
×
557
                return context.getBasedir().resolve(publicKey);
×
558
            }
559

560
            return resolveJReleaserHomeDir().resolve("cosign.pub");
×
561
        }
562

563
        private Path resolveJReleaserHomeDir() {
564
            String home = System.getenv("JRELEASER_USER_HOME");
×
565
            if (isBlank(home)) {
×
566
                home = System.getProperty("user.home") + File.separator + ".jreleaser";
×
567
            }
568

569
            return Paths.get(home);
×
570
        }
571
    }
572
}
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