Subversion Repositories DevTools

Rev

Rev 7050 | 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
	 */
7048 dpurdie 367
 
6914 dpurdie 368
    public char mRippleStop;
7048 dpurdie 369
 
370
    /**
371
     *  The calculated ripple build plan for this package
372
     *  Will not be calculated for all packages, just those of interest
373
     *  All packages that can (not must) be built when this package is built
374
     *  The list will not include packages that cannot be built at the moment
375
     *  
376
     *  Does not include this package
377
     */
378
    public ArrayList<Package> mRipplePlan = null;
379
 
380
    /** The duration (seconds) of the last build of this package
381
     *  Used to estimate the cost of building the package
382
     *  A WIP packages gets the buildTime of the package its based upon
383
     */
384
    public int mBuildTime;
6914 dpurdie 385
 
7048 dpurdie 386
    /** Calculated time ( seconds) that is may take to build this package and then ripple packages that depend on it
387
     *  both directly and indirectly. Based on mRipplePlan. 
388
     */
389
    public int mRippleTime = 0;
390
 
391
    /** Set to indicate that the package is NOT a part of the full release set
392
     *  The package is a WIP, TestBuild or a ForcedRipple
393
     *  
394
     *   Used to simplify detection of such packages and to limit processing of these packages
395
     *   May be cleared if the package is added to the full set
396
     */
397
    public boolean mIsNotReleased = false;
398
 
6914 dpurdie 399
    /**
400
     * Constructor
401
     * Used to create planned packages. In these packages the change_type is significant
402
     * 
403
     * @param pkg_id	   Package Name Identifier
404
     * @param pv_id        Package Version Id
405
     * @param pkg_name     Package Name
406
     * @param pkg_version  Package Version
407
     * @param v_ext        Package Suffix
408
     * @param alias        Package Alias
409
     * @param pkg_vcs_tag  Vcs Tag
410
     * @param ripple_field Ripple Field
411
     * @param change_type  Change Type
412
     */
7051 dpurdie 413
    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 414
    {
415
        mLogger.debug("Package 1: pv_id " + pv_id + " pkg_name " + pkg_name + " v_ext " + v_ext + " alias " + alias
416
                + " pkg_vcs_tag " + pkg_vcs_tag + " change_type " + change_type);
417
        mId = pv_id;
418
        mName = pkg_name;
419
        mPid = pkg_id;
420
        mVersion = "0.0.0000";
421
        mExtension = v_ext;
422
        mAlias = alias;
423
        mVcsTag = pkg_vcs_tag;
424
 
425
        // Remove the package suffix from package_version to create the fixed version number
426
        mFixedVersion = pkg_version;
427
        mFixedVersion = mFixedVersion.substring(0, mFixedVersion.length() - mExtension.length());
428
 
429
        // a ripple_field of 'L' indicates this package has limited version numbering
430
        if (change_type == 'M') {
431
            mChangeType.setMajor(ripple_field == 'L' ? true : false);
432
 
433
        } else if (change_type == 'N') {
434
            mChangeType.setMinor(ripple_field == 'L' ? true : false);
435
 
436
        } else if (change_type == 'P') {
437
            mChangeType.setPatch(ripple_field == 'L' ? true : false);
438
 
439
        } else if (change_type == 'F') {
440
            mChangeType.setFixed();
441
 
442
        } else {
443
            mChangeType.setUnknown();
444
        }
445
    }
446
 
447
    /**
448
     * Constructor
449
     * Used to create existing packages, in these packages the ripple_field is significant
450
     * 
451
     * @param pkg_id	   Package Name Identifier
452
     * @param pv_id        Package Version Id
453
     * @param pkg_name     Package Name
454
     * @param pkg_version  Package Version
455
     * @param v_ext        Package Suffix
456
     * @param alias        Package Alias
457
     * @param pkg_vcs_tag  Vcs Tag
458
     * @param ripple_field Ripple Field
459
     */
7051 dpurdie 460
    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 461
    {
462
        mLogger.debug("Package 2: pv_id " + pv_id + " pkg_name " + pkg_name + " pkg_version " + pkg_version + " v_ext "
463
                + v_ext + " alias " + alias + " pkg_vcs_tag " + pkg_vcs_tag + " ripple_field " + ripple_field);
464
        mId = pv_id;
465
        mName = pkg_name;
466
        mPid = pkg_id;
467
        mVersion = pkg_version;
468
        int endindex = mVersion.length() - v_ext.length();
469
 
470
        if (endindex > 0)
471
        {
472
            mVersion = mVersion.substring(0, endindex);
473
        }
474
 
475
        mExtension = v_ext;
476
        mAlias = alias;
477
        mVcsTag = pkg_vcs_tag;
478
 
479
        // setBuild is the default
480
        if (ripple_field == 'M') {
481
            mRippleField.setMajor();
482
 
483
        } else if (ripple_field == 'm') {
484
            mRippleField.setMinor();
485
 
486
        } else if (ripple_field == 'p') {
487
            mRippleField.setPatch();
488
 
489
        } else if (ripple_field == 'L') {
490
            mRippleField.setLimit();
491
        }
492
    }
493
 
494
    /**
495
     * constructor
496
     */
497
    Package()
498
    {
499
        mLogger.debug("Package 3");
500
        mId = 0;
501
        mName = "null";
502
        mExtension = "null";
503
        mAlias = "null";
504
        mVcsTag = "null";
505
    }
506
 
507
    /**
7049 dpurdie 508
     * Constructor for unit test purposes
7051 dpurdie 509
     *  Will invoke applyPV and save the results for the UTF framework
6914 dpurdie 510
     */
511
    public Package(ReleaseManager rm, String version, int majorLimit, int minorLimit, int patchLimit, int buildNumberLimit)
512
    {
513
        mId = -1;
514
        mRippleField.setLimit();
515
        mVersion = version;
516
        mMajorLimit = majorLimit;
517
        mMinorLimit = minorLimit;
518
        mPatchLimit = patchLimit;
519
        mBuildLimit = buildNumberLimit;
520
 
521
        if (version.endsWith(".cots"))
522
        {
523
            mExtension = ".cots";
524
            mVersion = version.substring(0, version.length() - 5);
525
            mChangeType.setMajor(false);
526
            mChangeType.setMinor(false);
527
            mChangeType.setPatch(true);
528
            mRippleField.setBuild();
529
        }
530
 
531
        try
532
        {
7050 dpurdie 533
            mId = applyPV(rm);
6914 dpurdie 534
        } catch (Exception e)
535
        {
536
        }
537
    }
