Subversion Repositories DevTools

Rev

Rev 7051 | 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.sql.SQLException;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.Iterator;
7
import java.util.List;
8
import java.util.ListIterator;
9
 
7033 dpurdie 10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
6914 dpurdie 12
 
13
import com.erggroup.buildtool.ripple.BuildFile.BuildFileState;
14
import com.erggroup.buildtool.ripple.ReleaseManager.BuildReason;
15
import com.erggroup.buildtool.smtp.CreateUrls;
16
import com.erggroup.buildtool.smtp.Smtpsend;
17
import com.erggroup.buildtool.utilities.StringAppender;
18
import com.erggroup.buildtool.utilities.XmlBuilder;
19
 
20
/**Plans release impact by generating a set of Strings containing build file content.
21
 */
22
public class RippleEngine
23
{
24
 
25
    /**configured mail server
26
     * @attribute
27
     */
28
    private String mMailServer = "";
29
 
30
    /**configured mail sender user
31
     * @attribute
32
     */
33
    private String mMailSender = "";
34
 
35
    /**configured global email target
36
     * @attribute
37
     */
38
    private String mMailGlobalTarget = "";
39
 
40
    /** Vector of email addresses for global and project wide use
41
     *  Most emails will be sent to this list of email recipients
42
     */
43
    public List<String> mMailGlobalCollection = new ArrayList<String>();
44
 
45
    /**name associated with the baseline
46
     * @attribute
47
     */
48
    public String mBaselineName = "";
49
 
50
    /**Collection of build exceptions associated with the baseline
51
     * Used to determine (and report) what change in build exceptions happens as part of planRelease
52
     * Daemon centric
53
     * @aggregation shared
54
     * @attribute
55
     */
56
    ArrayList<BuildExclusion> mBuildExclusionCollection = new ArrayList<BuildExclusion>();
57
 
58
    /**Logger
59
     * @attribute
60
     */
7033 dpurdie 61
    private static final Logger mLogger = LoggerFactory.getLogger(RippleEngine.class);
6914 dpurdie 62
 
63
    /** Escrow information - commands to set up escrow
64
     * @attribute
65
     */
66
    private String mEscrowSetup;
67
 
68
    /** Escrow information - Raw data (May not be used)
69
     * @attribute
70
     */
71
    private String mEscrowRawData;
72
 
7048 dpurdie 73
    /** Collections of packages
6914 dpurdie 74
     */
75
    private ArrayList<Package> mPackageCollection = new ArrayList<Package>();
7048 dpurdie 76
    private ArrayList<Package> mPackageCollectionWip = new ArrayList<Package>();
77
    private ArrayList<Package> mPackageCollectionTest = new ArrayList<Package>();
78
    private ArrayList<Package> mPackageCollectionRipple = new ArrayList<Package>();
79
    private ArrayList<Package> mPackageCollectionAll = new ArrayList<Package>();
80
 
6914 dpurdie 81
 
82
    /**index to current String item
83
     * @attribute
84
     */
85
    private int mBuildIndex;
86
 
87
    /**Database abstraction
88
     * @attribute
89
     */
90
    ReleaseManager mReleaseManager;
91
 
92
    /**Baseline identifier (rtag_id for a release manager baseline, bom_id for deployment manager baseline)
93
     * @attribute
94
     */
95
    private int mBaseline;
96
 
97
    /** Escrow Only: SBOM_ID
98
     */
99
    private int mSbomId;
100
 
101
    /** RTAG_ID
102
     *  Set from mBaseline
103
     */
104
    private int mRtagId;
105
 
106
    /**When true, mBuildCollection contains one item based on a release manager rtag_id and contains a daemon property
107
     * When false, mBuildCollection contains at least one item based on a deployment manager bom_id
108
     * Will be accessed by the Package class to calculate its mAlias
109
     * @attribute
110
     */
111
    public boolean mDaemon;
112
 
113
    /**collection of build file content in String form
114
     * @attribute
115
     */
116
    private ArrayList<BuildFile> mBuildCollection = new ArrayList<BuildFile>();
117
 
118
    /** List of packages that we plan to build
119
     * Used to provide feedback into RM
120
     * Only the first entry is about to be built as we re-plan every cycle
121
     */
122
    private ArrayList<Package> mBuildOrder = new ArrayList  <Package>();
123
    /**Warning message
124
     * @attribute
125
     */
126
    private static final String mAnyBuildPlatforms = "Warning. The following package versions are not reproducible on any build platform: ";
127
 
128
    /**Flag to control output to standard out
129
     * @attribute
130
     */
131
    private boolean mAnyBuildPlatformsFlag = true;
132
 
133
    /**Warning message
134
     * @attribute
135
     */
136
    private static final String mAssocBuildPlatforms = "Warning. The following package versions are not reproducible on the build platforms associated with this baseline: ";
137
 
138
    /**Flag to control output to standard out
139
     * @attribute
140
     */
141
    private boolean mAssocBuildPlatformsFlag = true;
142
 
143
    /**Warning message
144
     * @attribute
145
     */
146
    private static final String mNotInBaseline = "Warning. The following package versions are not reproducible as they are directly dependent upon package versions not in the baseline: ";
147
 
148
    /**Flag to control output to standard out
149
     * @attribute
150
     */
151
    private boolean mNotInBaselineFlag = true;
152
 
153
    /**Warning message
154
     * @attribute
155
     */
156
    private static final String mDependent = "Warning. The following package versions are not reproducible as they are directly/indirectly dependent upon not reproducible package versions: ";
157
 
158
    /**Flag to control output to standard out
159
     * @attribute
160
     */
161
    private boolean mDependentFlag = true;
162
 
163
    /**Warning message
164
     * @attribute
165
     */
166
    private static final String mCircularDependency = "Warning. The following package versions are not reproducible as they have circular dependencies: ";
167
 
168
    /**Flag to control output to standard out
169
     * @attribute
170
     */
171
    private boolean mCircularDependencyFlag = true;
172
 
173
    /** String used to terminate lines
174
     * @attribute
175
     */
176
    private static final  String mlf = System.getProperty("line.separator");
177
 
178
    /** XML File Prefix
179
     */
180
    private static final String mXmlHeader = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + mlf;
181
 
182
    /**RippleEngine constructor
183
     * @param releaseManager  - Associated releaseManager instance
184
     * @param rtagId         - Release Identifier
185
     * @param isDaemon        - Mode of operation. False: Escrow, True: Daemon
186
     */
187
    public RippleEngine(ReleaseManager releaseManager, int rtagId, boolean isDaemon)
188
    {
7048 dpurdie 189
        mLogger.debug("RippleEngine rtag_id {} isDaemon {}", rtagId, isDaemon);
6914 dpurdie 190
        mReleaseManager = releaseManager;
191
        mBaseline = rtagId;
192
        mRtagId = rtagId;
193
        mDaemon = isDaemon;
194
        mReleaseManager.setDaemonMode(mDaemon);
195
    }
196
 
197
    /**
198
     * getRtagId
7048 dpurdie 199
     * @return The rtagId of the Release attached to this instance of the RippleEngine
6914 dpurdie 200
     */
201
    public int getRtagId()
202
    {
203
        return mRtagId;
204
    }
205
 
206
    /**Plan what is to be built
207
     * 	<br>Discards all build file content
208
     * 	<br>Generates new build file content
209
     * 
210
     * @param lastBuildActive 		- False. Daemon Mode. The last build was a dummy. 
211
     *                                This planning session may not result in a build
212
     *                              - True. Daemon Mode. The last build was not a dummy.
213
     *                                There is a very good chance that this planning session
214
     *                                will result in a build, so it is given priority to connect 
215
     *                                to the database.	
216
     */
217
    public void planRelease(final boolean lastBuildActive) throws SQLException, Exception
218
    {
7048 dpurdie 219
        mLogger.warn("planRelease mDaemon {}", mDaemon);
6914 dpurdie 220
 
221
        mBuildCollection.clear();
222
        mPackageCollection.clear();
7048 dpurdie 223
        mPackageCollectionRipple.clear();
224
        mPackageCollectionTest.clear();
225
        mPackageCollectionWip.clear();
6914 dpurdie 226
        mBuildOrder.clear();
227
        mEscrowRawData = "";
228
        mEscrowSetup = "";
229
        Phase phase = new Phase("Plan");
230
 
231
        // use finally block in planRelease to ensure the connection is released
232
        try
233
        {
234
            phase.setPhase("connectForPlanning");
235
            mReleaseManager.connectForPlanning(lastBuildActive);
236
 
237
            if ( mDaemon )
238
            {
239
                // claim the mutex
240
                mLogger.warn("planRelease claimMutex");
241
                phase.setPhase("claimMutex");
242
                mReleaseManager.claimMutex();
243
 
244
                // Populate the mBuildExclusionCollection
245
                //
246
                // Builds are either 'Directly excluded' or 'Indirectly excluded'
247
                // Direct excludes result from:
248
                //      User request
249
                //      Build failure
250
                //      Inability to build package
251
                // Indirectly excluded packages result from have a build dependency on a package
252
                // that is directly excluded.
253
                //  
254
                // In the following code we will extract from the Database all build exclusions
255
                // We will then add 'Relevant' entries to mBuildExclusionCollection
256
                // and delete, from the database those that are no longer relevant - ie indirectly excluded
257
                // items where the root cause is no longer in the set.
258
                phase.setPhase("mBuildExclusionCollection");
259
                mBuildExclusionCollection.clear();
260
                ArrayList<BuildExclusion> tempBuildExclusionCollection = new ArrayList<BuildExclusion>();
261
 
262
                mLogger.debug("planRelease queryBuildExclusions");
263
                mReleaseManager.queryBuildExclusions(tempBuildExclusionCollection, mBaseline);
264
 
265
                // only populate mBuildExclusionCollection with tempBuildExclusionCollection entries which have a relevant root_pv_id
266
                // The entry is relevant if:
267
                //     It is for a directly excluded package,other than a RippleStop
268
                //     It is for an indirectly excluded package AND the reason for exclusion still exists
269
                //
270
 
271
                for (Iterator<BuildExclusion> it = tempBuildExclusionCollection.iterator(); it.hasNext(); )
272
                {
273
                    BuildExclusion buildExclusion = it.next();
274
 
275
                    if ( buildExclusion.isRelevant(tempBuildExclusionCollection) )
276
                    {
277
                        mBuildExclusionCollection.add(buildExclusion);
278
                    }
279
                    else
280
                    {
281
                        // Remove the indirectly excluded entry as its root cause
282
                        // is no longer present.
283
                        buildExclusion.includeToBuild(mReleaseManager, mBaseline);
284
                    }
285
                }
286
            }
287
 
288
            //-----------------------------------------------------------------------
289
            //	Query package versions
290
            //
291
            phase.setPhase("queryPackageVersions");
292
            mLogger.debug("planRelease queryPackageVersions");
293
            mReleaseManager.queryPackageVersions(this, mPackageCollection, mBaseline);
7048 dpurdie 294
            mReleaseManager.queryWips(this, mPackageCollectionWip, mBaseline);
295
            mReleaseManager.queryTest(this, mPackageCollectionTest, mBaseline);
296
            mReleaseManager.queryRipples(this, mPackageCollectionRipple, mBaseline);
297
            mPackageCollectionAll.addAll(mPackageCollection);
298
            mPackageCollectionAll.addAll(mPackageCollectionWip);
299
            mPackageCollectionAll.addAll(mPackageCollectionTest);
300
            mPackageCollectionAll.addAll(mPackageCollectionRipple);
301
 
302
            // Sort the collection by PVID
303
            //      Unit Test output order is known
304
            //      May assist in creating repeatable build orders
305
            //
306
            Collections.sort(mPackageCollectionAll, Package.SeqComparator);
6914 dpurdie 307
 
308
            //------------------------------------------------------------------------
309
            //    Process packages collected
310
            //    Determine and tag those we can't build
311
            phase.setPhase("processPackages");
312
            processPackages();
313
 
314
            //-----------------------------------------------------------------------
315
            //    At this point we have tagged all the packages that we cannot build
316
            //    Now we can determine what we are building
317
            phase.setPhase("planBuildOrder");
318
            mLogger.debug("planRelease process Remaining");
319
            planBuildOrder();
320
 
321
            //  Report excluded packages and the build plan
322
            //  This is being done with the MUTEX being held, but the 
323
            //  trade off is the cost of getting a connection.
324
            //
325
            if ( mDaemon )
326
            {
327
                phase.setPhase("Report Change");
328
                reportChange();
329
                phase.setPhase("Report Plan");            
330
                reportPlan();
331
            }
332
 
333
            //
334
            //	Generate the build Files
335
            //
336
            phase.setPhase("generateBuildFiles");
337
            generateBuildFiles();
338
        }
339
        finally
340
        {
341
            mLogger.debug("planRelease finally");
342
            // this block is executed regardless of what happens in the try block
343
            // even if an exception is thrown
344
            // ensure the SELECT FOR UPDATE is released
345
            try
346
            {
347
                if ( mDaemon )
348
                {
349
                    // attempt to release the SELECT FOR UPDATE through a commit
350
                    // a commit must be done in the normal case
351
                    // a commit may as well be done in the Exception case
352
                    // in the case of a SQLException indicating database connectivity has been lost
353
                    // having a go at the commit is superfluous
354
                    // as the SELECT FOR UPDATE will have been released upon disconnection
355
                    phase.setPhase("releaseMutex");
356
                    mReleaseManager.releaseMutex();
357
                }
358
            }
359
            finally
360
            {
361
                // ensure disconnect under all error conditions
362
                phase.setPhase("disconnectForPlanning");
363
                mReleaseManager.disconnectForPlanning(lastBuildActive);
364
            }
365
        }
366
 
7048 dpurdie 367
        mLogger.warn("planRelease mDaemon {} returned", mDaemon);
6914 dpurdie 368
        phase.setPhase("EndPlan");
369
    }
370
 
371
    /** Process packages that have been collected as a part of the plan
372
     * @param phase
373
     * @throws SQLException
374
     * @throws Exception
375
     */
376
    private void processPackages() throws SQLException, Exception {
377
 
378
        // Deal with test builds here as they may impact upon package attributes
7048 dpurdie 379
        //    eg: dependency collection and build standard differences
6914 dpurdie 380
        //    Note: Done before mPackageDependencyCollection is setup
381
        //
382
        if ( mDaemon )
383
        {
7048 dpurdie 384
            // Process test builds - they are in their own collection
385
            for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
6914 dpurdie 386
            {
387
                Package p = it.next();
7048 dpurdie 388
                mLogger.info("planRelease package test build {}", p.mAlias);
6914 dpurdie 389
 
7048 dpurdie 390
                //
391
                //    Cannot test build an SDK based package or a Pegged Package
392
                //        Remove the test build request from the database
393
                //        Send a warning email
394
                //
395
                if(p.mIsPegged || p.mIsSdk)
6914 dpurdie 396
                {
7048 dpurdie 397
                    String reason;
398
                    reason = (p.mIsPegged) ? "Pegged" : "SDK Based";
6914 dpurdie 399
 
7048 dpurdie 400
                    mLogger.error("planRelease Daemon Instruction (testBuild) of {} package deleted: {}", reason, p.mAlias);
401
                    mReleaseManager.markDaemonInstCompleted( p.mTestBuildInstruction );
402
                    emailRejectedDaemonInstruction("Cannot 'Test Build' a " + reason + " package",p);
403
                }
6914 dpurdie 404
 
7048 dpurdie 405
                // force patch for test build numbering
406
                p.mDirectlyPlanned = true;
407
                p.mChangeType.setPatch();
408
                p.mRequiresSourceControlInteraction = false;
409
                p.mBuildReason = BuildReason.Test;
410
                p.mIndirectlyPlanned = true;
6914 dpurdie 411
            }
412
        }
413
 
414
        // Set up mPackageDependencyCollection on each package
415
        //    Examine the dependencies by alias and convert this to a 'package' selected from the released package set
7048 dpurdie 416
        mLogger.debug("planRelease setup setPackageDependencyCollection");
417
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 418
        {
419
            Package p = it.next();
420
 
421
            for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
422
            {
423
                String alias = it2.next();
424
                Package dependency = findPackage(alias);
425
                p.mPackageDependencyCollection.add(dependency);
426
            }
7048 dpurdie 427
        }    
6914 dpurdie 428
 
7048 dpurdie 429
        // Detect and deal with circular dependencies
430
        // Examine all packages under consideration
431
        //
6914 dpurdie 432
        mLogger.debug("planRelease deal with circular dependencies");
7048 dpurdie 433
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 434
        {
435
            Package p = it.next();
436
 
437
            if ( p.hasCircularDependency( this ) )
438
            {
7048 dpurdie 439
                mLogger.info("planRelease circular dependency detected {}", p.mAlias);
6914 dpurdie 440
 
441
                //  Force this package to be marked as having a circular dependency - even if its been excluded
442
                p.mBuildFile = 0;
443
 
444
                // exclude all dependent packages
445
                // max 50 chars
446
                rippleBuildExclude(p, p.mId, "Package has circular dependency", null, null, true);
447
 
448
                // take the package out of the build
449
                p.mBuildFile = -6;
7048 dpurdie 450
                mLogger.info("planRelease set mBuildFile to -6 for package {}", p.mAlias );
6914 dpurdie 451
                standardOut(mCircularDependency, p.mAlias, mCircularDependencyFlag);
452
                mCircularDependencyFlag = false;
453
            }
454
        }
455
 
456
        // Scan for packages with missing dependencies
457
        //    ie: The dependent package is not in the package Collection
458
        //        DEVI 55483 now use the fully built mPackageDependencyCollection (in rippleBuildExclude)
459
        mLogger.debug("planRelease use the fully built mPackageDependencyCollection");
7048 dpurdie 460
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 461
        {
462
            Package p = it.next();
463
 
464
            if ( mDaemon )
465
            {
466
                //  Daemon Mode Only
467
                //  Not interested in the dependencies of a pegged package or a package provided from an SDK.
468
                //  Such packages will be deemed to not have missing dependencies
469
                if (p.mIsPegged || p.mIsSdk)
470
                {
471
                    continue;
472
                }
473
            }
474
 
475
            for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
476
            {
477
                String alias = it2.next();
478
                Package dependency = findPackage(alias);
479
 
480
                if (dependency == ReleaseManager.NULL_PACKAGE)
481
                {
7048 dpurdie 482
                    mLogger.info("planRelease dependency is not in the baseline {}", alias);
6914 dpurdie 483
                    // exclude all dependent packages
484
                    // max 50 chars
485
                    rippleBuildExclude(p, p.mId, "Package build dependency not in the release", null, null, true);
486
 
487
                    // take the package out of the build
488
                    p.mBuildFile = -4;
7048 dpurdie 489
                    mLogger.info("planRelease set mBuildFile to -4 for package {}", p.mAlias );
6914 dpurdie 490
                    standardOut(mNotInBaseline, p.mAlias, mNotInBaselineFlag);
491
                    mNotInBaselineFlag = false;
492
                    break;
493
                }
494
            }
495
        }
496
 
7048 dpurdie 497
        // Detect packages with no build standard and exclude them from the build
6914 dpurdie 498
        mLogger.debug("planRelease process packages which are not reproducible");
7048 dpurdie 499
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 500
        {
501
            Package p = it.next();
502
 
503
            if (p.mBuildFile == 0)
504
            {
505
                if ( mDaemon )
506
                {
507
                    //  Daemon Mode Only
508
                    //  Not interested in the reproducibility of a pegged package or a package provided from an SDK.
509
                    //  Such packages will be deemed to be reproducible - but out side of this release
510
                    if (p.mIsPegged || p.mIsSdk)
511
                    {
512
                        continue;
513
                    }
514
                }
515
 
7048 dpurdie 516
                // Does the package have a build standard. If not then we can't reproduce it.
517
                // Escrow - Assume the package is provided
518
                // Daemon - Exclude this package, but not its consumers. If the package is available then we can use it.
6914 dpurdie 519
                if (!p.isReproducible())
520
                {
7048 dpurdie 521
                    mLogger.info("planRelease package not reproducible {}" ,p.mName);
6914 dpurdie 522
                    // max 50 chars
7048 dpurdie 523
                    rippleBuildExclude(p, p.mId, "Package has no build environment", null, null, false);
6914 dpurdie 524
 
525
                    // package is not reproducible, discard
526
                    p.mBuildFile = -1;
7048 dpurdie 527
                    mLogger.info("planRelease set mBuildFile to -1 for package {}", p.mAlias );
6914 dpurdie 528
                    standardOut(mAnyBuildPlatforms, p.mAlias, mAnyBuildPlatformsFlag);
529
                    mAnyBuildPlatformsFlag = false;
530
                }
531
            }
532
        }
533
 
7048 dpurdie 534
        //    Process packages which are not reproducible on the configured set of build machines.
6914 dpurdie 535
        //
536
        //    Test each package and determine if the package contains a buildStandard that
537
        //    can be processed by one of the machines in the build set
538
        //
539
        //    ie: Package: Win32:Production and we have a BM with a class of 'Win32'
540
        //
541
        //    Only exclude the failing package and not its dependents
542
        //    May be legitimate in the release
543
        //
7048 dpurdie 544
//TODO - verify this code. I'm not sure it can be reached. I think that the "Package has no build environment" test above is detecting all these packages
6914 dpurdie 545
        mLogger.debug("planRelease process packages which are not reproducible2");
7048 dpurdie 546
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 547
        {
548
            Package p = it.next();
549
 
550
            if (p.mBuildFile == 0)
551
            {
552
                if ( mDaemon )
553
                {
554
                    //  Daemon Mode Only
555
                    //  Not interested in the reproducibility of a pegged package or a package provided from an SDK.
556
                    //  Such packages will be deemed to be reproducible - but out side of this release
557
                    if (p.mIsPegged || p.mIsSdk)
558
                    {
559
                        continue;
560
                    }
561
                }
562
 
563
                // package has yet to be processed
564
                // assume it does not need to be reproduced for this baseline
565
                //
566
                //    For each machineClass in the buildset
567
                boolean reproduce = false;
568
 
569
                for (Iterator<String> it2 = mReleaseManager.mReleaseConfigCollection.mMachineClasses.iterator(); it2.hasNext(); )
570
                {
571
                    String machineClass = it2.next();
572
 
573
                    if ( p.canBeBuildby(machineClass))
574
                    {
575
                        reproduce = true;
7048 dpurdie 576
                        mLogger.info("planRelease package built on {} {}", machineClass, p.mAlias );
6914 dpurdie 577
                        break;
578
                    }
579
                }
580
 
581
                if ( !reproduce )
582
                {
7048 dpurdie 583
                    mLogger.info("planRelease package not reproducible on the build platforms configured for this baseline {}", p.mName);
6914 dpurdie 584
 
7048 dpurdie 585
                    // max 50 chars
586
                    rippleBuildExclude(p, p.mId, "Package not built for configured platforms", null, null, false);
6914 dpurdie 587
 
588
                    // package is not reproducible on the build platforms configured for this baseline, discard
589
                    p.mBuildFile = -2;
7048 dpurdie 590
                    mLogger.info("planRelease set mBuildFile to -2 for package {}", p.mAlias );
6914 dpurdie 591
                    standardOut(mAssocBuildPlatforms, p.mAlias, mAssocBuildPlatformsFlag);
592
                    mAssocBuildPlatformsFlag = false;
593
                }
594
            }
595
        }      
596
 
597
        if (mDaemon)
598
        {
599
            // Daemon Mode Only
600
            // Process packages which are not ripple buildable, and all packages dependent upon them
601
            mLogger.debug("planRelease process packages which are not ripple buildable");
602
            for (ListIterator<BuildExclusion> it = mBuildExclusionCollection.listIterator(); it.hasNext(); )
603
            {
604
                BuildExclusion be = it.next();
605
 
606
                for (Iterator<Package> it1 = mPackageCollection.iterator(); it1.hasNext(); )
607
                {
608
                    Package p = it1.next();
609
 
610
                    // ensure only root cause, non test build, build exclusions are excluded
611
                    // mBuildExclusionCollection is at this point based on
612
                    // relevant (direct and indirect) excluded pv's in the database
613
                    if ( be.compare(p.mId) && be.isARootCause() && p.mTestBuildInstruction == 0 && p.mForcedRippleInstruction == 0 )
614
                    {
615
                        // package is not reproducible, discard
7048 dpurdie 616
 
6914 dpurdie 617
                        rippleBuildExclude( p, p.mId, null, it, be, true );
618
                        p.mBuildFile = -3;
7048 dpurdie 619
                        mLogger.info("planRelease set mBuildFile to -3 for package {}", p.mAlias );
6914 dpurdie 620
                        break;
621
                    }
622
                }
623
            }
624
 
625
            //  Daemon Mode Only
626
            //  Process packages which need to be ripple built
627
            mLogger.debug("planRelease process packages which need to be ripple built");
628
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
629
            {
630
                Package p = it.next();
631
 
632
                if (p.mBuildFile == 0)
633
                {
634
                    //  Not interested in a pegged package or a package provided from an SDK.
635
                    //  Such packages are not rippled
636
                    if (p.mIsPegged || p.mIsSdk)
637
                    {
638
                        continue;
639
                    }
640
 
7048 dpurdie 641
                    //    Examine this packages dependencies
642
                    //    If one of them does not exist in the 'official release' set then
643
                    //    the package needs to be built against the official release set
644
                    //    and we can't build any of its dependent packages
645
                    Iterator<Integer> it2 = p.mDependencyIDCollection.iterator();
646
                    Iterator<Package> it3 = p.mPackageDependencyCollection.iterator();
647
                    while ( it2.hasNext() && it3.hasNext() )
6914 dpurdie 648
                    {
7048 dpurdie 649
                        Integer dpvId = it2.next();
650
                        Package dependency = it3.next();
651
 
652
                        if ( !dependency.mAdvisoryRipple )
6914 dpurdie 653
                        {
7048 dpurdie 654
                            // not advisory, ie: has ripple build impact
655
                            if ( !isInRelease(dpvId) )
6914 dpurdie 656
                            {
7048 dpurdie 657
                                // the package is out of date
658
                                // exclude all dependent package versions
659
                                mLogger.info("planRelease package out of date {}", p.mName);
660
                                p.mBuildReason = BuildReason.Ripple;
661
                                rippleIndirectlyPlanned(p);
662
 
663
                                //  This package needs to be rippled
664
                                //  If this package has a rippleStop marker of 's', then we cannot
665
                                //  build this package at the moment.
666
                                //  Packages that depend on this package have been excluded
667
                                //  We need to exclude this one too
668
                                //
669
                                if (p.mRippleStop == 's' || p.mRippleStop == 'w') 
6914 dpurdie 670
                                {
7048 dpurdie 671
                                    // Package marked as a rippleStop
672
                                    // max 50 chars
673
                                    rippleBuildExclude(p, -2, "Ripple Required." + " Waiting for user", null, null, false);
674
 
675
                                    // package is unBuildable, mark reason and discard
676
                                    p.mBuildFile = -11;
6914 dpurdie 677
 
7048 dpurdie 678
                                    if (p.mRippleStop == 's' ) {
679
                                        // Need to flag to users that the package build is waiting user action
680
                                        mLogger.info("planRelease Ripple Required. Stopped by flag {}", p.mName);
681
                                        mReleaseManager.setRippleStopWait(mRtagId,p);
6914 dpurdie 682
                                    }
683
                                }
7048 dpurdie 684
 
685
                                break;
6914 dpurdie 686
                            }
687
                        }
688
                    }
689
                }
690
            }
691
 
692
            //  Daemon Mode Only
693
            //  Process packages which do not exist in the archive
694
            //  For unit test purposes, assume all packages exist in the archive if released
695
            mLogger.debug("planRelease process packages which do not exist in the archive");
7048 dpurdie 696
            if ( mReleaseManager.mUseDatabase )
6914 dpurdie 697
            {
698
                for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
699
                {
700
                    Package p = it.next();
701
 
702
                    if (p.mBuildFile == 0)
703
                    {
704
                        // package has yet to be processed
705
                        if (!p.mDirectlyPlanned && !p.mIndirectlyPlanned && p.mForcedRippleInstruction == 0)
706
                        {
707
                            // check package version archive existence
708
                            if (!p.existsInDpkgArchive())
709
                            {
710
                                if (! p.mIsBuildable)
711
                                {
712
                                    //  Package does not exist in dpkg_archive and it has been flagged as unbuildable
713
                                    //  This may be because is Unbuildable or Manually built
7048 dpurdie 714
                                    mLogger.info("planRelease Unbuildable package not found in archive {}", p.mName);
6914 dpurdie 715
                                    // max 50 chars
716
                                    rippleBuildExclude(p, p.mId, "Unbuildable" + " package not found in archive", null, null, true);
717
 
718
                                    // package is unBuildable, mark reason and discard
719
                                    p.mBuildFile = -10;
720
 
721
                                }
722
                                //  Not interested in a pegged package or a package provided from an SDK.
723
                                //  Such packages are not rippled
724
                                else if (p.mIsPegged || p.mIsSdk)
725
                                {
726
                                    String reason;
727
                                    reason = (p.mIsPegged) ? "Pegged" : "SDK";
728
 
729
                                    //  Pegged packages or packages provided from an SDK MUST exist in dpkg_archive
730
                                    //  They will not be built within the context of this release. It is the responsibility
731
                                    //  of another release to build them.
7048 dpurdie 732
                                    mLogger.info("planRelease {} package not found in archive {}", reason, p.mName);
6914 dpurdie 733
                                    // max 50 chars
734
                                    rippleBuildExclude(p, p.mId, reason + " package not found in archive", null, null, true);
735
 
736
                                    // package is not reproducible, mark reason and discard
737
                                    p.mBuildFile = -7;
738
 
739
                                }
740
                                else if (p.mForcedRippleInstruction == 0)
741
                                {
742
                                    //  [JATS-331] Unable to rebuild package with Advisory Ripple dependencies
743
                                    //    Examine this packages dependencies
744
                                    //    If one of them does not exist in the 'official release' set then
745
                                    //    the package cannot be rebuilt in this release.
746
                                    for (Iterator<Integer> it2 = p.mDependencyIDCollection.iterator() ; it2.hasNext() ;)
747
                                    {
748
                                        Integer dpvId = it2.next();
749
                                        if ( !isInRelease(dpvId) )
750
                                        {
751
                                            // This package cannot be rebuilt as one of its dependents is NOT in this release
752
                                            // exclude all dependent package versions
753
 
7048 dpurdie 754
                                            mLogger.info("planRelease package not found in archive. Cannot be rebuilt due to {}", p.mName);
6914 dpurdie 755
                                            // max 50 chars
756
                                            rippleBuildExclude(p, p.mId, "Package cannot be rebuilt in this release", null, null, true);
757
 
758
                                            // package is not reproducible, mark reason and discard
759
                                            p.mBuildFile = -4;
760
                                            break;
761
                                        }
762
                                    }
763
 
764
                                    //  The package has not been excluded from the build
765
                                    if (p.mBuildFile == 0)
766
                                    {
7048 dpurdie 767
                                        mLogger.info("planRelease package not found in archive {}", p.mName);
6914 dpurdie 768
                                        // DEVI 47395 the cause of this build is not WIP or ripple induced,
769
                                        // it simply does not exist in the archive (has been removed)
770
                                        // prevent source control interaction
771
                                        p.mRequiresSourceControlInteraction = false;
772
                                        p.mBuildReason = BuildReason.Restore;
773
                                        rippleIndirectlyPlanned(p);
774
                                    }
775
                                }
776
                            }
777
                        }
778
                    }
779
                }
780
            }
781
 
782
            //  Daemon Mode Only
7048 dpurdie 783
            //  Detect bad forced ripples requests and reject them
6914 dpurdie 784
            mLogger.debug("planRelease process forced ripples");
7048 dpurdie 785
            for (Iterator<Package> it = mPackageCollectionRipple.iterator(); it.hasNext(); )
6914 dpurdie 786
            {
787
                Package p = it.next();
788
 
789
                if (p.mBuildFile == 0)
790
                {
7048 dpurdie 791
                    //
792
                    //    Cannot force a ripple on an SDK based package or a Pegged Package
793
                    //        Remove the daemon instruction from the database
794
                    //        Send a warning email
795
                    //
796
                    if(p.mIsPegged || p.mIsSdk)
6914 dpurdie 797
                    {
7048 dpurdie 798
                        String reason;
799
                        reason = (p.mIsPegged) ? "Pegged" : "SDK Based";
6914 dpurdie 800
 
7048 dpurdie 801
                        mLogger.error("planRelease Daemon Instruction of {} package deleted: {}", reason, p.mName);
802
                        mReleaseManager.markDaemonInstCompleted( p.mForcedRippleInstruction );
803
                        emailRejectedDaemonInstruction("Cannot 'Ripple' a " + reason + " package",p);
6914 dpurdie 804
 
7048 dpurdie 805
                        p.mBuildFile = -8; 
6914 dpurdie 806
                    }
807
                }
808
            }
809
 
810
            //  Daemon Mode Only
811
            //  Mark Pegged and SDK packages as not to be built
812
            //  Have previously detected conflicts between pegged/sdk packages and daemon instructions
813
            //
814
            mLogger.debug("planRelease remove pegged and SDK packages from the build set");
815
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
816
            {
817
                Package p = it.next();
818
 
819
                if (p.mBuildFile == 0)
820
                {
821
                    //  Not interested in a pegged package or a package provided from an SDK.
822
                    //  Such packages are not built
823
                    if (p.mIsPegged || p.mIsSdk)
824
                    {
825
                        String reason;
826
                        reason = (p.mIsPegged) ? "Pegged" : "SDK";
827
 
7048 dpurdie 828
                        mLogger.info("planRelease {} not built in this release {}", reason, p.mName);
6914 dpurdie 829
                        p.mBuildFile = -8;
830
                    }
831
                }
832
            }
833
 
834
            //  Daemon Mode Only
835
            //  Locate Test Build Requests that cannot be satisfied - will not be built due to
836
            //  errors in dependent packages. Report the error to the user and remove the request
837
            //
7048 dpurdie 838
            for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
6914 dpurdie 839
            {
840
                Package p = it.next();
841
 
7048 dpurdie 842
                if (p.mBuildFile < 0)
6914 dpurdie 843
                {
7048 dpurdie 844
                    String reason;
845
                    switch (p.mBuildFile)
6914 dpurdie 846
                    {
7048 dpurdie 847
                    case -1:  reason = "Not reproducible"; break;
848
                    case -2:  reason = "Not reproducible on configured build platforms"; break;
849
                    case -3:  reason = "Marked as 'Do not ripple'"; break;
850
                    case -4:  reason = "Dependent on a package not in the release"; break;
851
                    case -5:  reason = "Indirectly dependent on a package not reproducible in the release"; break;
852
                    case -6:  reason = "Has a circular dependency"; break;
853
                    case -7:  reason = "Pegged or SDK package not in dpkg_archive"; break;
854
                    case -8:  reason = "Is a Pegged or SDK package"; break;
855
                    case -9:  reason = "Rejected Daemon Instruction"; break;
856
                    case -10: reason = "Unbuildable package not in dpkg_archive"; break;
857
                    case -11: reason = "Marked as 'RippleStop'"; break;
858
                    default:  reason = "Unknown reason. Code:" + p.mBuildFile; break;
6914 dpurdie 859
                    }
7048 dpurdie 860
                    mLogger.error("planRelease Test Build of an unbuildable of package deleted: {}", p.mName);
861
                    mReleaseManager.markDaemonInstCompleted( p.mTestBuildInstruction );
862
                    emailRejectedDaemonInstruction(reason,p);
6914 dpurdie 863
                }
864
            }
7048 dpurdie 865
 
6914 dpurdie 866
        }
867
        else
868
        {
869
            // escrow reporting only
870
            // Report packages that are not reproducible
871
            //
872
            //  Note: I don't believe this code can be executed
873
            //        The -3 is only set in daemon mode
874
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
875
            {
876
                Package p = it.next();
877
 
878
                if (p.mBuildFile == -3)
879
                {
880
                    standardOut(mDependent, p.mAlias, mDependentFlag);
881
                    mDependentFlag = false;
882
                }
883
            }
884
        }
885
    }
886
 
887
    /** Plan the build order.
888
     *  Assumes that a great deal of work has been done.
889
     *  This is a stand alone method to contain the work
890
     *  
891
     * @throws Exception
892
     * @throws SQLException
893
     */
894
    private void planBuildOrder() throws Exception, SQLException {
7052 dpurdie 895
 
896
//TODO - Planing is not working well
897
/**
898
 * Current status
899
 * The selection of the package to build next is deeply flawed
900
 * Currently it will select a ripple over a directly planned package - thus the unit tests are not working
901
 * The current algorithm is based on time - but all packages have zero build time ( in UTF )
902
 * Even if this is fixed the algorithm is broken as we will select the complete build with the shortest time
903
 * which will be the ripple of a leaf package ( perhaps that is good )
904
 * 
905
 * Also:
906
 *      Need to include all packages that we can now build into the final build plan, not just the first one and its build tree
907
 * 
908
 *      Need to generate a single package set - so that WIPS and others replace those in the final build set
909
 *      Remove duplicates from the complete package set
910
 *      
911
 *      Need more test cases
912
 *      
913
 *      Need to report all build options, not just the selected one
914
 *      
915
 *      Cleanup the ANT build file - don't list all the release dependencies, just those needed to build the current package
916
 */
6914 dpurdie 917
 
918
        // Process remaining packages which are need to be reproduced for this baseline.
919
        //    Determine the build file for each package
920
        //    For daemon builds:
7048 dpurdie 921
        //      Determine the next package that can be built now
922
        //          Sounds simple - doesn't it
6914 dpurdie 923
        //      Set its mBuildNumber to 1, all remaining reproducible packages to 2
924
        //    For escrow builds:
925
        //      Determine the package versions that can be built in the build iteration
926
        //      Set their mBuildNumber to the build iteration
927
        //      Increment the build iteration and repeat until all package versions 
928
        //      that need to be reproduced have been assigned a build iteration        
929
 
930
        boolean allProcessed = false;
931
        int buildFile = 1;
932
 
933
        do
934
        {
7048 dpurdie 935
            //
936
            //  Create the mBuildOrder collection
937
            //      Same for both Daemon and Escrow modes
938
            //      Will have package build order and build level
6914 dpurdie 939
            boolean allDependenciesProcessed = true;
940
            do
941
            {
942
                allDependenciesProcessed = true;
943
                for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
944
                {
945
                    Package p = it.next();
946
 
7048 dpurdie 947
                    if ( p.mBuildFile < 0  ) 
6914 dpurdie 948
                    {
7048 dpurdie 949
                        // Daemon: Flag packages that cannot be built
6914 dpurdie 950
                        // Escrow: Flag packages with a foreign build environment as processed
951
                        p.mProcessed = true;
7048 dpurdie 952
                        mLogger.info("planRelease package not buildable {}", p.mName);            
6914 dpurdie 953
                    }
7048 dpurdie 954
                    else if ( p.mBuildFile == 0 )
6914 dpurdie 955
                    {
956
                        // package yet to be processed and
7048 dpurdie 957
                        //  Daemon mode: Could be built
6914 dpurdie 958
                        //  Escrow mode: Can be reproduced
959
                        boolean canBeBuiltNow = true;
960
                        boolean allDependenciesForThisPackageProcessed = true;
961
 
962
                        //  Scan the packages dependencies
963
                        for ( Iterator<Package> it2 = p.mPackageDependencyCollection.iterator(); it2.hasNext(); )
964
                        {
965
                            Package dependency = it2.next();
966
 
967
                            if ( !dependency.mProcessed )
968
                            {
969
                                //  If all the dependencies have been processed, then we can potentially build this package
970
                                //  If any of them have not been processed, then cannot calculate canBeBuiltNow until this 
971
                                //  dependency has been processed
972
                                allDependenciesForThisPackageProcessed = false;
973
                                allDependenciesProcessed = false;
974
                            }
7048 dpurdie 975
                            else if (  (  mDaemon && (   dependency.mBuildFile == 0 ) ) 
6914 dpurdie 976
                                    || ( !mDaemon && ( ( dependency.mBuildFile == 0 ) ||
977
                                                           ( dependency.mBuildFile == buildFile &&
978
                                                           ( !p.haveSameBuildStandards(dependency)  ) ) ) ) )
979
                            {
980
                                // Daemon mode:
7048 dpurdie 981
                                //    This processed dependency has not been assigned to a build iteration - so can't built yet
6914 dpurdie 982
                                // Escrow mode: This package cannot be built now if
983
                                //    This processed dependency has not been assigned to a build iteration or
984
                                //    This processed dependency has been assigned to this build iteration, but the 
985
                                //    build standards of the package and this dependency prevent the package being
986
                                //    built in this iteration.   
987
                                canBeBuiltNow = false;
7048 dpurdie 988
                                mLogger.info("planRelease package cannot be built in this iteration {}", p.mName);
6914 dpurdie 989
                                break;
990
                            }
991
                        }
992
 
7048 dpurdie 993
                        //  All dependencies have been processed. May be able to build this package
994
                        //      Add the package to the build order list
995
                        //
6914 dpurdie 996
                        if (allDependenciesForThisPackageProcessed)
997
                        {
998
                            p.mProcessed = true;
7048 dpurdie 999
                            if ( canBeBuiltNow )
6914 dpurdie 1000
                            {
1001
                                mBuildOrder.add(p);
7048 dpurdie 1002
                                p.mBuildFile = buildFile;
1003
                                mLogger.info("planRelease set mBuildFile to {} for package {}",buildFile, p.mAlias );
6914 dpurdie 1004
                            }
1005
                        }
1006
                    }
1007
                }
1008
            } while( !allDependenciesProcessed );
7048 dpurdie 1009
 
1010
            //  Have process all the packages that we can at the moment
1011
            //      Examine all the packages in the collection to see if there are more that need to be extracted
1012
            //      These will be done at a different build-level
1013
            //  
1014
            allProcessed = true;
1015
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
1016
            {
1017
                Package p = it.next();
1018
                if ( p.mBuildFile == 0 )
1019
                {
1020
                    // more build files are required
1021
                    allProcessed = false;
1022
                    mLogger.info("planRelease more build files are required for {}", p.mName);
1023
                    break;
1024
                }
1025
            }
6914 dpurdie 1026
 
7048 dpurdie 1027
            buildFile++;
1028
            if (buildFile % 500 == 0 ) {
1029
                mLogger.error("planRelease. Too many build levels {}", buildFile);
1030
            }
1031
        } while( !allProcessed );
1032
 
1033
 
1034
        if ( mDaemon )
1035
        {
1036
 
6914 dpurdie 1037
            //
1038
            //  Daemon Mode:
7048 dpurdie 1039
            //  Locate all packages that we can build now
1040
            //      Packages that have a build requirement and have no reason we cannot build them
6914 dpurdie 1041
            //
7048 dpurdie 1042
            ArrayList<Package> buildCandidates = new ArrayList<Package>();
1043
 
1044
 
1045
            for (Iterator<Package> it = mBuildOrder.iterator(); it.hasNext(); )
6914 dpurdie 1046
            {
7048 dpurdie 1047
                Package p = it.next();
1048
                if ( p.mProcessed && p.mBuildFile > 0 )
6914 dpurdie 1049
                {
7048 dpurdie 1050
                    if (p.mBuildReason != null)
1051
                    {
1052
                        // Have a reason to build this package
1053
                        buildCandidates.add(p);
1054
                        mLogger.info("planRelease Candidate {}",p.mAlias);
1055
                    }
1056
                }
1057
            }
1058
 
1059
            //  Add in the WIPs, Tests and Ripple Requests so that we can process them as one collections
1060
            //  Now have a collection of packages that we would like to build right now
1061
            //  See if any of them can be excluded due to issues with creating a new package version
1062
            buildCandidates.addAll(mPackageCollectionWip);
1063
            buildCandidates.addAll(mPackageCollectionTest);
1064
            buildCandidates.addAll(mPackageCollectionRipple);
1065
 
1066
            for (Iterator<Package> it = buildCandidates.iterator(); it.hasNext(); )
1067
            {
1068
                Package p = it.next();
6914 dpurdie 1069
 
7048 dpurdie 1070
                if ( p.mBuildFile >= 0 )
1071
                {
7050 dpurdie 1072
                    int pvApplied = p.applyPV(mReleaseManager);
7048 dpurdie 1073
 
1074
                    if ( pvApplied == 1 )
6914 dpurdie 1075
                    {
7048 dpurdie 1076
                        // max 50 chars
1077
                        rippleBuildExclude(p, p.mId, "Package has non standard versioning", null, null, true);
1078
                    }
1079
                    else if ( pvApplied == 2 )
1080
                    {
1081
                        // max 50 chars
1082
                        rippleBuildExclude(p, p.mId, "Package has reached ripple field limitations", null, null, true);
1083
                    }
1084
                    else if ( pvApplied == 3 )
1085
                    {
1086
                        // max 50 chars
1087
                        rippleBuildExclude(p, p.mId, "Package has invalid change type", null, null, true);
1088
                    }
1089
 
1090
                    if ( pvApplied != 0) 
1091
                    {
1092
                        // If this package is not a WIP/TEST/RIPPLE, then remove it from this collection
7051 dpurdie 1093
                        // Want to keep all WIP/TEST/RIPPLE items to simplify reporting
7048 dpurdie 1094
                        if (! p.mIsNotReleased )
6914 dpurdie 1095
                        {
7048 dpurdie 1096
                            it.remove();
6914 dpurdie 1097
                        }
7048 dpurdie 1098
                    }
1099
 
1100
                    //
1101
                    //  Ensure that the mRippleTime is known for each package
1102
                    //  Collection includes: naturalRipples, ForcedRipples, TestBuilds and NewVersions
1103
                    if ( pvApplied == 0)
1104
                    {
1105
                        if (p.mTestBuildInstruction != 0)
6914 dpurdie 1106
                        {
7048 dpurdie 1107
                            // Test Build - there is no ripple effect
1108
                            // The time impact will be the estimated build time of this one package
1109
                            p.mRippleTime = p.mBuildTime;
1110
 
6914 dpurdie 1111
                        }
7048 dpurdie 1112
                        else 
1113
                        {
1114
                            //  Calculate the time to build the package AND all of the packages that depend on it
1115
                            //  Calculate the build plan for the package
1116
                            //
1117
                            calcBuildPlan(p);
1118
                        }
6914 dpurdie 1119
                    }
1120
                }
1121
            }
7048 dpurdie 1122
 
1123
            //
1124
            //  Determine the NON-test package the we will build next
1125
            //
1126
            Package build = ReleaseManager.NULL_PACKAGE; 
1127
 
1128
            for (Iterator<Package> it = buildCandidates.iterator(); it.hasNext(); )
6914 dpurdie 1129
            {
7048 dpurdie 1130
 
1131
                Package p = it.next();
1132
                if ( p.mBuildFile >= 0 )
6914 dpurdie 1133
                {
7048 dpurdie 1134
                    if (p.mTestBuildInstruction == 0)
6914 dpurdie 1135
                    {
7048 dpurdie 1136
                        //  Not a Test Build
1137
                        if (build == ReleaseManager.NULL_PACKAGE || p.mRippleTime < build.mRippleTime)
1138
                        {
1139
                            build = p;
1140
                        }
6914 dpurdie 1141
                    }
1142
                }
7048 dpurdie 1143
            }
6914 dpurdie 1144
 
7048 dpurdie 1145
            //  Determine the first test build package
1146
            //  Assume the collection is in build instruction id order, 
1147
            //      So that the first request will be built first
1148
            //  Add all buildable test-builds to the mBuildOrder collection 
1149
            Package testBuild = ReleaseManager.NULL_PACKAGE;
1150
            mBuildOrder.clear();
6914 dpurdie 1151
 
7048 dpurdie 1152
            for (Iterator<Package> it = buildCandidates.iterator(); it.hasNext(); )
1153
            {
1154
 
1155
                Package p = it.next();
1156
                if ( p.mBuildFile >= 0 )
6914 dpurdie 1157
                {
7048 dpurdie 1158
                    if (p.mTestBuildInstruction != 0)
6914 dpurdie 1159
                    {
7048 dpurdie 1160
                        //  Not a Test Build
1161
                        if (testBuild == ReleaseManager.NULL_PACKAGE)
1162
                        {
7051 dpurdie 1163
                            testBuild = p;
7048 dpurdie 1164
                        }
1165
                        mBuildOrder.add(p);
6914 dpurdie 1166
                    }
1167
                }
1168
            }
7048 dpurdie 1169
 
1170
            //
1171
            //  Extend mBuildOrder with the selected non-test build package and its build plan
1172
            //  Really only for display purposes
1173
            //
1174
            if (build != ReleaseManager.NULL_PACKAGE)
6914 dpurdie 1175
            {
7048 dpurdie 1176
                mBuildOrder.add(build);
1177
                mBuildOrder.addAll(build.mRipplePlan);
1178
            }
1179
 
1180
            //
1181
            //  Mark the first package in the build order as the one to be built
7051 dpurdie 1182
            //  This will give test builds priority, while indicating what will be built after that
7048 dpurdie 1183
            //
1184
 
1185
            if (!mBuildOrder.isEmpty()) {
1186
                build = mBuildOrder.get(0);
1187
                build.mBuildFile = 1;
1188
 
1189
                if ( build.mForcedRippleInstruction > 0 )
6914 dpurdie 1190
                {
7048 dpurdie 1191
                    mReleaseManager.markDaemonInstCompleted( build.mForcedRippleInstruction );
1192
                }
6914 dpurdie 1193
 
7048 dpurdie 1194
                if ( build.mTestBuildInstruction > 0 )
1195
                {
1196
                    mReleaseManager.markDaemonInstInProgress( build.mTestBuildInstruction );
1197
                }
1198
 
1199
                //  Now that we know which package we are building
1200
                //      Set the previously calculated nextVersion as the packages version number
1201
                //      Claim the version number to prevent other builds from using it. Unless doing a test build
1202
                //
1203
                if (build.mTestBuildInstruction == 0 && build.mNextVersion != null)
1204
                {
1205
                    mReleaseManager.claimVersion(build.mPid, build.mNextVersion + build.mExtension, mBaseline);
1206
                    build.mVersion = build.mNextVersion;
1207
                }
1208
            }
1209
 
1210
            //
1211
            //  To fit in with the old algorithm ( ie: could be improved )
1212
            //  Insert marks into all packages
1213
            //  Not sure exactly why - Its used in the generation of the ant build file
1214
            //  Want to set mNoBuildReason, mBuildFile
1215
            //
1216
            //      Package we have selected to build: 0     , 1
1217
            //      Package we could have built      : 2     , 3
1218
            //      Packages we can't build          : reason, 3
1219
            //      Packages that are OK             : 3     , 3
1220
 
1221
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
1222
            {
1223
                Package p = it.next();
1224
                if (p == build ) {
1225
                    p.mNoBuildReason = 0;
1226
                    p.mBuildFile = 1;
1227
                } 
1228
                else if ( p.mBuildFile < 0 )
1229
                {
1230
                    p.mNoBuildReason = p.mBuildFile;
1231
                    p.mBuildFile = 3;
1232
                }
1233
                else if (p.mBuildReason != null)
1234
                {
1235
                    p.mNoBuildReason = 2;
1236
                    p.mBuildFile = 3;
1237
                }
1238
                else
1239
                {
1240
                    p.mNoBuildReason = 0;
1241
                    p.mBuildFile = 3;
1242
                }
1243
            }
1244
        }
1245
 
1246
    }
1247
 
1248
    /**
1249
     * Calculate a build plan for the specified package
1250
     * Calculates : mRippleTime - time to build the package and the ripple effect
1251
     * Calculates : mBuildPlan - collection of packages in the plan that can be built at the moment
1252
     * 
1253
     * Needs to determine all packages that consume the package - and all packages that consume them
1254
     *  Note: The package may not be in the mPackageCollection ( it may be a WIP/TEST/RIPPLE )
1255
     *  
1256
     * Need to:
1257
     *      Only include a package once.
1258
     *      Only include packages that can/need to be built at the moment
1259
     * 
1260
     * @param p     - Package to process
1261
     */
1262
 
1263
    private void calcBuildPlan(Package p) {
1264
 
1265
        p.mRipplePlan = usedByPackages(p);
1266
 
1267
        //  Use a ListIterator so that we can add elements to the end of the list while processing
1268
        for (ListIterator<Package> it = p.mRipplePlan.listIterator(); it.hasNext(); )
1269
        {
1270
            Package pkg = it.next();
1271
            ArrayList<Package> usedBy = usedByPackages(pkg);
1272
            for (Iterator<Package> it1 = usedBy.iterator(); it1.hasNext(); )
1273
            {
1274
                Package uPkg = it1.next();
1275
                if ( ! p.mRipplePlan.contains( uPkg ))
1276
                {
1277
                    it.add(uPkg);
1278
                }
1279
            }
1280
        }
1281
 
1282
        //
1283
        //  Now have a plan on what will be affected when we build the package
1284
        //  Calculate the time it will take - include my time
1285
        //
1286
        p.mRippleTime = p.mBuildTime;
1287
        for (ListIterator<Package> it = p.mRipplePlan.listIterator(); it.hasNext(); )
1288
        {
1289
            Package pkg = it.next();
1290
            p.mRippleTime += pkg.mBuildTime;
1291
        }
1292
    }
1293
 
1294
    /** 
1295
     *  Calculate a collection of packages that actively use the named package
1296
     *  A consumer package does NOT use the named package,
1297
     *      If the consumer is an SDK or is Pegged
1298
     *      If the consumer is marked as advisoryRipple
1299
     *      If the consumer cannot be built
1300
     *   
1301
     * @param pkg - Package to process
1302
     * @return A collection of packages that actively 'use' the specified package
1303
 
1304
     */
1305
    private ArrayList<Package> usedByPackages(Package pkg) {
1306
 
1307
        ArrayList<Package> usedBy = new ArrayList<Package>();
1308
 
1309
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
1310
        {
1311
            Package p = it.next();
1312
 
1313
            //  Is this package 'actively used' in the current build
1314
            if (p.mBuildFile >= 0)
1315
            {
1316
                for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
1317
                {
1318
                    String alias = it2.next();
1319
                    if ( alias == pkg.mAlias) {
1320
                        //  Have found a consumer of 'pkg'
1321
                        usedBy.add(p);
6914 dpurdie 1322
                        break;
1323
                    }
1324
                }
1325
            }
7048 dpurdie 1326
        }
1327
 
1328
        return usedBy;
6914 dpurdie 1329
    }
1330
 
1331
    /** Determine if a given PVID is a member of the current release.
1332
     *  Used to determine if a package dependency is out of date
1333
     * 
1334
     * @param dpvId
1335
     * @return true - specified pvid is a full member of the Release
1336
     */
1337
    private boolean isInRelease(Integer dpvId) {
1338
 
7048 dpurdie 1339
        boolean inRelease = false;
6914 dpurdie 1340
 
7048 dpurdie 1341
        for ( Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
6914 dpurdie 1342
        {
7048 dpurdie 1343
            Package p = it.next();
6914 dpurdie 1344
 
7048 dpurdie 1345
            if ( p.mId == dpvId )
6914 dpurdie 1346
            {
7048 dpurdie 1347
                inRelease = ! p.mIsNotReleased;
6914 dpurdie 1348
                break;
1349
            }
1350
        }
7048 dpurdie 1351
        return inRelease;
6914 dpurdie 1352
    }
1353
 
1354
 
1355
    /**reports what change in build exceptions happens as part of planRelease
1356
     */
1357
    public void reportChange() throws SQLException, Exception
1358
    {
1359
        int counter = 0;
1360
        for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1361
        {
1362
            BuildExclusion buildExclusion = it.next();
1363
 
1364
            if ( !buildExclusion.isProcessed() )
1365
            {
7032 dpurdie 1366
                if (buildExclusion.isImported() && ! buildExclusion.isARootCause() ) {
1367
                    // Remove from the exclusion list
1368
                    buildExclusion.includeToBuild(mReleaseManager, mBaseline);
7048 dpurdie 1369
                    mLogger.error("reportChange remove unused exclusion: {}", buildExclusion.info());
7032 dpurdie 1370
                } else {
1371
                    // Exclude and notify
1372
                    buildExclusion.excludeFromBuild(mReleaseManager, mBaseline);
1373
                    buildExclusion.email(this, mPackageCollection);
1374
                    counter++;
1375
                }
6914 dpurdie 1376
            }
1377
        }
7048 dpurdie 1378
        mLogger.error("reportChange exclusion count: {}", counter);
6914 dpurdie 1379
    }
1380
 
1381
    /**reports the build plan
1382
     */
1383
    public void reportPlan() throws SQLException, Exception
1384
    {
1385
        mReleaseManager.reportPlan(mRtagId, mBuildOrder);
1386
    }
1387
 
1388
    /**Returns the first build file from the collection
1389
     * The build file will be flagged as empty if none exists
1390
     */
1391
    public BuildFile getFirstBuildFileContent()
1392
    {
1393
        mLogger.debug("getFirstBuildFileContent");
1394
 
1395
        mBuildIndex = -1;
1396
        return getNextBuildFileContent();
1397
    }
1398
 
1399
    /**Returns next build file from the collection
1400
     * The build file will be flagged as empty if none exists
1401
     */
1402
    public BuildFile getNextBuildFileContent()
1403
    {
1404
        mLogger.debug("getNextBuildFileContent");
1405
        BuildFile retVal = null;
1406
 
1407
        try
1408
        {
1409
            mBuildIndex++;
1410
            retVal = mBuildCollection.get( mBuildIndex );
1411
        }
1412
        catch( IndexOutOfBoundsException e )
1413
        {
1414
            // Ignore exception. retVal is still null.
1415
        }
1416
 
1417
        if (retVal == null)
1418
        {
1419
            retVal = new BuildFile();
1420
        }
1421
 
7048 dpurdie 1422
        mLogger.debug("getNextBuildFileContent returned {}", retVal.state.name() );
6914 dpurdie 1423
        return retVal;
1424
    }
1425
 
1426
 
1427
    /**collects meta data associated with the baseline
1428
     * this is sufficient to send an indefinite pause email notification 
1429
     *  
1430
     * Escrow: Used once to collect information about the SBOM and associated Release 
1431
     *         mBaseline is an SBOMID 
1432
     * Daemon: Used each build cycle to refresh the information 
1433
     *          mBaseline is an RTAGID
1434
     */
1435
    public void collectMetaData() throws SQLException, Exception
1436
    {
1437
        Phase phase = new Phase("cmd");
7048 dpurdie 1438
        mLogger.debug("collectMetaData mDaemon {}", mDaemon);
6914 dpurdie 1439
 
1440
        try
1441
        {
1442
            phase.setPhase("connect");
1443
            mReleaseManager.connect();
1444
 
1445
            if (! mDaemon)
1446
            {
1447
                mSbomId = mBaseline;
1448
                phase.setPhase("queryRtagIdForSbom");
1449
                mRtagId = mReleaseManager.queryRtagIdForSbom(mBaseline);
1450
                if (mRtagId == 0)
1451
                {
7033 dpurdie 1452
                    mLogger.error("SBOM does not have a matching Release. Cannot be used as a base for an Escrow"); 
6914 dpurdie 1453
                    throw new Exception("rtagIdForSbom show stopper. SBOM does not have an associated Release");
1454
                }
1455
            }
1456
 
1457
            phase.setPhase("queryReleaseConfig");
1458
            mReleaseManager.queryReleaseConfig(mRtagId);
1459
 
1460
            if (mDaemon)
1461
            {
1462
                phase.setPhase("queryMailServer");
1463
                setMailServer(mReleaseManager.queryMailServer());
1464
                phase.setPhase("queryMailSender");
1465
                setMailSender(mReleaseManager.queryMailSender());
1466
                phase.setPhase("queryGlobalAddresses");
1467
                setMailGlobalTarget(mReleaseManager.queryGlobalAddresses());
1468
                phase.setPhase("queryProjectEmail");
1469
                mMailGlobalCollection = mReleaseManager.queryProjectEmail(mBaseline);
1470
                phase.setPhase("mMailGlobalTarget");
1471
                mMailGlobalCollection.add(0,getMailGlobalTarget());
1472
            }
1473
            phase.setPhase("queryBaselineName");
1474
            mBaselineName = mReleaseManager.queryBaselineName(mBaseline);
1475
            phase.setPhase("Done");
1476
        }
1477
        finally
1478
        {
1479
            // this block is executed regardless of what happens in the try block
1480
            // even if an exception is thrown
1481
            // ensure disconnect
1482
            mReleaseManager.disconnect();
1483
        }
1484
    }
1485
 
1486
    /**
1487
     * Find Package by package alias
1488
     * Searches the complete package collection
1489
     * @param   alias               - alias of package to locate
1490
     * @return  Package with the matching mAlias or NULL_PACKAGE if no package has the mAlias
1491
     */
1492
    public Package findPackage(String alias)
1493
    {
1494
        mLogger.debug("findPackage");
1495
 
1496
        Package retVal = mReleaseManager.findPackage(alias, mPackageCollection);
1497
 
7048 dpurdie 1498
        mLogger.info("findPackage returned {}", retVal.mName);
6914 dpurdie 1499
        return retVal;
1500
    }
1501
 
1502
    /**
1503
     * Sets the mBuildFile to -5 (indirectly dependent on package versions which are not reproducible) 
7048 dpurdie 1504
     * for the package and all dependent packages that are a part of the release set.
1505
     *  
7032 dpurdie 1506
     * @param p             The package being excluded 
1507
     * @param rootPvId      The PVID of the package that is causing the exclusion. Null or -ve values are special
1508
     *                      This package is the root cause, -2: Excluded by Ripple Stop 
6914 dpurdie 1509
     *                   
7032 dpurdie 1510
     * @param rootCause     Text message. Max 50 characters imposed by RM database 
1511
     * @param list          If not null, add build exclusion to specified list, else use default(mBuildExclusionCollection) list. Allows insertions while iterating the list.
1512
     * @param be            If not null, process provided BuildExclusion element, otherwise find-existing/create a BuildExclusion element
1513
     * @param dependentToo  True: Exclude all packages that depend on the excluded package 
6914 dpurdie 1514
     */
1515
    private void rippleBuildExclude(Package p, int rootPvId, String rootCause, ListIterator<BuildExclusion> list, BuildExclusion be, boolean dependentToo )
1516
    {
1517
        mLogger.debug("rippleBuildExclude");
7048 dpurdie 1518
 
6914 dpurdie 1519
        if ( p.mBuildFile == 0 || p.mBuildFile == 1 )
1520
        {
1521
            p.mBuildFile = -5;
7048 dpurdie 1522
            mLogger.info("rippleBuildExclude set mBuildFile to -5 for package {}", p.mAlias );
6914 dpurdie 1523
 
1524
            if ( be != null )
1525
            {
7032 dpurdie 1526
                be.setProcessed();
6914 dpurdie 1527
            }
1528
            else
1529
            {
1530
                //  If no be item has been provided, then scan the complete collection looking for a matching item
1531
                //  If found, process it, else add it (unprocessed)
1532
                boolean found = false;
1533
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1534
                {
1535
                    BuildExclusion buildExclusion = it.next();
1536
 
1537
                    if ( buildExclusion.compare(p.mId, rootPvId, rootCause))
1538
                    {
7032 dpurdie 1539
                        buildExclusion.setProcessed();
6914 dpurdie 1540
                        found = true;
1541
                        break;
1542
                    }
1543
                }
1544
 
1545
                if (!found)
1546
                {
1547
                    // Entry not found in the mBuildExclusionCollection
1548
                    // Mark all occurrences for this package as processed
1549
                    // These will be superseded by a new build exclusion entry
1550
                    for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1551
                    {
1552
                        BuildExclusion buildExclusion = it.next();
1553
 
1554
                        if ( buildExclusion.compare(p.mId))
1555
                        {
7032 dpurdie 1556
                            buildExclusion.setProcessed();
6914 dpurdie 1557
                        }
1558
                    }
1559
 
1560
                    BuildExclusion buildExclusion = new BuildExclusion(p.mId, rootPvId, rootCause, p.mTestBuildInstruction);
1561
 
1562
                    //
1563
                    //  Add the new build exclusion to a list
1564
                    //    Either the default list or a user-specified list
1565
                    if ( list == null )
1566
                    {
1567
                        mBuildExclusionCollection.add(buildExclusion);
1568
                    }
1569
                    else
1570
                    {
1571
                        // must use the ListIterator interface to add to the collection whilst iterating through it
1572
                        list.add(buildExclusion);
1573
                    }
1574
                }
1575
            }
1576
 
1577
            //  Locate ALL packages that depend on this package and exclude them too
1578
            //  This process will be recursive
1579
            //    Not sure that this it is efficient 
7048 dpurdie 1580
            //  Only ripple a build exclusion through for packages that are a part of the full release set
1581
            //  NewWIPs, ForcedRipples and TestBuilds will not force consumer packages to be excluded
6914 dpurdie 1582
            //
7048 dpurdie 1583
            if ( ! p.mIsNotReleased && dependentToo)
6914 dpurdie 1584
            {
7048 dpurdie 1585
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1586
                {
1587
                    Package pkg = it.next();
1588
 
1589
                    if ( pkg != p )
1590
                    {
1591
                        for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
1592
                        {
1593
                            Package dependency = it2.next();
1594
 
1595
                            if ( dependency == p )
1596
                            {
1597
                                rippleBuildExclude( pkg, rootPvId, null, list, null, dependentToo );
1598
                                break;
1599
                            }
1600
                        }
1601
                    }
1602
                }
1603
            }
1604
        }
7048 dpurdie 1605
        mLogger.info("rippleBuildExclude set {} {}", p.mName, p.mBuildFile);
6914 dpurdie 1606
    }
1607
 
1608
    /**Simple XML string escaping
1609
     * 
1610
     * @param xml		- String to escape
1611
     * @return		- A copy of the string with XML-unfriendly characters escaped 
1612
     */
1613
    public static String escapeXml( String xml )
1614
    {
1615
        xml = xml.replaceAll("&", "&amp;");
1616
        xml = xml.replaceAll("<", "&lt;");
1617
        xml = xml.replaceAll(">", "&gt;");
1618
        xml = xml.replaceAll("\"","&quot;");
1619
        xml = xml.replaceAll("'", "&apos;");
1620
        xml = xml.replaceAll("\\$", "\\$\\$");
1621
 
1622
        return xml;
1623
    }
1624
 
1625
    /** Quote a string or a string pair
1626
     *  If two strings are provided, then they will be joined with a comma.
1627
     *   
1628
     * @param text		- First string to quote
1629
     * @param text2		- Optional, second string
1630
     * @return A string of the form 'text','text2'
1631
     */
1632
    public static String quoteString(String text, String text2)
1633
    {
1634
        String result;
1635
        result =  "\'" + text + "\'";
1636
        if (text2 != null )
1637
        {
1638
            result +=  ",\'" + text2 + "\'";  
1639
        }
1640
        return result;
1641
    }
1642
 
1643
    /** Generate build file information
1644
     * 
1645
     */
1646
    private void generateBuildFiles() 
1647
    {
1648
 
1649
        // persist the build files
1650
        boolean allProcessed = false;
1651
        int buildFile = 1;
1652
        StringBuilder rawData = new StringBuilder();
1653
        StringBuilder setUp = new StringBuilder();
1654
 
1655
        mLogger.debug("generateBuildFiles");
1656
 
1657
        if ( mDaemon )
1658
        {
1659
            // all interesting packages in daemon mode match the following filter
1660
            buildFile = 3;
1661
        }
1662
 
1663
        //-----------------------------------------------------------------------
1664
        //    Generate the build file
1665
        do
1666
        {
1667
            BuildFile buildEntry = new  BuildFile();
1668
            buildEntry.state = BuildFileState.Dummy;
1669
            XmlBuilder xml = generateBuildFileHeader();
1670
 
1671
 
1672
            //	Generate properties for each package in this build level or lower build levels
1673
            //	The properties link the packageAlias to the PackageName and PackageVersion
1674
            //
1675
            //	[DEVI 54816] In escrow mode all unreproducible packages are included 
7048 dpurdie 1676
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1677
            {
1678
                Package p = it.next();
1679
 
1680
                if ( ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) ) || ( !mDaemon && p.mBuildFile == -2 ) )
1681
                {
1682
                    xml.addProperty(p.mAlias, p.mName + " " + p.mVersion + p.mExtension);
1683
                }
1684
            }
1685
 
1686
            //	UTF Support
1687
            //	Insert additional info into the build file to provide extra checking
1688
            //
7048 dpurdie 1689
            if ( ! mReleaseManager.mUseDatabase )
6914 dpurdie 1690
            {
1691
                // UTF Support
1692
                // Insert per-package planning information
1693
                //
7048 dpurdie 1694
                xml.addComment("mPackageCollectionAll");
1695
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1696
                {
1697
                    Package p = it.next();
1698
                    generatePackageInfo(xml, p);
1699
                }
1700
 
1701
                // UTF Support
1702
                // Insert build exclusion information
1703
                xml.addComment("mBuildExclusionCollection");
1704
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1705
                {
1706
                    BuildExclusion buildExclusion = it.next();
1707
                    if (!buildExclusion.isProcessed())
1708
                    {
1709
                        xml.addComment(buildExclusion.info());
1710
                    }
1711
                }
1712
 
1713
                // UTF Support
1714
                // Insert build Plan
1715
                if (mDaemon)
1716
                {
1717
                    xml.addComment("mBuildOrder");
1718
                    int order = 0;
1719
                    for (Iterator<Package> it = mBuildOrder.iterator(); it.hasNext(); )
1720
                    {
1721
                        Package p = it.next();
1722
                        String comment =
1723
                                "pvid="+ p.mId +
7048 dpurdie 1724
                                " order=" + (++order) +
6914 dpurdie 1725
                                " name=\"" + p.mAlias + "\"";
1726
                        xml.addComment(comment);
1727
                    }
1728
                }
1729
            }
1730
 
1731
            //  Generate Taskdef information
1732
            generateTaskdef(xml);
1733
 
1734
            //
1735
            //  Insert known Machine Information
1736
            //  Escrow usage: 
1737
            //      Map machType to machClass
1738
            //  Also serves as a snapshot of the required build configuration
1739
            //  ie: machine types and buildfilters
1740
            //
1741
            if (!mDaemon)
1742
            {
1743
                generateMachineInfo(xml, null);
1744
            }
1745
 
1746
            //
1747
            //	Generate target rules for each package to be built within the current build file
1748
            //
1749
            boolean daemonHasTarget = false;
1750
 
7048 dpurdie 1751
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1752
            {
1753
                Package p = it.next();
1754
 
1755
                if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
1756
                {
1757
                    generateTarget(xml, buildEntry, p, buildFile);
1758
 
1759
                    if ( p.mBuildFile == 1 )
1760
                    {
1761
                        daemonHasTarget = true;
1762
 
1763
                        // Retain information about the target package
1764
                        buildEntry.mPkgId = p.mPid;
1765
                        buildEntry.mPvId = p.mId;
1766
                    }
1767
                }
1768
 
1769
                //	Generate escrow extraction commands
1770
                //	Only done on the first pass though the packages
1771
                //
1772
                if ( !mDaemon && buildFile == 1 )
1773
                {
1774
                    setUp.append("jats jats_vcsrelease -extractfiles"
1775
                                + " \"-label=" + p.mVcsTag + "\""
1776
                                + " \"-view=" + p.mAlias + "\""
1777
                                + " -root=. -noprefix"
1778
                                + mlf );
1779
                }
1780
 
1781
                //	Generate escrow raw CSV data
1782
                //	Note: I don't think this data is used at all
1783
 
1784
                if ( !mDaemon && ( p.mBuildFile == buildFile))
1785
                {
1786
                    StringAppender machines = new StringAppender(",");
1787
                    for (Iterator<BuildStandard> it1 = p.mBuildStandardCollection.iterator(); it1.hasNext();)
1788
                    {
1789
                        BuildStandard bs = it1.next();
1790
                        machines.append(bs.mMachClass);
1791
                    }
1792
 
1793
                    rawData.append(p.mAlias + "," +
1794
                                    buildFile + "," +
1795
                                    machines +
1796
                                    mlf);
1797
                }
1798
            }
1799
 
1800
            if ( mDaemon && !daemonHasTarget )
1801
            {
1802
                // must have AbtTestPath, AbtSetUp, AbtTearDown, and AbtPublish targets
1803
                XmlBuilder target = xml.addNewElement("target");
1804
                target.addAttribute("name", "AbtTestPath");
1805
 
1806
                target = xml.addNewElement("target");
1807
                target.addAttribute("name", "AbtSetUp");
1808
 
1809
                target = xml.addNewElement("target");
1810
                target.addAttribute("name", "AbtTearDown");
1811
 
1812
                target = xml.addNewElement("target");
1813
                target.addAttribute("name", "AbtPublish");
1814
            }
1815
 
1816
            generateDefaultTarget( xml, buildFile);
1817
 
1818
            //	Convert the Xml structure into text and save it in the build file
1819
            //	Add this build file to the mBuildCollection
1820
            buildEntry.content = mXmlHeader + xml.toString();
1821
            mBuildCollection.add(buildEntry);
1822
 
1823
            // are more build files required
1824
            allProcessed = true;
1825
 
1826
            if (!mDaemon)
1827
            {
1828
                // this is escrow mode centric
7048 dpurdie 1829
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1830
                {
1831
                    Package p = it.next();
1832
 
1833
                    if ( p.mBuildFile > buildFile )
1834
                    {
1835
                        // more build files are required
1836
                        allProcessed = false;
7048 dpurdie 1837
                        mLogger.info("planRelease reiterating package has no build requirement {} {} {}",p.mName, p.mBuildFile,  buildFile);
6914 dpurdie 1838
                        break;
1839
                    }
1840
                } 
1841
 
1842
                buildFile++;
1843
            }
1844
 
1845
        } while( !allProcessed );
1846
 
1847
        //	Save additional escrow data
1848
        if ( !mDaemon )
1849
        {
1850
            mEscrowSetup = setUp.toString();
1851
            mEscrowRawData = rawData.toString();
1852
        }
1853
    }
