-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathRpmMojo.java
More file actions
1465 lines (1253 loc) · 52.4 KB
/
Copy pathRpmMojo.java
File metadata and controls
1465 lines (1253 loc) · 52.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2016, 2023 IBH SYSTEMS GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0
*
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
* Red Hat Inc - upgrade to package drone 0.14.0, enhance features
* Bernd Warmuth - bugfix target folder creation
* Oliver Richter - Made packageName & defaultScriptInterpreter configurable
* Lucian Burja - Added setting for creating relocatable RPM packages
* Peter Wilkinson - add skip entry flag
* Daniel Singhal - Added primary artifact support
* Jarkko Sonninen - Added outputFileNameProperty
* Fraunhofer-Institut fuer Optronik, Systemtechnik und Bildauswertung IOSB - apply rules to implicit created intermediate directories
*******************************************************************************/
package de.dentrassi.rpm.builder;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.file.Files.readAllLines;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.model.License;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.codehaus.plexus.util.DirectoryScanner;
import org.eclipse.packager.rpm.Architecture;
import org.eclipse.packager.rpm.HashAlgorithm;
import org.eclipse.packager.rpm.OperatingSystem;
import org.eclipse.packager.rpm.RpmLead;
import org.eclipse.packager.rpm.RpmTag;
import org.eclipse.packager.rpm.RpmVersion;
import org.eclipse.packager.rpm.build.*;
import org.eclipse.packager.rpm.build.RpmBuilder.PackageInformation;
import org.eclipse.packager.rpm.build.RpmBuilder.Version;
import org.eclipse.packager.rpm.coding.PayloadCoding;
import org.eclipse.packager.rpm.coding.PayloadFlags;
import org.eclipse.packager.rpm.deps.RpmDependencyFlags;
import org.eclipse.packager.rpm.signature.RsaHeaderSignatureProcessor;
import org.eclipse.packager.rpm.signature.RsaSignatureProcessor;
import org.eclipse.packager.rpm.signature.SignatureProcessor;
import com.google.common.base.Strings;
import com.google.common.io.CharSource;
import de.dentrassi.rpm.builder.Naming.Case;
import de.dentrassi.rpm.builder.PackageEntry.Collector;
import de.dentrassi.rpm.builder.signatures.SignatureConfiguration;
/**
* Build an RPM file
*
* @author ctron
*/
@Mojo(name = "rpm", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true)
public class RpmMojo extends AbstractMojo {
private static final PayloadCoding DEFAULT_PAYLOAD_CODING = PayloadCoding.gzip;
private static final String DEFAULT_PAYLOAD_FLAGS = "9";
private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
/**
* The maven project
*/
@Parameter(property = "project", readonly = true, required = true)
protected MavenProject project;
@Component
MavenProjectHelper projectHelper;
/**
* The version string to be processed in case of a release build
*
* @see #snapshotVersion
*/
@Parameter(defaultValue = "${project.version}")
String version;
/**
* The version string to be processed in case of a SNAPSHOT build
*
* @see #version
*/
@Parameter(property = "rpm.snapshotVersion")
String snapshotVersion;
/**
* The RPM package name
*/
@Parameter(defaultValue = "${project.artifactId}", property = "rpm.packageName")
String packageName;
/**
* The architecture
*/
@Parameter(defaultValue = "noarch", property = "rpm.architecture")
String architecture = "noarch";
/**
* Override the lead architecture value.
* <p>
* Also see <a href="lead.html">Lead information</a>.
* </p>
*
* @since 0.10.2
*/
@Parameter(property = "rpm.leadOverride.architecture")
Architecture leadOverrideArchitecture;
public void setLeadOverrideArchitecture(final Architecture leadOverrideArchitecture) {
this.leadOverrideArchitecture = leadOverrideArchitecture;
}
/**
* The "operatingSystem" field in the RPM file.
*
* @since 0.10.2
*/
@Parameter(property = "rpm.operatingSystem")
String operatingSystem = "linux";
public void setOperatingSystem(final String operatingSystem) {
this.operatingSystem = operatingSystem;
}
/**
* Override the lead operating system value.
* <p>
* Also see <a href="lead.html">Lead information</a>.
* </p>
*
* @since 0.10.2
*/
@Parameter(property = "rpm.leadOverride.operatingSystem")
OperatingSystem leadOverrideOperatingSystem;
public void setLeadOverrideOperatingSystem(final OperatingSystem leadOverrideOperatingSystem) {
this.leadOverrideOperatingSystem = leadOverrideOperatingSystem;
}
/**
* Set the name of the source package.
*
* @since 0.11.0
*/
@Parameter(property = "rpm.sourcePackage")
String sourcePackage;
public void setSourcePackage(final String sourcePackage) {
this.sourcePackage = sourcePackage;
}
/**
* Whether to generate a default source package.
* <p>
* If the {@code sourceProperty} package is {@code null} or empty, this flag
* controls if a default value is generated for the source package or not.
* </p>
* <p>
* The default name will consist of the package name and the version with
* the suffix {@code .src.rpm}. The output file name is not used as a basis
* for the default source package name. If you need more control over the
* source package name you need to use the {@code sourcePackage} property
* instead.
* </p>
* <p>
* Before version 0.11.0 the source package was always empty. The new
* default behavior is to fill the source package with a package name
* derived from the package name. Setting this flag to {@code false} will
* revert to the old default behavior of leaving the source package header
* field unset.
* </p>
*
* @since 0.11.0
*/
@Parameter(property = "rpm.generateDefaultSourcePackage", defaultValue = "true")
boolean generateDefaultSourcePackage = true;
public void setGenerateDefaultSourcePackage(final boolean generateDefaultSourcePackage) {
this.generateDefaultSourcePackage = generateDefaultSourcePackage;
}
/**
* The prefix of the release if this is a snapshot build, will be suffixed
* with the snapshot build id
* <p>
* Also see: {@link #snapshotBuildId}
* </p>
*/
@Parameter(defaultValue = "0.", property = "rpm.snapshotReleasePrefix")
String snapshotReleasePrefix = "0.";
/**
* Set the build id which is used when a snapshot build is active.
* <p>
* If this parameter is left unset or empty then the current time (UTC) in
* the format {@code yyyyMMddHHmm} will be used.
* </p>
*
* @since 0.6.0
*/
@Parameter(property = "rpm.snapshotBuildId", required = false)
String snapshotBuildId;
/**
* The release which will be used if this is not a snapshot build
*/
@Parameter(property = "rpm.release", defaultValue = "1")
String release = "1";
/**
* Always use the "release" string
* <p>
* This parameter enforces the build to always use the RPM release
* information from the parameter "release", whether this is a snapshot
* build or not
* </p>
*
* @since 0.6.0
*/
@Parameter(property = "rpm.forceRelease", defaultValue = "false")
boolean forceRelease = false;
/**
* The classifier of the attached rpm
*/
@Parameter(property = "rpm.classifier", defaultValue = "rpm")
String classifier = "rpm";
/**
* Whether to attach the output file
*/
@Parameter(property = "rpm.attach", defaultValue = "true")
boolean attach = true;
/**
* The RPM epoch, leave unset for default
*/
@Parameter(property = "rpm.epoch")
Integer epoch;
/**
* The "summary" field of the RPM file
* <p>
* This defaults to the project name
* </p>
*/
@Parameter(property = "rpm.summary", defaultValue = "${project.name}")
String summary;
/**
* The "description" field of the RPM file
* <p>
* This defaults to the Maven project description
* </p>
*/
@Parameter(property = "rpm.description", defaultValue = "${project.description}")
String description;
/**
* The RPM group
* <p>
* See also
* <a href="https://fedoraproject.org/wiki/RPMGroups">https://fedoraproject.
* org/wiki/RPMGroups</a>
* </p>
*/
@Parameter(property = "rpm.group", defaultValue = "Unspecified")
String group;
/**
* The "distribution" field in the RPM file
*/
@Parameter(property = "rpm.distribution")
String distribution;
/**
* Whether the plugin should try to evaluate to hostname
* <p>
* If set to {@code false}, then he build hostname {@code localhost} will be
* used instead of the actual hostname
* </p>
*/
@Parameter(property = "rpm.evalHostname", defaultValue = "true")
boolean evalHostname = true;
/**
* The license of the RPM file
* <p>
* This defaults to a comma separated list of all license names specified in
* the projects POM file.
* </p>
*/
@Parameter(property = "rpm.license")
String license;
/**
* The vendor name of the RPM file
* <p>
* This defaults to the name of the organization in the POM file.
* </p>
*/
@Parameter(property = "rpm.vendor")
String vendor;
/**
* The name of the packager in the RPM file
* <p>
* This defaults to <tt>${project.organization.name}
* <${project.organization.url}></tt> if both values are set.
* </p>
* <p>
* See also <a href=
* "http://www.rpm.org/max-rpm/s1-rpm-inside-tags.html#S3-RPM-INSIDE-PACKAGER-TAG">
* http://www.rpm.org/max-rpm/s1-rpm-inside-tags.html#S3-RPM-INSIDE-PACKAGER
* -TAG</a>
* </p>
*/
@Parameter(property = "rpm.packager")
String packager;
/**
* Build relocatable packages.
*
* <pre>
* <prefixes>
* <prefix>/opt</prefix>
* <prefix>/var/log</prefix>
* </prefixes>
* </pre>
* <p>
* See also
* <a href="http://ftp.rpm.org/max-rpm/s1-rpm-reloc-prefix-tag.html">The
* prefix tag</a>
*
* @since 1.1.0
*/
@Parameter(property = "rpm.prefixes")
List<String> prefixes;
/**
* Base paths for which implicitly created intermediate directories should
* explicitly add to package.
*
* <pre>
* <generateIntermediateDirectories>
* <baseDirectory>/opt/mycompany/myapp</baseDirectory>
* <baseDirectory>/etc/mycompany</baseDirectory>
* </generateIntermediateDirectories>
* </pre>
*
* <p>
* For these given base directories, any intermediate directories created
* implicitly from {@code <entry>} elements are added to the package
* as explicit entries.
* The rules with file information are applied to these added directories as well.
* </p>
* <p>
* Note: In case of {@code <collect>} entries this feature is only applied to
* directories outside of the collection.
* </p>
*
* @since 1.12.0
*/
@Parameter(property = "rpm.generateIntermediateDirectories")
List<String> generateIntermediateDirectories;
/**
* The actual payload/file entries
* <p>
* Also see <a href="entry.html">entries</a>
* </p>
* <p>
* This is a list of {@code <entry>} elements with additional information:
* </p>
*
* <pre>
* <entries>
* <entry>
* <!-- target name -->
* <name>/etc/foo/bar.conf</name>
*
* <!-- either one of:
* <file>src/main/resources/bar.conf</file>
* <directory>true</directory>
* <collect>
* <from>src/main/resources/dir</from>
* </collect>
* -->
*
* </entry>
* </entries>
* </pre>
*/
@Parameter
List<PackageEntry> entries = new LinkedList<>();
/**
* Rulesets to configure the file information like "user", "modes", etc.
* <p>
* Also see <a href="rulesets.html">rulesets</a>.
* </p>
*/
@Parameter
List<Ruleset> rulesets = new LinkedList<>();
/**
* The default ruleset to use if no other is specified
*/
@Parameter
String defaultRuleset;
private Logger logger;
private RulesetEvaluator eval;
/**
* A script which is run before the installation takes place
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script beforeInstallation;
/**
* A script which is run after the installation took place
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script afterInstallation;
/**
* A script which is run before the removal takes place
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script beforeRemoval;
/**
* A script which is run after the removal took place
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script afterRemoval;
/**
* A script which is run before the entire transaction starts
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script beforeTransaction;
/**
* A script which is run after the entire transaction finishes
* <p>
* Also see <a href="rulesets.html">scripts</a>
* </p>
*/
@Parameter
Script afterTransaction;
/**
* The default script interpreter which is used if neither the script has
* one set explicitly, nor one could be detected
*/
@Parameter(property = "rpm.defaultScriptInterpreter", defaultValue = "/bin/sh")
String defaultScriptInterpreter;
/**
* RPM package requirements
* <p>
* Also see <a href="deps.html">dependencies</a>
* </p>
*/
@Parameter
List<Dependency> requires = new LinkedList<>();
/**
* RPM provides information
* <p>
* Also see <a href="deps.html">dependencies</a>
* </p>
*/
@Parameter
List<SimpleDependency> provides = new LinkedList<>();
/**
* RPM package conflicts
* <p>
* Also see <a href="deps.html">dependencies</a>
* </p>
*/
@Parameter
List<SimpleDependency> conflicts = new LinkedList<>();
/**
* RPM obsoletes information
* <p>
* Also see <a href="deps.html">dependencies</a>
* </p>
*/
@Parameter
List<SimpleDependency> obsoletes = new LinkedList<>();
/**
* RPM package requirements needed before the installation starts
* <p>
* Also see <a href="deps.html">dependencies</a>
* </p>
*/
@Parameter
List<SimpleDependency> prerequisites = new LinkedList<>();
/**
* Hint forward dependency.
* <p>
* Also see <a href="deps.html">dependencies</a> and
* <a href="https://fedoraproject.org/wiki/Packaging:WeakDependencies">Weak
* dependencies</a>.
* </p>
*/
@Parameter
List<SimpleDependency> suggests = new LinkedList<>();
/**
* Hint backward dependency.
* <p>
* Also see <a href="deps.html">dependencies</a> and
* <a href="https://fedoraproject.org/wiki/Packaging:WeakDependencies">Weak
* dependencies</a>.
* </p>
*/
@Parameter
List<SimpleDependency> enhances = new LinkedList<>();
/**
* Weak backward dependency.
* <p>
* Also see <a href="deps.html">dependencies</a> and
* <a href="https://fedoraproject.org/wiki/Packaging:WeakDependencies">Weak
* dependencies</a>.
* </p>
*/
@Parameter
List<SimpleDependency> supplements = new LinkedList<>();
/**
* Weak forward dependency.
* <p>
* Also see <a href="deps.html">dependencies</a> and
* <a href="https://fedoraproject.org/wiki/Packaging:WeakDependencies">Weak
* dependencies</a>.
* </p>
*/
@Parameter
List<SimpleDependency> recommends = new LinkedList<>();
/**
* An optional signature descriptor for GPG signing the final RPM
* <p>
* Also see <a href="signing.html">signing</a>
* </p>
*/
@Parameter(property = "rpm.signature")
Signature signature;
/**
* Optional payload flags to use for compressing the payload of the final RPM.
* <p>
* The coding must be one of the names returned by {@link PayloadCoding#values()}.
* The default coding is {@link PayloadCoding#gzip}.
* The level must be a number.
* The default level is {@code 9}.
* <p>
* Also see <a href="payload_compression.html">Payload compression</a>
*/
@Parameter(property = "rpm.payloadFlags")
PayloadFlags payloadFlags;
/**
* Disable the mojo altogether.
*
* @since 1.1.1
*/
@Parameter(property = "rpm.skip", defaultValue = "false")
boolean skip = false;
public void setSkip(final boolean skip) {
this.skip = skip;
}
/**
* Disable all package signing
*/
@Parameter(property = "rpm.skipSigning", defaultValue = "false")
boolean skipSigning = false;
public void setSkipSigning(final boolean skipSigning) {
this.skipSigning = skipSigning;
}
/**
* Provide package naming options
* <p>
* Also see <a href="naming.html">naming</a>
* </p>
*/
@Parameter(property = "rpm.naming")
Naming naming;
public void setNaming(final Naming naming) {
this.naming = naming;
}
/**
* The location to place the RPM file into.
*
* @since 0.10.1
*/
@Parameter(property = "rpm.targetDir", defaultValue = "${project.build.directory}")
File targetDir;
public void setTargetDir(final File targetDir) {
this.targetDir = targetDir;
}
/**
* The file name of the output file.
* <p>
* This defaults the to an internal builder which will use
* {@code <packageName>-<version>-<release>.<arch>.rpm}.
* Also see <a href="naming.html">naming</a>.
* </p>
* <p>
* Using this override will completely disable the internal
* name builder and simply use the provided value.
* </p>
*
* @since 0.10.1
*/
@Parameter(property = "rpm.outputFileName")
String outputFileName;
public void setOutputFileName(final String outputFileName) {
this.outputFileName = outputFileName;
}
/**
* Name of the property, which is set according to the final outputFileName
*
* @since 1.9.1
*/
@Parameter(property = "rpm.outputFileNameProperty", defaultValue="project.build.rpm.outputFileName")
String outputFileNameProperty = "project.build.rpm.outputFileName";
public void setOutputFileNameProperty(final String outputFileNameProperty) {
this.outputFileNameProperty = outputFileNameProperty;
}
/**
* The highest supported RPM version this package must conform to.
* <p>
* This allows to set a maximum version of RPM this package must be
* compatible with. If unset, it will not check the required RPM version.
* </p>
*
* @since 0.11.0
*/
@Parameter(property = "rpm.maximumSupportedRpmVersion")
Version maximumSupportedRpmVersion;
public void setMaximumSupportedRpmVersion(final Version maximumSupportedRpmVersion) {
this.maximumSupportedRpmVersion = maximumSupportedRpmVersion;
}
public void setMaximumSupportedRpmVersion(final String maximumSupportedRpmVersion) {
this.maximumSupportedRpmVersion = Version.fromVersionString(maximumSupportedRpmVersion).orElseThrow(() -> new IllegalArgumentException(String.format("Version '%s' is unknown", maximumSupportedRpmVersion)));
}
/**
* Specify the "hint" for a provider of a signature configuration.
* <p>
* By default, the RPM writer will calculate and add information like MD5,
* SHA1, SHA256, etc. to the signature header of the RPM file. However,
* some, especially older (really old) RPM versions, have issues when the
* encounter signature information they don't understand. This parameter
* allows you to configure this process.
* <p>
* What you configure here is the so-called "hint" (Plexus component
* name/hint) of the provider to use. This plexus component has to be found
* in the class path of the plugin, during runtime. There are two default
* providers available, one is <code>default</code> and the other is
* <code>md5-only</code>. The latter only adds MD5 checksum information.
* <p>
* The default is to add as much information as possible to the RPM. So
* normally you don't need this parameter.
* <p>
* Specifying a configuration provider which cannot be found during the
* build, will fail the build.
*
* @since 1.4.0
*/
@Parameter
String signatureConfiguration;
public void setSignatureConfiguration(final String signatureConfiguration) {
this.signatureConfiguration = signatureConfiguration;
}
/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
* <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
* <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
*
* @since XXX
*/
@Parameter(defaultValue = "${project.build.outputTimestamp}")
String outputTimestamp;
/**
* Configure the digest algorithm for files.
*
* <p>
* This configures the algorithm which is used to calculate a digest for each file. This information is stored
* (per file) in the RPM header section.
* </p>
*
* <p>
* The following variants are possible (from {@link DigestAlgorithm}, in no particular order):
* </p>
* <ul>
* <li><code>MD2</code></li>
* <li><code>MD5</code></li>
* <li><code>SHA1</code></li>
* <li><code>Double-SHA</code></li>
* <li><code>SHA-224</code></li>
* <li><code>SHA-256</code> (default)</li>
* <li><code>SHA-384</code></li>
* <li><code>SHA-512</code></li>
* <li><code>RIPE-MD160</code></li>
* <li><code>Tiger-192</code></li>
* <li><code>Haval-5-160</code></li>
* </ul>
*
* <p>
* <strong>NOTE:</strong> This relies on the JVM to provide a {@code MessageDigest} provider. If you choose a
* file digest algorithm for which the JVM doesn't provide an implementation, the build will fail. By default,
* JVMs (as of 1.8) should at least support MD5, SHA1, and SHA256. In practice SHA-224 to SHA-512 are supported
* by most JVMs.
* </p>
*
* <p>
* <strong>NOTE:</strong> This used to be <code>MD5</code> in releases before <code>1.10.0</code>. Starting
* with <code>1.10.0</code> this defaults to <code>SHA-256</code> and can be overridden using this setting.
* </p>
*
* @since 1.10.0
*/
@Parameter(defaultValue = "SHA-256", property = "rpm.fileDigestAlgorithm")
String fileDigestAlgorithm;
private Instant outputTimestampInstant;
@Component(role = SignatureConfiguration.class)
protected Map<String, SignatureConfiguration> signatureConfigurationProviders;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
this.logger = new Logger(getLog());
if (this.skip) {
this.logger.debug("Skipping execution");
return;
}
this.eval = new RulesetEvaluator(this.rulesets);
final Path targetDir;
if (this.targetDir != null) {
targetDir = this.targetDir.toPath();
} else {
targetDir = Paths.get(this.project.getBuild().getDirectory());
}
if (!Files.exists(targetDir)) {
try {
Files.createDirectories(targetDir);
} catch (final FileAlreadyExistsException e) {
// silently ignore
} catch (final IOException ioe) {
this.logger.debug("Unable to create target directory %s", targetDir);
throw new MojoExecutionException("RPM build failed.", ioe);
}
}
this.outputTimestampInstant = MavenArchiver.parseBuildOutputTimestamp(this.outputTimestamp).orElse(null);
if (this.outputTimestampInstant != null) {
this.logger.info("Creating reproducible RPM at timestamp: %s", this.outputTimestampInstant);
}
final String outputFileName = makeTargetFilename();
project.getProperties().setProperty(outputFileNameProperty, outputFileName);
final Path targetFile = makeTargetFile(targetDir, outputFileName);
this.logger.debug("Max supported RPM version: %s", this.maximumSupportedRpmVersion);
this.logger.info("Writing to target to: %s", targetFile);
this.logger.debug("Default script interpreter: %s", this.defaultScriptInterpreter);
this.logger.debug("Default ruleset: %s", this.defaultRuleset);
final String packageName = makePackageName();
final RpmVersion version = makeVersion();
this.logger.info("RPM base information - name: %s, version: %s, arch: %s", packageName, version, this.architecture);
testLeadFlags();
final BuilderOptions options = new BuilderOptions();
final DigestAlgorithm fileDigestAlgorithm = evalDigestAlgorithm(this.fileDigestAlgorithm);
this.logger.info("File Digest Algorithm: %s", fileDigestAlgorithm.getAlgorithm());
options.setFileDigestAlgorithm(fileDigestAlgorithm);
final PayloadCoding payloadCoding;
if (this.payloadFlags.getCoding() != null) {
payloadCoding = PayloadCoding.valueOf(this.payloadFlags.getCoding());
this.logger.info("Payload Coding: %s", payloadCoding);
} else {
payloadCoding = DEFAULT_PAYLOAD_CODING;
this.logger.info("Using default Payload Coding: %s", payloadCoding);
}
options.setPayloadCoding(payloadCoding);
if (this.payloadFlags != null && !this.payloadFlags.toString().isEmpty()) {
this.logger.info("Payload Flags: %s", this.payloadFlags);
} else {
this.payloadFlags = new PayloadFlags(payloadCoding, DEFAULT_PAYLOAD_FLAGS);
this.logger.info("Using default Payload Flags: %s", this.payloadFlags);
}
options.setPayloadFlags(this.payloadFlags);
// setup basic signature processors
final SignatureConfiguration provider;
if (this.signatureConfiguration != null) {
this.logger.info("Initialize with custom signature configuration: %s (%s)", this.signatureConfiguration, this.signatureConfiguration.getClass());
provider = this.signatureConfigurationProviders.get(this.signatureConfiguration);
if (provider == null) {
throw new MojoExecutionException(String.format("Unable to find requested signature configuration provider '%s', have: %s", this.signatureConfiguration, this.signatureConfigurationProviders.keySet()));
}
provider.applyOptions(options);
} else {
provider = null;
}
// start writing the RPM
try (final RpmBuilder builder = new RpmBuilder(packageName, version, this.architecture, targetFile, options)) {
this.logger.info("Writing target file: %s", builder.getTargetFile());
if (this.leadOverrideArchitecture != null) {
this.logger.info("Override RPM lead architecture: %s", this.leadOverrideArchitecture);
builder.setLeadOverrideArchitecture(this.leadOverrideArchitecture);
}
if (this.leadOverrideOperatingSystem != null) {
this.logger.info("Override RPM lead operating system: %s", this.leadOverrideOperatingSystem);
builder.setLeadOverrideOperatingSystem(this.leadOverrideOperatingSystem);
}
fillPackageInformation(builder);
fillScripts(builder);
fillDependencies(builder);
fillPayload(builder);
customizeHeader(builder);
// apply signature configuration, if we have one
if (provider != null) {
provider.applyBuilder(builder);
}
if (!this.skipSigning && this.signature != null) {
final SignatureProcessor[] signers = makeRsaSigners(this.signature);
if (signers != null) {
for (SignatureProcessor signer : signers) {
builder.addSignatureProcessor(signer);
}
}
}
// finally build the file
builder.build();
// version check
checkVersion(builder);
// attach when necessary
if (this.attach) {
this.logger.info("attaching %s", this.classifier);
if ("rpm".equals(this.project.getPackaging())) {
this.project.getArtifact().setFile(builder.getTargetFile().toFile());
} else {
this.projectHelper.attachArtifact(this.project, "rpm", this.classifier, builder.getTargetFile().toFile());
}
}
} catch (final IOException e) {
throw new MojoExecutionException("Failed to write RPM", e);
}
}
private DigestAlgorithm evalDigestAlgorithm(String algorithm) throws MojoFailureException {
try {
// try enum literal name first
return DigestAlgorithm.valueOf(algorithm);
}
catch (IllegalArgumentException ignored) {}
// try algorithm names next
for (DigestAlgorithm a : DigestAlgorithm.values()) {
if (a.getAlgorithm().equalsIgnoreCase(algorithm)) {
return a;
}
}
// fail
throw new MojoFailureException(String.format("Unknown file digest algorithm: %s", algorithm));
}
private String makeTargetFilename() {
String outputFileName = this.outputFileName;
if (outputFileName == null || outputFileName.isEmpty()) {
if (this.naming.getDefaultFormat() == Naming.DefaultFormat.LEGACY) {
outputFileName = RpmFileNameProvider.LEGACY_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(), this.architecture);
} else {
outputFileName = RpmFileNameProvider.DEFAULT_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(), this.architecture);
}
this.logger.debug("Using generated file name - %s", outputFileName, outputFileName);
}
return outputFileName;
}
private Path makeTargetFile(final Path targetDir, final String outputFileName) {
final Path targetFile = targetDir.resolve(outputFileName);
this.logger.debug("Resolved output file name - fileName: %s, fullName: %s", this.outputFileName, targetFile);
return targetFile;
}
protected void checkVersion(final RpmBuilder builder) throws MojoFailureException {
final Version version = builder.getRequiredRpmVersion();
this.logger.info("Required RPM version: %s", version);