-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathBuilder.java
1500 lines (1352 loc) · 59.7 KB
/
Builder.java
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
package org.redline_rpm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPOutputStream;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.redline_rpm.changelog.ChangelogHandler;
import org.redline_rpm.changelog.ChangelogParseException;
import org.redline_rpm.header.Architecture;
import org.redline_rpm.header.Format;
import org.redline_rpm.header.Os;
import org.redline_rpm.header.RpmType;
import org.redline_rpm.payload.Contents;
import org.redline_rpm.payload.CpioHeader;
import org.redline_rpm.payload.Directive;
import static org.redline_rpm.ChannelWrapper.*;
import static org.redline_rpm.header.AbstractHeader.*;
import static org.redline_rpm.header.Flags.*;
import static org.redline_rpm.header.Signature.SignatureTag.*;
import static org.redline_rpm.header.Header.HeaderTag.*;
/**
* The normal entry point to the API used for
* building and RPM. The API provides methods to
* configure and add contents to a new RPM. The
* current version of the RPM format (3.0) requires
* numerous headers to be set for an RPM to be
* valid. All of the required fields are either
* set automatically or exposed through setters in
* this builder class. Any required fields are
* marked in their respective method API documentation.
*/
public class Builder {
private static final int GPGSIZE = 65;
private static final int DSASIZE = 65;
private static final int SHASIZE = 41;
private static final int SHA256_SIZE = 65;
private static final int MD5SIZE = 32;
private static final String DEFAULTSCRIPTPROG = "/bin/sh";
private static final char[] ILLEGAL_CHARS_VARIABLE = new char[] { '-', '/' };
private static final char[] ILLEGAL_CHARS_NAME = new char[] { '/', ' ', '\t', '\n', '\r' };
protected final Format format = new Format();
protected final Set< PrivateKey> signatures = new HashSet< PrivateKey>();
protected final List< Dependency> requires = new LinkedList< Dependency>();
protected final List< Dependency> obsoletes = new LinkedList< Dependency>();
protected final List< Dependency> conflicts = new LinkedList< Dependency>();
protected final Map< String, Dependency> provides = new LinkedHashMap< String, Dependency>();
protected final List< String> triggerscripts = new LinkedList< String>();
protected final List< String> triggerscriptprogs = new LinkedList< String>();
protected final List< String> triggernames = new LinkedList< String>();
protected final List< String> triggerversions = new LinkedList< String>();
protected final List< Integer> triggerflags = new LinkedList< Integer>();
protected final List< Integer> triggerindexes = new LinkedList< Integer>();
private int triggerCounter = 0;
@SuppressWarnings( "unchecked")
protected final Entry< byte[]> signature = ( Entry< byte[]>) format.getSignature().addEntry( SIGNATURES, 16);
@SuppressWarnings( "unchecked")
protected final Entry< byte[]> immutable = ( Entry< byte[]>) format.getHeader().addEntry( HEADERIMMUTABLE, 16);
protected Contents contents = new Contents();
protected File privateKeyRingFile;
protected String privateKeyId;
protected String privateKeyPassphrase;
protected PGPPrivateKey privateKey;
/**
* Initializes the builder and sets some required fields to known values.
*/
public Builder() {
format.getHeader().createEntry( HEADERI18NTABLE, "C");
format.getHeader().createEntry( BUILDTIME, ( int) ( System.currentTimeMillis() / 1000));
format.getHeader().createEntry( RPMVERSION, "4.4.2");
format.getHeader().createEntry( PAYLOADFORMAT, "cpio");
format.getHeader().createEntry( PAYLOADCOMPRESSOR, "gzip");
addDependencyLess( "rpmlib(VersionedDependencies)", "3.0.3-1");
addDependencyLess( "rpmlib(CompressedFileNames)", "3.0.4-1");
addDependencyLess( "rpmlib(PayloadFilesHavePrefix)", "4.0-1");
}
public void addBuiltinDirectory(String builtinDirectory) {
contents.addLocalBuiltinDirectory(builtinDirectory);
}
public void addObsoletes(final String name, final int comparison, final String version) {
obsoletes.add(new Dependency(name, version, comparison));
}
public void addObsoletesLess (final CharSequence name, final CharSequence version) {
int flag = LESS | EQUAL;
addObsoletes(name, version, flag);
}
public void addObsoletesMore (final CharSequence name, final CharSequence version) {
int flag = GREATER | EQUAL;
addObsoletes(name, version, flag);
}
protected void addObsoletes( final CharSequence name, final CharSequence version, final int flag) {
obsoletes.add(new Dependency(name.toString(), version.toString(), flag));
}
public void addConflicts(final String name, final int comparison, final String version) {
conflicts.add(new Dependency(name, version, comparison));
}
public void addConflictsLess(final CharSequence name, final CharSequence version) {
int flag = LESS | EQUAL;
addConflicts(name, version, flag);
}
public void addConflictsMore(final CharSequence name, final CharSequence version) {
int flag = GREATER | EQUAL;
addConflicts(name, version, flag);
}
protected void addConflicts(final CharSequence name, final CharSequence version, final int flag) {
conflicts.add(new Dependency(name.toString(), version.toString(), flag));
}
public void addProvides(final String name, final String version) {
provides.put(name, new Dependency(name, version, version.length() > 0 ? EQUAL : 0));
}
protected void addProvides(final CharSequence name, final CharSequence version, final int flag) {
provides.put(name.toString(), new Dependency(name.toString(), version.toString(), flag));
}
/**
* Adds a dependency to the RPM package. This dependency version will be marked as the exact
* requirement, and the package will require the named dependency with exactly this version at
* install time.
*
* @param name the name of the dependency.
* @param comparison the comparison flag.
* @param version the version identifier.
*/
public void addDependency( final String name, final int comparison, final String version ) {
requires.add(new Dependency(name, version, comparison));
}
/**
* Adds a dependency to the RPM package. This dependency version will be marked as the maximum
* allowed, and the package will require the named dependency with this version or lower at
* install time.
*
* @param name the name of the dependency.
* @param version the version identifier.
*/
public void addDependencyLess( final CharSequence name, final CharSequence version) {
int flag = LESS | EQUAL;
if (name.toString().startsWith("rpmlib(")){
flag = flag | RPMLIB;
}
addDependency( name, version, flag);
}
/**
* Adds a dependency to the RPM package. This dependency version will be marked as the minimum
* allowed, and the package will require the named dependency with this version or higher at
* install time.
*
* @param name the name of the dependency.
* @param version the version identifier.
*/
public void addDependencyMore( final CharSequence name, final CharSequence version) {
addDependency( name, version, GREATER | EQUAL);
}
/**
* Adds a dependency to the RPM package. This dependency version will be marked as the exact
* requirement, and the package will require the named dependency with exactly this version at
* install time.
*
* @param name the name of the dependency.
* @param version the version identifier.
* @param flag the file flags
*/
protected void addDependency( final CharSequence name, final CharSequence version, final int flag) {
requires.add(new Dependency(name.toString(), version.toString(), flag));
}
/**
* Adds a header entry value to the header. For example use this to set the source RPM package
* name on your RPM
* @param tag the header tag to set
* @param value the value to set the header entry with
*/
public void addHeaderEntry( final Tag tag, final String value) {
format.getHeader().createEntry(tag, value);
}
/**
* Adds a header entry byte (8-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not byte[]
*/
public void addHeaderEntry( final Tag tag, final byte value) {
format.getHeader().createEntry(tag, new byte[] {value});
}
/**
* Adds a header entry char (8-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not byte[]
*/
public void addHeaderEntry( final Tag tag, final char value) {
format.getHeader().createEntry(tag, new byte[] {(byte) value});
}
/**
* Adds a header entry short (16-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not short[]
*/
public void addHeaderEntry( final Tag tag, final short value) {
format.getHeader().createEntry(tag, new short[] {value});
}
/**
* Adds a header entry int (32-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not int[]
*/
public void addHeaderEntry( final Tag tag, final int value) {
format.getHeader().createEntry(tag, new int[] {value});
}
/**
* Adds a header entry long (64-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not long[]
*/
public void addHeaderEntry( final Tag tag, final long value) {
format.getHeader().createEntry(tag, new long[] {value});
}
/**
* Adds a header entry byte array (8-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not byte[]
*/
public void addHeaderEntry( final Tag tag, final byte[] value) {
format.getHeader().createEntry(tag, value);
}
/**
* Adds a header entry short array (16-bit) value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not short[]
*/
public void addHeaderEntry( final Tag tag, final short[] value) {
format.getHeader().createEntry(tag, value);
}
/**
* Adds a header entry int (32-bit) array value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not int[]
*/
public void addHeaderEntry( final Tag tag, final int[] value) {
format.getHeader().createEntry(tag, value);
}
/**
* Adds a header entry long (64-bit) array value to the header.
* @param tag the header tag to set
* @param value the value to set the header entry with
* @throws ClassCastException - if the type required by tag.type() is not long[]
*/
public void addHeaderEntry( final Tag tag, final long[] value) {
format.getHeader().createEntry(tag, value);
}
/**
* @param illegalChars the illegal characters to check for.
* @param variable the character sequence to check for illegal characters.
* @param variableName the name to include in IllegalArgumentException
* @throws IllegalArgumentException if passed in character sequence contains dashes.
*/
private void checkVariableContainsIllegalChars(final char[] illegalChars, final CharSequence variable, final String variableName) {
for (int i = 0; i < variable.length(); i++) {
char currChar = variable.charAt(i);
for (char illegalChar : illegalChars) {
if (currChar == illegalChar) {
throw new IllegalArgumentException(variableName + " with value: '" + variable + "' contains illegal character " + currChar);
}
}
}
}
/**
* <b>Required Field</b>. Sets the package information, such as the rpm name, the version, and the release number.
*
* @param name the name of the RPM package.
* @param version the version of the new package.
* @param release the release number, specified after the version, of the new RPM.
* @param epoch the epoch number of the new RPM
* @throws IllegalArgumentException if version or release contain
* dashes, as they are explicitly disallowed by RPM file format.
*/
public void setPackage( final CharSequence name, final CharSequence version, final CharSequence release, final int epoch) {
checkVariableContainsIllegalChars(ILLEGAL_CHARS_NAME, name, "name");
checkVariableContainsIllegalChars(ILLEGAL_CHARS_VARIABLE, version, "version");
checkVariableContainsIllegalChars(ILLEGAL_CHARS_VARIABLE, release, "release");
format.getLead().setName( name + "-" + version + "-" + release);
format.getHeader().createEntry( NAME, name);
format.getHeader().createEntry( VERSION, version);
format.getHeader().createEntry( RELEASE, release);
format.getHeader().createEntry( EPOCH, epoch);
this.provides.clear();
addProvides(String.valueOf(name), "" + epoch + ":" + version + "-" + release);
}
public void setPackage( final CharSequence name, final CharSequence version, final CharSequence release) {
setPackage(name, version, release, 0);
}
/**
* <b>Required Field</b>. Sets the type of the RPM to be either binary or source.
*
* @param type the type of RPM to generate.
*/
public void setType( final RpmType type) {
format.getLead().setType( type);
}
/**
* <b>Required Field</b>. Sets the platform related headers for the resulting RPM. The platform is specified as a
* combination of target architecture and OS.
*
* @param arch the target architecture.
* @param os the target operating system.
*/
public void setPlatform( final Architecture arch, final Os os) {
format.getLead().setArch( arch);
format.getLead().setOs( os);
final CharSequence archName = arch.toString().toLowerCase();
final CharSequence osName = os.toString().toLowerCase();
format.getHeader().createEntry( ARCH, archName);
format.getHeader().createEntry( OS, osName);
format.getHeader().createEntry( PLATFORM, archName + "-" + osName);
format.getHeader().createEntry( RHNPLATFORM, archName);
}
/**
* <b>Required Field</b>. Sets the platform related headers for the resulting RPM. The platform is specified as a
* combination of target architecture and OS.
*
* @param arch the target architecture.
* @param osName the non-standard target operating system.
*/
public void setPlatform( final Architecture arch, final CharSequence osName) {
format.getLead().setArch( arch);
format.getLead().setOs( Os.UNKNOWN);
final CharSequence archName = arch.toString().toLowerCase();
format.getHeader().createEntry( ARCH, archName);
format.getHeader().createEntry( OS, osName);
format.getHeader().createEntry( PLATFORM, archName + "-" + osName);
format.getHeader().createEntry( RHNPLATFORM, archName);
}
/**
* <b>Required Field</b>. Sets the summary text for the file. The summary is generally a short, one line description of the
* function of the package, and is often shown by RPM tools.
*
* @param summary summary text.
*/
public void setSummary( final CharSequence summary) {
if ( summary != null) format.getHeader().createEntry( SUMMARY, summary);
}
/**
* <b>Required Field</b>. Sets the description text for the file. The description is often a paragraph describing the
* package in detail.
*
* @param description description text.
*/
public void setDescription( final CharSequence description) {
if ( description != null) format.getHeader().createEntry( DESCRIPTION, description);
}
/**
* <b>Required Field</b>. Sets the build host for the RPM. This is an internal field.
*
* @param host hostname of the build machine.
*/
public void setBuildHost( final CharSequence host) {
if ( host != null) format.getHeader().createEntry( BUILDHOST, host);
}
/**
* <b>Required Field</b>. Lists the license under which this software is distributed. This field may be
* displayed by RPM tools.
*
* @param license the chosen distribution license.
*/
public void setLicense( final CharSequence license) {
if ( license != null) format.getHeader().createEntry( LICENSE, license);
}
/**
* <b>Required Field</b>. Software group to which this package belongs. The group describes what sort of
* function the software package provides.
*
* @param group target group.
*/
public void setGroup( final CharSequence group) {
if ( group != null) format.getHeader().createEntry( GROUP, group);
}
/**
* <b>Required Field</b>. Distribution tag listing the distributable package.
*
* @param distribution the distribution.
*/
public void setDistribution( final CharSequence distribution) {
if ( distribution != null) format.getHeader().createEntry( DISTRIBUTION, distribution);
}
/**
* <b>Required Field</b>. Vendor tag listing the organization providing this software package.
*
* @param vendor software vendor.
*/
public void setVendor( final CharSequence vendor) {
if ( vendor != null) format.getHeader().createEntry( VENDOR, vendor);
}
/**
* <b>Required Field</b>. Build packager, usually the username of the account building this RPM.
*
* @param packager packager name.
*/
public void setPackager( final CharSequence packager) {
if ( packager != null) format.getHeader().createEntry( PACKAGER, packager);
}
/**
* <b>Required Field</b>. Website URL for this package, usually a project site.
*
* @param url the URL
*/
public void setUrl( CharSequence url) {
if ( url != null) format.getHeader().createEntry( URL, url);
}
/**
* Declares a dependency that this package exports, and that other packages can use to
* provide library functions. Note that this method causes the existing provides set to be
* overwritten and therefore should be called before adding any other contents via
* the <code>addProvides()</code> methods.
*
* You should use <code>addProvides()</code> instead.
*
* @param provides dependency provided by this package.
*/
public void setProvides( final CharSequence provides) {
if ( provides != null) {
this.provides.clear();
addProvides( provides, "", EQUAL);
}
}
/**
* Sets the group of contents to include in this RPM. Note that this method causes the existing
* file set to be overwritten and therefore should be called before adding any other contents via
* the <code>addFile()</code> methods.
*
* @param contents the set of contents to use in constructing this RPM.
*/
public void setFiles( final Contents contents) {
this.contents = contents;
}
/**
* Adds a source rpm.
*
* @param rpm name of rpm source file
*/
public void setSourceRpm( final String rpm) {
if ( rpm != null) format.getHeader().createEntry( SOURCERPM, rpm);
}
/**
* Sets the package prefix directories to allow any files installed under
* them to be relocatable.
*
* @param prefixes Path prefixes which may be relocated
*/
public void setPrefixes( final String... prefixes) {
if ( prefixes != null && 0 < prefixes.length) format.getHeader().createEntry( PREFIXES, prefixes);
}
/**
* Return the content of the specified script file as a String.
*
* @param file the script file to be read
*/
private String readScript( File file) throws IOException {
if ( file == null) return null;
StringBuilder script = new StringBuilder();
BufferedReader in = new BufferedReader( new FileReader(file));
try {
String line;
while (( line = in.readLine()) != null) {
script.append( line);
script.append( "\n");
}
} finally {
in.close();
}
return script.toString();
}
/**
* Returns the program use to run the specified script (guessed by parsing
* the shebang at the beginning of the script)
*
* @param script
*/
private String readProgram( String script) {
String program = null;
if ( script != null) {
Pattern pattern = Pattern.compile( "^#!(/.*)");
Matcher matcher = pattern.matcher( script);
if ( matcher.find()) {
program = matcher.group( 1);
}
}
return program;
}
/**
* Declares a script to be run as part of the RPM pre-transaction. The
* script will be run using the interpreter declared with the
* {@link #setPreTransProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPreTransScript( final String script) {
setPreTransProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( PRETRANSSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM pre-transaction. The
* script will be run using the interpreter declared with the
* {@link #setPreTransProgram(String)} method.
*
* @param file Script to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPreTransScript( final File file) throws IOException {
setPreTransScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* pre-transaction script that can be set with the
* {@link #setPreTransScript(String)} method.
*
* @param program Path to the interpreter
*/
public void setPreTransProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( PRETRANSPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( PRETRANSPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( PRETRANSPROG, program);
}
}
/**
* Declares a script to be run as part of the RPM pre-installation. The
* script will be run using the interpreter declared with the
* {@link #setPreInstallProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPreInstallScript( final String script) {
setPreInstallProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( PREINSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM pre-installation. The
* script will be run using the interpreter declared with the
* {@link #setPreInstallProgram(String)} method.
*
* @param file Script to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPreInstallScript( final File file) throws IOException {
setPreInstallScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* pre-installation script that can be set with the
* {@link #setPreInstallScript(String)} method.
*
* @param program Path to the interpretter
*/
public void setPreInstallProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( PREINPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( PREINPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( PREINPROG, program);
}
}
/**
* Declares a script to be run as part of the RPM post-installation. The
* script will be run using the interpreter declared with the
* {@link #setPostInstallProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPostInstallScript( final String script) {
setPostInstallProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( POSTINSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM post-installation. The
* script will be run using the interpreter declared with the
* {@link #setPostInstallProgram(String)} method.
*
* @param file Script to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPostInstallScript( final File file) throws IOException {
setPostInstallScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* post-installation script that can be set with the
* {@link #setPostInstallScript(String)} method.
*
* @param program Path to the interpreter
*/
public void setPostInstallProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( POSTINPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( POSTINPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( POSTINPROG, program);
}
}
/**
* Declares a script to be run as part of the RPM pre-uninstallation. The
* script will be run using the interpreter declared with the
* {@link #setPreUninstallProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPreUninstallScript( final String script) {
setPreUninstallProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( PREUNSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM pre-uninstallation. The
* script will be run using the interpreter declared with the
* {@link #setPreUninstallProgram(String)} method.
*
* @param file Script to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPreUninstallScript( final File file) throws IOException {
setPreUninstallScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* pre-uninstallation script that can be set with the
* {@link #setPreUninstallScript(String)} method.
*
* @param program Path to the interpreter
*/
public void setPreUninstallProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( PREUNPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( PREUNPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( PREUNPROG, program);
}
}
/**
* Declares a script to be run as part of the RPM post-uninstallation. The
* script will be run using the interpreter declared with the
* {@link #setPostUninstallProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPostUninstallScript( final String script) {
setPostUninstallProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( POSTUNSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM post-uninstallation. The
* script will be run using the interpreter declared with the
* {@link #setPostUninstallProgram(String)} method.
*
* @param file Script contents to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPostUninstallScript( final File file) throws IOException {
setPostUninstallScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* post-uninstallation script that can be set with the
* {@link #setPostUninstallScript(String)} method.
*
* @param program Path to the interpreter
*/
public void setPostUninstallProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( POSTUNPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( POSTUNPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( POSTUNPROG, program);
}
}
/**
* Declares a script to be run as part of the RPM post-transaction. The
* script will be run using the interpreter declared with the
* {@link #setPostTransProgram(String)} method.
*
* @param script Script contents to run (i.e. shell commands)
*/
public void setPostTransScript( final String script) {
setPostTransProgram(readProgram(script));
if ( script != null) format.getHeader().createEntry( POSTTRANSSCRIPT, script);
}
/**
* Declares a script file to be run as part of the RPM post-transaction. The
* script will be run using the interpreter declared with the
* {@link #setPostTransProgram(String)} method.
*
* @param file Script contents to run (i.e. shell commands)
* @throws IOException there was an IO error
*/
public void setPostTransScript( final File file) throws IOException {
setPostTransScript(readScript(file));
}
/**
* Declares the interpreter to be used when invoking the RPM
* post-transaction script that can be set with the
* {@link #setPostTransScript(String)} method.
*
* @param program Path to the interpreter
*/
public void setPostTransProgram( final String program) {
if ( null == program) {
format.getHeader().createEntry( POSTTRANSPROG, DEFAULTSCRIPTPROG);
} else if ( 0 == program.length()){
format.getHeader().createEntry( POSTTRANSPROG, DEFAULTSCRIPTPROG);
} else {
format.getHeader().createEntry( POSTTRANSPROG, program);
}
}
/**
* Adds a trigger to the RPM package.
*
* @param script the script to add.
* @param prog the interpreter with which to run the script.
* @param depends the map of rpms and versions that will trigger the script
* @param flag the trigger type (SCRIPT_TRIGGERPREIN, SCRIPT_TRIGGERIN, SCRIPT_TRIGGERUN, or SCRIPT_TRIGGERPOSTUN)
* @throws IOException there was an IO error
*/
public void addTrigger( final File script, final String prog, final Map< String, IntString> depends, final int flag) throws IOException {
triggerscripts.add(readScript(script));
if ( null == prog) {
triggerscriptprogs.add(DEFAULTSCRIPTPROG);
} else if ( 0 == prog.length()){
triggerscriptprogs.add(DEFAULTSCRIPTPROG);
} else {
triggerscriptprogs.add(prog);
}
for ( Map.Entry< String, IntString> depend : depends.entrySet()) {
triggernames.add( depend.getKey());
triggerflags.add( depend.getValue().getInt() | flag);
triggerversions.add( depend.getValue().getString());
triggerindexes.add ( triggerCounter);
}
triggerCounter++;
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @param dirmode the mode of the parent directories in standard three octet notation, or -1 for default.
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final int dirmode) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, dirmode);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @param dirmode the mode of the parent directories in standard three octet notation, or -1 for default.
* @param uname user owner for the given file
* @param gname group owner for the given file
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final int dirmode, final String uname, final String gname) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, null, uname, gname, dirmode);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @param dirmode the mode of the parent directories in standard three octet notation, or -1 for default.
* @param directive directive indicating special handling for this file.
* @param uname user owner for the given file
* @param gname group owner for the given file
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final int dirmode, final Directive directive, final String uname, final String gname) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, directive, uname, gname, dirmode);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation, or -1 for default.
* @param dirmode the mode of the parent directories in standard three octet notation, or -1 for default.
* @param directive directive indicating special handling for this file.
* @param uname user owner for the given file, or null for default user.
* @param gname group owner for the given file, or null for default group.
* @param addParents whether to create parent directories for the file, defaults to true for other methods.
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final int dirmode, final Directive directive, final String uname, final String gname, final boolean addParents) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, directive, uname, gname, dirmode, addParents);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation, or -1 for default.
* @param dirmode the mode of the parent directories in standard three octet notation, or -1 for default.
* @param directive directive indicating special handling for this file.
* @param uname user owner for the given file, or null for default user.
* @param gname group owner for the given file, or null for default group.
* @param addParents whether to create parent directories for the file, defaults to true for other methods.
* @param verifyFlags verify flags
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final int dirmode, final Directive directive, final String uname, final String gname, final boolean addParents, final int verifyFlags) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, directive, uname, gname, dirmode, addParents, verifyFlags);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @param directive directive indicating special handling for this file.
* @param uname user owner for the given file
* @param gname group owner for the given file
* @throws NoSuchAlgorithmException the algorithm isn't supported
* @throws IOException there was an IO error
*/
public void addFile( final String path, final File source, final int mode, final Directive directive, final String uname, final String gname) throws NoSuchAlgorithmException, IOException {
contents.addFile( path, source, mode, directive, uname, gname);
}
/**
* Add the specified file to the repository payload in order.
* The required header entries will automatically be generated
* to record the directory names and file names, as well as their
* digests.
*
* @param path the absolute path at which this file will be installed.
* @param source the file content to include in this rpm.
* @param mode the mode of the target file in standard three octet notation
* @param directive directive indicating special handling for this file.
* @throws NoSuchAlgorithmException the algorithm isn't supported