1854
 
1855
    /**returns a build file header for the mBaseline
1856
     */
1857
    private XmlBuilder generateBuildFileHeader()
1858
    {
1859
        mLogger.debug("generateBuildFileHeader");
1860
        XmlBuilder element = new XmlBuilder("project");
1861
 
1862
        element.addAttribute("name", "mass");
1863
        element.addAttribute("default", "full");
1864
        element.addAttribute("basedir", ".");
1865
 
1866
        if ( mDaemon )
1867
        {
1868
            element.addProperty("abt_mail_server", getMailServer());
1869
            element.addProperty("abt_mail_sender", getMailSender()); 
1870
            element.addProperty("abt_rtag_id", mBaseline);
1871
            element.addProperty("abt_daemon", mReleaseManager.currentTimeMillis());
1872
            element.makePropertyTag("abt_packagetarball", true);
1873
            element.makePropertyTag("abt_usetestarchive", !ReleaseManager.getUseMutex());
1874
 
7048 dpurdie 1875
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 1876
            {
1877
                Package p = it.next();
1878
 
1879
                if ( p.mBuildFile == 1 )
1880
                {
1881
                    element.addProperty("abt_package_name", p.mName);
1882
                    element.addProperty("abt_package_version", p.mVersion + p.mExtension);
1883
                    element.addProperty("abt_package_extension", p.mExtension);
1884
                    element.addProperty("abt_package_location", getBuildLocation(p));
1885
                    element.addProperty("abt_package_ownerlist", p.emailInfoNonAntTask(this));
1886
                    element.addProperty("abt_package_build_info", buildInfoText(p));
1887
 
1888
                    // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
1889
                    StringAppender depends = new StringAppender(";");
1890
 
1891
                    for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
1892
                    {
1893
                        Package depend = it3.next();
1894
                        depends.append( quoteString(depend.mName, depend.mVersion + depend.mExtension) );
1895
                    }
1896
 
1897
                    element.addProperty("abt_package_depends", depends.toString());
1898
                    element.addProperty("abt_is_ripple", p.mDirectlyPlanned ? "0" : "1");
1899
                    element.addProperty("abt_build_reason", p.mBuildReason.toString());
1900
                    element.addProperty("abt_package_version_id", p.mId);
1901
                    element.addProperty("abt_does_not_require_source_control_interaction", ! p.mRequiresSourceControlInteraction ? "true" : "false" );
1902
                    element.addProperty("abt_test_build_instruction", p.mTestBuildInstruction);
1903
                }
1904
            }
1905
        }
1906
        else
1907
        {
1908
            //    Escrow Mode
1909
            element.addProperty("abt_rtag_id", mRtagId);
1910
            element.addProperty("abt_sbom_id", mSbomId);
1911
        }
1912
 
1913
        element.addProperty("abt_release", escapeXml(mBaselineName));
1914
        element.addProperty("abt_buildtool_version", mReleaseManager.getMajorVersionNumber() );
1915
 
1916
        element.addNewElement("condition")
1917
        .addAttribute("property", "abt_family")
1918
        .addAttribute("value", "windows")
1919
        .addNewElement("os")
1920
        .addAttribute("family", "windows");
1921
        element.addProperty("abt_family", "unix");
1922
 
1923
        return element;
1924
    }