538
 
539
    /**
7051 dpurdie 540
     * Constructor for unit test purposes
541
     * Performs a partial copy of a package - sufficient for test purposes
542
     * @param base      - Base package  
543
     * @param newPvId   - New pvid of the package
544
     */
545
    public Package(int newPvId, Package base) {
546
 
547
        mId = newPvId;
548
        mPid = base.mPid;
549
        mName = base.mName;
550
        mExtension = base.mExtension;
551
        mVersion = base.mVersion;
552
        mAlias = base.mAlias;
553
        mVcsTag = base.mVcsTag;
554
        mFixedVersion = base.mFixedVersion;
555
        mChangeType = base.mChangeType;
556
        mRippleField = base.mRippleField;
557
        mBuildTime = base.mBuildTime;
558
        mHasAutomatedUnitTests = base.mHasAutomatedUnitTests;
559
        mSeqId = base.mSeqId;
560
 
561
        mBuildFailureEmailCollection = (Vector<String>) base.mBuildFailureEmailCollection.clone();
562
        mPackageDependencyCollection = (Vector<Package>) base.mPackageDependencyCollection.clone();
563
        mDependencyIDCollection = (Vector<Integer>) base.mDependencyIDCollection.clone();
564
        mDependencyCollection = (Vector<String>) base.mDependencyCollection.clone();
565
        mBuildStandardCollection = (Vector<BuildStandard>) base.mBuildStandardCollection.clone();
566
 
567
    }
568
 
569
    /**
6914 dpurdie 570
     * accessor for unit test purposes
571
     */
572
    public int getId()
573
    {
574
        return mId;
575
    }
576
 
577
    /**
578
     * accessor for unit test purposes
579
     */
580
    public String getVersion()
581
    {
582
        return mVersion;
583
    }
584
 
7049 dpurdie 585
    /**
586
     * accessor for unit test purposes
587
     */
588
    public String getNextVersion()
589
    {
590
        return mNextVersion;
591
    }
592
 
6914 dpurdie 593
 
594
    /**
595
     * returns true if mBuildStandardCollection is not empty
596
     */
597
    boolean isReproducible()
598
    {
7048 dpurdie 599
        mLogger.debug("isReproducible on Package {}", mName);
6914 dpurdie 600
        boolean retVal = ! mBuildStandardCollection.isEmpty();
7048 dpurdie 601
        mLogger.info("isReproducible returned {}", retVal);
6914 dpurdie 602
        return retVal;
603
    }
604
 
605
 
606
    /**
607
     * returns true if at least one of its BuildStandards has mGeneric true
608
     */
609
    boolean isGeneric()
610
    {
7048 dpurdie 611
        mLogger.debug("isGeneric on Package {}", mName);
6914 dpurdie 612
        boolean retVal = false;
613
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
614
        {
615
            BuildStandard buildStandard = it.next();
616
 
617
            if (buildStandard.isGeneric())
618
            {
619
                retVal = true;
620
                break;
621
            }
622
        }
623
 
7048 dpurdie 624
        mLogger.info("isGeneric returned {}", retVal);
6914 dpurdie 625
        return retVal;
626
    }
627
 
628
    /**
629
     * Returns true if at least one of the packages build standards can be 
630
     * built in the named machine class. 
631
     *  
632
     * Used to determine if the package can be built with the current buildset 
633
     * by iteration over all machine classes in the buildset. 
634
     */
635
    boolean canBeBuildby(String machineClass)
636
    {
637
        mLogger.debug("canBeBuildby on Package " + mName);
638
        boolean retVal = false;
639
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
640
        {
641
            BuildStandard buildStandard = it.next();
642
 
643
            if (buildStandard.isGeneric())
644
            {
645
                retVal = true;
646
                break;
647
            }
648
 
649
            if (buildStandard.mMachClass.equals(machineClass))
650
            {
651
                retVal = true;
652
                break;
653
            }
654
        }
655
 
656
        mLogger.info("canBeBuildby returned " + retVal);
657
        return retVal;
658
    }
659
 
660
    /**
661
     * Compare the build standards of two packages 
662
     * Used only in escrow mode 
663
     * Used to compare a package and its dependents (one by one) 
664
     *  
665
     * Returns true if the parent (this) package  can be built in the same escrow 
666
     * build iteration as the dependent package. 
667
     *  
668
     * This is a complex decision and has a few built in assumptions. 
669
     *  
670
     * If the dependent package is 'generic' then the parent package can be built 
671
     *  
672
     * If the parent package is generic then is can only be built if the dependent is 
673
     * also generic. Otherwise we must assume that the parent package is an agregator 
674
     * package and requires artifacts from the dependent package built by all of its 
675
     * required build machines. 
676
     *  
677
     * If both packages are not generic, then if the build standards of the parent and the 
678
     * dependent are identical then 
679
     *  
680
     *      If we have one build standard, we can build the parent in this iteration as
681
     *      the dependent package has been completely built.
682
     *  
683
     *      If we have more than one build standard ( but they are identical ) then we
684
     *      ASSUME that we can build the parent in this iteration. The assumption is that
685
     *      there is no mixing between build machines. ie: Windows consumer users Windows
686
     *      artifacts and the Linux consumer uses Linux artifacts ...
687
     *  
688
     * If both packages are not generic and the build standards are not identical, then 
689
     * things get hard. The safest solution is to assume the parent cannot be built in this 
690
     * iteration. This is not a bad assumption. 
691
     *  
692
     */
693
    boolean haveSameBuildStandards(Package d)
