Subversion Repositories DevTools

Rev

Rev 7070 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.io.File;
4
import java.sql.SQLException;
5
import java.util.ArrayList;
7048 dpurdie 6
import java.util.Comparator;
6914 dpurdie 7
import java.util.HashMap;
8
import java.util.Iterator;
9
import java.util.LinkedHashSet;
10
import java.util.Vector;
11
 
7033 dpurdie 12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
6914 dpurdie 14
 
15
import com.erggroup.buildtool.ripple.ReleaseManager.BuildReason;
16
import com.erggroup.buildtool.smtp.CreateUrls;
17
import com.erggroup.buildtool.smtp.Smtpsend;
18
import com.erggroup.buildtool.utilities.MutableInt;
19
import com.erggroup.buildtool.utilities.XmlBuilder;
20
import com.erggroup.buildtool.utilities.utilities;
21
 
22
public class Package
23
{
24
    /**
25
     * name of package, must not contain spaces
26
     * 
27
     * @attribute
28
     */
29
    String mName = new String();
30
 
31
    /**
32
     * package scope
33
     * 
34
     * @attribute
35
     */
36
    String mExtension = new String();
37
 
38
    /**
39
     * instance identifier
40
     * 
41
     * @attribute
42
     */
43
    public String mVersion = new String();
7048 dpurdie 44
 
45
    /**
46
     * If this package is a candidate for building, then this value will be calculated
47
     * and will  be used if the package is selected for building
48
     */
49
    public String mNextVersion = null;
6914 dpurdie 50
 
51
    /**
52
     * Version string as specified by the user. Used with a ripple type of 'F'
53
     */
54
    String mFixedVersion = new String();
55
 
56
    /**
57
     * unique identifier 
58
     *      daemon builds = mName + mExtension
59
     *      escrow builds = mName + mVersion + mExtension
60
     * 
61
     * @attribute
62
     */
63
    public String mAlias = new String();
64
 
65
    /**
66
     * Version Control System Tag
67
     * 
68
     * @attribute
69
     */
70
    String mVcsTag = new String();
71
 
72
    /**
73
     * build standards
74
     * 
75
     * @attribute
76
     */
77
    public Vector<BuildStandard> mBuildStandardCollection = new Vector<BuildStandard>();
78
 
79
    /**
80
     * GBE_MACHTYPE used to build generic packages for this baseline only has
81
     * meaning in the daemon build, not the escrow build accessed by
82
     * BuildStandard::getPlatform, getBuildStandard
83
     * 
84
     * @attribute
85
     */
86
    public static String mGenericMachtype = System.getenv("GBE_MACHTYPE");
87
 
88
    /**
89
     * build dependencies by package alias
90
     * 
91
     * @attribute
92
     */
93
    public Vector<String> mDependencyCollection = new Vector<String>();
94
 
95
    /**
96
     * primary package version key pv_id in database
97
     * 
98
     * @attribute
99
     */
100
    public int mId;
101
 
102
    /**
103
     * indication of the nature of change
104
     * 
105
     * @attribute
106
     */
107
    Package.VersionNumberingStandard mChangeType = new VersionNumberingStandard();
108
 
109
    /**
110
     * determines what field is rippled on a package version whose dependencies
111
     * have changed
112
     * 
113
     * @attribute
114
     */
115
    Package.VersionNumberingStandard mRippleField = new VersionNumberingStandard();
116
 
117
    /**
118
     * interested owners
119
     * 
120
     * @attribute
121
     */
122
    private Vector<String> mBuildFailureEmailCollection = new Vector<String>();
123
 
124
    /**
125
     * when true will trigger unit tests as part of the package build phase in
126
     * daemon mode
127
     * 
128
     * @attribute
129
     */
130
    public boolean mHasAutomatedUnitTests = false;
131
 
132
    /**
133
     * when true, do not ripple this package through packages which are
134
     * dependent upon it in daemon mode
135
     * 
136
     * @attribute
137
     */
138
    public boolean mAdvisoryRipple = false;
139
 
140
    /**
141
     * Pegged packages will:
142
     *   - Not be rippled
143
     *   - Not be test buildable
144
     *   - Dependencies will not be considered
145
     *   Daemon Mode:
146
     *      Are not built in this release
147
     *      Are imported with out consideration as to their dependencies
148
     *      Must exist in dpkg_archive - will not be built if not present
149
     *   Escrow Mode:
150
     *      Have no special consideration
151
     *      The package and its dependencies will be built
152
     *
153
     * Packages imported into the release from an SDK will be treated as if they were
154
     * pegged by the built system.
155
     * 
156
     */
157
    public boolean mIsPegged = false;
158
    public boolean mIsSdk = false;
159
 
160
    /**
161
     * Unbuildable packages will not be candidates for a ripple or a rebuild
162
     * If they do not exist in dpkg_archive, then then will cause an error
163
     */
164
    public boolean mIsBuildable = true;
165
 
166
    /**
167
     * determines the build file the package is built in, or not
7048 dpurdie 168
     * <br>   1 Post Plan: build file - Result of planning
169
     * <br>   2 Post Plan: Future build requirement
170
     * <br>   3 Post Plan: Package has no build requirement
171
     * <br>   0 not yet processed (initial value) 
172
     * <br>  -1 not reproducible
173
     * <br>  -2 escrow: not reproducible on the build platforms configured for this release
174
     * <br>  -3 daemon: do not ripple
175
     * <br>  -4 directly dependent on package versions not in the baseline
176
     * <br>  -5 indirectly dependent on package versions which are not reproducible due to detected fault
177
     * <br>  -6 circular dependency
178
     * <br>  -7 Pegged or SDK Imported package not in dpkg_archive
179
     * <br>  -8 Pegged or SDK Imported package
180
     * <br>  -9 Rejected Daemon Instruction
181
     * <br>  -10 UnBuildable Package not in dpkg_archive
182
     * <br>  -11 Marked as RippleStop
6914 dpurdie 183
     * 
184
     */
185
    int mBuildFile = 0;
186
 
187
    /** Retained reason the package will not be built
188
     *  Save negative values as mBuildFile
189
     * @attribute
190
     */
191
    int mNoBuildReason = 0;
192
 
193
    /**
194
     * build dependencies by package
195
     * Calculated from information in mDependencyCollection
196
     * 
197
     * @attribute
198
     */
199
    Vector<Package> mPackageDependencyCollection = new Vector<Package>();
200
 
201
    /**
202
     * used for escrow build purposes set true when a package has been processed
203
     * 
204
     * @attribute
205
     */
206
    boolean mProcessed = false;
207
 
208
    /**
209
     * Reason that a package is being built
210
     */
211
    public BuildReason mBuildReason = null;
212
 
213
    /**
214
     * set true for WIP package versions only used in daemon mode
215
     * 
216
     * @attribute
217
     */
218
    public boolean mDirectlyPlanned = false;
219
 
220
    /**
221
     * set true when it is determined to be ripple built
222
     * 
223
     * @attribute
224
     */
225
    boolean mIndirectlyPlanned = false;
226
 
227
    /**
228
     * non zero instruction number when it is determined to be ripple built by force
229
     * 
230
     * @attribute
231
     */
7048 dpurdie 232
    public int mForcedRippleInstruction = 0;
6914 dpurdie 233
 
234
    /**
235
     * test build - non zero instruction number when it is determined to be test built
236
     * 
237
     * @attribute
238
     */
7048 dpurdie 239
    public int mTestBuildInstruction = 0;
6914 dpurdie 240
 
241
    /**
242
     * build dependencies by pv_id (-1 or not used for planned dependencies)
243
     * 
244
     * @attribute
245
     */
246
    public Vector<Integer> mDependencyIDCollection = new Vector<Integer>();
247
 
248
    /**
249
     * unique pkg_id in the database used for querying package version existence
250
     * in the database in daemon mode
251
     * 
252
     * @attribute
253
     */
254
    public int mPid;
255
 
256
    /**
257
     * maximum major number supported for determining ripple number
258
     * 
259
     * @attribute
260
     */
261
    int mMajorLimit;
262
 
263
    /**
264
     * maximum minor number supported for determining ripple number
265
     * 
266
     * @attribute
267
     */
268
    int mMinorLimit;
269
 
270
    /**
271
     * maximum patch number supported for determining ripple number
272
     * 
273
     * @attribute
274
     */
275
    int mPatchLimit;
276
 
277
    /**
278
     * maximum build number number supported for determining ripple number
279
     * 
280
     * @attribute
281
     */
282
    int mBuildLimit;
283
 
284
    /**
285
     * Logger
286
     * 
287
     * @attribute
288
     */
7033 dpurdie 289
    private static final Logger mLogger = LoggerFactory.getLogger(Package.class);
6914 dpurdie 290
 
291
    /**
292
     * dpkg archive location - The writable dpkg_archive
293
     * 
294
     * @attribute
295
     */
296
    public static String mGbeDpkg = System.getenv("GBE_DPKG");
297
 
298
    /**
299
     *  A physically close replica of dpkg_archive
300
     *  Is not writable 
301
     */
302
    public static final String mGbeDpkgReplica = System.getenv("GBE_DPKG_REPLICA");
303
 
304
    /**
305
     * Exception message used upon detection an archive does not exist Seems
306
     * this is a rare but transient and recoverable scenario
307
     * 
308
     * @attribute
309
     */
310
    public static final String mRecoverable = "dpkg_archive does not exist, recovery will be attempted";
311
 
312
    /**
313
     * true if the package exists in the package archive (dpkg_archive)
314
     * 
315
     * @attribute
316
     */
317
    private boolean mArchivalExistence = true;
318
 
319
    /**
320
     * when true will trigger source control interaction eg labelling
321
     * 
322
     * @attribute
323
     */
324
    public boolean mRequiresSourceControlInteraction = true;
325
 
326
    /**
327
     * when true has been checked for circular dependency
328
     * 
329
     * @attribute
330
     */
331
    boolean mCheckedCircularDependency = false;
332
 
333
    /**
334
     * when true has circular dependency, or in the process of detecting a circular dependency
335
     * 
336
     * @attribute
337
     */
338
    boolean mHasCircularDependency = false;
339
 
340
    /**
341
     * Bread crumb used to detect circular dependencies
342
     * 0 - Normal state
343
     * 1 - Crumb has been set
344
     * 2 - Crumb is a part of a circular dependency
345
     * 3 - Crumb is the start/end of the loop
346
     */
347
    int mBreadCrumb = 0;
348
 
349
    /**
350
     * Planned packages (WIPS) need calculate a new version number
351
     * This should be based on the Version of the package that the WIP was based upon
352
     */
353
	public String mPrevVersion;
354
 
7048 dpurdie 355
    /** Used to preserve the basic ordering of the package list(s)
356
     *  Only valid for the duration of the comparison sorts
357
     */
358
    int mSeqId;	
359
 
6914 dpurdie 360
	/** Indicates that the package not be ripple built at this time
361
	 *  Sequence is:
362
	 *     User sets to 's'
363
	 *     This buildtool will set to 'w' when a ripple has been detected
364
	 *     User resets to NULL when the ripple can be resumed. This is stored as an 'n'
365
	 * 
366
	 */
367
    public char mRippleStop;
7048 dpurdie 368
 
369
    /**
370
     *  The calculated ripple build plan for this package
371
     *  Will not be calculated for all packages, just those of interest
372
     *  All packages that can (not must) be built when this package is built
373
     *  The list will not include packages that cannot be built at the moment
374
     *  
375
     *  Does not include this package
376
     */
377
    public ArrayList<Package> mRipplePlan = null;
378
 
379
    /** The duration (seconds) of the last build of this package
380
     *  Used to estimate the cost of building the package
381
     *  A WIP packages gets the buildTime of the package its based upon
382
     */
383
    public int mBuildTime;
6914 dpurdie 384
 
7048 dpurdie 385
    /** Calculated time ( seconds) that is may take to build this package and then ripple packages that depend on it
386
     *  both directly and indirectly. Based on mRipplePlan. 
387
     */
388
    public int mRippleTime = 0;
389
 
7070 dpurdie 390
    /** Used in the calculation of a ripple plan
391
     * 
392
     */
393
    public int mRippleOrder = 0;
394
 
7048 dpurdie 395
    /** Set to indicate that the package is NOT a part of the full release set
396
     *  The package is a WIP, TestBuild or a ForcedRipple
397
     *  
398
     *   Used to simplify detection of such packages and to limit processing of these packages
399
     *   May be cleared if the package is added to the full set
400
     */
401
    public boolean mIsNotReleased = false;
7070 dpurdie 402
 
403
    /** Used by some algorithms for various indications
404
     * 
405
     */
406
    public boolean mIsProcessed = false;
7048 dpurdie 407
 
6914 dpurdie 408
    /**
409
     * Constructor
410
     * Used to create planned packages. In these packages the change_type is significant
411
     * 
412
     * @param pkg_id	   Package Name Identifier
413
     * @param pv_id        Package Version Id
414
     * @param pkg_name     Package Name
415
     * @param pkg_version  Package Version
416
     * @param v_ext        Package Suffix
417
     * @param alias        Package Alias
418
     * @param pkg_vcs_tag  Vcs Tag
419
     * @param ripple_field Ripple Field
420
     * @param change_type  Change Type
421
     */
7051 dpurdie 422
    public Package(int pkg_id, int pv_id, String pkg_name, String pkg_version, String v_ext, String alias, String pkg_vcs_tag, char ripple_field, char change_type)
6914 dpurdie 423
    {
424
        mLogger.debug("Package 1: pv_id " + pv_id + " pkg_name " + pkg_name + " v_ext " + v_ext + " alias " + alias
425
                + " pkg_vcs_tag " + pkg_vcs_tag + " change_type " + change_type);
426
        mId = pv_id;
427
        mName = pkg_name;
428
        mPid = pkg_id;
429
        mVersion = "0.0.0000";
430
        mExtension = v_ext;
431
        mAlias = alias;
432
        mVcsTag = pkg_vcs_tag;
433
 
434
        // Remove the package suffix from package_version to create the fixed version number
435
        mFixedVersion = pkg_version;
436
        mFixedVersion = mFixedVersion.substring(0, mFixedVersion.length() - mExtension.length());
437
 
438
        // a ripple_field of 'L' indicates this package has limited version numbering
439
        if (change_type == 'M') {
440
            mChangeType.setMajor(ripple_field == 'L' ? true : false);
441
 
442
        } else if (change_type == 'N') {
443
            mChangeType.setMinor(ripple_field == 'L' ? true : false);
444
 
445
        } else if (change_type == 'P') {
446
            mChangeType.setPatch(ripple_field == 'L' ? true : false);
447
 
448
        } else if (change_type == 'F') {
449
            mChangeType.setFixed();
450
 
451
        } else {
452
            mChangeType.setUnknown();
453
        }
454
    }
455
 
456
    /**
457
     * Constructor
458
     * Used to create existing packages, in these packages the ripple_field is significant
459
     * 
460
     * @param pkg_id	   Package Name Identifier
461
     * @param pv_id        Package Version Id
462
     * @param pkg_name     Package Name
463
     * @param pkg_version  Package Version
464
     * @param v_ext        Package Suffix
465
     * @param alias        Package Alias
466
     * @param pkg_vcs_tag  Vcs Tag
467
     * @param ripple_field Ripple Field
468
     */
7051 dpurdie 469
    public Package(int pkg_id,int pv_id, String pkg_name, String pkg_version, String v_ext, String alias, String pkg_vcs_tag, char ripple_field)
6914 dpurdie 470
    {
471
        mLogger.debug("Package 2: pv_id " + pv_id + " pkg_name " + pkg_name + " pkg_version " + pkg_version + " v_ext "
472
                + v_ext + " alias " + alias + " pkg_vcs_tag " + pkg_vcs_tag + " ripple_field " + ripple_field);
473
        mId = pv_id;
474
        mName = pkg_name;
475
        mPid = pkg_id;
476
        mVersion = pkg_version;
477
        int endindex = mVersion.length() - v_ext.length();
478
 
479
        if (endindex > 0)
480
        {
481
            mVersion = mVersion.substring(0, endindex);
482
        }
483
 
484
        mExtension = v_ext;
485
        mAlias = alias;
486
        mVcsTag = pkg_vcs_tag;
487
 
488
        // setBuild is the default
489
        if (ripple_field == 'M') {
490
            mRippleField.setMajor();
491
 
492
        } else if (ripple_field == 'm') {
493
            mRippleField.setMinor();
494
 
495
        } else if (ripple_field == 'p') {
496
            mRippleField.setPatch();
497
 
498
        } else if (ripple_field == 'L') {
499
            mRippleField.setLimit();
500
        }
501
    }
502
 
503
    /**
504
     * constructor
505
     */
506
    Package()
507
    {
508
        mLogger.debug("Package 3");
509
        mId = 0;
510
        mName = "null";
511
        mExtension = "null";
512
        mAlias = "null";
513
        mVcsTag = "null";
514
    }
515
 
516
    /**
7049 dpurdie 517
     * Constructor for unit test purposes
7051 dpurdie 518
     *  Will invoke applyPV and save the results for the UTF framework
6914 dpurdie 519
     */
520
    public Package(ReleaseManager rm, String version, int majorLimit, int minorLimit, int patchLimit, int buildNumberLimit)
521
    {
522
        mId = -1;
523
        mRippleField.setLimit();
524
        mVersion = version;
525
        mMajorLimit = majorLimit;
526
        mMinorLimit = minorLimit;
527
        mPatchLimit = patchLimit;
528
        mBuildLimit = buildNumberLimit;
529
 
530
        if (version.endsWith(".cots"))
531
        {
532
            mExtension = ".cots";
533
            mVersion = version.substring(0, version.length() - 5);
534
            mChangeType.setMajor(false);
535
            mChangeType.setMinor(false);
536
            mChangeType.setPatch(true);
537
            mRippleField.setBuild();
538
        }
539
 
540
        try
541
        {
7050 dpurdie 542
            mId = applyPV(rm);
6914 dpurdie 543
        } catch (Exception e)
544
        {
545
        }
546
    }
547
 
548
    /**
7051 dpurdie 549
     * Constructor for unit test purposes
550
     * Performs a partial copy of a package - sufficient for test purposes
551
     * @param base      - Base package  
552
     * @param newPvId   - New pvid of the package
553
     */
7070 dpurdie 554
    @SuppressWarnings("unchecked")
7051 dpurdie 555
    public Package(int newPvId, Package base) {
556
 
557
        mId = newPvId;
558
        mPid = base.mPid;
559
        mName = base.mName;
560
        mExtension = base.mExtension;
561
        mVersion = base.mVersion;
562
        mAlias = base.mAlias;
563
        mVcsTag = base.mVcsTag;
564
        mFixedVersion = base.mFixedVersion;
565
        mChangeType = base.mChangeType;
566
        mRippleField = base.mRippleField;
567
        mBuildTime = base.mBuildTime;
568
        mHasAutomatedUnitTests = base.mHasAutomatedUnitTests;
569
        mSeqId = base.mSeqId;
570
 
571
        mBuildFailureEmailCollection = (Vector<String>) base.mBuildFailureEmailCollection.clone();
572
        mPackageDependencyCollection = (Vector<Package>) base.mPackageDependencyCollection.clone();
573
        mDependencyIDCollection = (Vector<Integer>) base.mDependencyIDCollection.clone();
574
        mDependencyCollection = (Vector<String>) base.mDependencyCollection.clone();
575
        mBuildStandardCollection = (Vector<BuildStandard>) base.mBuildStandardCollection.clone();
576
 
577
    }
578
 
579
    /**
6914 dpurdie 580
     * accessor for unit test purposes
581
     */
582
    public int getId()
583
    {
584
        return mId;
585
    }
586
 
587
    /**
588
     * accessor for unit test purposes
589
     */
590
    public String getVersion()
591
    {
592
        return mVersion;
593
    }
594
 
7049 dpurdie 595
    /**
596
     * accessor for unit test purposes
597
     */
598
    public String getNextVersion()
599
    {
600
        return mNextVersion;
601
    }
602
 
6914 dpurdie 603
 
604
    /**
605
     * returns true if mBuildStandardCollection is not empty
606
     */
607
    boolean isReproducible()
608
    {
7048 dpurdie 609
        mLogger.debug("isReproducible on Package {}", mName);
6914 dpurdie 610
        boolean retVal = ! mBuildStandardCollection.isEmpty();
7048 dpurdie 611
        mLogger.info("isReproducible returned {}", retVal);
6914 dpurdie 612
        return retVal;
613
    }
614
 
615
 
616
    /**
617
     * returns true if at least one of its BuildStandards has mGeneric true
618
     */
619
    boolean isGeneric()
620
    {
7048 dpurdie 621
        mLogger.debug("isGeneric on Package {}", mName);
6914 dpurdie 622
        boolean retVal = false;
623
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
624
        {
625
            BuildStandard buildStandard = it.next();
626
 
627
            if (buildStandard.isGeneric())
628
            {
629
                retVal = true;
630
                break;
631
            }
632
        }
633
 
7048 dpurdie 634
        mLogger.info("isGeneric returned {}", retVal);
6914 dpurdie 635
        return retVal;
636
    }
637
 
638
    /**
639
     * Returns true if at least one of the packages build standards can be 
640
     * built in the named machine class. 
641
     *  
642
     * Used to determine if the package can be built with the current buildset 
643
     * by iteration over all machine classes in the buildset. 
644
     */
645
    boolean canBeBuildby(String machineClass)
646
    {
647
        mLogger.debug("canBeBuildby on Package " + mName);
648
        boolean retVal = false;
649
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
650
        {
651
            BuildStandard buildStandard = it.next();
652
 
653
            if (buildStandard.isGeneric())
654
            {
655
                retVal = true;
656
                break;
657
            }
658
 
659
            if (buildStandard.mMachClass.equals(machineClass))
660
            {
661
                retVal = true;
662
                break;
663
            }
664
        }
665
 
666
        mLogger.info("canBeBuildby returned " + retVal);
667
        return retVal;
668
    }
669
 
670
    /**
671
     * Compare the build standards of two packages 
672
     * Used only in escrow mode 
673
     * Used to compare a package and its dependents (one by one) 
674
     *  
675
     * Returns true if the parent (this) package  can be built in the same escrow 
676
     * build iteration as the dependent package. 
677
     *  
678
     * This is a complex decision and has a few built in assumptions. 
679
     *  
680
     * If the dependent package is 'generic' then the parent package can be built 
681
     *  
682
     * If the parent package is generic then is can only be built if the dependent is 
683
     * also generic. Otherwise we must assume that the parent package is an agregator 
684
     * package and requires artifacts from the dependent package built by all of its 
685
     * required build machines. 
686
     *  
687
     * If both packages are not generic, then if the build standards of the parent and the 
688
     * dependent are identical then 
689
     *  
690
     *      If we have one build standard, we can build the parent in this iteration as
691
     *      the dependent package has been completely built.
692
     *  
693
     *      If we have more than one build standard ( but they are identical ) then we
694
     *      ASSUME that we can build the parent in this iteration. The assumption is that
695
     *      there is no mixing between build machines. ie: Windows consumer users Windows
696
     *      artifacts and the Linux consumer uses Linux artifacts ...
697
     *  
698
     * If both packages are not generic and the build standards are not identical, then 
699
     * things get hard. The safest solution is to assume the parent cannot be built in this 
700
     * iteration. This is not a bad assumption. 
701
     *  
702
     */
703
    boolean haveSameBuildStandards(Package d)
704
    {
705
        HashMap<String, Boolean> standardSet = new HashMap<String, Boolean>();
706
        boolean isGeneric = false;
707
        boolean isGeneric_d = false;
708
        boolean isIdentical = true;
709
 
710
        // Scan the build standards of the parent package and create a hash map for each machine
711
        // class required by the parent. Also determine if the parent is generic.
712
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
713
        {
714
            BuildStandard bs = it.next();
715
            standardSet.put(bs.mMachClass, false);
716
 
717
            if (bs.isGeneric())
718
            {
719
                isGeneric = true;
720
                break;
721
            }
722
        }
723
 
724
        // Scan the build standards in the dependent package and remove items from the map
725
        // If it was not in the map then the dependent package builds for platforms that the
726
        // parent package does not - thus the build standards cannot be identical
727
        // Also determine if the dependent is generic.
728
        for (Iterator<BuildStandard> it = d.mBuildStandardCollection.iterator(); it.hasNext();)
729
        {
730
            BuildStandard bs = it.next();
731
             if (bs.isGeneric())
732
             {
733
             isGeneric_d = true;
734
             break;
735
             }
736
 
737
            Boolean value = standardSet.remove(bs.mMachClass);
738
            if (value == null)
739
            {
740
                isIdentical = false;
741
                break;
742
            }
743
        }
744
 
745
        //
746
        // If there are any items left in the map then the parent package builds on machines
747
        // that the dependent does not. The two are not identical.
748
 
749
        if (!standardSet.isEmpty())
750
        {
751
            isIdentical = false;
752
        }
753
 
754
        // If dependent is generic, then it will be build on the first platform in this iteration
755
        // All is good
756
 
757
        if( isGeneric_d)
758
            return true;
759
 
760
        //  If I am generic and the dependent is generic, then I can be built at this time
761
        // 
762
        //  Will not reach here as we have already said that if dependenbt is generic, then all is good
763
        //  if (isGeneric_d && isGeneric)
764
        //  {
765
        //      return true;
766
        //  }
767
 
768
 
769
        //  If I am generic then I must wait for ALL dependent to be built on all platforms
770
        //  Thus I can't be built this round
771
        //
772
        if (isGeneric)
773
            return false;
774
 
775
        //
776
        //  If the two sets of build standards don't have generic, BUT are identical
777
        //  the we can assume that there is no cross breading. and that windows bits build from windows bits
778
        //  and solaris bits build from solaris
779
        //
780
        if (isIdentical)
781
            return true;
782
 
783
        //  The two sets of build standards are not an exact match
784
        //  Cheap solution: Assume that I can't be built this round
785
        //  Possible solution: If I am a subset of the dependent - then I can be built
786
        //                     If I am a superset of the dependent - then ???
787
        return false;
788
 
789
    }
790
 
791
    /**
7048 dpurdie 792
     * Applies the required version number change. Will calculate mNextVersion
7050 dpurdie 793
     * while not changing mVersion.
6914 dpurdie 794
     * 
795
     * @param releaseManager    Release Manager instance to work against
796
     * 
7048 dpurdie 797
     * @return 0 : success
798
     *         1 : cannot work with non standard versioning
799
     *         2 : ripple field limitations prevent a ripple build
800
     *         3 : Invalid Change Type
6914 dpurdie 801
     * @exception Exception
802
     */
7050 dpurdie 803
 
804
    int applyPV(ReleaseManager releaseManager) throws Exception
6914 dpurdie 805
    {
806
        String logInfo = "applyPV," + mName;
807
        mLogger.debug("applyPV on Package " + mName);
7048 dpurdie 808
 
6914 dpurdie 809
        //
7048 dpurdie 810
        //  This method used to actually perform the version change
811
        //  Now it just calculates the potential value
812
        //  Must not alter mVersion as it will be used if the package is not selected to be built,
813
        //  but some of the code assumes that it can be.
814
        //
815
        String originalVersion = mVersion;
816
 
817
        //
6914 dpurdie 818
        // Four scenarios, only applyPV for 3 of them
819
        // mDirectlyPlanned mIndirectlyPlanned mArchivalExistence mForcedRipple
820
        // Action
821
        // WIP/test build exists: true true don't care don't care applyPV
822
        // Package version is out of date: false true true don't care applyPV
823
        // Forced ripple: false true don't care > 0 applyPV
824
        // Package version does not exist: false true false = 0 do not applyPV
825
        //
826
        if (!mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence && mForcedRippleInstruction == 0)
827
        {
828
            // the package has an mIndirectlyPlanned flag set true in daemon
829
            // mode because the package does not exist in an archive
830
            // do not apply a different package version
7048 dpurdie 831
            mLogger.info("applyPV. Rebuild Package {}", mName);
6914 dpurdie 832
            mLogger.info("applyPv returned 0");
833
            return 0;
834
        }
835
 
836
        // override - no longer doing a rebuild - version number change from this point on
837
        if (mTestBuildInstruction == 0)
838
        {
839
            mRequiresSourceControlInteraction = true;
840
        }
841
 
842
        //	Force test builds to use a sensible version number
843
        if (mTestBuildInstruction > 0 )
844
        {
845
        	mChangeType.resetData();		// Resolve conflict via build numbers
846
        	mRippleField.setBuild();
847
        	mVersion = "99.99.98999";		// Such that rippling build number will goto 99.99.99000
848
        }
849
 
850
        //
851
        // Detect invalid change type
852
        // Flagged when package instance is created
853
        //
854
        if (mChangeType.mUnknown)
855
        {
7048 dpurdie 856
            mLogger.info("Package Version specified on Package {} New Version: {}", mName, mVersion);
6914 dpurdie 857
            mLogger.info("applyPv returned 3");
858
            return 3;
859
        }
860
 
861
        // If we are not calculating the new package version because the user
862
        // has fixed the version of the package. We are given the new package version.
863
        if (mChangeType.mFixed)
864
        {
865
            // mVersion is already setup
866
 
7048 dpurdie 867
            mNextVersion = mFixedVersion;
868
            mLogger.info("Package Version specified on Package {} New Version: {}", mName,  mVersion);
6914 dpurdie 869
            mLogger.info("applyPv returned 0");
870
            return 0;
871
        }
872
 
873
        // We need to calculate the new version number
874
        //
875
        MutableInt major = new MutableInt(0);
876
        MutableInt minor = new MutableInt(0);
877
        MutableInt patch = new MutableInt(1000);
878
 
879
        // Planned packages have a previous version number to be used as the bases for the
880
        // calculation. Ripples won't.
881
        //
882
        if (mPrevVersion != null)
883
        {
884
        	mVersion = mPrevVersion;
885
        }
886
        String[] field = mVersion.split("\\D");
887
        String nonStandardCotsVersion = "";
888
        logInfo += ", Prev:" + mVersion;
889
 
890
        if (field.length == 3)
891
        {
892
            major.value = Integer.parseInt(field[0]);
893
            minor.value = Integer.parseInt(field[1]);
894
            patch.value = Integer.parseInt(field[2]);
895
        } 
896
        else
897
        {
898
            //
899
            // Can ripple a .cots package under very controlled conditions
900
            // Its ends with a .patchBuild field
901
            // Package is marked as ripple via build number
902
            // Change type of Major and Minor are not allowed
903
            //
7048 dpurdie 904
            if (!mChangeType.mMajor && !mChangeType.mMinor && mRippleField.mBuild && mExtension.compareTo(".cots") == 0 && field.length > 0)
6914 dpurdie 905
            {
906
                // allow and work with (ripple build) versions a.b.c.d....xxxx
907
                // where xxxx.length > 3
908
                String patchStr = field[field.length - 1];
909
                int patchLen = patchStr.length();
910
 
911
                // check patchStr is the last (at least 4) digits
912
                if (patchLen > 3
913
                        && mVersion.substring(mVersion.length() - patchLen, mVersion.length()).compareTo(patchStr) == 0)
914
                {
915
                    patch.value = Integer.parseInt(patchStr);
916
                    nonStandardCotsVersion = mVersion.substring(0, mVersion.length() - patchLen);
917
                }
918
            }
919
 
920
            if (nonStandardCotsVersion.length() == 0)
921
            {
922
                // cannot work with non standard versioning
923
                mLogger.error("applyPV cannot work with non standard versioning");
924
                mLogger.info("applyPv returned 1");
925
                return 1;
926
            }
927
        }
928
 
929
        if (nonStandardCotsVersion.length() == 0 && patch.value < 1000 && field[2].substring(0, 1).compareTo("0") != 0)
930
        {
7048 dpurdie 931
            mLogger.info("applyPV accomodate old style Version of the form 1.0.1");
6914 dpurdie 932
            patch.value = patch.value * 1000;
933
        }
934
 
935
        // mChangeType overrides mRippleField
936
        do
937
        {
938
            if (mChangeType.mMajor)
939
            {
940
                logInfo += ",CT Major";
941
                if (!incrementFieldsAccordingToLimits(4, major, minor, patch))
942
                {
943
                    mLogger.info("applyPv returned 2");
7048 dpurdie 944
                    mVersion = originalVersion;
6914 dpurdie 945
                    return 2;
946
                }
947
            } else if (mChangeType.mMinor)
948
            {
949
                logInfo += ",CT Minor";
950
                if (!incrementFieldsAccordingToLimits(3, major, minor, patch))
951
                {
952
                    mLogger.info("applyPv returned 2");
7048 dpurdie 953
                    mVersion = originalVersion;
6914 dpurdie 954
                    return 2;
955
                }
956
            } else if (mChangeType.mPatch)
957
            {
958
                logInfo += ",CT Patch";
959
                if (!incrementFieldsAccordingToLimits(2, major, minor, patch))
960
                {
961
                    mLogger.info("applyPv returned 2");
7048 dpurdie 962
                    mVersion = originalVersion;
6914 dpurdie 963
                    return 2;
964
                }
965
            } else
966
            {
967
                if (mRippleField.mMajor)
968
                {
969
                    logInfo += ",R Major";
970
                    major.value++;
7048 dpurdie 971
                    mLogger.info("applyPV mRippleField.mMajor {}", major.value);
6914 dpurdie 972
                    minor.value = 0;
973
                    patch.value = 0;
974
                } else if (mRippleField.mMinor)
975
                {
976
                    logInfo += ",R Minor";
977
                    minor.value++;
7048 dpurdie 978
                    mLogger.info("applyPV mRippleField.mMinor {}", minor.value);
6914 dpurdie 979
                    patch.value = 0;
980
                } else if (mRippleField.mPatch)
981
                {
982
                    logInfo += ",R Patch";
983
                    patch.value = ((patch.value / 1000) + 1) * 1000; 
7048 dpurdie 984
                    mLogger.info("applyPV mRippleField.mPatch {}", patch.value);
6914 dpurdie 985
                } else if (mRippleField.mBuild)
986
                {
987
                    logInfo += ", R Build";
988
                    patch.value++;
7048 dpurdie 989
                    mLogger.info("applyPV mRippleField.mBuild {}", patch.value);
6914 dpurdie 990
                } else
991
                {
992
                    if (!incrementFieldsAccordingToLimits(1, major, minor, patch))
993
                    {
994
                        mLogger.info("applyPv returned 2");
7048 dpurdie 995
                        mVersion = originalVersion;
6914 dpurdie 996
                        return 2;
997
                    }
998
                }
999
            }
1000
 
1001
            if (nonStandardCotsVersion.length() == 0)
1002
            {
1003
                mVersion = String.valueOf(major.value) + "." + String.valueOf(minor.value) + ".";
1004
            } else
1005
            {
1006
                mVersion = nonStandardCotsVersion;
1007
            }
1008
 
1009
            if (patch.value < 10)
1010
            {
1011
                mVersion += "000";
1012
            } else if (patch.value < 100)
1013
            {
1014
                mVersion += "00";
1015
            } else if (patch.value < 1000)
1016
            {
1017
                mVersion += "0";
1018
            }
1019
 
1020
            mVersion += String.valueOf(patch.value);
7050 dpurdie 1021
        } while (exists(releaseManager));
6914 dpurdie 1022
 
7048 dpurdie 1023
        logInfo += ", Next Version:" + mVersion;
7033 dpurdie 1024
        mLogger.error(logInfo);
6914 dpurdie 1025
        mLogger.info("applyPv returned 0");
7048 dpurdie 1026
        mNextVersion = mVersion;
1027
        mVersion = originalVersion;
6914 dpurdie 1028
        return 0;
1029
    }
1030
 
1031
    /**
1032
     * increments fields according to mRippleField.mLimit if necessary will
1033
     * apply it to the field passed as follows 1 = build 2 = patch 3 = minor
1034
     * other = major returns true on success false on ripple field limitations
1035
     * prevent a ripple build
1036
     */
1037
    private boolean incrementFieldsAccordingToLimits(int field, MutableInt major, MutableInt minor, MutableInt patch)
1038
    {
1039
        boolean retVal = true;
1040
 
1041
        if (!mChangeType.mLimit && !mRippleField.mLimit)
1042
        {
1043
            // simple case
1044
            // no need to take field limits into consideration
1045
            switch (field)
1046
            {
1047
            case 1:
1048
                // unreachable
1049
                // the only scenario involving build number manipulation
1050
                // involves the mRippleField.mLimit being set
1051
                retVal = false;
1052
                break;
1053
            case 2:
1054
                do
1055
                {
1056
                    patch.value++;
1057
                } while ((patch.value / 1000) * 1000 != patch.value);
1058
                mLogger.info("incrementFieldsAccordingToLimits patch " + patch.value);
1059
                break;
1060
            case 3:
1061
                minor.value++;
1062
                mLogger.info("incrementFieldsAccordingToLimits minor " + minor.value);
1063
                patch.value = 0;
1064
                break;
1065
            default:
1066
                major.value++;
1067
                mLogger.info("incrementFieldsAccordingToLimits major " + major.value);
1068
                minor.value = 0;
1069
                patch.value = 0;
1070
            }
1071
        } else
1072
        {
1073
            // take field limits into consideration
1074
            boolean changeOccurred = false;
1075
            boolean incrementField = true;
1076
 
1077
            switch (field)
1078
            {
1079
            case 1:
1080
                if (mBuildLimit != 0)
1081
                {
1082
                    // increment or reset the patch build number
1083
                    int buildNumber = patch.value - (patch.value / 1000) * 1000;
1084
 
1085
                    if (buildNumber < mBuildLimit)
1086
                    {
1087
                        // can increment the patch build number
1088
                        patch.value++;
1089
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit build number " + patch.value);
1090
                        changeOccurred = true;
1091
                        incrementField = false;
1092
                    } else
1093
                    {
1094
                        if (mPatchLimit == 0)
1095
                        {
1096
                            // reset the patch number and patch build number
1097
                            patch.value = 0;
1098
                        }
1099
                    }
1100
                }
1101
                // no break by design
1102
            case 2:
1103
                if (mPatchLimit != 0 && incrementField)
1104
                {
1105
                    // increment or reset the patch number
1106
                    if ((patch.value / 1000) < mPatchLimit)
1107
                    {
1108
                        do
1109
                        {
1110
                            patch.value++;
1111
                        } while ((patch.value / 1000) * 1000 != patch.value);
1112
 
1113
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit patch " + patch.value);
1114
                        changeOccurred = true;
1115
                        incrementField = false;
1116
                    } else
1117
                    {
1118
                        // reset the patch number and patch build number
1119
                        patch.value = 0;
1120
                    }
1121
                }
1122
                // no break by design
1123
            case 3:
1124
                if (mMinorLimit != 0 && incrementField)
1125
                {
1126
                    // increment or reset the minor number
1127
                    if (minor.value < mMinorLimit)
1128
                    {
1129
                        minor.value++;
1130
                        patch.value = 0;
1131
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit minor " + minor.value);
1132
                        changeOccurred = true;
1133
                        incrementField = false;
1134
                    } else
1135
                    {
1136
                        // reset the minor number
1137
                        minor.value = 0;
1138
                    }
1139
                }
1140
                // no break by design
1141
            default:
1142
                if (mMajorLimit != 0 && incrementField)
1143
                {
1144
                    // increment or reset the major number
1145
                    if (major.value < mMajorLimit)
1146
                    {
1147
                        // increment the major number
1148
                        changeOccurred = true;
1149
                        major.value++;
1150
                        minor.value = 0;
1151
                        patch.value = 0;
1152
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit major " + major.value);
1153
                    }
1154
                }
1155
            }
1156
 
1157
            if (!changeOccurred)
1158
            {
1159
                // unable to increment a field due to field limitations
1160
                mLogger.error("incrementFieldsAccordingToLimits ripple field limitations prevent a ripple build");
1161
                mLogger.info("incrementFieldsAccordingToLimits returned false");
1162
                retVal = false;
1163
            }
1164
        }
1165
 
1166
        return retVal;
1167
    }
1168
 
1169
    /**
7048 dpurdie 1170
     * Check if a specified Version of the package exists in dpkg_archive or the Release Manager Database
6914 dpurdie 1171
     * 
1172
     * @param releaseManager Release Manager Instance
1173
     * 
1174
     * @return True if the Package Version exists within the Release Manager Database
1175
     * @exception Exception
1176
     */
7050 dpurdie 1177
    private boolean exists(ReleaseManager releaseManager) throws Exception
6914 dpurdie 1178
    {
1179
        mLogger.debug("exists on Package " + mName + " version " + mVersion + " extension " + mExtension);
1180
        boolean retVal = false;
1181
 
7048 dpurdie 1182
        if (!releaseManager.mUseDatabase)
6914 dpurdie 1183
        {
1184
            mLogger.info("exists !releaseManager.mUseDatabase");
1185
        }
1186
        else
1187
        {
1188
            //  Check Package Archive
1189
            retVal = existsInDpkgArchive();
1190
            if (!retVal)
1191
            {
1192
                //  Check Release Manager Database
1193
                retVal = releaseManager.queryPackageVersions(mPid, mVersion + mExtension);
1194
            }
1195
        }
1196
 
1197
        mLogger.info("exists returned " + retVal);
1198
        return retVal;
1199
    }
1200
 
1201
 
1202
    /**
1203
     * Check to see if a package exists in dpkg_archive
1204
     * 
1205
     * @return true if the version exists in dpkg_archive
1206
     * @exception Exception Thrown if dpkg_archive does not exist. The 'cause' of 'mRecoverable' is special and
1207
     *                      will be trapped later to determine if this is a recoverable exception.
1208
     */
1209
    boolean existsInDpkgArchive() throws Exception
1210
    {
1211
        mLogger.debug("existsInDpkgArchive on " + mName);
1212
        boolean retVal = false;
1213
        String name = utilities.catDir(mName, mVersion + mExtension );
1214
 
1215
        //  If a replica exists, then check it first
1216
        //  If we are configured with a replica its because access to the main archive is slow
1217
        //  and we want this check to be fast
1218
        //
1219
        if (mGbeDpkgReplica != null && mGbeDpkgReplica.length() > 0)
1220
        {
1221
            File dpkg = new File(mGbeDpkgReplica);
1222
            if (!dpkg.exists())
1223
            {
7033 dpurdie 1224
                mLogger.error("existsInDpkgArchive. mGbeDpkgReplica not accessable. " + mRecoverable);
6914 dpurdie 1225
                throw new Exception(mRecoverable);
1226
            }
1227
 
1228
            if( utilities.freshFileExists(utilities.catDir(mGbeDpkgReplica, name) ) )
1229
            {
1230
                mLogger.info("existsInDpkgArchive mGbeDpkgReplica");
1231
                retVal = true;
1232
            }
1233
        }
1234
 
1235
        //  Check (possibly remote) dpkg_archive for files existence if it was not found locally
1236
        //
1237
        if ( !retVal )
1238
        {
1239
 
1240
            //  If the package archive does not exist at the moment, then we have a network issue
1241
            //  This is a recoverable error
1242
 
1243
            File dpkg = new File(mGbeDpkg);
1244
            if (!dpkg.exists())
1245
            {
7033 dpurdie 1246
                mLogger.error("existsInDpkgArchive. mGbeDpkg not accessable. " + mRecoverable);
6914 dpurdie 1247
                throw new Exception(mRecoverable);
1248
            }
1249
 
1250
            if( utilities.freshFileExists(utilities.catDir(mGbeDpkg, name) ) )
1251
            {
1252
                mLogger.info("existsInDpkgArchive mGbeDpkg");
1253
                retVal = true;
1254
            }
1255
        }
1256
 
1257
        mArchivalExistence = retVal;
1258
        mLogger.info("existsInDpkgArchive returned " + retVal);
1259
        return retVal;
1260
    }
1261
 
1262
    /**
1263
     * returns true if the required package archives (dpkg_archive) exist
1264
     * attempt to recover from their transient loss
1265
     */
1266
    public static boolean recover()
1267
    {
1268
        mLogger.debug("recover");
1269
        boolean retVal = false;
1270
 
1271
        String Release = mGbeDpkg;
1272
        if (Release != null)
1273
        {
1274
            if ( utilities.freshFileExists(mGbeDpkg) )
1275
            {
1276
                retVal = true;
7033 dpurdie 1277
                mLogger.error("recover: dpkg_archive access has been restored");
6914 dpurdie 1278
            }
1279
        }
1280
 
1281
        mLogger.info("recover returned " + retVal);
1282
        return retVal;
1283
    }
1284
 
1285
    /**
1286
     * Returns a data structure of unique email addresses
1287
     * Uses the Global Email Collection and the packages own failure email collection
1288
     */
1289
    private LinkedHashSet<String>buildEmailList(RippleEngine rippleEngine)
1290
    {
1291
        //  Create a single list of email targets ensuring only one instance of each email address
1292
        //  ie: Remove duplicates, null and empty strings
1293
        LinkedHashSet<String> hs = new LinkedHashSet<String>();
1294
 
1295
        // Global and Project Wide emails
1296
        for (Iterator<String> it = rippleEngine.mMailGlobalCollection.iterator(); it.hasNext();)
1297
        {
1298
            String item = it.next();
1299
            if (item != null && item.length() > 0) 
1300
            {
1301
                hs.add(item);
1302
            }
1303
        }
1304
 
1305
        // Package specific collection
1306
        for (Iterator<String> it = mBuildFailureEmailCollection.iterator(); it.hasNext();)
1307
        {
1308
            String item = it.next();
1309
            if (item != null && item.length() > 0) 
1310
            {
1311
                hs.add(item);
1312
            }
1313
        }
1314
 
1315
        return hs;
1316
    }
1317
 
1318
    /**
1319
     * Add email information in a form suitable for creating an Ant file
1320
     * @param   rippleEngine    - Ripple Engine Instance
1321
     * @param   xml             - An XmlBuilder element to extend
1322
     */
1323
    void emailInfo(RippleEngine rippleEngine, XmlBuilder xml)
1324
    {
1325
 
1326
        //  Create a single list of email targets ensuring only one instance of each email address
1327
        //  ie: Remove duplicates
1328
        LinkedHashSet<String> hs = buildEmailList(rippleEngine);
1329
 
1330
        for (Iterator<String> it = hs.iterator(); it.hasNext();)
1331
        {
1332
            String email = it.next();
1333
            XmlBuilder entry = xml.addNewElement("owner");
1334
            entry.addAttribute("email", email);
1335
        }
1336
    }
1337
 
1338
    /**
1339
     * Returns email information in a form suitable for direct use
1340
     * @param   rippleEngine Current Release Manager context
1341
     * @return  A comma separated list of user names. May return a 'null' String
1342
     */
1343
    String emailInfoNonAntTask(RippleEngine rippleEngine)
1344
    {
1345
        //  Create a single list of email targets ensuring only one instance of each email address
1346
        //  ie: Remove duplicates
1347
        LinkedHashSet<String> hs = buildEmailList(rippleEngine);
1348
 
1349
        String retVal = null;
1350
        for (Iterator<String> it = hs.iterator(); it.hasNext();)
1351
        {
1352
            String email = it.next();
1353
 
1354
            if (retVal == null)
1355
            {
1356
                retVal = new String();
1357
            } else
1358
            {
1359
                retVal += ",";
1360
            }
1361
            retVal += email;
1362
        }
1363
 
1364
        return retVal;
1365
    }
1366
 
1367
    /**
1368
     * Adds email to mBuildFailureEmailCollection.
1369
     * Do not worry about multiple entries. These will be handled when the data is extracted
7048 dpurdie 1370
     * @param   email   - Email address. Null is allowed and will not be added
6914 dpurdie 1371
     */
1372
    public void addEmail(String email)
1373
    {
7048 dpurdie 1374
        if (email != null) 
6914 dpurdie 1375
        {
7048 dpurdie 1376
            mBuildFailureEmailCollection.add(email);
6914 dpurdie 1377
        }
1378
    }
1379
 
1380
    /**
1381
     * End of Processing for a Test Build
1382
     *     - sends email notification
1383
     *     - marks the instruction complete in the database
1384
     */
1385
    public void completeTestBuild(RippleEngine rippleEngine, boolean success) throws SQLException, Exception
1386
    {
1387
        mLogger.debug("completeTestBuild");
1388
 
1389
        if (mTestBuildInstruction == 0)
1390
        {
1391
            mLogger.info("completeTestBuild. Not Build Instruction");
1392
            return;
1393
        }
1394
 
1395
        //  Email Subject
1396
        String subject = (success == true ? "TEST BUILD COMPLETED SUCCESSFULLY" : "TEST BUILD FAILED") 
1397
                + " on package "
1398
                + mAlias;
1399
 
1400
        // Email Body
1401
        String mailBody = "";
1402
        if ( success != true)
1403
        {
1404
            mailBody += "Test build issues are identified in preceding build failure email.<p>"; 
1405
        }
1406
        mailBody += "Release: " + rippleEngine.mBaselineName + "<br>" 
1407
                  + "Package: " + mAlias + "<br>" 
1408
                  + "Rm Ref: " + CreateUrls.generateRmUrl(rippleEngine.getRtagId(), mId) + "<br>" 
1409
                  + "VcsTag: " + mVcsTag + "<br>"
1410
                  + "Build dependencies:<br>";
1411
 
1412
        String indentString = "&nbsp;&nbsp;&nbsp;&nbsp;";
1413
 
1414
        for (Iterator<Package> it3 = mPackageDependencyCollection.iterator(); it3.hasNext();)
1415
        {
1416
            Package depend = it3.next();
1417
 
1418
            String dependsExtension = depend.mExtension;
1419
            String dependsVersion = depend.mVersion;
1420
 
1421
            if (dependsExtension.length() > 0)
1422
            {
1423
                dependsVersion += dependsExtension;
1424
            }
1425
            mailBody += indentString + RippleEngine.quoteString(depend.mName, dependsVersion) + "<br>";
1426
        }
1427
 
1428
        mailBody += "<br>Build standards:<br>";
1429
 
1430
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
1431
        {
1432
            BuildStandard bs = it.next();
1433
 
1434
            String bsText = bs.getBuildStandardText();
1435
            if (bsText.length() > 0)
1436
            {
1437
                mailBody += indentString + bsText + "<br>";
1438
            }
1439
        }
1440
 
1441
        mailBody += "<p><hr>";
1442
        try
1443
        {
1444
            String target = emailInfoNonAntTask(rippleEngine);
7033 dpurdie 1445
            mLogger.error("completeTestBuildEmail Server: " + rippleEngine.getMailServer());
1446
            mLogger.error("completeTestBuildEmail Sender: " + rippleEngine.getMailSender());
1447
            mLogger.error("completeTestBuildEmail Target: " + target);
6914 dpurdie 1448
 
1449
            Smtpsend.send(rippleEngine.getMailServer(), // mailServer
1450
                    rippleEngine.getMailSender(),       // source
1451
                    target,                         // target
1452
                    rippleEngine.getMailSender(),       // cc
1453
                    null,                           // bcc
1454
                    subject,                        // subject
1455
                    mailBody,                       // body
1456
                    null                            // attachment
1457
            );
1458
        } catch (Exception e)
1459
        {
1460
            mLogger.warn("Email Failure: completeTestBuild:" + e.getMessage());
1461
        }
1462
 
1463
        // Update the Release Manager Database
1464
        rippleEngine.mReleaseManager.markDaemonInstCompleted(mTestBuildInstruction);
7033 dpurdie 1465
        mLogger.error("completeTest. Returning");
6914 dpurdie 1466
    }
1467
 
1468
 
1469
    /**
1470
     * Returns true if the package is a part of a circular dependency
1471
     * 
1472
     * If the package depends on a package with a circular dependency then the function
1473
     * will return false.
1474
     */
1475
    public boolean hasCircularDependency(RippleEngine ripEng)
1476
    {
7048 dpurdie 1477
        mLogger.debug("hasCircularDependency: {}", mAlias);
6914 dpurdie 1478
        boolean retVal = detectCircularDependency(mAlias, ripEng, null);
7048 dpurdie 1479
        mLogger.info("hasCircularDependency returned {} ", retVal);
6914 dpurdie 1480
        return retVal;
1481
    }
1482
 
1483
    /**
1484
     * Returns true is a part of a circular dependency
1485
     * Will examine all the packages sub dependencies and mark those that do have a
1486
     * circular dependency.
1487
     * 
1488
     * This process works by descending the dependency tree and dropping a bread crumb
1489
     * If the bread crumb is seen during the decent, then a circle has been detected and
1490
     * the package (with the bread crumb) will be marked as having a circular dependency
1491
     * 
1492
     *  Assumes that the caller will walk ALL packages and flag those with a circular
1493
     *  dependence AND those that depend on that package.
1494
     * 
1495
     */
1496
    private boolean detectCircularDependency(String alias, RippleEngine ripEng, Package parent)
1497
    {
1498
        mLogger.debug("detectCircularDependency");
1499
        boolean retVal = false;
1500
 
1501
        // if this package has yet to be checked for circular dependency
1502
        if (!mCheckedCircularDependency)
1503
        {
1504
            // Will be set as we drill down through dependencies
1505
            // If we see this marker (bread crumb) then we have a loop
1506
            if (mBreadCrumb != 0)
1507
            {
1508
                mBreadCrumb = 3;
1509
 
1510
                mHasCircularDependency = true;
1511
                if(parent != null && parent.mBreadCrumb != 3 )
1512
                {
1513
                    parent.mBreadCrumb = 2;
1514
                }
1515
            }
1516
            else
1517
            {
1518
                // Mark this package as potentially having a circular dependency
1519
                // Will now drill down and see if we hit a marker
1520
                mBreadCrumb = 1;
1521
 
1522
                // Recurse down the dependencies and sub dependencies
1523
                for (Iterator<String> it2 = mDependencyCollection.iterator(); it2.hasNext();)
1524
                {
1525
                    String dependencyAlias = it2.next();
1526
                    Package dependency = ripEng.findPackage(dependencyAlias);
1527
                    dependency.detectCircularDependency(alias, ripEng, this);
1528
                }
1529
 
1530
                if (mBreadCrumb == 2)
1531
                {
1532
                    mHasCircularDependency = true;
1533
                    if(parent != null && parent.mBreadCrumb != 3 )
1534
                    {
1535
                        parent.mBreadCrumb = 2;
1536
                    }
1537
                }
1538
                mBreadCrumb = 0;
1539
            }
1540
 
1541
            // Flag package as having been examined
1542
            mCheckedCircularDependency = true;
1543
        } 
1544
 
1545
        // return the persisted circular dependency outcome
1546
        retVal = mHasCircularDependency;
7048 dpurdie 1547
        mLogger.info("detectCircularDependency 2 returned {}", retVal);
6914 dpurdie 1548
        return retVal;
1549
    }
7048 dpurdie 1550
 
1551
    /** Set the sequence of all packages in the list
1552
     *  Used so that the Unit Tests function can preserve the basic ordering of the list 
1553
     */
1554
    public static void setSequence(ArrayList<Package> al)
1555
    {
1556
        int seq = 1;
1557
        for (Iterator<Package> it = al.iterator(); it.hasNext(); )
1558
        {
1559
            Package p = it.next();
1560
            p.mSeqId = seq++;
1561
        }
1562
    }
6914 dpurdie 1563
 
7070 dpurdie 1564
    /** Reset the processed flag on a collection of packages
1565
     * 
1566
     */
1567
    public static void resetProcessed (ArrayList<Package> al)
1568
    {
1569
        for (Iterator<Package> it = al.iterator(); it.hasNext(); )
1570
        {
1571
            Package p = it.next();
1572
            p.mIsProcessed = false;
1573
        }
1574
    }
7048 dpurdie 1575
 
7070 dpurdie 1576
    /** Reset the rippleOrder flag on a collection of packages
1577
     * 
1578
     */
1579
    public static void resetRippleOrder (ArrayList<Package> al)
1580
    {
1581
        for (Iterator<Package> it = al.iterator(); it.hasNext(); )
1582
        {
1583
            Package p = it.next();
1584
            p.mRippleOrder = 0;
1585
        }
1586
    }   
1587
 
7048 dpurdie 1588
    /** Comparator for sorting package collections by mSeqId
1589
     *  Used to preserve order for unit testing
1590
     */
1591
    public static final Comparator<Package> SeqComparator = new Comparator<Package>() {
1592
 
1593
        /**
1594
         * Returns -ve: p1 is less than p2
1595
         *           0: p1 = p2
1596
         *         +ve: p1 > p2
1597
         */
1598
        public int compare (Package p1, Package p2) {
1599
                return p1.mSeqId - p2.mSeqId;
1600
        }
7070 dpurdie 1601
    };
1602
 
1603
    /** Comparator for sorting package collections by mRippleTimme and mRippleOrder
1604
     *  Preserve rippleOrder
1605
     *  
1606
     */
1607
    public static final Comparator<Package> PlanComparator = new Comparator<Package>() {
1608
 
1609
        /**
1610
         * Returns -ve: p1 is less than p2
1611
         *           0: p1 = p2
1612
         *         +ve: p1 > p2
1613
         */
1614
        public int compare (Package p1, Package p2) {
1615
            if (p1.mRippleOrder == p2.mRippleOrder)
1616
            {
1617
                return p1.mRippleTime - p2.mRippleTime;
1618
            }
1619
 
1620
            return p1.mRippleOrder - p2.mRippleOrder;
1621
 
1622
        }
1623
    };
1624
 
1625
    /** Comparator for sorting package collections by mRippleTimme (only)
1626
     *  
1627
     */
1628
    public static final Comparator<Package> RippleTimeComparator = new Comparator<Package>() {
1629
 
1630
        /**
1631
         * Returns -ve: p1 is less than p2
1632
         *           0: p1 = p2
1633
         *         +ve: p1 > p2
1634
         */
1635
        public int compare (Package p1, Package p2) {
1636
            return p1.mRippleTime - p2.mRippleTime;
1637
        }
1638
    };
1639
 
7048 dpurdie 1640
 
6914 dpurdie 1641
    /**
1642
     * entity class supporting the ERG version numbering standard:
1643
     * <major>.<minor>.<patch/build> patch/build is at least a 4 digit number
1644
     * whose last 3 digits represent the build
1645
     */
1646
    public class VersionNumberingStandard
1647
    {
1648
        /**
1649
         * in terms of the mChangeType Package field, when true indicates the
1650
         * contract of the package has changed in a non backwardly compatible
1651
         * manner in terms of the mRippleField Package field, when true indicates
1652
         * the major version number will be incremented
1653
         * 
1654
         * @attribute
1655
         */
1656
        private boolean mMajor = false;
1657
 
1658
        /**
1659
         * in terms of the mChangeType Package field, when true indicates the
1660
         * contract of the package has changed in a backwardly compatible manner
1661
         * in terms of the mRippleField Package field, when true indicates the
1662
         * minor version number will be incremented
1663
         * 
1664
         * @attribute
1665
         */
1666
        private boolean mMinor = false;
1667
 
1668
        /**
1669
         * in terms of the mChangeType Package field, when true indicates the
1670
         * contract of the package has not changed, but the package has changed
1671
         * internally in terms of the mRippleField Package field, when true
1672
         * indicates the minor version number will be incremented
1673
         * 
1674
         * @attribute
1675
         */
1676
        private boolean mPatch = false;
1677
 
1678
        /**
1679
         * in terms of the mChangeType Package field, when true indicates the
1680
         * package has not changed, its dependencies potentially have in terms
1681
         * of the mRippleField Package field, when true indicates the build
1682
         * number will be incremented
1683
         * 
1684
         * @attribute
1685
         */
1686
        private boolean mBuild = true;
1687
 
1688
        /**
1689
         * in terms of the mChangeType Package field, when true indicates the
1690
         * major, minor, and patch number will be incremented according to field
1691
         * limits in terms of the mRippleField Package field, when true indicates
1692
         * the major, minor, patch and build number will be incremented
1693
         * according to field limits
1694
         * 
1695
         * @attribute
1696
         */
1697
        private boolean mLimit = false;
1698
 
1699
        /**
1700
         * in terms of the mChangeType Package field, when true indicates the
1701
         * package version number will not be rippled. The user will have fixed
1702
         * the version number. This is only application to WIP packages
1703
         * 
1704
         * @attribute
1705
         */
1706
        private boolean mFixed = false;
1707
 
1708
        /**
1709
         * in terms of the mChangeType Package field, when true indicates the
1710
         * method of rippling a package version number is not known.
1711
         * 
1712
         * @attribute
1713
         */
1714
        private boolean mUnknown = false;
1715
 
1716
        /**
1717
         * constructor
1718
         */
1719
        private VersionNumberingStandard()
1720
        {
1721
            mLogger.debug("VersionNumberingStandard");
1722
        }
1723
 
1724
        /**
1725
         * Reset all values to a known state
1726
         * 
1727
         */
1728
        void resetData()
1729
        {
1730
            mBuild = false;
1731
            mMajor = false;
1732
            mMinor = false;
1733
            mPatch = false;
1734
            mLimit = false;
1735
            mFixed = false;
1736
            mUnknown = false;
1737
        }
1738
 
1739
        /**
1740
         * sets mBuild true, mMajor false, mMinor false, mPatch false, mLimit
1741
         * false
1742
         */
1743
        void setBuild()
1744
        {
1745
            mLogger.debug("setBuild");
1746
            resetData();
1747
            mBuild = true;
1748
        }
1749
 
1750
        /**
1751
         * sets mBuild false, mMajor true, mMinor false, mPatch false, mLimit
1752
         * false
1753
         */
1754
        void setMajor()
1755
        {
1756
            mLogger.debug("setMajor");
1757
            resetData();
1758
            mMajor = true;
1759
        }
1760
 
1761
        /**
1762
         * sets mBuild false, mMajor true, mMinor false, mPatch false, mLimit
1763
         * limit
1764
         */
1765
        void setMajor(boolean limit)
1766
        {
1767
            mLogger.debug("setMajor " + limit);
1768
            resetData();
1769
            mMajor = true;
1770
            mLimit = limit;
1771
        }
1772
 
1773
        /**
1774
         * sets mBuild false, mMajor false, mMinor true, mPatch false, mLimit
1775
         * false
1776
         */
1777
        void setMinor()
1778
        {
1779
            mLogger.debug("setMinor");
1780
            resetData();
1781
            mMinor = true;
1782
        }
1783
 
1784
        /**
1785
         * sets mBuild false, mMajor false, mMinor true, mPatch false, mLimit
1786
         * limit
1787
         */
1788
        void setMinor(boolean limit)
1789
        {
1790
            mLogger.debug("setMinor " + limit);
1791
            resetData();
1792
            mMinor = true;
1793
            mLimit = limit;
1794
        }
1795
 
1796
        /**
1797
         * sets mBuild false, mMajor false, mMinor false, mPatch true, mLimit
1798
         * false
1799
         */
1800
        void setPatch()
1801
        {
1802
            mLogger.debug("setPatch");
1803
            resetData();
1804
            mPatch = true;
1805
        }
1806
 
1807
        /**
1808
         * sets mBuild false, mMajor false, mMinor false, mPatch true, mLimit
1809
         * limit
1810
         */
1811
        void setPatch(boolean limit)
1812
        {
1813
            mLogger.debug("setPatch");
1814
            resetData();
1815
            mPatch = true;
1816
            mLimit = limit;
1817
        }
1818
 
1819
        /**
1820
         * sets mBuild false, mMajor false, mMinor false, mPatch false, mLimit
1821
         * true
1822
         */
1823
        void setLimit()
1824
        {
1825
            mLogger.debug("setPatch");
1826
            resetData();
1827
            mLimit = true;
1828
        }
1829
 
1830
        /**
1831
         * sets parameters to indicate that the change type is Fixed. The
1832
         * version number is set by the user and a ripple will not be calculated
1833
         */
1834
        void setFixed()
1835
        {
1836
            mLogger.debug("setFixed");
1837
            resetData();
1838
            mFixed = true;
1839
        }
1840
 
1841
        /**
1842
         * Sets parameters to indicate that the change type is not known
1843
         * 
1844
         */
1845
        void setUnknown()
1846
        {
1847
            resetData();
1848
            mUnknown = true;
1849
        }
1850
 
1851
    }
1852
 
7070 dpurdie 1853
    /**
1854
     *  Add a package dependency
1855
     *  UTF Use
1856
     *  @param p - The package to add as a dependent
1857
     *  @return - The current package to allow chaining of calls
1858
     */
1859
    public Package addDependency(Package p) {
1860
        mDependencyCollection.add(p.mAlias);
1861
        mDependencyIDCollection.add(p.mId);
1862
        return this;
1863
    }
1864
 
7071 dpurdie 1865
    /** Clear the packages list of dependencies
1866
     *  UTF use
1867
     *  @return - The current package to allow chaining of calls
1868
     */
1869
    public Package resetDependencies() {
1870
        mDependencyCollection.clear();
1871
        mDependencyIDCollection.clear();
1872
        return this;
1873
    }
1874
 
6914 dpurdie 1875
}