1925
 
1926
    /** Add task def XML items taskdef for the abt ant task
1927
     * @param xml 	- xml item to extend
1928
     */
1929
    private void generateTaskdef(XmlBuilder xml)
1930
    {
1931
        mLogger.debug("generateTaskdef");
1932
        xml.addNewElement("taskdef")
1933
        .addAttribute("name", "abt")
1934
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABT");
1935
 
1936
        xml.addNewElement("taskdef")
1937
        .addAttribute("name", "abtdata")
1938
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABTData");
1939
    }
1940
 
1941
    /** returns the command abtdata items
1942
     *  <br>Common machine information
1943
     *  <br>Common email address
1944
     *  
1945
     *  
1946
     *  @param	xml - Xml element to extend   
1947
     *  @param    p - Package (May be null)
1948
     */
1949
    private void generateMachineInfo(XmlBuilder xml, Package p)
1950
    {
1951
        XmlBuilder element = xml.addNewElement("abtdata");
1952
        element.addAttribute("id", "global-abt-data");
1953
 
1954
        //
1955
        //  Iterate over all the machines and create a nice entry
1956
        //
1957
        for (Iterator<ReleaseConfig> it = mReleaseManager.mReleaseConfigCollection.mReleaseConfig.iterator(); it.hasNext(); )
1958
        {
1959
            ReleaseConfig rc = it.next();
1960
            element.addElement(rc.getMachineEntry());
1961
        }
1962
 
1963
        //
1964
        //  Now the email information
1965
        //
1966
        if ( p != null)
1967
        {
1968
            p.emailInfo(this, element);
1969
        }
1970
    }