694
    {
695
        HashMap<String, Boolean> standardSet = new HashMap<String, Boolean>();
696
        boolean isGeneric = false;
697
        boolean isGeneric_d = false;
698
        boolean isIdentical = true;
699
 
700
        // Scan the build standards of the parent package and create a hash map for each machine
701
        // class required by the parent. Also determine if the parent is generic.
702
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
703
        {
704
            BuildStandard bs = it.next();
705
            standardSet.put(bs.mMachClass, false);
706
 
707
            if (bs.isGeneric())
708
            {
709
                isGeneric = true;
710
                break;
711
            }
712
        }
713
 
714
        // Scan the build standards in the dependent package and remove items from the map
715
        // If it was not in the map then the dependent package builds for platforms that the
716
        // parent package does not - thus the build standards cannot be identical
717
        // Also determine if the dependent is generic.
718
        for (Iterator<BuildStandard> it = d.mBuildStandardCollection.iterator(); it.hasNext();)
719
        {
720
            BuildStandard bs = it.next();
721
             if (bs.isGeneric())
722
             {
723
             isGeneric_d = true;
724
             break;
725
             }
726
 
727
            Boolean value = standardSet.remove(bs.mMachClass);
728
            if (value == null)
729
            {
730
                isIdentical = false;
731
                break;
732
            }
733
        }
734
 
735
        //
736
        // If there are any items left in the map then the parent package builds on machines
737
        // that the dependent does not. The two are not identical.
738
 
739
        if (!standardSet.isEmpty())
740
        {
741
            isIdentical = false;
742
        }
743
 
744
        // If dependent is generic, then it will be build on the first platform in this iteration
745
        // All is good
746
 
747
        if( isGeneric_d)
748
            return true;
749
 
750
        //  If I am generic and the dependent is generic, then I can be built at this time
751
        // 
752
        //  Will not reach here as we have already said that if dependenbt is generic, then all is good
753
        //  if (isGeneric_d && isGeneric)
754
        //  {
755
        //      return true;
756
        //  }
757
 
758
 
759
        //  If I am generic then I must wait for ALL dependent to be built on all platforms
760
        //  Thus I can't be built this round
761
        //
762
        if (isGeneric)
763
            return false;
764
 
765
        //
766
        //  If the two sets of build standards don't have generic, BUT are identical
767
        //  the we can assume that there is no cross breading. and that windows bits build from windows bits
768
        //  and solaris bits build from solaris
769
        //
770
        if (isIdentical)
771
            return true;
772
 
773
        //  The two sets of build standards are not an exact match
774
        //  Cheap solution: Assume that I can't be built this round
775
        //  Possible solution: If I am a subset of the dependent - then I can be built
776
        //                     If I am a superset of the dependent - then ???
777
        return false;
778
 
779
    }
780
 
781
    /**
7048 dpurdie 782
     * Applies the required version number change. Will calculate mNextVersion
7050 dpurdie 783
     * while not changing mVersion.
6914 dpurdie 784
     * 
785
     * @param releaseManager    Release Manager instance to work against
786
     * 
7048 dpurdie 787
     * @return 0 : success
788
     *         1 : cannot work with non standard versioning
789
     *         2 : ripple field limitations prevent a ripple build
790
     *         3 : Invalid Change Type
6914 dpurdie 791
     * @exception Exception
792
     */
7050 dpurdie 793
 
794
    int applyPV(ReleaseManager releaseManager) throws Exception
