Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/BuildSpec.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2007, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9tools.om;
23
24
import java.io.File;
25
import java.io.PrintStream;
26
import java.text.MessageFormat;
27
import java.util.Collection;
28
import java.util.Collections;
29
import java.util.HashMap;
30
import java.util.HashSet;
31
import java.util.Map;
32
import java.util.Set;
33
import java.util.TreeMap;
34
35
/**
36
* The {@link BuildSpec} class describes the details of a J9 specification. It defines the flags,
37
* sources, and featuers which make up the specification as well as any other relevant information.
38
*
39
* @author Maciek Klimkowski
40
* @author Gabriel Castro
41
*/
42
public class BuildSpec extends OMObject implements IFlagContainer, ISourceContainer, Comparable<BuildSpec> {
43
private String id = null; /* !< build spec id */
44
private String name = null; /* !< build spec name */
45
private String runtime = null;
46
private String cpuArchitecture = null;
47
private String os = null;
48
private DefaultSizes defaultSizes = null;
49
private AsmBuilder asmBuilder = null;
50
private JclConfiguration jclConfiguration = null;
51
private int priority = -1;
52
53
private final Map<String, Feature> features = new TreeMap<String, Feature>();
54
private final Map<String, Flag> flags = new TreeMap<String, Flag>();
55
private final Map<String, Owner> owners = new TreeMap<String, Owner>();
56
private final Map<String, Source> sources = new TreeMap<String, Source>();
57
private final Map<String, Property> properties = new TreeMap<String, Property>();
58
59
/**
60
* Retrieves the specification ID from the given file name. The file name must have the
61
* specification file extension {@link ConfigDirectory#BUILD_SPEC_FILE_EXTENSION}.
62
*
63
* @param filename the specification file
64
* @return the spec ID or <code>null</code> if the filename is not identified as a spec file
65
*/
66
public static String getIDFromFileName(String filename) {
67
if (filename != null && filename.endsWith(ConfigDirectory.BUILD_SPEC_FILE_EXTENSION)) {
68
return filename.substring(filename.lastIndexOf(File.separator) + 1, filename.length() - (ConfigDirectory.BUILD_SPEC_FILE_EXTENSION.length()));
69
}
70
71
return null;
72
}
73
74
/**
75
* Adds a spec owner to this build spec.
76
*
77
* @param owner one of the owners of this build spec
78
*/
79
public void addOwner(Owner owner) {
80
owners.put(owner.getId(), owner);
81
}
82
83
/**
84
* Retrieves the owner of this build spec for the given owner ID.
85
*
86
* @param ownerId the ID of the owner
87
* @return Owner instance identified by ownerId
88
*/
89
public Owner getOwner(String ownerId) {
90
return owners.get(ownerId);
91
}
92
93
public Map<String, Owner> getOwners() {
94
return Collections.unmodifiableMap(owners);
95
}
96
97
/**
98
* Retrieves a set of owner IDs defined for this build spec.
99
*
100
* @return a Set<String> of owner ids
101
*/
102
public Set<String> getOwnerIds() {
103
return owners.keySet();
104
}
105
106
/**
107
* Removes the given owner from this build spec.
108
*
109
* @param owner the owner to be remove
110
*/
111
public void removeOwner(Owner owner) {
112
owners.remove(owner.getId());
113
}
114
115
/**
116
* Removes the owner with the given ID from this build spec.
117
*
118
* @param ownerId the ID of the owner to be removed
119
*/
120
public void removeOwner(String ownerId) {
121
owners.remove(ownerId);
122
}
123
124
/**
125
* @see com.ibm.j9tools.om.IFlagContainer#addFlag(com.ibm.j9tools.om.Flag)
126
*/
127
public void addFlag(Flag flag) {
128
flags.put(flag.getId(), flag);
129
}
130
131
/**
132
* @see com.ibm.j9tools.om.IFlagContainer#getFlag(java.lang.String)
133
*/
134
public Flag getFlag(String flagId) {
135
if (flags.containsKey(flagId)) {
136
return flags.get(flagId);
137
}
138
139
for (Feature feature : features.values()) {
140
if (feature.hasFlag(flagId)) {
141
return feature.getFlag(flagId);
142
}
143
}
144
145
return null;
146
}
147
148
/**
149
* Returns a local Flag
150
* @param flagId ID of the Flag that needs to be returned
151
* @return Flag The Flag that is wanted, or <code>null</code> if the Flag does not exist
152
*/
153
public Flag getLocalFlag(String flagId) {
154
return flags.get(flagId);
155
}
156
157
/**
158
* @see com.ibm.j9tools.om.IFlagContainer#getFlags()
159
*/
160
public Map<String, Flag> getFlags() {
161
Map<String, Flag> allFlags = new TreeMap<String, Flag>();
162
allFlags.putAll(flags);
163
164
for (Feature feature : features.values()) {
165
allFlags.putAll(feature.getFlags());
166
}
167
168
return Collections.unmodifiableMap(allFlags);
169
}
170
171
/**
172
* @see com.ibm.j9tools.om.IFlagContainer#getFlags(java.lang.String)
173
*/
174
public Map<String, Flag> getFlags(String category) {
175
Map<String, Flag> allFlags = new TreeMap<String, Flag>();
176
177
for (Flag flag : getFlags().values()) {
178
if (flag.getCategory().equals(category)) {
179
allFlags.put(flag.getId(), flag);
180
}
181
}
182
183
return Collections.unmodifiableMap(allFlags);
184
}
185
186
/**
187
* Retrieves only the flags that were defined in this build spec. This does not include
188
* any flags defined in this J9 specification's features.
189
*
190
* @return a {@link Map} of the local flags
191
*/
192
public Map<String, Flag> getLocalFlags() {
193
return Collections.unmodifiableMap(flags);
194
}
195
196
/**
197
* @see com.ibm.j9tools.om.IFlagContainer#getLocalFlags(java.lang.String)
198
*/
199
public Map<String, Flag> getLocalFlags(String category) {
200
Map<String, Flag> allFlags = new TreeMap<String, Flag>();
201
202
for (Flag flag : flags.values()) {
203
if (flag.getCategory().equals(category)) {
204
allFlags.put(flag.getId(), flag);
205
}
206
}
207
208
return Collections.unmodifiableMap(allFlags);
209
}
210
211
/**
212
* Checks for existence of a flag. Not to be confused with the value of a flag.
213
*
214
* @param flagId ID of the flag to check for
215
* @return <code>true</code> if the flag is included for this spec, <code>false</code> otherwise
216
*/
217
public boolean hasFlag(String flagId) {
218
if (flags.containsKey(flagId)) {
219
return true;
220
}
221
222
// Check if one of the features has the flag
223
for (Feature feature : features.values()) {
224
if (feature.hasFlag(flagId)) {
225
return true;
226
}
227
}
228
229
return false;
230
}
231
232
/**
233
* Checks for the existence of a local flag.
234
*
235
* @param flagId ID of the flag to check for
236
* @return <code>true</code> if the flag is included for this spec, <code>false</code> otherwise
237
*/
238
public boolean hasLocalFlag(String flagId) {
239
return flags.containsKey(flagId);
240
}
241
242
/**
243
* @see com.ibm.j9tools.om.IFlagContainer#removeFlag(com.ibm.j9tools.om.Flag)
244
*/
245
public void removeFlag(Flag flag) {
246
flags.remove(flag.getId());
247
}
248
249
/**
250
* @see com.ibm.j9tools.om.IFlagContainer#removeFlag(java.lang.String)
251
*/
252
public void removeFlag(String flagId) {
253
flags.remove(flagId);
254
}
255
256
/**
257
* Adds a fully initialized feature to the build spec. Non-conflicting flags are removed from the local
258
* list since they're contributed to the build spec by the feature. Sources also found in the feature
259
* are removed from the build spec.
260
*
261
* @param feature loaded instance of Feature
262
*/
263
public void addFeature(Feature feature) {
264
addFeature(feature, false);
265
}
266
267
/**
268
* Adds a fully initialized feature to the build spec. Non-conflicting flags are removed from the local
269
* list since they're contributed to the build spec by the feature. Sources also found in the feature
270
* are removed from the build spec.
271
*
272
* @param feature loaded instance of Feature
273
* @param overwrite when <code>true</code> overwrites all flags regardless of conflict
274
*/
275
public void addFeature(Feature feature, boolean overwrite) {
276
features.put(feature.getId(), feature);
277
278
// Remove sources already found in the in feature
279
sources.values().removeAll(feature.getSources().values());
280
281
for (Flag featureFlag : feature.getFlags().values()) {
282
Flag localFlag = flags.get(featureFlag.getId());
283
284
if (overwrite || (localFlag != null && localFlag.equals(featureFlag))) {
285
flags.remove(featureFlag.getId());
286
}
287
}
288
}
289
290
/**
291
* Removes the given feature from this build spec.
292
*
293
* @param feature the feature to be removed
294
*/
295
public Feature removeFeature(Feature feature) {
296
return features.remove(feature.getId());
297
}
298
299
/**
300
* Removes the feature with the given ID from this build spec.
301
*
302
* @param featureId the ID of the feature to be removed
303
*/
304
public Feature removeFeature(String featureId) {
305
return features.remove(featureId);
306
}
307
308
/**
309
* Removes the given feature from this build spec and returns its inherited sources
310
* and flags to the build spec.
311
*
312
* @param feature the feature to be removed
313
*/
314
public void unbundleFeature(Feature feature) {
315
Feature localFeature = features.remove(feature.getId());
316
317
if (localFeature != null) {
318
for (Source source : localFeature.getSources().values()) {
319
addSource(source);
320
}
321
322
for (Flag flag : localFeature.getFlags().values()) {
323
addFlag(flag);
324
}
325
}
326
}
327
328
/**
329
* Removes the feature with the given ID from this build spec and returns its inherited sources
330
* and flags to the build spec.
331
*
332
* @param featureId the ID of the feature to be removed
333
*/
334
public void unbundleFeature(String featureId) {
335
Feature localFeature = features.remove(featureId);
336
337
if (localFeature != null) {
338
for (Source source : localFeature.getSources().values()) {
339
addSource(source);
340
}
341
342
for (Flag flag : localFeature.getFlags().values()) {
343
addFlag(flag);
344
}
345
}
346
}
347
348
/**
349
* Retrieves a set of features defined for this build spec
350
*
351
* @return a Collection<Feature>.
352
*/
353
public Map<String, Feature> getFeatures() {
354
return Collections.unmodifiableMap(features);
355
}
356
357
/**
358
* Retrieves a Feature identified by the featureId parameter
359
*
360
* @param featureId Feature to Retrieves from the build spec
361
* @return a Feature
362
*/
363
public Feature getFeature(String featureId) {
364
return features.get(featureId);
365
}
366
367
/**
368
* Checks for existence of a feature.
369
*
370
* @param featureId ID of the feature to check for
371
* @return <code>true</code> if the feature is included for this spec, <code>false</code> otherwise
372
*/
373
public boolean hasFeature(String featureId) {
374
return features.containsKey(featureId);
375
}
376
377
/**
378
* Retrieves the set of sources defined for in build spec.
379
*
380
* @return a {@link Map} of all the sources
381
*/
382
public Map<String, Source> getSources() {
383
Map<String, Source> allSources = new TreeMap<String, Source>();
384
allSources.putAll(sources);
385
386
for (Feature feature : features.values()) {
387
allSources.putAll(feature.getSources());
388
}
389
390
return Collections.unmodifiableMap(allSources);
391
}
392
393
/**
394
* Retrieves all the local sources for this build spec. This does not include sources
395
* defined in included features.
396
*
397
* @return a {@link Map} of the local sources
398
*/
399
public Map<String, Source> getLocalSources() {
400
return Collections.unmodifiableMap(sources);
401
}
402
403
/**
404
* Retrieves a source module definition
405
*
406
* @param sourceId The ID of the source module
407
* @return the requested source
408
*/
409
public Source getSource(String sourceId) {
410
if (sources.containsKey(sourceId)) {
411
return sources.get(sourceId);
412
}
413
414
for (Feature feature : features.values()) {
415
if (feature.hasSource(sourceId)) {
416
return feature.getSource(sourceId);
417
}
418
}
419
420
return null;
421
}
422
423
/**
424
* Retrieves a source module definition that is local to this container
425
*
426
* @param sourceId The ID of the source module
427
* @return the requested source
428
*/
429
public Source getLocalSource(String sourceId) {
430
return sources.get(sourceId);
431
}
432
433
/**
434
* Adds the given source to this build spec.
435
*
436
* @param source the source to be added
437
*/
438
public void addSource(Source source) {
439
sources.put(source.getId(), source);
440
}
441
442
/**
443
* Removes the given source from this build spec.
444
*
445
* @param source the source to be removed
446
*/
447
public void removeSource(Source source) {
448
sources.remove(source.getId());
449
}
450
451
/**
452
* Removes the source with the given source ID from this build spec.
453
*
454
* @param sourceId the ID of the source
455
*/
456
public void removeSource(String sourceId) {
457
sources.remove(sourceId);
458
}
459
460
/**
461
* Checks for existence of a source.
462
*
463
* @param sourceId ID of the source to check for
464
* @return <code>true</code> if the source is included for this spec, <code>false</code> otherwise
465
*/
466
public boolean hasSource(String sourceId) {
467
if (sources.containsKey(sourceId)) {
468
return true;
469
}
470
471
// Check if one of the features has the flag
472
for (Feature feature : features.values()) {
473
if (feature.hasSource(sourceId)) {
474
return true;
475
}
476
}
477
478
return false;
479
}
480
481
/**
482
* Checks for existence of a local source.
483
*
484
* @param sourceId ID of the source to check for
485
* @return <code>true</code> if the source is included for this container, <code>false</code> otherwise
486
*/
487
public boolean hasLocalSource(String sourceId) {
488
return sources.containsKey(sourceId);
489
}
490
491
/**
492
* Retrieves the set of properties defined for this build spec.
493
*
494
* @return a Collection<Property>
495
*/
496
public Map<String, Property> getProperties() {
497
return Collections.unmodifiableMap(properties);
498
}
499
500
/**
501
* Retrieves a Property matching given ID
502
*
503
* @param propertyId The ID of the property
504
* @return a Property
505
*/
506
public Property getProperty(String propertyId) {
507
return properties.get(propertyId);
508
}
509
510
/**
511
* Adds the given property to this build spec.
512
*
513
* @param property the property to be added
514
*/
515
public void addProperty(Property property) {
516
properties.put(property.getName(), property);
517
}
518
519
/**
520
* Removes the given property from this build spec.
521
*
522
* @param property the property to be removed
523
*/
524
public void removeProperty(Property property) {
525
properties.remove(property.getName());
526
}
527
528
/**
529
* Removes the property with the given ID from this build spec.
530
*
531
* @param propertyId the property ID
532
*/
533
public void removeProperty(String propertyId) {
534
properties.remove(propertyId);
535
}
536
537
/**
538
* Retrieves the assembly builder defined in this build spec.
539
*
540
* @return the name assembly builder
541
*/
542
public AsmBuilder getAsmBuilder() {
543
return asmBuilder;
544
}
545
546
/**
547
* Sets the name of the assembly builder for this build spec.
548
*
549
* @param asmBuilder the assembly builder
550
*/
551
public void setAsmBuilder(AsmBuilder asmBuilder) {
552
this.asmBuilder = asmBuilder;
553
}
554
555
/**
556
* Retrieves the name of the CPU architecture defined for this build spec.
557
*
558
* @return the name of the CPU architecture
559
*/
560
public String getCpuArchitecture() {
561
return cpuArchitecture;
562
}
563
564
/**
565
* Sets the name of the CPU architecture for this build spec.
566
* @param cpuArchitecture
567
*/
568
public void setCpuArchitecture(String cpuArchitecture) {
569
this.cpuArchitecture = cpuArchitecture;
570
}
571
572
/**
573
* Retries the name of the default JCL configuration for this build spec.
574
*
575
* @return the name of the default JCL configuration
576
*/
577
public JclConfiguration getDefaultJCL() {
578
return jclConfiguration;
579
}
580
581
/**
582
* Sets the name of the default JCL configuration for this build spec.
583
*
584
* @param jclConfiguration the default JCL configuration
585
*/
586
public void setDefaultJCL(JclConfiguration jclConfiguration) {
587
this.jclConfiguration = jclConfiguration;
588
}
589
590
/**
591
* Retrieves the default size for this build spec.
592
*
593
* @return the default size
594
*/
595
public DefaultSizes getDefaultSizes() {
596
return defaultSizes;
597
}
598
599
/**
600
* Sets the default size for this build spec.
601
*
602
* @param defaultSizes the default size
603
*/
604
public void setDefaultSizes(DefaultSizes defaultSizes) {
605
this.defaultSizes = defaultSizes;
606
}
607
608
/**
609
* Retrieves this J9 specification's ID.
610
*
611
* @return the ID
612
*/
613
public String getId() {
614
return id;
615
}
616
617
public String getIdFromFile() {
618
return getIDFromFileName(getLocation().getFileName());
619
}
620
621
/**
622
* Sets this J9 specification's ID.
623
*
624
* @param id the build spec ID
625
*/
626
public void setId(String id) {
627
this.id = id;
628
}
629
630
/**
631
* Retrieves this J9 specification's name.
632
*
633
* @return the name
634
*/
635
public String getName() {
636
return name;
637
}
638
639
/**
640
* Retrieves this J9 specification's unique name. If the runtime is available the unique name
641
* consists of the runtime and the specification id; otherwise, only the ID is returned.
642
*
643
* @return the unique specification name
644
*/
645
public String getUniqueName() {
646
if (runtime != null) {
647
return runtime + ":" + id; //$NON-NLS-1$
648
}
649
650
return getId();
651
}
652
653
/**
654
* Sets this J9 specification's name.
655
*
656
* @param name the name
657
*/
658
public void setName(String name) {
659
this.name = name;
660
}
661
662
/**
663
* Returns the runtime to which this build spec belongs
664
*
665
* @return the runtime name
666
*/
667
public String getRuntime() {
668
return runtime;
669
}
670
671
/**
672
* Sets the runtime to which this build spec belongs.
673
*
674
* @param runtime the new runtime
675
*/
676
protected void setRuntime(String runtime) {
677
if (runtime != null) {
678
this.runtime = runtime;
679
}
680
}
681
682
/**
683
* Retrieves the operating system for this build spec.
684
*
685
* @return the operating system name
686
*/
687
public String getOs() {
688
return os;
689
}
690
691
/**
692
* Sets the name of the operating system for this build spec.
693
*
694
* @param os operating system name
695
*/
696
public void setOs(String os) {
697
this.os = os;
698
}
699
700
/**
701
* Retrieves the priority for this build spec.
702
*
703
* @return the priority value
704
*/
705
public int getPriority() {
706
return priority;
707
}
708
709
/**
710
* Sets the priority for this build spec.
711
*
712
* @param priority the priority value
713
*/
714
public void setPriority(int priority) {
715
this.priority = priority;
716
}
717
718
/**
719
* Verifies the validity of this {@link BuildSpec}'s assembly builders, JCL profiles, sources and flags.
720
*
721
* For ASM builders, JCL profiles, and sources validity implies those being defined in the runtime's
722
* {@link BuildInfo}. Source verification is done by a {@link SourceVerifier}.
723
*
724
* Flag verification is done by a {@link FlagVerifier}.
725
*
726
* @param flagDefinitions the runtime's flag definitions
727
* @param buildInfo the runtime's build information
728
*
729
* @throws InvalidBuildSpecException thrown when ASMBuilder, JCL, source, or flag errors are found
730
*/
731
public void verify(FlagDefinitions flagDefinitions, BuildInfo buildInfo) throws InvalidBuildSpecException {
732
Collection<Throwable> errors = new HashSet<Throwable>();
733
734
Map<String, Property> featureProperties = new HashMap<String, Property>();
735
Map<String, Flag> featureFlags = new HashMap<String, Flag>();
736
Map<String, Source> featureSources = new HashMap<String, Source>();
737
738
String idFromFile = getIDFromFileName(getLocation().getFileName());
739
740
if (!id.equalsIgnoreCase(idFromFile)) {
741
errors.add(new InvalidSpecIDException(Messages.getString("BuildSpec.specIDAndFilenameNotEqual"), this)); //$NON-NLS-1$
742
}
743
744
if (buildInfo == null || !buildInfo.getASMBuilders().contains(asmBuilder.getId())) {
745
errors.add(new InvalidAsmBuilderException(MessageFormat.format(Messages.getString("BuildSpec.invalidASM"), new Object[] { asmBuilder.getId() }), asmBuilder)); //$NON-NLS-1$
746
}
747
748
if (buildInfo == null || !buildInfo.getJCLs().contains(jclConfiguration.getId())) {
749
errors.add(new InvalidJCLException(MessageFormat.format(Messages.getString("BuildSpec.invalidJCL"), new Object[] { jclConfiguration.getId() }), jclConfiguration)); //$NON-NLS-1$
750
}
751
752
if (buildInfo == null || (buildInfo.validateDefaultSizes() && !buildInfo.getDefaultSizes().containsKey(defaultSizes.getId()))) {
753
errors.add(new InvalidDefaultSizesException(MessageFormat.format(Messages.getString("BuildSpec.invalidDefaultSize"), new Object[] { defaultSizes.getId() }), defaultSizes)); //$NON-NLS-1$
754
}
755
756
for (Feature feature : features.values()) {
757
if (feature.isComplete()) {
758
featureProperties.putAll(feature.getProperties());
759
featureFlags.putAll(feature.getFlags());
760
featureSources.putAll(feature.getSources());
761
} else {
762
errors.add(new InvalidFeatureException(MessageFormat.format(Messages.getString("BuildSpec.invalidFeature"), new Object[] { feature.getId() }), feature)); //$NON-NLS-1$
763
}
764
}
765
766
// Check that properties defined in features are set properly
767
for (Property property : featureProperties.values()) {
768
if (!properties.containsKey(property.getName())) {
769
errors.add(new MissingPropertyException(property, this.getLocation().getFileName()));
770
}
771
}
772
773
// Check for local flags that are already defined in feature
774
for (Flag flag : getLocalFlags().values()) {
775
if (featureFlags.containsKey(flag.getId())) {
776
errors.add(new InvalidFlagException(MessageFormat.format(Messages.getString("BuildSpec.invalidFlag"), new Object[] { flag.getId() }), flag)); //$NON-NLS-1$
777
}
778
}
779
780
// Check for local sources that are already defined in feature
781
for (Source source : getLocalSources().values()) {
782
if (featureSources.containsKey(source.getId())) {
783
errors.add(new InvalidSourceException(MessageFormat.format(Messages.getString("BuildSpec.invalidSource"), new Object[] { source.getId() }), source)); //$NON-NLS-1$
784
}
785
}
786
787
// Verify sources for existence in Build Info definition
788
SourceVerifier sourceVerifier = (buildInfo == null) ? new SourceVerifier(this, new HashSet<String>()) : new SourceVerifier(this, buildInfo.getSources());
789
errors.addAll(sourceVerifier.verify());
790
791
// Verify the validity of all flags
792
FlagVerifier flagVerifier = new FlagVerifier(this, flagDefinitions);
793
errors.addAll(flagVerifier.verify());
794
795
if (errors.size() > 0) {
796
throw new InvalidBuildSpecException(errors, this);
797
}
798
}
799
800
/**
801
* Debug helper used to dump this spec's member variables and lists
802
*
803
* @param out output stream to print to
804
* @param prefix prefix to prepend to each line
805
* @param indentLevel number of spaces to append to the prefix
806
*/
807
public void dump(PrintStream out, String prefix, int indentLevel) {
808
StringBuffer indent = new StringBuffer(prefix);
809
for (int i = 0; i < indentLevel; i++) {
810
indent.append(' ');
811
}
812
813
out.println(indent + "Spec: " + this.getId()); //$NON-NLS-1$
814
out.println(indent + " |--- name: " + this.getName()); //$NON-NLS-1$
815
out.println(indent + " |--- asmBuilderName: " + this.getAsmBuilder().getId()); //$NON-NLS-1$
816
out.println(indent + " |--- cpuArchitecture: " + this.getCpuArchitecture()); //$NON-NLS-1$
817
out.println(indent + " |--- os: " + this.getOs()); //$NON-NLS-1$
818
out.println(indent + " |--- defaultJCL: " + this.getDefaultJCL().getId()); //$NON-NLS-1$
819
out.println(indent + " |--- defaultSizes: " + this.getDefaultSizes()); //$NON-NLS-1$
820
out.println(indent + " |--- priority: " + this.getPriority()); //$NON-NLS-1$
821
822
out.println(indent + " |"); //$NON-NLS-1$
823
out.println(indent + " |--- Features "); //$NON-NLS-1$
824
for (Feature f : getFeatures().values()) {
825
out.println(indent + " | |-- Feature"); //$NON-NLS-1$
826
out.println(indent + " | | |- id: " + f.getId()); //$NON-NLS-1$
827
out.println(indent + " | | +- is complete: " + f.isComplete()); //$NON-NLS-1$
828
}
829
830
out.println(indent + " |"); //$NON-NLS-1$
831
out.println(indent + " |--- Flags "); //$NON-NLS-1$
832
for (Flag f : getFlags().values()) {
833
out.println(indent + " | |-- Flag"); //$NON-NLS-1$
834
out.println(indent + " | | +-- id: " + f.getId()); //$NON-NLS-1$
835
out.println(indent + " | | +-- state: " + f.getState()); //$NON-NLS-1$
836
}
837
838
out.println(indent + " |"); //$NON-NLS-1$
839
out.println(indent + " |--- Sources "); //$NON-NLS-1$
840
for (Source s : getSources().values()) {
841
out.println(indent + " | |-- source"); //$NON-NLS-1$
842
out.println(indent + " | | +-- id: " + s.getId()); //$NON-NLS-1$
843
}
844
845
}
846
847
/**
848
* Compares this build spec to another build spec for ordering. This ordering
849
* is based on the build spec ID and its runtime (if one is set).
850
*
851
* @see java.lang.Comparable#compareTo(java.lang.Object)
852
*/
853
public int compareTo(BuildSpec buildSpec) {
854
int idCompareResult = id.compareTo(buildSpec.id);
855
856
if (idCompareResult == 0 && runtime != null && buildSpec.getRuntime() != null) {
857
return runtime.compareTo(buildSpec.getRuntime());
858
}
859
860
return idCompareResult;
861
}
862
863
/**
864
* @see java.lang.Object#toString()
865
*/
866
@Override
867
public String toString() {
868
StringBuilder sb = new StringBuilder();
869
if (runtime != null) {
870
sb.append(runtime);
871
sb.append(":"); //$NON-NLS-1$
872
}
873
sb.append(id);
874
875
return sb.toString();
876
}
877
878
/**
879
* @see java.lang.Object#equals(java.lang.Object)
880
*/
881
@Override
882
public boolean equals(Object o) {
883
if (o instanceof BuildSpec) {
884
BuildSpec spec = (BuildSpec) o;
885
if (runtime != null && spec.getRuntime() != null) {
886
return runtime.equals(spec.getRuntime()) && name.equals(spec.getName()) && id.equals(spec.getId());
887
}
888
889
return name.equals(spec.getName()) && id.equals(spec.getId());
890
}
891
892
return false;
893
}
894
895
}
896
897