1971
 
1972
    /** Generate package information
1973
     *  Only when running unit tests
1974
     *  
1975
     * @param xml	- An xml element to append data to
1976
     * @param p	- Package to process
1977
     */
1978
    private void generatePackageInfo (XmlBuilder xml, Package p)
1979
    {
7051 dpurdie 1980
        String joiner = "";
1981
 
6914 dpurdie 1982
        String comment =
1983
                "pvid="+ p.mId + 
1984
                " name=\"" + p.mAlias + "\""+
1985
                " reason=" + p.mNoBuildReason +" "+ 
1986
                " buildFile=" + p.mBuildFile + " "+
1987
                " directlyPlanned=" + p.mDirectlyPlanned + " "+
7051 dpurdie 1988
                " indirectlyPlanned=" + p.mIndirectlyPlanned + " depends=[" ;
1989
 
1990
        for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
1991
        {
1992
            String alias = it2.next();
1993
            comment += joiner + alias;
1994
            joiner = ",";
1995
        }
1996
 
1997
        comment += "]";
6914 dpurdie 1998
 
1999
        xml.addComment(comment);            
2000
    }
2001
 
2002
    /**returns an ant target for the passed Package
2003
     * in daemon mode:
2004
     *  packages are categorized with one of three mBuildFile values:
2005
     *   1 the package to be built by this buildfile
2006
     *   2 the packages with a future build requirement
2007
     *   3 the packages with no build requirement
2008
     *  the returned target depends on this categorization and will have
2009
     *   1 full abt info
2010
     *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
2011
     *   3 only a name attribute (will not build this package)
2012
     * in escrow mode:
2013
     *  if the passed Package's mBuildFile is different (less than) the passed build file,
2014
     *  the returned target have only a name attribute (will not build this package)
2015
     *   
2016
     * @param xml - Xml element to extend
2017
     * @param buildEntry - Record build type (dummy/generic/not generic)
2018
     * @param p - Package to process
2019
     * @param buildFile - buildfile level being processed
2020
     */