6914 dpurdie 795
    {
796
        String logInfo = "applyPV," + mName;
797
        mLogger.debug("applyPV on Package " + mName);
7048 dpurdie 798
 
6914 dpurdie 799
        //
7048 dpurdie 800
        //  This method used to actually perform the version change
801
        //  Now it just calculates the potential value
802
        //  Must not alter mVersion as it will be used if the package is not selected to be built,
803
        //  but some of the code assumes that it can be.
804
        //
805
        String originalVersion = mVersion;
806
 
807
        //
6914 dpurdie 808
        // Four scenarios, only applyPV for 3 of them
809
        // mDirectlyPlanned mIndirectlyPlanned mArchivalExistence mForcedRipple
810
        // Action
811
        // WIP/test build exists: true true don't care don't care applyPV
812
        // Package version is out of date: false true true don't care applyPV
813
        // Forced ripple: false true don't care > 0 applyPV
814
        // Package version does not exist: false true false = 0 do not applyPV
815
        //
816
        if (!mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence && mForcedRippleInstruction == 0)
817
        {
818
            // the package has an mIndirectlyPlanned flag set true in daemon
819
            // mode because the package does not exist in an archive
820
            // do not apply a different package version
7048 dpurdie 821
            mLogger.info("applyPV. Rebuild Package {}", mName);
6914 dpurdie 822
            mLogger.info("applyPv returned 0");
823
            return 0;
824
        }
825
 
826
        // override - no longer doing a rebuild - version number change from this point on
827
        if (mTestBuildInstruction == 0)
828
        {
829
            mRequiresSourceControlInteraction = true;
830
        }
831
 
832
        //	Force test builds to use a sensible version number
833
        if (mTestBuildInstruction > 0 )
834
        {
835
        	mChangeType.resetData();		// Resolve conflict via build numbers
836
        	mRippleField.setBuild();
837
        	mVersion = "99.99.98999";		// Such that rippling build number will goto 99.99.99000
838
        }
839
 
840
        //
841
        // Detect invalid change type
842
        // Flagged when package instance is created
843
        //
844
        if (mChangeType.mUnknown)
845
        {
7048 dpurdie 846
            mLogger.info("Package Version specified on Package {} New Version: {}", mName, mVersion);
6914 dpurdie 847
            mLogger.info("applyPv returned 3");
848
            return 3;
849
        }
850
 
851
        // If we are not calculating the new package version because the user
852
        // has fixed the version of the package. We are given the new package version.
853
        if (mChangeType.mFixed)
854
        {
855
            // mVersion is already setup
856
 
7048 dpurdie 857
            mNextVersion = mFixedVersion;
858
            mLogger.info("Package Version specified on Package {} New Version: {}", mName,  mVersion);
6914 dpurdie 859
            mLogger.info("applyPv returned 0");
860
            return 0;
861
        }
862
 
863
        // We need to calculate the new version number
864
        //
865
        MutableInt major = new MutableInt(0);
866
        MutableInt minor = new MutableInt(0);
867
        MutableInt patch = new MutableInt(1000);
868
 
869
        // Planned packages have a previous version number to be used as the bases for the
870
        // calculation. Ripples won't.
871
        //
872
        if (mPrevVersion != null)
873
        {
874
        	mVersion = mPrevVersion;
875
        }
876
        String[] field = mVersion.split("\\D");
877
        String nonStandardCotsVersion = "";
878
        logInfo += ", Prev:" + mVersion;
879
 
880
        if (field.length == 3)
881
        {
882
            major.value = Integer.parseInt(field[0]);
883
            minor.value = Integer.parseInt(field[1]);
884
            patch.value = Integer.parseInt(field[2]);
885
        } 
886
        else
887
        {
888
            //
889
            // Can ripple a .cots package under very controlled conditions
890
            // Its ends with a .patchBuild field
891
            // Package is marked as ripple via build number
892
            // Change type of Major and Minor are not allowed
893
            //
7048 dpurdie 894
            if (!mChangeType.mMajor && !mChangeType.mMinor && mRippleField.mBuild && mExtension.compareTo(".cots") == 0 && field.length > 0)
6914 dpurdie 895
            {
896
                // allow and work with (ripple build) versions a.b.c.d....xxxx
897
                // where xxxx.length > 3
898
                String patchStr = field[field.length - 1];
899
                int patchLen = patchStr.length();
900
 
901
                // check patchStr is the last (at least 4) digits
902
                if (patchLen > 3
903
                        && mVersion.substring(mVersion.length() - patchLen, mVersion.length()).compareTo(patchStr) == 0)
904
                {
905
                    patch.value = Integer.parseInt(patchStr);
906
                    nonStandardCotsVersion = mVersion.substring(0, mVersion.length() - patchLen);
907
                }
908
            }
909
 
910
            if (nonStandardCotsVersion.length() == 0)
911
            {
912
                // cannot work with non standard versioning
913
                mLogger.error("applyPV cannot work with non standard versioning");
914
                mLogger.info("applyPv returned 1");
915
                return 1;
916
            }
917
        }
918
 
919
        if (nonStandardCotsVersion.length() == 0 && patch.value < 1000 && field[2].substring(0, 1).compareTo("0") != 0)
920
        {
7048 dpurdie 921
            mLogger.info("applyPV accomodate old style Version of the form 1.0.1");
6914 dpurdie 922
            patch.value = patch.value * 1000;
923
        }
924
 
925
        // mChangeType overrides mRippleField
926
        do
927
        {
928
            if (mChangeType.mMajor)
929
            {
930
                logInfo += ",CT Major";
931
                if (!incrementFieldsAccordingToLimits(4, major, minor, patch))
932
                {
933
                    mLogger.info("applyPv returned 2");
7048 dpurdie 934
                    mVersion = originalVersion;
6914 dpurdie 935
                    return 2;
936
                }
937
            } else if (mChangeType.mMinor)
938
            {
939
                logInfo += ",CT Minor";
940
                if (!incrementFieldsAccordingToLimits(3, major, minor, patch))
941
                {
942
                    mLogger.info("applyPv returned 2");
7048 dpurdie 943
                    mVersion = originalVersion;
6914 dpurdie 944
                    return 2;
945
                }
946
            } else if (mChangeType.mPatch)
947
            {
948
                logInfo += ",CT Patch";
949
                if (!incrementFieldsAccordingToLimits(2, major, minor, patch))
950
                {
951
                    mLogger.info("applyPv returned 2");
7048 dpurdie 952
                    mVersion = originalVersion;
6914 dpurdie 953
                    return 2;
954
                }
955
            } else
956
            {
957
                if (mRippleField.mMajor)
958
                {
959
                    logInfo += ",R Major";
960
                    major.value++;
7048 dpurdie 961
                    mLogger.info("applyPV mRippleField.mMajor {}", major.value);
6914 dpurdie 962
                    minor.value = 0;
963
                    patch.value = 0;
964
                } else if (mRippleField.mMinor)
965
                {
966
                    logInfo += ",R Minor";
967
                    minor.value++;
7048 dpurdie 968
                    mLogger.info("applyPV mRippleField.mMinor {}", minor.value);
6914 dpurdie 969
                    patch.value = 0;
970
                } else if (mRippleField.mPatch)
971
                {
972
                    logInfo += ",R Patch";
973
                    patch.value = ((patch.value / 1000) + 1) * 1000; 
7048 dpurdie 974
                    mLogger.info("applyPV mRippleField.mPatch {}", patch.value);
6914 dpurdie 975
                } else if (mRippleField.mBuild)
976
                {
977
                    logInfo += ", R Build";
978
                    patch.value++;
7048 dpurdie 979
                    mLogger.info("applyPV mRippleField.mBuild {}", patch.value);
6914 dpurdie 980
                } else
981
                {
982
                    if (!incrementFieldsAccordingToLimits(1, major, minor, patch))
983
                    {
984
                        mLogger.info("applyPv returned 2");
7048 dpurdie 985
                        mVersion = originalVersion;
6914 dpurdie 986
                        return 2;
987
                    }
988
                }
989
            }
990
 
991
            if (nonStandardCotsVersion.length() == 0)
992
            {
993
                mVersion = String.valueOf(major.value) + "." + String.valueOf(minor.value) + ".";
994
            } else
995
            {
996
                mVersion = nonStandardCotsVersion;
997
            }
998
 
999
            if (patch.value < 10)
1000
            {
1001
                mVersion += "000";
1002
            } else if (patch.value < 100)
1003
            {
1004
                mVersion += "00";
1005
            } else if (patch.value < 1000)
1006
            {
1007
                mVersion += "0";
1008
            }
1009
 
1010
            mVersion += String.valueOf(patch.value);
7050 dpurdie 1011
        } while (exists(releaseManager));
6914 dpurdie 1012
 
7048 dpurdie 1013
        logInfo += ", Next Version:" + mVersion;
7033 dpurdie 1014
        mLogger.error(logInfo);
6914 dpurdie 1015
        mLogger.info("applyPv returned 0");
7048 dpurdie 1016
        mNextVersion = mVersion;
1017
        mVersion = originalVersion;
6914 dpurdie 1018
        return 0;
1019
    }
1020
 
1021
    /**
1022
     * increments fields according to mRippleField.mLimit if necessary will
1023
     * apply it to the field passed as follows 1 = build 2 = patch 3 = minor
1024
     * other = major returns true on success false on ripple field limitations
1025
     * prevent a ripple build
1026
     */
1027
    private boolean incrementFieldsAccordingToLimits(int field, MutableInt major, MutableInt minor, MutableInt patch)
