Subversion Repositories DevTools

Rev

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