2021
    private void generateTarget(XmlBuilder xml, BuildFile buildEntry, Package p, int buildFile)
2022
    {
2023
        mLogger.debug("generateTarget");
2024
 
2025
        //---------------------------------------------------------------------
2026
        //  Generate the AbtData - common machine and email information
2027
        //  Only used by the daemon builds
2028
        //
2029
        if ( mDaemon && p.mBuildFile == 1 )
2030
        {
2031
            generateMachineInfo(xml, p );
2032
        }
2033
 
2034
        //-------------------------------------------------------------------------
2035
        //  Generate the <target name=... /> construct
2036
        //  There are two types
2037
        //      1) Simple dummy place holder. Just has the PackageName.PackageExt
2038
        //      2) Full target. Has all information to build the package including
2039
        //              AbtSetUp, AbtTearDown and AbtPublish targets
2040
        //
2041
 
2042
        if ( !mDaemon && ( p.mBuildFile < buildFile ) )
2043
        {
2044
            XmlBuilder target = xml.addNewElement("target");
2045
            target.addAttribute("name", p.mAlias);
2046
        }
2047
        else
2048
        {
2049
            if (!mDaemon) 
2050
            {
2051
                //  Escrow Only:
2052
                //  Generate the 'wrapper' target
2053
                //  This is used to ensure that the required dependencies have been built - I think
2054
                //
2055
                StringAppender dependList = new StringAppender(",");
2056
                if ( !p.mPackageDependencyCollection.isEmpty() )
2057
                {
2058
                    for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2059
                    {
2060
                        Package dependency = it.next();
2061
                        if ( !mDaemon && dependency.mBuildFile == -2 )
2062
                        {
2063
                            // ignore targets which build in foreign environments in escrow mode
2064
                            continue;
2065
                        }
2066
                        dependList.append(dependency.mAlias);
2067
                    }
2068
                }
2069
 
2070
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2071
                target.addAttribute("name", p.mAlias + ".wrap");
2072
 
2073
                if (dependList.length() > 0)
2074
                {
2075
                    target.addAttribute("depends", dependList.toString() );
2076
                }
2077
 
2078
                if ( !mDaemon )
2079
                {
2080
                    boolean hasDependenciesBuiltInThisIteration = false;
2081
                    if ( ( !p.mPackageDependencyCollection.isEmpty()) )
2082
                    {
2083
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2084
                        {
2085
                            Package dependency = it.next();
2086
 
2087
                            if ( dependency.mBuildFile == buildFile )
2088
                            {
2089
                                hasDependenciesBuiltInThisIteration = true;
2090
                                break;
2091
                            }
2092
                        }
2093
                    }
2094
 
2095
                    if ( hasDependenciesBuiltInThisIteration )
2096
                    {
2097
                        XmlBuilder condition = target.addNewElement("condition");
2098
                        condition.addAttribute("property",  p.mAlias + ".build");
2099
 
2100
                        XmlBuilder and = condition.addNewElement("and");
2101
 
2102
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2103
                        {
2104
                            Package dependency = it.next();
2105
 
2106
                            if ( dependency.mBuildFile == buildFile )
2107
                            {
2108
                                XmlBuilder or = and.addNewElement("or");
2109
 
2110
                                XmlBuilder equal1 = or.addNewElement("equals");
2111
                                equal1.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2112
                                equal1.addAttribute("arg2", "0");
2113
 
2114
                                XmlBuilder equal2 = or.addNewElement("equals");
2115
                                equal2.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2116
                                equal2.addAttribute("arg2", "257");
2117
                            }
2118
                        }
2119
                    }
2120
                    else
2121
                    {
2122
                        target.addProperty(p.mAlias + ".build", "");
2123
                    }
2124
                }
2125
            }
2126
 
2127
 
2128
            //
2129
            //  Generate the 'body' of the target package
2130
            //  Escrow Mode: Always
2131
            //  Daemon Mode: Only for the one target we are building
2132
            //                  Simplifies the XML
2133
            //                  Reduces noise in the logs
2134
            //              Don't add target dependencies. 
2135
            //                  We are only building one target and the 
2136
            //                  dependency management has been done way before now.
2137
            //                  All it does is makes the logs noisy.
2138
            //
2139
            if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
2140
            {
2141
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2142
                target.addAttribute("name", p.mAlias);
2143
 
2144
                if ( !mDaemon )
2145
                {
2146
                    target.addAttribute("depends",  p.mAlias + ".wrap");
2147
                    target.addAttribute("if",p.mAlias + ".build");
2148
                }
2149
 
2150
                if ( mDaemon && p.mBuildFile == 1 )
2151
                {
2152
                    target.addProperty(p.mAlias + "pkg_id",p.mPid);
2153
                    target.addProperty(p.mAlias + "pv_id",p.mId);
2154
                }
2155
 
2156
                target.addProperty(p.mAlias + "packagename",p.mName);        		
2157
                target.addProperty(p.mAlias + "packageversion",p.mVersion);
2158
                target.addProperty(p.mAlias + "packageextension",p.mExtension);
2159
                target.addProperty(p.mAlias + "packagevcstag",p.mVcsTag);
2160
 
2161
                target.makePropertyTag(p.mAlias + "directchange", p.mDirectlyPlanned); 
2162
                target.makePropertyTag(p.mAlias + "doesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2163
 
2164
                buildEntry.state = BuildFile.BuildFileState.NonGeneric;
2165
                if ( p.isGeneric() )
2166
                {
2167
                    buildEntry.state = BuildFile.BuildFileState.Generic;
2168
                    target.makePropertyTag(p.mAlias + "generic", true); 
2169
                }
2170
 
2171
                target.addProperty(p.mAlias + "loc", getBuildLocation(p));
2172
                target.makePropertyTag(p.mAlias + "unittests", p.mHasAutomatedUnitTests && mDaemon);
2173
 
2174
                //    Add our own task and associated information
2175
                //
2176
                XmlBuilder abt = target.addNewElement("abt").isExpanded();
2177
 
2178
                for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2179
                {
2180
                    Package dependency = it.next();
2181
                    XmlBuilder depend = abt.addNewElement("depend");
2182
                    depend.addAttribute("package_alias", "${" + dependency.mAlias + "}");
2183
                }
2184
 
2185
                buildInfo(abt,p);
2186
 
2187
                if ( mDaemon && p.mBuildFile == 1 )
2188
                {
2189
                    //    AbtTestPath
2190
                    target = xml.addNewElement("target").isExpanded();
2191
                    target.addAttribute("name", "AbtTestPath");
2192
                    target.addProperty("AbtTestPathpackagevcstag", p.mVcsTag);
2193
                    target.addProperty("AbtTestPathpackagename", p.mName);
2194
                    abt = target.addNewElement("abt").isExpanded();
2195
                    buildInfo(abt, p);
2196
 
2197
 
2198
                    //    AbtSetUp
2199
                    target = xml.addNewElement("target").isExpanded();
2200
                    target.addAttribute("name", "AbtSetUp");
2201
                    target.addProperty("AbtSetUppackagevcstag", p.mVcsTag);
2202
                    target.addProperty("AbtSetUppackagename", p.mName);
2203
 
2204
                    abt = target.addNewElement("abt").isExpanded();
2205
                    buildInfo(abt, p);
2206
 
2207
                    //    AbtTearDown
2208
                    target = xml.addNewElement("target").isExpanded();
2209
                    target.addAttribute("name", "AbtTearDown");
2210
                    target.addProperty("AbtTearDownpackagevcstag", p.mVcsTag);
2211
                    target.addProperty("AbtTearDownpackagename", p.mName);
2212
                    target.addProperty("AbtTearDownpackageversion", p.mVersion);
2213
                    target.addProperty("AbtTearDownpackageextension", p.mExtension);
2214
                    target.makePropertyTag(p.mAlias + "generic", p.isGeneric());
2215
 
2216
                    abt = target.addNewElement("abt").isExpanded();
2217
                    buildInfo(abt, p);
2218
 
2219
 
2220
                    //  AbtPublish
2221
                    target = xml.addNewElement("target").isExpanded();
2222
                    target.addAttribute("name", "AbtPublish");
2223
 
2224
                    target.addProperty("AbtPublishpackagevcstag", p.mVcsTag);
2225
                    target.addProperty("AbtPublishpackagename", p.mName);
2226
                    target.addProperty("AbtPublishpackageversion", p.mVersion);
2227
                    target.addProperty("AbtPublishpackageextension", p.mExtension);
2228
                    target.makePropertyTag("AbtPublishdirectchange", p.mDirectlyPlanned);
2229
                    target.makePropertyTag("AbtPublishdoesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2230
                    target.makePropertyTag("AbtPublishgeneric", p.isGeneric());
2231
                    target.addProperty("AbtPublishloc", getBuildLocation(p));
2232
 
2233
                    abt = target.addNewElement("abt").isExpanded();
2234
                    buildInfo(abt, p);
2235
 
2236
                }
2237
            }
2238
        }
2239
    }
2240
 
2241
    /** Extends the xml object. Adds ant default target for the current build iteration
2242
     * @param xml - The XmlBuilder Object to extend
2243
     * @param buildFile - The current build file level. This differs for Daemon and Escrow mode. In Daemon mode it will not be a '1' 
2244
     */
2245
    private void generateDefaultTarget(XmlBuilder xml, int buildFile)
2246
    {
2247
        mLogger.debug("generateDefaultTarget");
2248
 
2249
        XmlBuilder target = xml.addNewElement("target").isExpanded();
2250
        target.addAttribute("name", "fullstart");
2251
 
2252
        if (buildFile == 1)
2253
        {
2254
            antEcho(target, "${line.separator}" + mAnyBuildPlatforms + "${line.separator}${line.separator}");
7048 dpurdie 2255
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2256
            {
2257
                Package p = it.next();
2258
 
2259
                if ( p.mBuildFile == -1 )
2260
                {
2261
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2262
                }
2263
            }
2264
 
2265
            antEcho(target, "${line.separator}" + mAssocBuildPlatforms + "${line.separator}${line.separator}");
7048 dpurdie 2266
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2267
            {
2268
                Package p = it.next();
2269
 
2270
                if ( p.mBuildFile == -2 )
2271
                {
2272
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2273
                }
2274
            }
2275
 
2276
            antEcho(target, "${line.separator}" + mNotInBaseline + "${line.separator}${line.separator}");
7048 dpurdie 2277
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2278
            {
2279
                Package p = it.next();
2280
 
2281
                if ( p.mBuildFile == -4 )
2282
                {
2283
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2284
                }
2285
            }
2286
 
2287
            antEcho(target, "${line.separator}" + mDependent + "${line.separator}${line.separator}");
7048 dpurdie 2288
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2289
            {
2290
                Package p = it.next();
2291
 
2292
                if ( p.mBuildFile == -5 )
2293
                {
2294
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2295
                }
2296
            }
2297
        }
2298
 
2299
        if ( !mDaemon )
2300
        {
2301
            antEcho(target, "${line.separator}Build Started:${line.separator}${line.separator}");
2302
        }
2303
 
2304
        //
2305
        //	Create a comma separated list of all the required targets
2306
        //      Escrow : All packages
2307
        //      Daemon : Just the package being built
2308
        //
2309
        StringAppender dependList = new StringAppender(",");
2310
        dependList.append("fullstart");
7048 dpurdie 2311
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2312
        {
2313
            Package p = it.next();
2314
 
2315
            if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
2316
            {
2317
                if ((mDaemon && p.mBuildFile == 1) || !mDaemon)
2318
                {
2319
                    dependList.append(p.mAlias);                    
2320
                }
2321
            }
2322
        }
2323
 
2324
        target = xml.addNewElement("target").isExpanded();
2325
        target.addAttribute("name", "full");
2326
        target.addAttribute("depends", dependList.toString());
2327
 
2328
        if ( !mDaemon )
2329
        {
2330
            antEcho(target, "${line.separator}Build Finished${line.separator}");
2331
        }
2332
    }
2333
 
2334
    /** Internal helper function to create an ant 'echo statement
2335
     *  Many of the parameters are fixed
2336
     */
2337
    private void antEcho( XmlBuilder xml, String message)
2338
    {
2339
        XmlBuilder msg = xml.addNewElement("echo");
2340
        msg.addAttribute("message", message);
2341
        msg.addAttribute("file", "publish.log");
2342
        msg.addAttribute("append", "true");
2343
    }
2344
 
2345
    /**sets the mIndirectlyPlanned true for the package and all dependent packages
2346
     */
2347
    private void rippleIndirectlyPlanned(Package p)
2348
    {
2349
        mLogger.debug("rippleIndirectlyPlanned");
2350
        if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
2351
        {
2352
            p.mIndirectlyPlanned = true;
2353
 
7048 dpurdie 2354
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2355
            {
2356
                Package pkg = it.next();
2357
 
2358
                if ( pkg != p )
2359
                {
2360
                    for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
2361
                    {
2362
                        Package dependency = it2.next();
2363
 
2364
                        if ( dependency == p )
2365
                        {
2366
                            rippleIndirectlyPlanned( pkg );
2367
                            break;
2368
                        }
2369
                    }
2370
                }
2371
            }
2372
        }
7048 dpurdie 2373
        mLogger.info("rippleIndirectlyPlanned set {} {}", p.mName, p.mIndirectlyPlanned);    
6914 dpurdie 2374
    }
2375
 
2376
    /**accessor method
2377
     */
2378
    public String getEscrowSetUp()
2379
    {
2380
        mLogger.debug("getEscrowSetUp");
2381
        String retVal = mEscrowSetup;
2382
 
7048 dpurdie 2383
        mLogger.debug("getEscrowSetUp returned {}", retVal);
6914 dpurdie 2384
        return retVal;
2385
    }
2386
 
2387
    /**accessor method
2388
     */
2389
    public String getRawData()
2390
    {
2391
        mLogger.debug("getRawData");
2392
        String retVal = mEscrowRawData;
2393
 
7048 dpurdie 2394
        mLogger.debug("getRawData returned {}", retVal);
6914 dpurdie 2395
        return retVal;
2396
    }
2397
 
2398
    /**Get the build loc (location)
2399
     * This is package specific and will depend on the build mode (Escrow/Daemon)
2400
     * 
2401
     * @param	p - Package being built
2402
     * @return A string that describes the build location
2403
     */
2404
    private String getBuildLocation(Package p)
2405
    {
2406
        mLogger.debug("locationProperty");
2407
        String location = "";
2408
 
2409
        if (mDaemon)
2410
        {
2411
            // Daemon: Start in root of view/workspace
2412
            location += mBaseline;
2413
        }
2414
        else
2415
        {
2416
            // Escrow: mAlias used with jats -extractfiles -view
2417
            location += p.mAlias;
2418
        }
2419
 
2420
        //
2421
        //  Always use '/' as a path separator - even if user has specified '\'
2422
        //  Ant can handle it.
2423
        //
2424
        location = location.replace('\\', '/');
2425
        return location;
2426
    }
2427
 
2428
    /**Adds package build into as XML elements 
2429
     * @param	  xml 	- Xml element to extend
2430
     * @param   p       - Package to process
2431
     */
2432
    private void buildInfo(XmlBuilder xml, Package p)
2433
    {
2434
        mLogger.debug("buildInfo");
2435
 
2436
        //
2437
        // Create the xml build information
2438
        // <platform gbe_machtype="linux_i386" type="jats" arg="all"/>
2439
        //
2440
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext();)
2441
        {
2442
            BuildStandard bs = it.next();
2443
            bs.getBuildStandardXml(xml);
2444
        }
2445
    }
2446
 
2447
    /**returns the buildInfo as a single line of text
2448
     * Used for reporting purposes only
2449
     * @param   p       - Package to process
2450
     * 
2451
     */
2452
    public String buildInfoText(Package p)
2453
    {
2454
        mLogger.debug("buildInfoText");
2455
 
2456
        StringAppender result = new StringAppender (";");
2457
 
2458
        //
2459
        //  Create platform:standards
2460
        //      
2461
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
2462
        {
2463
            BuildStandard bs = it.next();
2464
 
2465
            if ( bs.isActive() )
2466
            {
2467
                String info = bs.getBuildStandardText();
2468
                result.append(info);
2469
            }
2470
        }
2471
 
7048 dpurdie 2472
        mLogger.info("buildInfoText returned {}", result);
6914 dpurdie 2473
        return result.toString();
2474
    }
2475
 
2476
    /**prints to standard out in escrow mode only
2477
     * <br>Prints a title and information. The title is only printed once.
2478
     * 
2479
     * @param header - The message title to display, if printMessage is true
2480
     * @param text - A package name. Really just the 2nd line of the message
2481
     * @param printHeader -  Controls the printing of the message argument
2482
     */
2483
    private void standardOut(final String header, final String text, boolean printHeader)
2484
    {
2485
        mLogger.debug("standardOut");
2486
        if (!mDaemon)
2487
        {
2488
            if ( printHeader )
2489
            {
2490
                System.out.println(header);
2491
            }
2492
 
2493
            System.out.println(text);
2494
        }
2495
    }
2496
 
2497
 
2498
    /**
2499
     *  Email users about a rejected daemon instruction
2500
     *  @param  reason  - Reason for the rejection
2501
     *  @param  pkg     - Package to be affected by the instruction
2502
     *  
2503
     */
2504
    public void emailRejectedDaemonInstruction(String reason, Package p)
2505
    {
2506
        mLogger.debug("emailRejectedDaemonInstruction");
2507
 
2508
        //  Email Subject
2509
        String subject = "BUILD FAILURE of Daemon Instruction on package " + p.mAlias;
2510
 
2511
        // Email Body
2512
        String mailBody = "The build system reject the the Daemon Instruction";
2513
        mailBody += "<br>Reason: " + reason; 
2514
 
2515
        mailBody += "<p>Release: " + mBaselineName 
2516
                +  "<br>Package: " + p.mAlias 
2517
                +  "<br>Rm Ref: " + CreateUrls.generateRmUrl(getRtagId(), p.mId); 
2518
 
2519
        mailBody += "<p><hr>";
2520
 
2521
        String target = p.emailInfoNonAntTask(this);
2522
 
7048 dpurdie 2523
        mLogger.error("emailRejectedDaemonInstruction Server: {}", getMailServer());
2524
        mLogger.error("emailRejectedDaemonInstruction Sender: {}", getMailSender());
2525
        mLogger.error("emailRejectedDaemonInstruction Target: {}", target);
6914 dpurdie 2526
 
2527
        try
2528
        {
2529
            //    
7048 dpurdie 2530
            Smtpsend.send(getMailServer(),  // mailServer
2531
                    getMailSender(),        // source
2532
                    target,                 // target
2533
                    getMailSender(),        // cc
2534
                    null,                   // bcc
2535
                    subject,                // subject
2536
                    mailBody,               // body
2537
                    null                    // attachment
6914 dpurdie 2538
                    );
2539
        } catch (Exception e)
2540
        {
7048 dpurdie 2541
            mLogger.warn("Email Failure: emailRejectedDaemonInstruction:{}", e.getMessage());
6914 dpurdie 2542
        }
2543
    }
2544
 
2545
    /**
2546
     * @return the mMailServer
2547
     */
2548
    public String getMailServer() {
2549
        return mMailServer;
2550
    }
2551
 
2552
    /**
2553
     * @param mMailServer the mMailServer to set
2554
     */
2555
    public void setMailServer(String mMailServer) {
2556
        this.mMailServer = mMailServer;
2557
    }
2558
 
2559
    /**
2560
     * @return the mMailSender
2561
     */
2562
    public String getMailSender() {
2563
        return mMailSender;
2564
    }
2565
 
2566
    /**
2567
     * @param mMailSender the mMailSender to set
2568
     */
2569
    public void setMailSender(String mMailSender) {
2570
        this.mMailSender = mMailSender;
2571
    }
2572
 
2573
    /**
2574
     * @return the mMailGlobalTarget
2575
     */
2576
    public String getMailGlobalTarget() {
2577
        return mMailGlobalTarget;
2578
    }
2579
 
2580
    /**
2581
     * @param mMailGlobalTarget the mMailGlobalTarget to set
2582
     */
2583
    public void setMailGlobalTarget(String mMailGlobalTarget) {
2584
        this.mMailGlobalTarget = mMailGlobalTarget;
2585
    }
2586
 
2587
}