1028
    {
1029
        boolean retVal = true;
1030
 
1031
        if (!mChangeType.mLimit && !mRippleField.mLimit)
1032
        {
1033
            // simple case
1034
            // no need to take field limits into consideration
1035
            switch (field)
1036
            {
1037
            case 1:
1038
                // unreachable
1039
                // the only scenario involving build number manipulation
1040
                // involves the mRippleField.mLimit being set
1041
                retVal = false;
1042
                break;
1043
            case 2:
1044
                do
1045
                {
1046
                    patch.value++;
1047
                } while ((patch.value / 1000) * 1000 != patch.value);
1048
                mLogger.info("incrementFieldsAccordingToLimits patch " + patch.value);
1049
                break;
1050
            case 3:
1051
                minor.value++;
1052
                mLogger.info("incrementFieldsAccordingToLimits minor " + minor.value);
1053
                patch.value = 0;
1054
                break;
1055
            default:
1056
                major.value++;
1057
                mLogger.info("incrementFieldsAccordingToLimits major " + major.value);
1058
                minor.value = 0;
1059
                patch.value = 0;
1060
            }
1061
        } else
1062
        {
1063
            // take field limits into consideration
1064
            boolean changeOccurred = false;
1065
            boolean incrementField = true;
1066
 
1067
            switch (field)
1068
            {
1069
            case 1:
1070
                if (mBuildLimit != 0)
1071
                {
1072
                    // increment or reset the patch build number
1073
                    int buildNumber = patch.value - (patch.value / 1000) * 1000;
1074
 
1075
                    if (buildNumber < mBuildLimit)
1076
                    {
1077
                        // can increment the patch build number
1078
                        patch.value++;
1079
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit build number " + patch.value);
1080
                        changeOccurred = true;
1081
                        incrementField = false;
1082
                    } else
1083
                    {
1084
                        if (mPatchLimit == 0)
1085
                        {
1086
                            // reset the patch number and patch build number
1087
                            patch.value = 0;
1088
                        }
1089
                    }
1090
                }
1091
                // no break by design
1092
            case 2:
1093
                if (mPatchLimit != 0 && incrementField)
1094
                {
1095
                    // increment or reset the patch number
1096
                    if ((patch.value / 1000) < mPatchLimit)
1097
                    {
1098
                        do
1099
                        {
1100
                            patch.value++;
1101
                        } while ((patch.value / 1000) * 1000 != patch.value);
1102
 
1103
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit patch " + patch.value);
1104
                        changeOccurred = true;
1105
                        incrementField = false;
1106
                    } else
1107
                    {
1108
                        // reset the patch number and patch build number
1109
                        patch.value = 0;
1110
                    }
1111
                }
1112
                // no break by design
1113
            case 3:
1114
                if (mMinorLimit != 0 && incrementField)
1115
                {
1116
                    // increment or reset the minor number
1117
                    if (minor.value < mMinorLimit)
1118
                    {
1119
                        minor.value++;
1120
                        patch.value = 0;
1121
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit minor " + minor.value);
1122
                        changeOccurred = true;
1123
                        incrementField = false;
1124
                    } else
1125
                    {
1126
                        // reset the minor number
1127
                        minor.value = 0;
1128
                    }
1129
                }
1130
                // no break by design
1131
            default:
1132
                if (mMajorLimit != 0 && incrementField)
1133
                {
1134
                    // increment or reset the major number
1135
                    if (major.value < mMajorLimit)
1136
                    {
1137
                        // increment the major number
1138
                        changeOccurred = true;
1139
                        major.value++;
1140
                        minor.value = 0;
1141
                        patch.value = 0;
1142
                        mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit major " + major.value);
1143
                    }
1144
                }
1145
            }
1146
 
1147
            if (!changeOccurred)
1148
            {
1149
                // unable to increment a field due to field limitations
1150
                mLogger.error("incrementFieldsAccordingToLimits ripple field limitations prevent a ripple build");
1151
                mLogger.info("incrementFieldsAccordingToLimits returned false");
1152
                retVal = false;
1153
            }
1154
        }
1155
 
1156
        return retVal;
1157
    }
1158
 
1159
    /**
7048 dpurdie 1160
     * Check if a specified Version of the package exists in dpkg_archive or the Release Manager Database
6914 dpurdie 1161
     * 
1162
     * @param releaseManager Release Manager Instance
1163
     * 
1164
     * @return True if the Package Version exists within the Release Manager Database
1165
     * @exception Exception
1166
     */
7050 dpurdie 1167
    private boolean exists(ReleaseManager releaseManager) throws Exception
6914 dpurdie 1168
    {
1169
        mLogger.debug("exists on Package " + mName + " version " + mVersion + " extension " + mExtension);
1170
        boolean retVal = false;
1171
 
7048 dpurdie 1172
        if (!releaseManager.mUseDatabase)
6914 dpurdie 1173
        {
1174
            mLogger.info("exists !releaseManager.mUseDatabase");
1175
        }
1176
        else
1177
        {
1178
            //  Check Package Archive
1179
            retVal = existsInDpkgArchive();
1180
            if (!retVal)
1181
            {
1182
                //  Check Release Manager Database
1183
                retVal = releaseManager.queryPackageVersions(mPid, mVersion + mExtension);
1184
            }
1185
        }
1186
 
1187
        mLogger.info("exists returned " + retVal);
1188
        return retVal;
1189
    }
1190
 
1191
 
1192
    /**
1193
     * Check to see if a package exists in dpkg_archive
1194
     * 
1195
     * @return true if the version exists in dpkg_archive
1196
     * @exception Exception Thrown if dpkg_archive does not exist. The 'cause' of 'mRecoverable' is special and
1197
     *                      will be trapped later to determine if this is a recoverable exception.
1198
     */
1199
    boolean existsInDpkgArchive() throws Exception
1200
    {
1201
        mLogger.debug("existsInDpkgArchive on " + mName);
1202
        boolean retVal = false;
1203
        String name = utilities.catDir(mName, mVersion + mExtension );
1204
 
1205
        //  If a replica exists, then check it first
1206
        //  If we are configured with a replica its because access to the main archive is slow
1207
        //  and we want this check to be fast
1208
        //
1209
        if (mGbeDpkgReplica != null && mGbeDpkgReplica.length() > 0)
1210
        {
1211
            File dpkg = new File(mGbeDpkgReplica);
1212
            if (!dpkg.exists())
1213
            {
7033 dpurdie 1214
                mLogger.error("existsInDpkgArchive. mGbeDpkgReplica not accessable. " + mRecoverable);
6914 dpurdie 1215
                throw new Exception(mRecoverable);
1216
            }
1217
 
1218
            if( utilities.freshFileExists(utilities.catDir(mGbeDpkgReplica, name) ) )
1219
            {
1220
                mLogger.info("existsInDpkgArchive mGbeDpkgReplica");
1221
                retVal = true;
1222
            }
1223
        }
1224
 
1225
        //  Check (possibly remote) dpkg_archive for files existence if it was not found locally
1226
        //
1227
        if ( !retVal )
1228
        {
1229
 
1230
            //  If the package archive does not exist at the moment, then we have a network issue
1231
            //  This is a recoverable error
1232
 
1233
            File dpkg = new File(mGbeDpkg);
1234
            if (!dpkg.exists())
1235
            {
7033 dpurdie 1236
                mLogger.error("existsInDpkgArchive. mGbeDpkg not accessable. " + mRecoverable);
6914 dpurdie 1237
                throw new Exception(mRecoverable);
1238
            }
1239
 
1240
            if( utilities.freshFileExists(utilities.catDir(mGbeDpkg, name) ) )
1241
            {
1242
                mLogger.info("existsInDpkgArchive mGbeDpkg");
1243
                retVal = true;
1244
            }
1245
        }
1246
 
1247
        mArchivalExistence = retVal;
1248
        mLogger.info("existsInDpkgArchive returned " + retVal);
1249
        return retVal;
1250
    }
1251
 
1252
    /**
1253
     * returns true if the required package archives (dpkg_archive) exist
1254
     * attempt to recover from their transient loss
1255
     */
1256
    public static boolean recover()
1257
    {
1258
        mLogger.debug("recover");
1259
        boolean retVal = false;
1260
 
1261
        String Release = mGbeDpkg;
1262
        if (Release != null)
1263
        {
1264
            if ( utilities.freshFileExists(mGbeDpkg) )
1265
            {
1266
                retVal = true;
7033 dpurdie 1267
                mLogger.error("recover: dpkg_archive access has been restored");
6914 dpurdie 1268
            }
1269
        }
1270
 
1271
        mLogger.info("recover returned " + retVal);
1272
        return retVal;
1273
    }
1274
 
1275
    /**
1276
     * Returns a data structure of unique email addresses
1277
     * Uses the Global Email Collection and the packages own failure email collection
1278
     */
1279
    private LinkedHashSet<String>buildEmailList(RippleEngine rippleEngine)
1280
    {
1281
        //  Create a single list of email targets ensuring only one instance of each email address
1282
        //  ie: Remove duplicates, null and empty strings
1283
        LinkedHashSet<String> hs = new LinkedHashSet<String>();
1284
 
1285
        // Global and Project Wide emails
1286
        for (Iterator<String> it = rippleEngine.mMailGlobalCollection.iterator(); it.hasNext();)
1287
        {
1288
            String item = it.next();
1289
            if (item != null && item.length() > 0) 
1290
            {
1291
                hs.add(item);
1292
            }
1293
        }
1294
 
1295
        // Package specific collection
1296
        for (Iterator<String> it = mBuildFailureEmailCollection.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
        return hs;
1306
    }
1307
 
1308
    /**
1309
     * Add email information in a form suitable for creating an Ant file
1310
     * @param   rippleEngine    - Ripple Engine Instance
1311
     * @param   xml             - An XmlBuilder element to extend
1312
     */
1313
    void emailInfo(RippleEngine rippleEngine, XmlBuilder xml)
1314
    {
1315
 
1316
        //  Create a single list of email targets ensuring only one instance of each email address
1317
        //  ie: Remove duplicates
1318
        LinkedHashSet<String> hs = buildEmailList(rippleEngine);
1319
 
1320
        for (Iterator<String> it = hs.iterator(); it.hasNext();)
1321
        {
1322
            String email = it.next();
1323
            XmlBuilder entry = xml.addNewElement("owner");
1324
            entry.addAttribute("email", email);
1325
        }
1326
    }
1327
 
1328
    /**
1329
     * Returns email information in a form suitable for direct use
1330
     * @param   rippleEngine Current Release Manager context
1331
     * @return  A comma separated list of user names. May return a 'null' String
1332
     */
1333
    String emailInfoNonAntTask(RippleEngine rippleEngine)
1334
    {
1335
        //  Create a single list of email targets ensuring only one instance of each email address
1336
        //  ie: Remove duplicates
1337
        LinkedHashSet<String> hs = buildEmailList(rippleEngine);
1338
 
1339
        String retVal = null;
1340
        for (Iterator<String> it = hs.iterator(); it.hasNext();)
1341
        {
1342
            String email = it.next();
1343
 
1344
            if (retVal == null)
1345
            {
1346
                retVal = new String();
1347
            } else
1348
            {
1349
                retVal += ",";
1350
            }
1351
            retVal += email;
1352
        }
1353
 
1354
        return retVal;
1355
    }
1356
 
1357
    /**
1358
     * Adds email to mBuildFailureEmailCollection.
1359
     * Do not worry about multiple entries. These will be handled when the data is extracted
7048 dpurdie 1360
     * @param   email   - Email address. Null is allowed and will not be added
6914 dpurdie 1361
     */
1362
    public void addEmail(String email)
1363
    {
7048 dpurdie 1364
        if (email != null) 
6914 dpurdie 1365
        {
7048 dpurdie 1366
            mBuildFailureEmailCollection.add(email);
6914 dpurdie 1367
        }
1368
    }
1369
 
1370
    /**
1371
     * End of Processing for a Test Build
1372
     *     - sends email notification
1373
     *     - marks the instruction complete in the database
1374
     */
1375
    public void completeTestBuild(RippleEngine rippleEngine, boolean success) throws SQLException, Exception
1376
    {
1377
        mLogger.debug("completeTestBuild");
1378
 
1379
        if (mTestBuildInstruction == 0)
1380
        {
1381
            mLogger.info("completeTestBuild. Not Build Instruction");
1382
            return;
1383
        }
1384
 
1385
        //  Email Subject
1386
        String subject = (success == true ? "TEST BUILD COMPLETED SUCCESSFULLY" : "TEST BUILD FAILED") 
1387
                + " on package "
1388
                + mAlias;
1389
 
1390
        // Email Body
1391
        String mailBody = "";
1392
        if ( success != true)
1393
        {
1394
            mailBody += "Test build issues are identified in preceding build failure email.<p>"; 
1395
        }
1396
        mailBody += "Release: " + rippleEngine.mBaselineName + "<br>" 
1397
                  + "Package: " + mAlias + "<br>" 
1398
                  + "Rm Ref: " + CreateUrls.generateRmUrl(rippleEngine.getRtagId(), mId) + "<br>" 
1399
                  + "VcsTag: " + mVcsTag + "<br>"
1400
                  + "Build dependencies:<br>";
1401
 
1402
        String indentString = "&nbsp;&nbsp;&nbsp;&nbsp;";
1403
 
1404
        for (Iterator<Package> it3 = mPackageDependencyCollection.iterator(); it3.hasNext();)
1405
        {
1406
            Package depend = it3.next();
1407
 
1408
            String dependsExtension = depend.mExtension;
1409
            String dependsVersion = depend.mVersion;
1410
 
1411
            if (dependsExtension.length() > 0)
1412
            {
1413
                dependsVersion += dependsExtension;
1414
            }
1415
            mailBody += indentString + RippleEngine.quoteString(depend.mName, dependsVersion) + "<br>";
1416
        }
1417
 
1418
        mailBody += "<br>Build standards:<br>";
1419
 
1420
        for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext();)
1421
        {
1422
            BuildStandard bs = it.next();
1423
 
1424
            String bsText = bs.getBuildStandardText();
1425
            if (bsText.length() > 0)
1426
            {
1427
                mailBody += indentString + bsText + "<br>";
1428
            }
1429
        }
1430
 
1431
        mailBody += "<p><hr>";
1432
        try
1433
        {
1434
            String target = emailInfoNonAntTask(rippleEngine);
7033 dpurdie 1435
            mLogger.error("completeTestBuildEmail Server: " + rippleEngine.getMailServer());
1436
            mLogger.error("completeTestBuildEmail Sender: " + rippleEngine.getMailSender());
1437
            mLogger.error("completeTestBuildEmail Target: " + target);
6914 dpurdie 1438
 
1439
            Smtpsend.send(rippleEngine.getMailServer(), // mailServer
1440
                    rippleEngine.getMailSender(),       // source
1441
                    target,                         // target
1442
                    rippleEngine.getMailSender(),       // cc
1443
                    null,                           // bcc
1444
                    subject,                        // subject
1445
                    mailBody,                       // body
1446
                    null                            // attachment
1447
            );
1448
        } catch (Exception e)
1449
        {
1450
            mLogger.warn("Email Failure: completeTestBuild:" + e.getMessage());
1451
        }
1452
 
1453
        // Update the Release Manager Database
1454
        rippleEngine.mReleaseManager.markDaemonInstCompleted(mTestBuildInstruction);
7033 dpurdie 1455
        mLogger.error("completeTest. Returning");
6914 dpurdie 1456
    }
1457
 
1458
 
1459
    /**
1460
     * Returns true if the package is a part of a circular dependency
1461
     * 
1462
     * If the package depends on a package with a circular dependency then the function
1463
     * will return false.
1464
     */
1465
    public boolean hasCircularDependency(RippleEngine ripEng)
1466
    {
7048 dpurdie 1467
        mLogger.debug("hasCircularDependency: {}", mAlias);
6914 dpurdie 1468
        boolean retVal = detectCircularDependency(mAlias, ripEng, null);
7048 dpurdie 1469
        mLogger.info("hasCircularDependency returned {} ", retVal);
6914 dpurdie 1470
        return retVal;
1471
    }
1472
 
1473
    /**
1474
     * Returns true is a part of a circular dependency
1475
     * Will examine all the packages sub dependencies and mark those that do have a
1476
     * circular dependency.
1477
     * 
1478
     * This process works by descending the dependency tree and dropping a bread crumb
1479
     * If the bread crumb is seen during the decent, then a circle has been detected and
1480
     * the package (with the bread crumb) will be marked as having a circular dependency
1481
     * 
1482
     *  Assumes that the caller will walk ALL packages and flag those with a circular
1483
     *  dependence AND those that depend on that package.
1484
     * 
1485
     */
1486
    private boolean detectCircularDependency(String alias, RippleEngine ripEng, Package parent)
1487
    {
1488
        mLogger.debug("detectCircularDependency");
1489
        boolean retVal = false;
1490
 
1491
        // if this package has yet to be checked for circular dependency
1492
        if (!mCheckedCircularDependency)
1493
        {
1494
            // Will be set as we drill down through dependencies
1495
            // If we see this marker (bread crumb) then we have a loop
1496
            if (mBreadCrumb != 0)
1497
            {
1498
                mBreadCrumb = 3;
1499
 
1500
                mHasCircularDependency = true;
1501
                if(parent != null && parent.mBreadCrumb != 3 )
1502
                {
1503
                    parent.mBreadCrumb = 2;
1504
                }
1505
            }
1506
            else
1507
            {
1508
                // Mark this package as potentially having a circular dependency
1509
                // Will now drill down and see if we hit a marker
1510
                mBreadCrumb = 1;
1511
 
1512
                // Recurse down the dependencies and sub dependencies
1513
                for (Iterator<String> it2 = mDependencyCollection.iterator(); it2.hasNext();)
1514
                {
1515
                    String dependencyAlias = it2.next();
1516
                    Package dependency = ripEng.findPackage(dependencyAlias);
1517
                    dependency.detectCircularDependency(alias, ripEng, this);
1518
                }
1519
 
1520
                if (mBreadCrumb == 2)
1521
                {
1522
                    mHasCircularDependency = true;
1523
                    if(parent != null && parent.mBreadCrumb != 3 )
1524
                    {
1525
                        parent.mBreadCrumb = 2;
1526
                    }
1527
                }
1528
                mBreadCrumb = 0;
1529
            }
1530
 
1531
            // Flag package as having been examined
1532
            mCheckedCircularDependency = true;
1533
        } 
1534
 
1535
        // return the persisted circular dependency outcome
1536
        retVal = mHasCircularDependency;
7048 dpurdie 1537
        mLogger.info("detectCircularDependency 2 returned {}", retVal);
6914 dpurdie 1538
        return retVal;
1539
    }
7048 dpurdie 1540
 
1541
    /** Set the sequence of all packages in the list
1542
     *  Used so that the Unit Tests function can preserve the basic ordering of the list 
1543
     */
1544
    public static void setSequence(ArrayList<Package> al)
1545
    {
1546
        int seq = 1;
1547
        for (Iterator<Package> it = al.iterator(); it.hasNext(); )
1548
        {
1549
            Package p = it.next();
1550
            p.mSeqId = seq++;
1551
        }
1552
    }
6914 dpurdie 1553
 
7048 dpurdie 1554
 
1555
    /** Comparator for sorting package collections by mSeqId
1556
     *  Used to preserve order for unit testing
1557
     */
1558
    public static final Comparator<Package> SeqComparator = new Comparator<Package>() {
1559
 
1560
        /**
1561
         * Returns -ve: p1 is less than p2
1562
         *           0: p1 = p2
1563
         *         +ve: p1 > p2
1564
         */
1565
        public int compare (Package p1, Package p2) {
1566
                return p1.mSeqId - p2.mSeqId;
1567
        }
1568
    };    
1569
 
6914 dpurdie 1570
    /**
1571
     * entity class supporting the ERG version numbering standard:
1572
     * <major>.<minor>.<patch/build> patch/build is at least a 4 digit number
1573
     * whose last 3 digits represent the build
1574
     */
1575
    public class VersionNumberingStandard
1576
    {
1577
        /**
1578
         * in terms of the mChangeType Package field, when true indicates the
1579
         * contract of the package has changed in a non backwardly compatible
1580
         * manner in terms of the mRippleField Package field, when true indicates
1581
         * the major version number will be incremented
1582
         * 
1583
         * @attribute
1584
         */
1585
        private boolean mMajor = false;
1586
 
1587
        /**
1588
         * in terms of the mChangeType Package field, when true indicates the
1589
         * contract of the package has changed in a backwardly compatible manner
1590
         * in terms of the mRippleField Package field, when true indicates the
1591
         * minor version number will be incremented
1592
         * 
1593
         * @attribute
1594
         */
1595
        private boolean mMinor = false;
1596
 
1597
        /**
1598
         * in terms of the mChangeType Package field, when true indicates the
1599
         * contract of the package has not changed, but the package has changed
1600
         * internally in terms of the mRippleField Package field, when true
1601
         * indicates the minor version number will be incremented
1602
         * 
1603
         * @attribute
1604
         */
1605
        private boolean mPatch = false;
1606
 
1607
        /**
1608
         * in terms of the mChangeType Package field, when true indicates the
1609
         * package has not changed, its dependencies potentially have in terms
1610
         * of the mRippleField Package field, when true indicates the build
1611
         * number will be incremented
1612
         * 
1613
         * @attribute
1614
         */
1615
        private boolean mBuild = true;
1616
 
1617
        /**
1618
         * in terms of the mChangeType Package field, when true indicates the
1619
         * major, minor, and patch number will be incremented according to field
1620
         * limits in terms of the mRippleField Package field, when true indicates
1621
         * the major, minor, patch and build number will be incremented
1622
         * according to field limits
1623
         * 
1624
         * @attribute
1625
         */
1626
        private boolean mLimit = false;
1627
 
1628
        /**
1629
         * in terms of the mChangeType Package field, when true indicates the
1630
         * package version number will not be rippled. The user will have fixed
1631
         * the version number. This is only application to WIP packages
1632
         * 
1633
         * @attribute
1634
         */
1635
        private boolean mFixed = false;
1636
 
1637
        /**
1638
         * in terms of the mChangeType Package field, when true indicates the
1639
         * method of rippling a package version number is not known.
1640
         * 
1641
         * @attribute
1642
         */
1643
        private boolean mUnknown = false;
1644
 
1645
        /**
1646
         * constructor
1647
         */
1648
        private VersionNumberingStandard()
1649
        {
1650
            mLogger.debug("VersionNumberingStandard");
1651
        }
1652
 
1653
        /**
1654
         * Reset all values to a known state
1655
         * 
1656
         */
1657
        void resetData()
1658
        {
1659
            mBuild = false;
1660
            mMajor = false;
1661
            mMinor = false;
1662
            mPatch = false;
1663
            mLimit = false;
1664
            mFixed = false;
1665
            mUnknown = false;
1666
        }
1667
 
1668
        /**
1669
         * sets mBuild true, mMajor false, mMinor false, mPatch false, mLimit
1670
         * false
1671
         */
1672
        void setBuild()
1673
        {
1674
            mLogger.debug("setBuild");
1675
            resetData();
1676
            mBuild = true;
1677
        }
1678
 
1679
        /**
1680
         * sets mBuild false, mMajor true, mMinor false, mPatch false, mLimit
1681
         * false
1682
         */
1683
        void setMajor()
1684
        {
1685
            mLogger.debug("setMajor");
1686
            resetData();
1687
            mMajor = true;
1688
        }
1689
 
1690
        /**
1691
         * sets mBuild false, mMajor true, mMinor false, mPatch false, mLimit
1692
         * limit
1693
         */
1694
        void setMajor(boolean limit)
1695
        {
1696
            mLogger.debug("setMajor " + limit);
1697
            resetData();
1698
            mMajor = true;
1699
            mLimit = limit;
1700
        }
1701
 
1702
        /**
1703
         * sets mBuild false, mMajor false, mMinor true, mPatch false, mLimit
1704
         * false
1705
         */
1706
        void setMinor()
1707
        {
1708
            mLogger.debug("setMinor");
1709
            resetData();
1710
            mMinor = true;
1711
        }
1712
 
1713
        /**
1714
         * sets mBuild false, mMajor false, mMinor true, mPatch false, mLimit
1715
         * limit
1716
         */
1717
        void setMinor(boolean limit)
1718
        {
1719
            mLogger.debug("setMinor " + limit);
1720
            resetData();
1721
            mMinor = true;
1722
            mLimit = limit;
1723
        }
1724
 
1725
        /**
1726
         * sets mBuild false, mMajor false, mMinor false, mPatch true, mLimit
1727
         * false
1728
         */
1729
        void setPatch()
1730
        {
1731
            mLogger.debug("setPatch");
1732
            resetData();
1733
            mPatch = true;
1734
        }
1735
 
1736
        /**
1737
         * sets mBuild false, mMajor false, mMinor false, mPatch true, mLimit
1738
         * limit
1739
         */
1740
        void setPatch(boolean limit)
1741
        {
1742
            mLogger.debug("setPatch");
1743
            resetData();
1744
            mPatch = true;
1745
            mLimit = limit;
1746
        }
1747
 
1748
        /**
1749
         * sets mBuild false, mMajor false, mMinor false, mPatch false, mLimit
1750
         * true
1751
         */
1752
        void setLimit()
1753
        {
1754
            mLogger.debug("setPatch");
1755
            resetData();
1756
            mLimit = true;
1757
        }
1758
 
1759
        /**
1760
         * sets parameters to indicate that the change type is Fixed. The
1761
         * version number is set by the user and a ripple will not be calculated
1762
         */
1763
        void setFixed()
1764
        {
1765
            mLogger.debug("setFixed");
1766
            resetData();
1767
            mFixed = true;
1768
        }
1769
 
1770
        /**
1771
         * Sets parameters to indicate that the change type is not known
1772
         * 
1773
         */
1774
        void setUnknown()
1775
        {
1776
            resetData();
1777
            mUnknown = true;
1778
        }
1779
 
1780
    }
1781
 
1782
}