Subversion Repositories DevTools

Rev

Rev 7107 | Rev 7118 | 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
 
7082 dpurdie 73
    /** Collections of packages
6914 dpurdie 74
     */
75
    private ArrayList<Package> mPackageCollection = new ArrayList<Package>();
7082 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
     */
7082 dpurdie 122
    private ArrayList<PlannedPackage> mBuildOrder = new ArrayList  <PlannedPackage>();
6914 dpurdie 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
    {
7044 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
7044 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
    {
7044 dpurdie 219
        mLogger.warn("planRelease mDaemon {}", mDaemon);
6914 dpurdie 220
 
221
        mBuildCollection.clear();
222
        mPackageCollection.clear();
7082 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);
7082 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
 
7044 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
7082 dpurdie 379
        //    eg: dependency collection and build standard differences
6914 dpurdie 380
        //    Note: Done before mPackageDependencyCollection is setup
381
        //
382
        if ( mDaemon )
383
        {
7082 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();
7082 dpurdie 388
                mLogger.info("planRelease package test build {}", p.mAlias);
6914 dpurdie 389
 
7082 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
                {
7088 dpurdie 397
                    String reason;
398
                    reason = (p.mIsPegged) ? "Pegged" : "SDK Based";
6914 dpurdie 399
 
7082 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
 
7088 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
7082 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
            }
7082 dpurdie 427
        }    
6914 dpurdie 428
 
7082 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");
7082 dpurdie 433
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 434
        {
435
            Package p = it.next();
436
 
7082 dpurdie 437
            if ( p.hasCircularDependency( mPackageCollectionAll ) )
6914 dpurdie 438
            {
7044 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
 
7082 dpurdie 444
                // Exclude the package
6914 dpurdie 445
                // max 50 chars
7082 dpurdie 446
                rippleBuildExclude(p, p.mId, "Package has circular dependency", -6);
6914 dpurdie 447
 
448
                // take the package out of the build
449
                standardOut(mCircularDependency, p.mAlias, mCircularDependencyFlag);
450
                mCircularDependencyFlag = false;
451
            }
452
        }
453
 
454
        // Scan for packages with missing dependencies
455
        //    ie: The dependent package is not in the package Collection
456
        mLogger.debug("planRelease use the fully built mPackageDependencyCollection");
7082 dpurdie 457
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 458
        {
459
            Package p = it.next();
460
 
461
            if ( mDaemon )
462
            {
463
                //  Daemon Mode Only
464
                //  Not interested in the dependencies of a pegged package or a package provided from an SDK.
465
                //  Such packages will be deemed to not have missing dependencies
466
                if (p.mIsPegged || p.mIsSdk)
467
                {
468
                    continue;
469
                }
470
            }
471
 
472
            for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
473
            {
474
                String alias = it2.next();
475
                Package dependency = findPackage(alias);
476
 
477
                if (dependency == ReleaseManager.NULL_PACKAGE)
478
                {
7044 dpurdie 479
                    mLogger.info("planRelease dependency is not in the baseline {}", alias);
7088 dpurdie 480
                    // Exclude the package
6914 dpurdie 481
                    // max 50 chars
7082 dpurdie 482
                    rippleBuildExclude(p, p.mId, "Package build dependency not in the release", -4);
6914 dpurdie 483
 
484
                    // take the package out of the build
485
                    standardOut(mNotInBaseline, p.mAlias, mNotInBaselineFlag);
486
                    mNotInBaselineFlag = false;
487
                    break;
488
                }
489
            }
490
        }
491
 
7082 dpurdie 492
        // Detect packages with no build standard and exclude them from the build
6914 dpurdie 493
        mLogger.debug("planRelease process packages which are not reproducible");
7082 dpurdie 494
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 495
        {
496
            Package p = it.next();
497
 
498
            if (p.mBuildFile == 0)
499
            {
500
                if ( mDaemon )
501
                {
502
                    //  Daemon Mode Only
503
                    //  Not interested in the reproducibility of a pegged package or a package provided from an SDK.
504
                    //  Such packages will be deemed to be reproducible - but out side of this release
505
                    if (p.mIsPegged || p.mIsSdk)
506
                    {
507
                        continue;
508
                    }
509
                }
510
 
7082 dpurdie 511
                // Does the package have a build standard. If not then we can't reproduce it.
512
                // Escrow - Assume the package is provided
513
                // Daemon - Exclude this package, but not its consumers. If the package is available then we can use it.
6914 dpurdie 514
                if (!p.isReproducible())
515
                {
7044 dpurdie 516
                    mLogger.info("planRelease package not reproducible {}" ,p.mName);
7088 dpurdie 517
 
518
                    // Exclude the package
6914 dpurdie 519
                    // max 50 chars
7082 dpurdie 520
                    rippleBuildExclude(p, p.mId, "Package has no build environment", -1);
6914 dpurdie 521
 
522
                    // package is not reproducible, discard
523
                    standardOut(mAnyBuildPlatforms, p.mAlias, mAnyBuildPlatformsFlag);
524
                    mAnyBuildPlatformsFlag = false;
525
                }
526
            }
527
        }
528
 
7082 dpurdie 529
        //    Process packages which are not reproducible on the configured set of build machines.
6914 dpurdie 530
        //
531
        //    Test each package and determine if the package contains a buildStandard that
532
        //    can be processed by one of the machines in the build set
533
        //
534
        //    ie: Package: Win32:Production and we have a BM with a class of 'Win32'
535
        //
536
        //    Only exclude the failing package and not its dependents
537
        //    May be legitimate in the release
538
        //
539
        mLogger.debug("planRelease process packages which are not reproducible2");
7082 dpurdie 540
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 541
        {
542
            Package p = it.next();
543
 
544
            if (p.mBuildFile == 0)
545
            {
546
                if ( mDaemon )
547
                {
548
                    //  Daemon Mode Only
549
                    //  Not interested in the reproducibility of a pegged package or a package provided from an SDK.
550
                    //  Such packages will be deemed to be reproducible - but out side of this release
551
                    if (p.mIsPegged || p.mIsSdk)
552
                    {
553
                        continue;
554
                    }
555
                }
556
 
557
                // package has yet to be processed
558
                // assume it does not need to be reproduced for this baseline
559
                //
560
                //    For each machineClass in the buildset
561
                boolean reproduce = false;
562
 
563
                for (Iterator<String> it2 = mReleaseManager.mReleaseConfigCollection.mMachineClasses.iterator(); it2.hasNext(); )
564
                {
565
                    String machineClass = it2.next();
566
 
567
                    if ( p.canBeBuildby(machineClass))
568
                    {
569
                        reproduce = true;
7044 dpurdie 570
                        mLogger.info("planRelease package built on {} {}", machineClass, p.mAlias );
6914 dpurdie 571
                        break;
572
                    }
573
                }
574
 
575
                if ( !reproduce )
576
                {
7044 dpurdie 577
                    mLogger.info("planRelease package not reproducible on the build platforms configured for this baseline {}", p.mName);
6914 dpurdie 578
 
7082 dpurdie 579
                    // Exclude the package
580
                    // max 50 chars
581
                    rippleBuildExclude(p, p.mId, "Package not built for configured platforms", -2);
6914 dpurdie 582
 
583
                    // package is not reproducible on the build platforms configured for this baseline, discard
584
                    standardOut(mAssocBuildPlatforms, p.mAlias, mAssocBuildPlatformsFlag);
585
                    mAssocBuildPlatformsFlag = false;
586
                }
587
            }
588
        }      
589
 
7082 dpurdie 590
        if (mDaemon )
6914 dpurdie 591
        {
592
 
593
            //  Daemon Mode Only
594
            //  Process packages which need to be ripple built
595
            mLogger.debug("planRelease process packages which need to be ripple built");
596
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
597
            {
598
                Package p = it.next();
599
 
600
                if (p.mBuildFile == 0)
601
                {
602
                    //  Not interested in a pegged package or a package provided from an SDK.
603
                    //  Such packages are not rippled
604
                    if (p.mIsPegged || p.mIsSdk)
605
                    {
606
                        continue;
607
                    }
608
 
7082 dpurdie 609
                    //    Examine this packages dependencies
610
                    //    If one of them does not exist in the 'official release' set then
611
                    //    the package needs to be built against the official release set
612
                    //    and we can't build any of its dependent packages
613
                    Iterator<Integer> it2 = p.mDependencyIDCollection.iterator();
614
                    Iterator<Package> it3 = p.mPackageDependencyCollection.iterator();
615
                    while ( it2.hasNext() && it3.hasNext() )
6914 dpurdie 616
                    {
7088 dpurdie 617
                        Integer dpvId = it2.next();
618
                        Package dependency = it3.next();
619
 
620
                        if ( !dependency.mAdvisoryRipple )
6914 dpurdie 621
                        {
7082 dpurdie 622
                            // not advisory, ie: has ripple build impact
623
                            if ( !isInRelease(dpvId) )
6914 dpurdie 624
                            {
7082 dpurdie 625
                                // the package is out of date
626
                                // exclude all dependent package versions
627
                                mLogger.info("planRelease package out of date {}", p.mName);
628
                                p.mBuildReason = BuildReason.Ripple;
629
                                rippleIndirectlyPlanned(p);
630
 
631
                                //  This package needs to be rippled
632
                                //  If this package has a rippleStop marker of 's', then we cannot
633
                                //  build this package at the moment.
634
                                //  Packages that depend on this package have been excluded
635
                                //  We need to exclude this one too
636
                                //
637
                                if (p.mRippleStop == 's' || p.mRippleStop == 'w') 
6914 dpurdie 638
                                {
7088 dpurdie 639
                                    // Package marked as a rippleStop
640
                                    // max 50 chars
641
                                    rippleBuildExclude(p, -2, "Ripple Required." + " Waiting for user", -11);
6914 dpurdie 642
 
7088 dpurdie 643
                                    if (p.mRippleStop == 's' ) {
644
                                        // Need to flag to users that the package build is waiting user action
645
                                        mLogger.info("planRelease Ripple Required. Stopped by flag {}", p.mName);
646
                                        mReleaseManager.setRippleStopWait(mRtagId,p);
6914 dpurdie 647
                                    }
648
                                }
7082 dpurdie 649
 
650
                                break;
6914 dpurdie 651
                            }
652
                        }
653
                    }
654
                }
655
            }
656
 
657
            //  Daemon Mode Only
658
            //  Process packages which do not exist in the archive
659
            //  For unit test purposes, assume all packages exist in the archive if released
660
            mLogger.debug("planRelease process packages which do not exist in the archive");
7046 dpurdie 661
            if ( mReleaseManager.mUseDatabase )
6914 dpurdie 662
            {
663
                for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
664
                {
665
                    Package p = it.next();
666
 
667
                    if (p.mBuildFile == 0)
668
                    {
669
                        // package has yet to be processed
670
                        if (!p.mDirectlyPlanned && !p.mIndirectlyPlanned && p.mForcedRippleInstruction == 0)
671
                        {
672
                            // check package version archive existence
673
                            if (!p.existsInDpkgArchive())
674
                            {
675
                                if (! p.mIsBuildable)
676
                                {
677
                                    //  Package does not exist in dpkg_archive and it has been flagged as unbuildable
678
                                    //  This may be because is Unbuildable or Manually built
7044 dpurdie 679
                                    mLogger.info("planRelease Unbuildable package not found in archive {}", p.mName);
7088 dpurdie 680
                                    // Exclude the package
6914 dpurdie 681
                                    // max 50 chars
7082 dpurdie 682
                                    rippleBuildExclude(p, p.mId, "Unbuildable" + " package not found in archive", -10);
6914 dpurdie 683
 
684
                                }
685
                                //  Not interested in a pegged package or a package provided from an SDK.
686
                                //  Such packages are not rippled
687
                                else if (p.mIsPegged || p.mIsSdk)
688
                                {
689
                                    String reason;
690
                                    reason = (p.mIsPegged) ? "Pegged" : "SDK";
691
 
692
                                    //  Pegged packages or packages provided from an SDK MUST exist in dpkg_archive
693
                                    //  They will not be built within the context of this release. It is the responsibility
694
                                    //  of another release to build them.
7044 dpurdie 695
                                    mLogger.info("planRelease {} package not found in archive {}", reason, p.mName);
7088 dpurdie 696
                                    // Exclude the package
6914 dpurdie 697
                                    // max 50 chars
7082 dpurdie 698
                                    rippleBuildExclude(p, p.mId, reason + " package not found in archive", -7);
6914 dpurdie 699
                                }
700
                                else if (p.mForcedRippleInstruction == 0)
701
                                {
702
                                    //  [JATS-331] Unable to rebuild package with Advisory Ripple dependencies
703
                                    //    Examine this packages dependencies
704
                                    //    If one of them does not exist in the 'official release' set then
705
                                    //    the package cannot be rebuilt in this release.
706
                                    for (Iterator<Integer> it2 = p.mDependencyIDCollection.iterator() ; it2.hasNext() ;)
707
                                    {
708
                                        Integer dpvId = it2.next();
709
                                        if ( !isInRelease(dpvId) )
710
                                        {
711
                                            // This package cannot be rebuilt as one of its dependents is NOT in this release
712
                                            // exclude all dependent package versions
713
 
7044 dpurdie 714
                                            mLogger.info("planRelease package not found in archive. Cannot be rebuilt due to {}", p.mName);
7088 dpurdie 715
                                            // Exclude the package
6914 dpurdie 716
                                            // max 50 chars
7082 dpurdie 717
                                            rippleBuildExclude(p, p.mId, "Package cannot be rebuilt in this release", -4);
6914 dpurdie 718
                                            break;
719
                                        }
720
                                    }
721
 
722
                                    //  The package has not been excluded from the build
723
                                    if (p.mBuildFile == 0)
724
                                    {
7044 dpurdie 725
                                        mLogger.info("planRelease package not found in archive {}", p.mName);
6914 dpurdie 726
                                        // DEVI 47395 the cause of this build is not WIP or ripple induced,
727
                                        // it simply does not exist in the archive (has been removed)
728
                                        // prevent source control interaction
729
                                        p.mRequiresSourceControlInteraction = false;
730
                                        p.mBuildReason = BuildReason.Restore;
731
                                        rippleIndirectlyPlanned(p);
732
                                    }
733
                                }
734
                            }
735
                        }
736
                    }
737
                }
738
            }
739
 
740
            //  Daemon Mode Only
7082 dpurdie 741
            //  Detect bad forced ripples requests and reject them
6914 dpurdie 742
            mLogger.debug("planRelease process forced ripples");
7082 dpurdie 743
            for (Iterator<Package> it = mPackageCollectionRipple.iterator(); it.hasNext(); )
6914 dpurdie 744
            {
745
                Package p = it.next();
746
 
747
                if (p.mBuildFile == 0)
748
                {
7082 dpurdie 749
                    //
750
                    //    Cannot force a ripple on an SDK based package or a Pegged Package
751
                    //        Remove the daemon instruction from the database
752
                    //        Send a warning email
753
                    //
754
                    if(p.mIsPegged || p.mIsSdk)
6914 dpurdie 755
                    {
7082 dpurdie 756
                        String reason;
757
                        reason = (p.mIsPegged) ? "Pegged" : "SDK Based";
6914 dpurdie 758
 
7088 dpurdie 759
                        mLogger.error("planRelease Daemon Instruction of {} package deleted: {}", reason, p.mName);
760
                        mReleaseManager.markDaemonInstCompleted( p.mForcedRippleInstruction );
761
                        emailRejectedDaemonInstruction("Cannot 'Ripple' a " + reason + " package",p);
6914 dpurdie 762
 
7088 dpurdie 763
                        p.mBuildFile = -8; 
6914 dpurdie 764
                    }
765
                }
766
            }
767
 
768
            //  Daemon Mode Only
769
            //  Mark Pegged and SDK packages as not to be built
7082 dpurdie 770
            //  Mark RippleStoped packages as not to be build
6914 dpurdie 771
            //  Have previously detected conflicts between pegged/sdk packages and daemon instructions
772
            //
773
            mLogger.debug("planRelease remove pegged and SDK packages from the build set");
774
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
775
            {
776
                Package p = it.next();
777
 
778
                if (p.mBuildFile == 0)
779
                {
7082 dpurdie 780
                    String reason = null;
781
 
782
                    //  Not interested in a pegged package or a package provided from an SDK or packages with an active RippleStop
6914 dpurdie 783
                    //  Such packages are not built
7088 dpurdie 784
                    if (p.mIsPegged ) {
785
                        reason = "Pegged";
6914 dpurdie 786
                        p.mBuildFile = -8;
7082 dpurdie 787
                    } else if (p.mIsSdk) {
788
                        reason = "SDK";
789
                        p.mBuildFile = -8;
790
                    } else if (p.mRippleStop == 's' || p.mRippleStop == 'w') {
791
                        reason = "RippleStop";
792
                        p.mBuildFile = -11;
6914 dpurdie 793
                    }
7082 dpurdie 794
 
795
                    if (reason != null)
796
                    {
797
                        mLogger.info("planRelease {} not built in this release {}", reason, p.mName);
798
                    }
6914 dpurdie 799
                }
800
            }
801
 
802
            //  Daemon Mode Only
803
            //  Locate Test Build Requests that cannot be satisfied - will not be built due to
804
            //  errors in dependent packages. Report the error to the user and remove the request
805
            //
7082 dpurdie 806
            for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
807
            {
808
                Package p = it.next();
809
 
810
                if (p.mBuildFile < 0)
811
                {
812
                    String reason;
813
                    switch (p.mBuildFile)
814
                    {
815
                    case -1:  reason = "Not reproducible"; break;
816
                    case -2:  reason = "Not reproducible on configured build platforms"; break;
817
                    case -3:  reason = "Marked as 'Do not ripple'"; break;
818
                    case -4:  reason = "Dependent on a package not in the release"; break;
819
                    case -5:  reason = "Indirectly dependent on a package not reproducible in the release"; break;
820
                    case -6:  reason = "Has a circular dependency"; break;
821
                    case -7:  reason = "Pegged or SDK package not in dpkg_archive"; break;
822
                    case -8:  reason = "Is a Pegged or SDK package"; break;
823
                    case -9:  reason = "Rejected Daemon Instruction"; break;
824
                    case -10: reason = "Unbuildable package not in dpkg_archive"; break;
825
                    case -11: reason = "Marked as 'RippleStop'"; break;
826
                    default:  reason = "Unknown reason. Code:" + p.mBuildFile; break;
827
                    }
828
                    mLogger.error("planRelease Test Build of an unbuildable of package deleted: {}", p.mName);
829
                    mReleaseManager.markDaemonInstCompleted( p.mTestBuildInstruction );
830
                    emailRejectedDaemonInstruction(reason,p);
831
                }
832
            }
6914 dpurdie 833
        }
834
        else
835
        {
836
            // escrow reporting only
837
            // Report packages that are not reproducible
838
            //
839
            //  Note: I don't believe this code can be executed
840
            //        The -3 is only set in daemon mode
841
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
842
            {
843
                Package p = it.next();
844
 
845
                if (p.mBuildFile == -3)
846
                {
847
                    standardOut(mDependent, p.mAlias, mDependentFlag);
848
                    mDependentFlag = false;
849
                }
850
            }
851
        }
852
    }
7082 dpurdie 853
 
6914 dpurdie 854
    /** Plan the build order.
7082 dpurdie 855
         *  Assumes that a great deal of work has been done.
856
         *  This is a stand alone method to contain the work
857
         *  
858
         * @throws Exception
859
         * @throws SQLException
860
         */
861
        private void planBuildOrder() throws Exception, SQLException 
862
        {
863
 
864
    /**
865
     * Current status
7099 dpurdie 866
     *  basicPlan - time to complete current ripple
867
     *  FullPlan - Include all WIPS/RIPPLES into the release set
868
     *  
869
     *  If the full Plan does NOT extend the time of the basicPLan by 20% then use the full plan
870
     *  otherwise complete the current ripple and the include WIPs/RIPPLEs\
871
     *  
872
     *  TEST requests will be done first.
873
     *
6914 dpurdie 874
     */
7082 dpurdie 875
 
876
            // Process remaining packages which are need to be reproduced for this baseline.
877
            //    Determine the build file for each package
878
            //    For daemon builds:
879
            //      Determine the next package that can be built now
880
            //          Sounds simple - doesn't it
881
            //      Set its mBuildNumber to 1, all remaining reproducible packages to 2
882
            //    For escrow builds:
883
            //      Determine the package versions that can be built in the build iteration
884
            //      Set their mBuildNumber to the build iteration
885
            //      Increment the build iteration and repeat until all package versions 
886
            //      that need to be reproduced have been assigned a build iteration        
887
 
888
            //
889
            //  Generate a plan for the packages that are in the current release
890
            //  These may be the result of a ripple going through the system 
891
            //  or a rebuild of a missing package or the result of a merge.
892
            //
893
            //  This will provide our basic plan, before we consider adding new packages to the
894
            //  mix, such as those from user WIPS and RIPPLE requests.
895
            //  
896
            PlanResults basicPlan = planCollection("Basic", mPackageCollection, true);
897
 
898
            //  Have not considered any of the WIP or RIPPLE packages
899
            //  If any of them are in the basic plan, then we can ignore them as we will build them
900
            //  when we build the basic plan
901
            //
902
            //  Determine a set of packages that will not be included if we build the basic plan
903
            //
904
            //  At the moment - lets assume there are none
905
            //  What do we do ?
906
            //      Select the first request
907
            //      Replace the package in the released collection
908
            //      Run the plan algorithm
909
            //      Restore the release collection
910
            //
911
            if ( mDaemon )
912
            {
913
                //
914
                //  Need to consider the TEST requests
915
                //      - Valid requests will be placed first on the build order
916
                //
917
                mBuildOrder.clear();
918
                for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
919
                {
920
                    Package p = it.next();
921
                    if (p.mBuildFile >= 0)
922
                    {
923
                        mBuildOrder.add( new PlannedPackage(p,0 ) );
924
                    }
925
                }
926
 
927
                //  First attempt
928
                //  Insert all the WIPs and RIPPLES into the buildset. 
929
                //  Generate a plan and see how much the time is extended.
930
                //
931
                //  Don't modify mPackageCollection, although data in the 'Package' in the underlying packages may change
932
 
933
                PlanResults fullPlan = postRipplePlan("Full", basicPlan, true);
934
 
935
                //  Decide with plan to use
936
                //  At the moment we have, at most two.
937
                //      - (basic) Current Release ripples
938
                //      - (full) Current Release + All WIPS and RIPPLES
939
                //
940
                //  If we have both then if the full plan is < 20% longer than the basic plan, use the full plan
941
                //  Otherwise we use basic plan FOLLOWED by the a MODIFIED full plan (one without the natural ripples)
942
                //  Add the planned packages into the buildOrder
943
 
944
                if( !basicPlan.planCollection.isEmpty() && !fullPlan.planCollection.isEmpty() )
945
                {
7099 dpurdie 946
                    mLogger.error("Two plan selection: {} {}, {} <= {}", basicPlan.planTime,fullPlan.planTime, basicPlan.planTime * 12, fullPlan.planTime * 10);
947
 
948
                    //
949
                    //  Report numbers for Bryan - can be removed after Aug-2019
950
                    //  See PX-14283
951
                    //
952
                    {
7107 dpurdie 953
                        String bi = "--";
954
                        String be = "--";
7099 dpurdie 955
                        if (fullPlan.planTime != basicPlan.planTime &&  basicPlan.planTime  != 0) {
7107 dpurdie 956
                            bi = Float.toString( (fullPlan.planTime - basicPlan.planTime) / (float)basicPlan.planTime);
957
                            be = Float.toString( (float)fullPlan.planTime  / (fullPlan.planTime - basicPlan.planTime));
7099 dpurdie 958
                        }
959
                        mLogger.error("PLAN STATS: Estimated time to complete current plan (ETC): {}", basicPlan.planTime);
960
                        mLogger.error("PLAN STATS: Estimated time to full plan (PBT): {}", fullPlan.planTime);
7107 dpurdie 961
                        mLogger.error("PLAN STATS: Build Impact (BI): {}", bi);
962
                        mLogger.error("PLAN STATS: Build Efficiency (BE): {}", be);
7099 dpurdie 963
                    }
964
 
965
 
7082 dpurdie 966
                    if ( (basicPlan.planTime * 12) <= (fullPlan.planTime * 10) )
967
                    {
968
                        //  Use the basic plan FOLLOWED by a plan that does not include
969
                        //      Ripples done by the basic plan
970
                        //      WIPs/RIPPLES done in the course of doing the basic plan
7099 dpurdie 971
                        mLogger.error("Use basic plan, then modified full plan");
7082 dpurdie 972
                        mBuildOrder.addAll(basicPlan.planCollection);
973
                        fullPlan = postRipplePlan("Full-Ripples", basicPlan, false);
974
                        mBuildOrder.addAll(fullPlan.planCollection);
975
 
976
                    } else {
977
                        //  Use the full plan
7099 dpurdie 978
                        mLogger.error("Use full plan");
7082 dpurdie 979
                        mBuildOrder.addAll(fullPlan.planCollection);
980
                    }
981
                } else if (!basicPlan.planCollection.isEmpty() ) {
982
                    // Use the basic plan
7099 dpurdie 983
                    mLogger.error("Use basic plan");
7082 dpurdie 984
                    mBuildOrder.addAll(basicPlan.planCollection);
985
 
986
                } else if ( !fullPlan.planCollection.isEmpty() ) {
987
                    // Use the full plan
7099 dpurdie 988
                    mLogger.error("Use full plan");
7082 dpurdie 989
                    mBuildOrder.addAll(fullPlan.planCollection);
990
 
991
                } else {
992
                    // Do not have a plan
993
                    // May have tests requests
7099 dpurdie 994
                    mLogger.error("Use NO plan");
7082 dpurdie 995
                }
996
 
997
                //
7099 dpurdie 998
                //  Now have a build order
999
                //  Allocate new version numbers
1000
                //      Examine packages with a buidLevel of zero
1001
                //  If we fail all of them then we can't build anything
1002
                //
1003
                mLogger.error("Determine new version numbers");
7082 dpurdie 1004
                Package build = ReleaseManager.NULL_PACKAGE;
7099 dpurdie 1005
                for (Iterator<PlannedPackage> it = mBuildOrder.iterator(); it.hasNext(); )
1006
                {
1007
                    PlannedPackage pkg = it.next();
1008
                    if (pkg.mBuildLevel != 0)
1009
                    {
1010
                        continue;
1011
                    }
1012
 
1013
                    //
1014
                    //  Attempt to allocate a new version number
1015
                    //  If we can't generate a new version number, then this is considered to be a build failure
1016
                    //  The package will be excluded and the user will be emailed
1017
                    //
1018
                    Package p = pkg.mPkg;
1019
 
1020
                    int pvApplied = p.applyPV(mReleaseManager);
1021
 
1022
                    if ( pvApplied == 0)
1023
                    {
1024
                        build = p;
1025
                        break;
1026
                    }
1027
                    else if ( pvApplied == 1 )
1028
                    {
1029
                        // max 50 chars
1030
                        rippleBuildExclude(p, p.mId, "Package has non standard versioning", -12);
1031
                    }
1032
                    else if ( pvApplied == 2 )
1033
                    {
1034
                        // max 50 chars
1035
                        rippleBuildExclude(p, p.mId, "Package has reached ripple field limitations", -12);
1036
                    }
1037
                    else if ( pvApplied == 3 )
1038
                    {
1039
                        // max 50 chars
1040
                        rippleBuildExclude(p, p.mId, "Package has invalid change type", -12);
1041
                    }
1042
                    else
1043
                    {
1044
                        // max 50 chars
1045
                        // Bad programming - should not get here
1046
                        rippleBuildExclude(p, p.mId, "Unable to calculate next version", -12);
1047
                    }
1048
                }
1049
 
1050
 
1051
                //  Now have an mBuildOrder
1052
                //  Mark the selected package in the build order as the one to be built
1053
                //  May need to process its it a bit more
1054
                //  
7107 dpurdie 1055
                if ( build != ReleaseManager.NULL_PACKAGE)
1056
                {
7082 dpurdie 1057
                    build.mBuildFile = 1;
1058
 
1059
                    if ( build.mForcedRippleInstruction > 0 )
1060
                    {
1061
                        mReleaseManager.markDaemonInstCompleted( build.mForcedRippleInstruction );
1062
                    }
1063
 
1064
                    if ( build.mTestBuildInstruction > 0 )
1065
                    {
1066
                        mReleaseManager.markDaemonInstInProgress( build.mTestBuildInstruction );
1067
                    }
1068
 
1069
                    //  Now that we know which package we are building
1070
                    //      Set the previously calculated nextVersion as the packages version number
1071
                    //      Claim the version number to prevent other builds from using it. Even if doing a test build
1072
                    //
7099 dpurdie 1073
                    mLogger.error("Update mVersion: {}", build);
7082 dpurdie 1074
                    if (build.mNextVersion != null)
1075
                    {
1076
                        mReleaseManager.claimVersion(build.mPid, build.mNextVersion + build.mExtension, mBaseline);
1077
                        build.mVersion = build.mNextVersion;
7099 dpurdie 1078
                        mLogger.error("Update mVersion: {} to {}", build, build.mVersion);
7082 dpurdie 1079
                    }
1080
 
7107 dpurdie 1081
                    //
1082
                    //  Ensure that the package we are about to build is present in the mPackageCollection as its
1083
                    //  this list that is used to generate the build.xml file - that may be a bad way to do it , but ...
1084
                    //
1085
                    //  Note: Can't really modify others as they will be used as dependencies
1086
                    //
1087
                    Package pEntry = findPackage(build.mAlias);
1088
                    if ( pEntry != ReleaseManager.NULL_PACKAGE)
7082 dpurdie 1089
                    {
7107 dpurdie 1090
                        mPackageCollection.set(mReleaseManager.findPackageLastIndex, build);
1091
                        build.mIsNotReleased = false;
1092
                    } else {
1093
                        mPackageCollection.add(build);
1094
                        build.mIsNotReleased = false;
7082 dpurdie 1095
                    }
1096
                }
7107 dpurdie 1097
 
7082 dpurdie 1098
                //
1099
                //  Report packages that are indirectly excluded
1100
                //  ie: They will not be built because one, or more, of there dependents is not buildable
1101
                //
1102
                mLogger.debug("planBuildOrder process packages which are not ripple buildable");
1103
 
1104
                 for (ListIterator<BuildExclusion> it = mBuildExclusionCollection.listIterator(); it.hasNext(); )
1105
                 {
1106
                     BuildExclusion be = it.next();
1107
 
1108
                     for (Iterator<Package> it1 = mPackageCollection.iterator(); it1.hasNext(); )
1109
                     {
1110
                         Package p = it1.next();
1111
 
1112
                         // ensure only root cause, non test build, build exclusions are excluded
1113
                         // mBuildExclusionCollection is at this point based on
1114
                         // relevant (direct and indirect) excluded pv's in the database
1115
 
1116
                         if ( be.compare(p.mId) && be.isARootCause() && p.mTestBuildInstruction == 0 && p.mForcedRippleInstruction == 0 )
1117
                         {
1118
                             // package is not reproducible, discard it and its consumers
1119
                             //
1120
                             mLogger.info("Excluded Package {}, {}", p.mAlias, be );                                     
1121
 
1122
                             ArrayList<Package> toExclude = new ArrayList<Package>();
1123
                             toExclude.addAll(usedByAnyPackages(p, mPackageCollection ));
1124
 
1125
                             //  Process packages that we need to exclude indirectly
1126
                             //
1127
                             while ( ! toExclude.isEmpty())
1128
                             {
1129
                                 Package pkg = toExclude.remove(0);
1130
 
1131
                                 // If this package has not been excluded (for whatever reason), than add it
1132
                                 boolean found = false;
1133
                                 for (Iterator<BuildExclusion> it2 = mBuildExclusionCollection.iterator(); it2.hasNext(); )
1134
                                 {
1135
                                     BuildExclusion buildExclusion = it2.next();
1136
                                     if (buildExclusion.compare(pkg.mId) )
1137
                                     {
1138
                                         found = true;
1139
                                         if  ( buildExclusion.isImported() )
1140
                                         {
1141
                                             // An exclusion for this package already exists
1142
                                             // If it was 'imported' from the database then 
1143
                                             // mark it as processed so that it will be persisted
1144
                                             //
1145
                                             // Otherwise it will be a new one
1146
                                             //
1147
                                             buildExclusion.setProcessed();
1148
                                         }
1149
                                         break;
1150
                                     }
1151
                                 }
1152
 
1153
                                 if (!found)
1154
                                 {
1155
                                     BuildExclusion buildExclusion = new BuildExclusion(pkg.mId, p.mId, null, p.mTestBuildInstruction);
1156
                                     it.add(buildExclusion);
7099 dpurdie 1157
                                     mLogger.info("Indirectly Excluded Package {}", pkg.mAlias);
1158
                                     pkg.mBuildFile = -5; 
7082 dpurdie 1159
 
7099 dpurdie 1160
                                     ArrayList<Package> usedBy = usedByAnyPackages(pkg, mPackageCollectionAll );
7082 dpurdie 1161
                                     toExclude.addAll(usedBy);
1162
                                 }
1163
                             }
1164
                         }
1165
                     }
1166
                 }
7099 dpurdie 1167
 
1168
                 //
1169
                 //  Examine the build order and 'delete' entries with a -ve mBuildFile
1170
                 //  These will be the product of pvApply errors and the packages that depend on them
1171
 
1172
                 for (Iterator<PlannedPackage> it = mBuildOrder.iterator(); it.hasNext(); )
1173
                 {
1174
                     PlannedPackage pkg = it.next();
1175
                     if (pkg.mPkg.mBuildFile < 0)
1176
                     {
1177
                         it.remove();
1178
                         mLogger.error("Purge mBuildOrder {}", pkg.mPkg);
1179
                     }
1180
                 }
1181
 
1182
 
7082 dpurdie 1183
 
1184
                //
1185
                //  To fit in with the old algorithm ( ie: could be improved )
1186
                //  Insert marks into all packages
1187
                //  Not sure exactly why - Its used in the generation of the ant build file
1188
                //                     Want to set mNoBuildReason, mBuildFile
1189
                //
1190
                //      Package we have selected to build: 0     , 1
1191
                //      Package we could have built      : 0     , 2
1192
                //      Packages we can't build          : reason, 3
1193
                //      Packages that are OK             : 3     , 3
1194
                //      ????                             : 0     , 3
1195
 
1196
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
1197
                {
1198
                    Package p = it.next();
1199
                    if (p == build ) {
1200
                        p.mNoBuildReason = 0;
1201
                        p.mBuildFile = 1;
1202
                    } 
1203
                    else if ( p.mBuildFile < 0 )
1204
                    {
1205
                        p.mNoBuildReason = p.mBuildFile;
1206
                        p.mBuildFile = 3;
1207
                    }
1208
                    else if (p.mBuildReason != null)
1209
                    {
1210
                        p.mNoBuildReason = 0;
1211
                        p.mBuildFile = 2;
1212
                    }
1213
                    else
1214
                    {
1215
                        p.mNoBuildReason = 0;
1216
                        p.mBuildFile = 3;
1217
                    }
1218
                }
1219
 
1220
            }
1221
            else
1222
            {
1223
                //  Escrow
1224
                //  The basic plan is the escrow build order
1225
                mBuildOrder = basicPlan.planCollection;
1226
            }
1227
 
1228
            mLogger.error("Final Plan");
1229
            for (Iterator<PlannedPackage> it = mBuildOrder.iterator(); it.hasNext(); )
1230
            {
1231
                PlannedPackage p = it.next();
1232
                mLogger.error("Plan: {} {} {}", p.mBuildLevel, p.mPkg.mAlias, p.mPkg.mId);
1233
            }
1234
 
1235
 
1236
        }
1237
 
1238
    /** Internal class to contain intermediate results
1239
     */
1240
    class PlanResults {
1241
        int planTime = 0;
1242
        ArrayList<PlannedPackage> planCollection = new ArrayList<PlannedPackage>(); 
1243
    }
1244
 
1245
    /**
1246
     * Process a collection of packages and generate a collection of package plans
1247
     * A package plan is a collection of packages that can be built
1248
     *      The first item in the list is a package that can be built right now
1249
     *      Other items in the list will be packages that can be built now or will need to be built as the result
1250
     *      of a ripple
1251
     *      
1252
     * The method will be called multiple times so that we can evaluate different plans
1253
     * The underling packages will have data and flags that will need to be rested before a calculation      
1254
     *
1255
     * @param name - Name of the plan
1256
     * @param packageCollection - Base collection of packages to plan
1257
     * @param mode - true: Include 'Ripples'
1258
     * 
1259
     * @return
1260
     */
1261
    private PlanResults planCollection(String name, ArrayList<Package> packageCollection, boolean mode)
1262
    {
7099 dpurdie 1263
        Phase phase = new Phase("PlanCollection"); 
7082 dpurdie 1264
        ArrayList<PlannedPackage> ripplePlan = new ArrayList<PlannedPackage>();
1265
        PlanResults results = new PlanResults();
1266
 
1267
        //  Reset flags used in the calculations
1268
        Package.resetProcessed(packageCollection);
6914 dpurdie 1269
 
7082 dpurdie 1270
        //  Exclude all packages that cannot be built and all packages that depend on them
1271
        //      First find packages to be directly excluded
1272
        ArrayList<Package>exclude = new ArrayList<Package>();
7099 dpurdie 1273
        phase.setPhase("Exclude Unbuildable");
7082 dpurdie 1274
        for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
6914 dpurdie 1275
        {
7082 dpurdie 1276
            Package p = it.next();
1277
            if ( p.mBuildFile == -8 ) {
1278
 
1279
                //  Mark SDK or Pegged so that we don't build them, but can build their dependents
1280
                p.mProcessed = true;
1281
                p.mIsProcessed = true;
1282
                mLogger.error("SDK/Peg Exclude: {}", p);
1283
 
1284
            } else if (p.mBuildFile < 0 ) {
1285
                exclude.add(p);
1286
                mLogger.error("Direct Exclude: {}", p);
1287
 
1288
            }
6914 dpurdie 1289
        }
1290
 
7082 dpurdie 1291
        //  Exclude packages that have failed to be built
1292
        //      These are recorded in mBuildExclusionCollection
7099 dpurdie 1293
        phase.setPhase("Exclude Build Failures");
7082 dpurdie 1294
        for (ListIterator<BuildExclusion> it = mBuildExclusionCollection.listIterator(); it.hasNext(); )
1295
        {
1296
            BuildExclusion be = it.next();
7099 dpurdie 1297
            mLogger.error("BE: {}", be);
1298
            if ( !be.isAIndirectError() )
7082 dpurdie 1299
            {
1300
                for (Iterator<Package> it1 = packageCollection.iterator(); it1.hasNext(); )
1301
                {
1302
                    Package p = it1.next();
1303
                    if (p.mBuildFile >= 0 && p.mId == be.mId) {
1304
                        p.mBuildFile  = -3;
7099 dpurdie 1305
                        mLogger.error("AddExclude {}",p);
7082 dpurdie 1306
                        exclude.add(p);
1307
                        break;
1308
                    }
1309
                }
1310
            }
1311
        }
1312
 
1313
 
1314
        //  Process the list of packages to be excluded
1315
        //  Add to the list packages that depend on the excluded package that have not already been excluded
7099 dpurdie 1316
        phase.setPhase("ExcludeAllUsed");
7082 dpurdie 1317
        while( !exclude.isEmpty() )
1318
        {
1319
            Package p = exclude.remove(0);
1320
            p.mProcessed = true;
1321
            p.mIsProcessed = true;
1322
            mLogger.error("planCollection package not buildable {}", p.mName);
1323
 
1324
            for (Iterator<Package> it1 = packageCollection.iterator(); it1.hasNext(); )
1325
            {
1326
                Package pkg = it1.next();
1327
                if (pkg.mProcessed) {
1328
                    continue;
1329
                }
1330
 
1331
                for (Iterator<String> it = pkg.mDependencyCollection.iterator(); it.hasNext(); )
1332
                {
1333
                    String alias = it.next();
1334
                    if ( p.mAlias.compareTo( alias ) == 0 ) {
7114 dpurdie 1335
                        if (!pkg.mProcessed) {
1336
                            exclude.add(pkg);
1337
                        }
7082 dpurdie 1338
                    }
1339
                }
1340
            }
1341
        }
1342
 
1343
        //  Now have a collection of packages with those that we cannot build have been marked
1344
        //  Process the list and determine packages that we can build right now
1345
        //      ie: they have not been excluded, have not already been discovered and do not depend on any package in the collection
1346
        //      Continue to do this until all packages have been extracted
1347
        //      Allocate build levels as we go
1348
        //
7099 dpurdie 1349
        phase.setPhase("Determine Build Order");
6914 dpurdie 1350
        boolean allProcessed = false;
7082 dpurdie 1351
        int buildLevel = 1;
6914 dpurdie 1352
 
1353
        do
1354
        {
7082 dpurdie 1355
            //
1356
            //  Create the mBuildOrder collection
1357
            //      Same for both Daemon and Escrow modes
1358
            //      Will have package build order and build level
6914 dpurdie 1359
            boolean allDependenciesProcessed = true;
1360
            do
1361
            {
1362
                allDependenciesProcessed = true;
7082 dpurdie 1363
                for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
6914 dpurdie 1364
                {
1365
                    Package p = it.next();
7082 dpurdie 1366
 
1367
                    //  Skip packages that have been processed - have determined build order, or cannot build
1368
                    if (p.mIsProcessed) {
1369
                        continue;
1370
                    }
6914 dpurdie 1371
 
7082 dpurdie 1372
                    // Package yet to be processed and
1373
                    //      Daemon mode: Could be built
1374
                    //      Escrow mode: Can be reproduced
1375
                    boolean canBeBuiltNow = true;
1376
                    boolean allDependenciesForThisPackageProcessed = true;
1377
 
1378
                    //  Scan the packages dependencies
1379
                    for ( Iterator<Package> it2 = p.mPackageDependencyCollection.iterator(); it2.hasNext(); )
6914 dpurdie 1380
                    {
7088 dpurdie 1381
                        Package dependency = it2.next();
6914 dpurdie 1382
 
7082 dpurdie 1383
                        if ( !dependency.mProcessed )
6914 dpurdie 1384
                        {
7088 dpurdie 1385
                            //  If all the dependencies have been processed, then we can potentially build this package
1386
                            //  If any of them have not been processed, then cannot calculate canBeBuiltNow until this 
1387
                            //  dependency has been processed
1388
                            allDependenciesForThisPackageProcessed = false;
1389
                            allDependenciesProcessed = false;
6914 dpurdie 1390
                        }
7082 dpurdie 1391
                        else if (  (  mDaemon && (   dependency.mBuildFile == 0 ) ||  (dependency.mBuildFile == buildLevel)) 
1392
                                || ( !mDaemon && ( ( dependency.mBuildFile == 0 ) ||
1393
                                                       ( dependency.mBuildFile == buildLevel &&
1394
                                                       ( !p.haveSameBuildStandards(dependency)  ) ) ) ) )
1395
                        {
1396
                            // Can be built - yet
1397
                            // Daemon mode:
1398
                            //    This processed dependency has not been assigned to a build iteration
1399
                            //    This processed dependency has been assigned to this build iteration
1400
                            // Escrow mode: This package cannot be built now if
1401
                            //    This processed dependency has not been assigned to a build iteration or
1402
                            //    This processed dependency has been assigned to this build iteration, but the 
1403
                            //    build standards of the package and this dependency prevent the package being
1404
                            //    built in this iteration.   
1405
                            canBeBuiltNow = false;
1406
                            mLogger.info("planRelease package cannot be built in this iteration {}", p.mName);
1407
                            break;
1408
                        }
1409
                    }
6914 dpurdie 1410
 
7082 dpurdie 1411
                    //  All dependencies have been processed. May be able to build this package
1412
                    //      Add the package to the build order list
1413
                    //
1414
                    if (allDependenciesForThisPackageProcessed)
1415
                    {
1416
                        p.mProcessed = true;
1417
                        if ( canBeBuiltNow )
6914 dpurdie 1418
                        {
7088 dpurdie 1419
                            results.planCollection.add( new PlannedPackage(p, buildLevel));
1420
                            p.mBuildFile = buildLevel;
1421
                            p.mIsProcessed = true;
1422
                            mLogger.info("planRelease set mBuildFile to {} for package {}",buildLevel, p.mAlias );
6914 dpurdie 1423
                        }
1424
                    }
1425
                }
1426
            } while( !allDependenciesProcessed );
7082 dpurdie 1427
 
7099 dpurdie 1428
            //  Have process all the packages that we can build at the moment
7082 dpurdie 1429
            //      Examine all the packages in the collection to see if there are more that need to be extracted
1430
            //      These will be done at a different build-level
1431
            //  
1432
            allProcessed = true;
1433
            for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
1434
            {
1435
                Package p = it.next();
1436
                if ( !  p.mIsProcessed )
1437
                {
1438
                    // more build files are required
1439
                    allProcessed = false;
1440
                    mLogger.info("planRelease more build files are required for {}", p.mName);
1441
                    break;
1442
                }
1443
            }
6914 dpurdie 1444
 
7082 dpurdie 1445
            buildLevel++;
1446
            if (buildLevel % 500 == 0 ) {
1447
                mLogger.error("planRelease. Too many build levels {}", buildLevel);
1448
            }
1449
        } while( !allProcessed );
1450
 
1451
        //  Now we have a collection packages that we can build right now
1452
        //      The packages currently have a build level set into mBuildFile
1453
        //
1454
        if (mDaemon)
1455
        {
7099 dpurdie 1456
            phase.setPhase("Calc Build Order");
1457
            //
7082 dpurdie 1458
            //  Determine if we have a reason to build anything in this collection of buildable packages
7099 dpurdie 1459
            //      Reset the calculated buildLevel - It will be calculated again
1460
            //      Reset the mProcessed - it will be used to detect  that we have processed a package
1461
 
7082 dpurdie 1462
            ArrayList<PlannedPackage> toBuild = new ArrayList<PlannedPackage>();
1463
            for (Iterator<PlannedPackage> it = results.planCollection.iterator(); it.hasNext(); )
6914 dpurdie 1464
            {
7082 dpurdie 1465
                PlannedPackage p = it.next();
1466
                p.mBuildLevel = 0;
7099 dpurdie 1467
                p.mPkg.mCheckedCircularDependency = false;
7082 dpurdie 1468
 
1469
                if (p.mPkg.mBuildReason != null) {
1470
                    if (mode || ( !mode && p.mPkg.mBuildReason != BuildReason.Ripple ))
6914 dpurdie 1471
                    {
7088 dpurdie 1472
                        toBuild.add(p);
6914 dpurdie 1473
                    }
1474
                }
1475
            }
7082 dpurdie 1476
 
1477
            //  Need (would like to) build stuff
1478
            //  Determine the packages that we need to build and the time that it will take
1479
            //
1480
            if ( !toBuild.isEmpty() )
6914 dpurdie 1481
            {
7099 dpurdie 1482
                //  Locate the packages that we need to build
1483
                //  The build order cannot be correctly determined at this time
1484
                //      Need to add elements to the end of the list while processing
1485
                //      Sum the buildTimes of the packages that we add to the list
7082 dpurdie 1486
                while ( ! toBuild.isEmpty())
6914 dpurdie 1487
                {
7082 dpurdie 1488
                    PlannedPackage pkg = toBuild.remove(0);
1489
 
7099 dpurdie 1490
                    if (pkg.mBuildLevel > 400 ) {
7082 dpurdie 1491
                        mLogger.error("Circular dependency detected - not handled well");
1492
                        break;
1493
                    }
1494
 
7099 dpurdie 1495
                    if ( ! pkg.mPkg.mCheckedCircularDependency )
6914 dpurdie 1496
                    {
7082 dpurdie 1497
                        ripplePlan.add(pkg);
1498
                        results.planTime += pkg.mPkg.mBuildTime;
7099 dpurdie 1499
                        pkg.mPkg.mCheckedCircularDependency = true;
1500
 
1501
                        ArrayList<PlannedPackage> usedBy = usedByPackages(pkg, results.planCollection);
1502
                        toBuild.addAll(usedBy);
6914 dpurdie 1503
                    }
1504
                }
7082 dpurdie 1505
 
7099 dpurdie 1506
                //
1507
                //  Now we have a collection of packages to build ( and only the packages to build)
1508
                //  Need to determine the order in which it can be done and assign build levels
1509
                //  Basically:
1510
                //      Scan the collection looking for any package whose dependencies do not exist in the collection
1511
                //      or they have been allocated a build level.
1512
                //
1513
                //      Need to do this in waves so that we can correctly determine the build level.
1514
                //  
1515
                //
1516
                for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1517
                {
1518
                    PlannedPackage p = it.next();
1519
                    p.mPkg.mCheckedCircularDependency = true;
1520
                    p.mBuildLevel = 0;
1521
                }
1522
 
1523
                buildLevel = 0;
1524
                boolean more = true;
1525
                do  {
1526
                    ArrayList<PlannedPackage> thisLevel = new ArrayList<PlannedPackage>();
1527
                    for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1528
                    {
1529
                        PlannedPackage p = it.next();
1530
                        if ( p.mPkg.mCheckedCircularDependency )
1531
                        {
1532
                            boolean found = false;
1533
                            for (Iterator<String> it2 = p.mPkg.mDependencyCollection.iterator(); !found && it2.hasNext(); )
1534
                            {
1535
                                String alias = it2.next();
1536
                                for (Iterator<PlannedPackage> it3 = ripplePlan.iterator(); !found && it3.hasNext(); )
1537
                                {
1538
                                    PlannedPackage pkg = it3.next();
1539
                                    if (pkg.mPkg.mAlias.compareTo( alias ) == 0)
1540
                                    {
1541
                                        found = pkg.mPkg.mCheckedCircularDependency ;
1542
                                        break;
1543
                                    }
1544
                                }
1545
                            }
1546
 
1547
                            if (!found)
1548
                            {
1549
                                //  None of this packages dependencies can be found in the collection of packages to build
1550
                                //  Thus we can build it - at the current level
1551
                                p.mBuildLevel = buildLevel;
1552
                                thisLevel.add(p);
1553
                            }
1554
                        }
1555
                    }
1556
 
1557
                    //  Mark all the packages at this level as have been processed
1558
                    //  Cannot do this while we are determining the packages in the level 
1559
                    for (Iterator<PlannedPackage> it = thisLevel.iterator(); it.hasNext(); )
1560
                    {
1561
                        PlannedPackage p = it.next();
1562
                        p.mPkg.mCheckedCircularDependency = false;
1563
                    }
1564
 
1565
                    more = !thisLevel.isEmpty(); 
1566
                    buildLevel++;
1567
 
1568
                } while (more);
1569
 
7082 dpurdie 1570
                //  Sort the packages by buildOrder and buildTime
7099 dpurdie 1571
                phase.setPhase("Sort Plan");
7082 dpurdie 1572
                Collections.sort(ripplePlan, PlannedPackage.BuildOrderComparitor);
1573
 
7099 dpurdie 1574
                phase.setPhase("Display Build Order");
1575
                mLogger.error("Plan Build {} Time: {}", name, results.planTime);
7082 dpurdie 1576
                for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1577
                {
1578
                    PlannedPackage p = it.next();
7099 dpurdie 1579
                    mLogger.error("Plan: {} {} t:{}", p.mBuildLevel, p.mPkg.mAlias, p.mPkg.mBuildTime);
7082 dpurdie 1580
                }
1581
            }
1582
 
1583
            //  Daemon mode: Returning calculated plan
1584
            results.planCollection = ripplePlan;
1585
        }
7099 dpurdie 1586
 
1587
        phase.setPhase("EndPlanCollection");
7082 dpurdie 1588
        return results;
1589
    }
6914 dpurdie 1590
 
7082 dpurdie 1591
    /** Generate a plan based on a modified set of packages
1592
     * 
1593
     * @param name      - Name of the plan
1594
     * @param basicPlan - basicPlan
1595
     * @param mode      - True: Include natural ripples and WIPS/RIPPLES that would have been done
1596
     *                          as a part of the basic plan
1597
     * @return
1598
     */
1599
    private PlanResults postRipplePlan(String name, PlanResults basicPlan, boolean mode) {
6914 dpurdie 1600
 
7082 dpurdie 1601
        ArrayList<Package> fullPlanCollection = new ArrayList<Package>(mPackageCollection);
1602
        ArrayList<Package> buildCandidates = new ArrayList<Package>();
1603
        buildCandidates.addAll(mPackageCollectionWip);
1604
        buildCandidates.addAll(mPackageCollectionRipple);
1605
 
1606
        if ( !buildCandidates.isEmpty() )
1607
        {
1608
            for (Iterator<Package> it = buildCandidates.iterator(); it.hasNext(); )
1609
            {
1610
                Package p = it.next();
1611
                if (p.mBuildFile >= 0)
6914 dpurdie 1612
                {
7082 dpurdie 1613
                    if (!mode)
6914 dpurdie 1614
                    {
7088 dpurdie 1615
                        //  Exclude packages that would have been processed in the basicPlan
1616
                        for (Iterator<PlannedPackage> it1 = basicPlan.planCollection.iterator(); it1.hasNext(); )
1617
                        {
1618
                            PlannedPackage pkg = it1.next();
1619
                            if (pkg.mPkg == p)
1620
                            {
7099 dpurdie 1621
                                mLogger.error("Test Plan without {}", p.mAlias);
7088 dpurdie 1622
                                continue;
1623
                            }
1624
                        }
6914 dpurdie 1625
                    }
7082 dpurdie 1626
 
7099 dpurdie 1627
                    mLogger.error("Test Plan with {}", p.mAlias);
7082 dpurdie 1628
                    Package foundInRelease = mReleaseManager.findPackage(p.mAlias, fullPlanCollection);
1629
                    int foundIndex = mReleaseManager.findPackageLastIndex;
1630
                    if (foundInRelease == ReleaseManager.NULL_PACKAGE)
1631
                    {
1632
                        fullPlanCollection.add(p);
1633
                    }
1634
                    else
1635
                    {
1636
                        fullPlanCollection.set(foundIndex, p);
1637
                    }
1638
 
1639
                    Package.resetCircularDependency (fullPlanCollection);
1640
                    if ( p.hasCircularDependency( fullPlanCollection ) )
1641
                    {
1642
                        mLogger.info("planRelease circular dependency detected {}", p.mAlias);
1643
 
1644
                        //  Force this package to be marked as having a circular dependency - even if its been excluded
1645
                        p.mBuildFile = 0;
1646
 
1647
                        // Exclude the package
1648
                        // max 50 chars
1649
                        rippleBuildExclude(p, p.mId, "Package has circular dependency", -6);
1650
                    }
6914 dpurdie 1651
                }
1652
            }
7082 dpurdie 1653
 
1654
        }
1655
        return planCollection(name, fullPlanCollection, mode);
1656
    }
1657
 
1658
    /** 
1659
     *  Calculate a collection of packages that actively use the named package
1660
     *  A consumer package does NOT use the named package,
1661
     *      If the consumer is an SDK or is Pegged
1662
     *      If the consumer is marked as advisoryRipple
1663
     *      If the consumer cannot be built
1664
     *   
1665
     * @param pkg - Package to process
1666
     * @param planCollection - collection of packages to scan
1667
     *
1668
     * @return A collection of packages that actively 'use' the specified package
1669
 
1670
     */
7099 dpurdie 1671
    private ArrayList<PlannedPackage> usedByPackages(PlannedPackage pkg, ArrayList<PlannedPackage> planCollection) {
7082 dpurdie 1672
 
1673
        ArrayList<PlannedPackage> usedBy = new ArrayList<PlannedPackage>();
1674
 
1675
        for (Iterator<PlannedPackage> it = planCollection.iterator(); it.hasNext(); )
1676
        {
1677
            PlannedPackage p = it.next();
1678
 
1679
            //  Is this package 'actively used' in the current build
1680
            if (p.mPkg.mBuildFile >= 0)
6914 dpurdie 1681
            {
7082 dpurdie 1682
                for (Iterator<String> it2 = p.mPkg.mDependencyCollection.iterator(); it2.hasNext(); )
6914 dpurdie 1683
                {
7088 dpurdie 1684
                    String alias = it2.next();
1685
                    if (  pkg.mPkg.mAlias.compareTo( alias ) == 0  ) {
1686
                        //  Have found a consumer of 'pkg'
1687
                        usedBy.add(p);
6914 dpurdie 1688
                        break;
1689
                    }
1690
                }
7082 dpurdie 1691
            }
1692
        }
1693
 
1694
        return usedBy;
1695
    }
1696
 
1697
    /** 
1698
     *  Calculate a collection of packages that use the named package
1699
     *   
1700
     * @param pkg - Package to process
1701
     * @param pkgCollection - collection of packages to scan
1702
     *
1703
     * @return A collection of packages that actively 'use' the specified package
6914 dpurdie 1704
 
7082 dpurdie 1705
     */
1706
    private ArrayList<Package> usedByAnyPackages(Package pkg, ArrayList<Package> pkgCollection) {
1707
 
1708
        ArrayList<Package> usedBy = new ArrayList<Package>();
1709
 
1710
        for (Iterator<Package> it = pkgCollection.iterator(); it.hasNext(); )
1711
        {
1712
            Package p = it.next();
1713
 
1714
            for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
1715
            {
1716
                String alias = it2.next();
1717
                if (  pkg.mAlias.compareTo( alias ) == 0  ) {
1718
                    usedBy.add(p);
1719
                    break;
1720
                }
6914 dpurdie 1721
            }
7082 dpurdie 1722
        }
1723
 
1724
        return usedBy;
6914 dpurdie 1725
    }
1726
 
1727
    /** Determine if a given PVID is a member of the current release.
1728
     *  Used to determine if a package dependency is out of date
1729
     * 
1730
     * @param dpvId
1731
     * @return true - specified pvid is a full member of the Release
1732
     */
1733
    private boolean isInRelease(Integer dpvId) {
1734
 
7082 dpurdie 1735
        boolean inRelease = false;
6914 dpurdie 1736
 
7082 dpurdie 1737
        for ( Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
6914 dpurdie 1738
        {
7082 dpurdie 1739
            Package p = it.next();
6914 dpurdie 1740
 
7082 dpurdie 1741
            if ( p.mId == dpvId )
6914 dpurdie 1742
            {
7082 dpurdie 1743
                inRelease = ! p.mIsNotReleased;
6914 dpurdie 1744
                break;
1745
            }
1746
        }
7082 dpurdie 1747
        return inRelease;
6914 dpurdie 1748
    }
1749
 
1750
 
7082 dpurdie 1751
    /** Reports what change in build exceptions happens as part of planRelease
1752
     * 
1753
     *  There are three types of exceptions
1754
     *      PlanError - These may be removed, if the error was not seen in the last plan
1755
     *      BuildErrors - These we persist
1756
     *      IndirectErrors - Packages that depend on a Plan or Build errors
6914 dpurdie 1757
     */
1758
    public void reportChange() throws SQLException, Exception
1759
    {
1760
        int counter = 0;
1761
        for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1762
        {
1763
            BuildExclusion buildExclusion = it.next();
1764
 
7082 dpurdie 1765
            //  Skip 'Processed' entries
1766
            //  These will be the result of a PlanError that we have seen again
1767
            //
1768
            //  PlanErrors - Add/Remove as detected
1769
            //  BuildErrors - Persist. 
1770
            //  IndirectErrors - Add/Remove as detected
1771
            //  
1772
 
1773
            if ( !buildExclusion.isABuildError() )
6914 dpurdie 1774
            {
7088 dpurdie 1775
                if ( !buildExclusion.isProcessed() )
1776
                {
1777
                    if (buildExclusion.isImported() && !buildExclusion.isARootCause() ) {
1778
                        // Remove from the exclusion list
1779
                        buildExclusion.includeToBuild(mReleaseManager, mBaseline);
1780
                        mLogger.error("reportChange remove unused exclusion: {}", buildExclusion );
1781
                    } else {
1782
                        // Exclude and notify
1783
                        buildExclusion.excludeFromBuild(mReleaseManager, mBaseline);
1784
                        buildExclusion.email(this, mPackageCollectionAll);
1785
                        counter++;
1786
                    }
7032 dpurdie 1787
                }
6914 dpurdie 1788
            }
1789
        }
7044 dpurdie 1790
        mLogger.error("reportChange exclusion count: {}", counter);
6914 dpurdie 1791
    }
1792
 
1793
    /**reports the build plan
1794
     */
1795
    public void reportPlan() throws SQLException, Exception
1796
    {
1797
        mReleaseManager.reportPlan(mRtagId, mBuildOrder);
1798
    }
1799
 
1800
    /**Returns the first build file from the collection
1801
     * The build file will be flagged as empty if none exists
1802
     */
1803
    public BuildFile getFirstBuildFileContent()
1804
    {
1805
        mLogger.debug("getFirstBuildFileContent");
1806
 
1807
        mBuildIndex = -1;
1808
        return getNextBuildFileContent();
1809
    }
1810
 
1811
    /**Returns next build file from the collection
1812
     * The build file will be flagged as empty if none exists
1813
     */
1814
    public BuildFile getNextBuildFileContent()
1815
    {
1816
        mLogger.debug("getNextBuildFileContent");
1817
        BuildFile retVal = null;
1818
 
1819
        try
1820
        {
1821
            mBuildIndex++;
1822
            retVal = mBuildCollection.get( mBuildIndex );
1823
        }
1824
        catch( IndexOutOfBoundsException e )
1825
        {
1826
            // Ignore exception. retVal is still null.
1827
        }
1828
 
1829
        if (retVal == null)
1830
        {
1831
            retVal = new BuildFile();
1832
        }
1833
 
7044 dpurdie 1834
        mLogger.debug("getNextBuildFileContent returned {}", retVal.state.name() );
6914 dpurdie 1835
        return retVal;
1836
    }
1837
 
1838
 
1839
    /**collects meta data associated with the baseline
1840
     * this is sufficient to send an indefinite pause email notification 
1841
     *  
1842
     * Escrow: Used once to collect information about the SBOM and associated Release 
1843
     *         mBaseline is an SBOMID 
1844
     * Daemon: Used each build cycle to refresh the information 
1845
     *          mBaseline is an RTAGID
1846
     */
1847
    public void collectMetaData() throws SQLException, Exception
1848
    {
1849
        Phase phase = new Phase("cmd");
7044 dpurdie 1850
        mLogger.debug("collectMetaData mDaemon {}", mDaemon);
6914 dpurdie 1851
 
1852
        try
1853
        {
1854
            phase.setPhase("connect");
1855
            mReleaseManager.connect();
1856
 
1857
            if (! mDaemon)
1858
            {
1859
                mSbomId = mBaseline;
1860
                phase.setPhase("queryRtagIdForSbom");
1861
                mRtagId = mReleaseManager.queryRtagIdForSbom(mBaseline);
1862
                if (mRtagId == 0)
1863
                {
7033 dpurdie 1864
                    mLogger.error("SBOM does not have a matching Release. Cannot be used as a base for an Escrow"); 
6914 dpurdie 1865
                    throw new Exception("rtagIdForSbom show stopper. SBOM does not have an associated Release");
1866
                }
1867
            }
1868
 
1869
            phase.setPhase("queryReleaseConfig");
1870
            mReleaseManager.queryReleaseConfig(mRtagId);
1871
 
1872
            if (mDaemon)
1873
            {
1874
                phase.setPhase("queryMailServer");
1875
                setMailServer(mReleaseManager.queryMailServer());
1876
                phase.setPhase("queryMailSender");
1877
                setMailSender(mReleaseManager.queryMailSender());
1878
                phase.setPhase("queryGlobalAddresses");
1879
                setMailGlobalTarget(mReleaseManager.queryGlobalAddresses());
1880
                phase.setPhase("queryProjectEmail");
1881
                mMailGlobalCollection = mReleaseManager.queryProjectEmail(mBaseline);
1882
                phase.setPhase("mMailGlobalTarget");
1883
                mMailGlobalCollection.add(0,getMailGlobalTarget());
1884
            }
1885
            phase.setPhase("queryBaselineName");
1886
            mBaselineName = mReleaseManager.queryBaselineName(mBaseline);
1887
            phase.setPhase("Done");
1888
        }
1889
        finally
1890
        {
1891
            // this block is executed regardless of what happens in the try block
1892
            // even if an exception is thrown
1893
            // ensure disconnect
1894
            mReleaseManager.disconnect();
1895
        }
1896
    }
1897
 
1898
    /**
1899
     * Find Package by package alias
7082 dpurdie 1900
     * Searches the released package collection
6914 dpurdie 1901
     * @param   alias               - alias of package to locate
1902
     * @return  Package with the matching mAlias or NULL_PACKAGE if no package has the mAlias
1903
     */
1904
    public Package findPackage(String alias)
1905
    {
1906
        mLogger.debug("findPackage");
1907
 
1908
        Package retVal = mReleaseManager.findPackage(alias, mPackageCollection);
1909
 
7044 dpurdie 1910
        mLogger.info("findPackage returned {}", retVal.mName);
6914 dpurdie 1911
        return retVal;
1912
    }
7082 dpurdie 1913
 
6914 dpurdie 1914
    /**
7082 dpurdie 1915
     * Sets the mBuildFile to the specified value for the package
1916
     * Does not handle dependent packages - this will be done later  
1917
     *  
7032 dpurdie 1918
     * @param p             The package being excluded 
1919
     * @param rootPvId      The PVID of the package that is causing the exclusion. Null or -ve values are special
1920
     *                      This package is the root cause, -2: Excluded by Ripple Stop 
1921
     * @param rootCause     Text message. Max 50 characters imposed by RM database 
7082 dpurdie 1922
     * @param reason        New value for mBuildFile
6914 dpurdie 1923
     */
7082 dpurdie 1924
    private void rippleBuildExclude(Package p, int rootPvId, String rootCause, int reason )
6914 dpurdie 1925
    {
1926
        mLogger.debug("rippleBuildExclude");
7082 dpurdie 1927
 
7099 dpurdie 1928
        if ( p.mBuildFile >= 0 )
6914 dpurdie 1929
        {
7088 dpurdie 1930
            p.mBuildFile = reason;
7099 dpurdie 1931
            mLogger.info("rippleBuildExclude set mBuildFile to {} for package {}", reason, p.mAlias );
7088 dpurdie 1932
 
1933
            //  Scan the complete collection looking for a matching item
1934
            //  If found then assume that this error is a a PlanError that is still present
1935
            //      Mark it as Processed to indicate that its still present
1936
            //  If found, process it, else add it (unprocessed)
1937
            boolean found = false;
1938
            for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1939
            {
1940
                BuildExclusion buildExclusion = it.next();
6914 dpurdie 1941
 
7082 dpurdie 1942
                if ( buildExclusion.compare(p.mId, rootPvId, rootCause))
1943
                {
1944
                    buildExclusion.setProcessed();
1945
                    found = true;
1946
                    break;
1947
                }
6914 dpurdie 1948
            }
7082 dpurdie 1949
 
1950
            if (!found)
6914 dpurdie 1951
            {
7082 dpurdie 1952
                // Entry not found in the mBuildExclusionCollection. Its a new error
1953
                // 
1954
                // Mark all occurrences for this package as processed
1955
                // These will be superseded by a new build exclusion entry
6914 dpurdie 1956
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1957
                {
1958
                    BuildExclusion buildExclusion = it.next();
1959
 
7082 dpurdie 1960
                    if ( buildExclusion.compare(p.mId))
6914 dpurdie 1961
                    {
7032 dpurdie 1962
                        buildExclusion.setProcessed();
6914 dpurdie 1963
                    }
1964
                }
1965
 
7082 dpurdie 1966
                //  Add the new build exclusion to a list
1967
                BuildExclusion buildExclusion = new BuildExclusion(p.mId, rootPvId, rootCause, p.mTestBuildInstruction);
1968
                mBuildExclusionCollection.add(buildExclusion);
6914 dpurdie 1969
            }
7082 dpurdie 1970
        }
6914 dpurdie 1971
 
7088 dpurdie 1972
        mLogger.info("rippleBuildExclude set {} {}", p.mAlias, p.mBuildFile);
6914 dpurdie 1973
    }
1974
 
1975
    /**Simple XML string escaping
1976
     * 
1977
     * @param xml		- String to escape
1978
     * @return		- A copy of the string with XML-unfriendly characters escaped 
1979
     */
1980
    public static String escapeXml( String xml )
1981
    {
1982
        xml = xml.replaceAll("&", "&amp;");
1983
        xml = xml.replaceAll("<", "&lt;");
1984
        xml = xml.replaceAll(">", "&gt;");
1985
        xml = xml.replaceAll("\"","&quot;");
1986
        xml = xml.replaceAll("'", "&apos;");
1987
        xml = xml.replaceAll("\\$", "\\$\\$");
1988
 
1989
        return xml;
1990
    }
1991
 
1992
    /** Quote a string or a string pair
1993
     *  If two strings are provided, then they will be joined with a comma.
1994
     *   
1995
     * @param text		- First string to quote
1996
     * @param text2		- Optional, second string
1997
     * @return A string of the form 'text','text2'
1998
     */
1999
    public static String quoteString(String text, String text2)
2000
    {
2001
        String result;
2002
        result =  "\'" + text + "\'";
2003
        if (text2 != null )
2004
        {
2005
            result +=  ",\'" + text2 + "\'";  
2006
        }
2007
        return result;
2008
    }
2009
 
2010
    /** Generate build file information
2011
     * 
2012
     */
2013
    private void generateBuildFiles() 
2014
    {
2015
 
2016
        // persist the build files
2017
        boolean allProcessed = false;
2018
        int buildFile = 1;
2019
        StringBuilder rawData = new StringBuilder();
2020
        StringBuilder setUp = new StringBuilder();
2021
 
2022
        mLogger.debug("generateBuildFiles");
2023
 
2024
        if ( mDaemon )
2025
        {
2026
            // all interesting packages in daemon mode match the following filter
2027
            buildFile = 3;
2028
        }
2029
 
2030
        //-----------------------------------------------------------------------
2031
        //    Generate the build file
2032
        do
2033
        {
2034
            BuildFile buildEntry = new  BuildFile();
2035
            buildEntry.state = BuildFileState.Dummy;
2036
            XmlBuilder xml = generateBuildFileHeader();
2037
 
2038
 
2039
            //	Generate properties for each package in this build level or lower build levels
2040
            //	The properties link the packageAlias to the PackageName and PackageVersion
2041
            //
2042
            //	[DEVI 54816] In escrow mode all unreproducible packages are included 
2043
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
2044
            {
2045
                Package p = it.next();
2046
 
2047
                if ( ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) ) || ( !mDaemon && p.mBuildFile == -2 ) )
2048
                {
2049
                    xml.addProperty(p.mAlias, p.mName + " " + p.mVersion + p.mExtension);
2050
                }
2051
            }
2052
 
2053
            //	UTF Support
2054
            //	Insert additional info into the build file to provide extra checking
2055
            //
7046 dpurdie 2056
            if ( ! mReleaseManager.mUseDatabase )
6914 dpurdie 2057
            {
2058
                // UTF Support
2059
                // Insert per-package planning information
2060
                //
2061
                xml.addComment("mPackageCollection");
2062
                for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
2063
                {
2064
                    Package p = it.next();
2065
                    generatePackageInfo(xml, p);
2066
                }
2067
 
7082 dpurdie 2068
                xml.addComment("mPackageCollectionWip");
2069
                for (Iterator<Package> it = mPackageCollectionWip.iterator(); it.hasNext(); )
2070
                {
2071
                    Package p = it.next();
2072
                    if (p.mIsNotReleased )
2073
                        generatePackageInfo(xml, p);
2074
                }
2075
 
2076
                xml.addComment("mPackageCollectionTest");
2077
                for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
2078
                {
2079
                    Package p = it.next();
2080
                    if (p.mIsNotReleased )
2081
                        generatePackageInfo(xml, p);
2082
                }
2083
 
2084
                xml.addComment("mPackageCollectionTestRipple");
2085
                for (Iterator<Package> it = mPackageCollectionRipple.iterator(); it.hasNext(); )
2086
                {
2087
                    Package p = it.next();
2088
                    if (p.mIsNotReleased )
2089
                        generatePackageInfo(xml, p);
2090
                }
2091
 
6914 dpurdie 2092
                // UTF Support
2093
                // Insert build exclusion information
2094
                xml.addComment("mBuildExclusionCollection");
2095
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
2096
                {
2097
                    BuildExclusion buildExclusion = it.next();
2098
                    {
7082 dpurdie 2099
                        xml.addComment(buildExclusion.toString());
6914 dpurdie 2100
                    }
2101
                }
7082 dpurdie 2102
            }
2103
 
2104
            // UTF Support (Also while trailing the changes)
2105
            // Insert build Plan
2106
            if (mDaemon)
2107
            {
2108
                xml.addComment("mBuildOrder");
2109
                for (Iterator<PlannedPackage> it = mBuildOrder.iterator(); it.hasNext(); )
6914 dpurdie 2110
                {
7082 dpurdie 2111
                    PlannedPackage p = it.next();
2112
                    String comment =
2113
                            "pvid="+ p.mPkg.mId +
2114
                            " order=" + p.mBuildLevel +
2115
                            " time=" + p.mPkg.mBuildTime +
2116
                            " name=\"" + p.mPkg.mAlias + "\"";
2117
                    xml.addComment(comment);
6914 dpurdie 2118
                }
2119
            }
2120
 
2121
            //  Generate Taskdef information
2122
            generateTaskdef(xml);
2123
 
2124
            //
2125
            //  Insert known Machine Information
2126
            //  Escrow usage: 
2127
            //      Map machType to machClass
2128
            //  Also serves as a snapshot of the required build configuration
2129
            //  ie: machine types and buildfilters
2130
            //
2131
            if (!mDaemon)
2132
            {
2133
                generateMachineInfo(xml, null);
2134
            }
2135
 
2136
            //
2137
            //	Generate target rules for each package to be built within the current build file
2138
            //
2139
            boolean daemonHasTarget = false;
2140
 
7082 dpurdie 2141
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2142
            {
2143
                Package p = it.next();
2144
 
2145
                if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
2146
                {
2147
                    generateTarget(xml, buildEntry, p, buildFile);
2148
 
2149
                    if ( p.mBuildFile == 1 )
2150
                    {
2151
                        daemonHasTarget = true;
2152
 
2153
                        // Retain information about the target package
2154
                        buildEntry.mPkgId = p.mPid;
2155
                        buildEntry.mPvId = p.mId;
2156
                    }
2157
                }
2158
 
2159
                //	Generate escrow extraction commands
2160
                //	Only done on the first pass though the packages
2161
                //
2162
                if ( !mDaemon && buildFile == 1 )
2163
                {
2164
                    setUp.append("jats jats_vcsrelease -extractfiles"
2165
                                + " \"-label=" + p.mVcsTag + "\""
2166
                                + " \"-view=" + p.mAlias + "\""
2167
                                + " -root=. -noprefix"
2168
                                + mlf );
2169
                }
2170
 
2171
                //	Generate escrow raw CSV data
2172
                //	Note: I don't think this data is used at all
2173
 
2174
                if ( !mDaemon && ( p.mBuildFile == buildFile))
2175
                {
2176
                    StringAppender machines = new StringAppender(",");
2177
                    for (Iterator<BuildStandard> it1 = p.mBuildStandardCollection.iterator(); it1.hasNext();)
2178
                    {
2179
                        BuildStandard bs = it1.next();
2180
                        machines.append(bs.mMachClass);
2181
                    }
2182
 
2183
                    rawData.append(p.mAlias + "," +
2184
                                    buildFile + "," +
2185
                                    machines +
2186
                                    mlf);
2187
                }
2188
            }
2189
 
2190
            if ( mDaemon && !daemonHasTarget )
2191
            {
2192
                // must have AbtTestPath, AbtSetUp, AbtTearDown, and AbtPublish targets
2193
                XmlBuilder target = xml.addNewElement("target");
2194
                target.addAttribute("name", "AbtTestPath");
2195
 
2196
                target = xml.addNewElement("target");
2197
                target.addAttribute("name", "AbtSetUp");
2198
 
2199
                target = xml.addNewElement("target");
2200
                target.addAttribute("name", "AbtTearDown");
2201
 
2202
                target = xml.addNewElement("target");
2203
                target.addAttribute("name", "AbtPublish");
2204
            }
2205
 
2206
            generateDefaultTarget( xml, buildFile);
2207
 
2208
            //	Convert the Xml structure into text and save it in the build file
2209
            //	Add this build file to the mBuildCollection
2210
            buildEntry.content = mXmlHeader + xml.toString();
2211
            mBuildCollection.add(buildEntry);
2212
 
2213
            // are more build files required
2214
            allProcessed = true;
2215
 
2216
            if (!mDaemon)
2217
            {
2218
                // this is escrow mode centric
7082 dpurdie 2219
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2220
                {
2221
                    Package p = it.next();
2222
 
2223
                    if ( p.mBuildFile > buildFile )
2224
                    {
2225
                        // more build files are required
2226
                        allProcessed = false;
7044 dpurdie 2227
                        mLogger.info("planRelease reiterating package has no build requirement {} {} {}",p.mName, p.mBuildFile,  buildFile);
6914 dpurdie 2228
                        break;
2229
                    }
2230
                } 
2231
 
2232
                buildFile++;
2233
            }
2234
 
2235
        } while( !allProcessed );
2236
 
2237
        //	Save additional escrow data
2238
        if ( !mDaemon )
2239
        {
2240
            mEscrowSetup = setUp.toString();
2241
            mEscrowRawData = rawData.toString();
2242
        }
2243
    }
2244
 
2245
    /**returns a build file header for the mBaseline
2246
     */
2247
    private XmlBuilder generateBuildFileHeader()
2248
    {
2249
        mLogger.debug("generateBuildFileHeader");
2250
        XmlBuilder element = new XmlBuilder("project");
2251
 
2252
        element.addAttribute("name", "mass");
2253
        element.addAttribute("default", "full");
2254
        element.addAttribute("basedir", ".");
2255
 
2256
        if ( mDaemon )
2257
        {
2258
            element.addProperty("abt_mail_server", getMailServer());
2259
            element.addProperty("abt_mail_sender", getMailSender()); 
2260
            element.addProperty("abt_rtag_id", mBaseline);
2261
            element.addProperty("abt_daemon", mReleaseManager.currentTimeMillis());
2262
            element.makePropertyTag("abt_packagetarball", true);
2263
            element.makePropertyTag("abt_usetestarchive", !ReleaseManager.getUseMutex());
2264
 
7082 dpurdie 2265
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2266
            {
2267
                Package p = it.next();
2268
 
2269
                if ( p.mBuildFile == 1 )
2270
                {
2271
                    element.addProperty("abt_package_name", p.mName);
2272
                    element.addProperty("abt_package_version", p.mVersion + p.mExtension);
2273
                    element.addProperty("abt_package_extension", p.mExtension);
2274
                    element.addProperty("abt_package_location", getBuildLocation(p));
2275
                    element.addProperty("abt_package_ownerlist", p.emailInfoNonAntTask(this));
2276
                    element.addProperty("abt_package_build_info", buildInfoText(p));
2277
 
2278
                    // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
2279
                    StringAppender depends = new StringAppender(";");
2280
 
2281
                    for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
2282
                    {
2283
                        Package depend = it3.next();
2284
                        depends.append( quoteString(depend.mName, depend.mVersion + depend.mExtension) );
2285
                    }
2286
 
2287
                    element.addProperty("abt_package_depends", depends.toString());
2288
                    element.addProperty("abt_is_ripple", p.mDirectlyPlanned ? "0" : "1");
2289
                    element.addProperty("abt_build_reason", p.mBuildReason.toString());
2290
                    element.addProperty("abt_package_version_id", p.mId);
2291
                    element.addProperty("abt_does_not_require_source_control_interaction", ! p.mRequiresSourceControlInteraction ? "true" : "false" );
2292
                    element.addProperty("abt_test_build_instruction", p.mTestBuildInstruction);
2293
                }
2294
            }
2295
        }
2296
        else
2297
        {
2298
            //    Escrow Mode
2299
            element.addProperty("abt_rtag_id", mRtagId);
2300
            element.addProperty("abt_sbom_id", mSbomId);
2301
        }
2302
 
2303
        element.addProperty("abt_release", escapeXml(mBaselineName));
2304
        element.addProperty("abt_buildtool_version", mReleaseManager.getMajorVersionNumber() );
2305
 
2306
        element.addNewElement("condition")
2307
        .addAttribute("property", "abt_family")
2308
        .addAttribute("value", "windows")
2309
        .addNewElement("os")
2310
        .addAttribute("family", "windows");
2311
        element.addProperty("abt_family", "unix");
2312
 
2313
        return element;
2314
    }
2315
 
2316
    /** Add task def XML items taskdef for the abt ant task
2317
     * @param xml 	- xml item to extend
2318
     */
2319
    private void generateTaskdef(XmlBuilder xml)
2320
    {
2321
        mLogger.debug("generateTaskdef");
2322
        xml.addNewElement("taskdef")
2323
        .addAttribute("name", "abt")
2324
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABT");
2325
 
2326
        xml.addNewElement("taskdef")
2327
        .addAttribute("name", "abtdata")
2328
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABTData");
2329
    }
2330
 
2331
    /** returns the command abtdata items
2332
     *  <br>Common machine information
2333
     *  <br>Common email address
2334
     *  
2335
     *  
2336
     *  @param	xml - Xml element to extend   
2337
     *  @param    p - Package (May be null)
2338
     */
2339
    private void generateMachineInfo(XmlBuilder xml, Package p)
2340
    {
2341
        XmlBuilder element = xml.addNewElement("abtdata");
2342
        element.addAttribute("id", "global-abt-data");
2343
 
2344
        //
2345
        //  Iterate over all the machines and create a nice entry
2346
        //
2347
        for (Iterator<ReleaseConfig> it = mReleaseManager.mReleaseConfigCollection.mReleaseConfig.iterator(); it.hasNext(); )
2348
        {
2349
            ReleaseConfig rc = it.next();
2350
            element.addElement(rc.getMachineEntry());
2351
        }
2352
 
2353
        //
2354
        //  Now the email information
2355
        //
2356
        if ( p != null)
2357
        {
2358
            p.emailInfo(this, element);
2359
        }
2360
    }
2361
 
2362
    /** Generate package information
2363
     *  Only when running unit tests
2364
     *  
2365
     * @param xml	- An xml element to append data to
2366
     * @param p	- Package to process
2367
     */
2368
    private void generatePackageInfo (XmlBuilder xml, Package p)
2369
    {
7082 dpurdie 2370
        StringBuilder comment = new StringBuilder();
2371
        StringBuilder deps = new StringBuilder();
2372
 
2373
        String joiner = "";
2374
        for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
2375
        {
2376
            String alias = it2.next();
2377
            deps.append(joiner).append(alias); 
2378
            joiner = ",";
2379
        }
2380
 
2381
        comment.append("pvid=").append(p.mId);
2382
        comment.append(" name=").append('"').append(p.mAlias).append('"');
2383
        comment.append(" reason=").append(p.mNoBuildReason);
2384
        comment.append(" buildFile=").append(p.mBuildFile);
2385
        comment.append(" directlyPlanned=").append(p.mDirectlyPlanned);
2386
        comment.append(" indirectlyPlanned=").append(p.mIndirectlyPlanned);
2387
        comment.append(" depends=[").append(deps).append("]");
6914 dpurdie 2388
 
7082 dpurdie 2389
        xml.addComment(comment.toString());            
6914 dpurdie 2390
    }
2391
 
2392
    /**returns an ant target for the passed Package
2393
     * in daemon mode:
2394
     *  packages are categorized with one of three mBuildFile values:
2395
     *   1 the package to be built by this buildfile
2396
     *   2 the packages with a future build requirement
2397
     *   3 the packages with no build requirement
2398
     *  the returned target depends on this categorization and will have
2399
     *   1 full abt info
2400
     *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
2401
     *   3 only a name attribute (will not build this package)
2402
     * in escrow mode:
2403
     *  if the passed Package's mBuildFile is different (less than) the passed build file,
2404
     *  the returned target have only a name attribute (will not build this package)
2405
     *   
2406
     * @param xml - Xml element to extend
2407
     * @param buildEntry - Record build type (dummy/generic/not generic)
2408
     * @param p - Package to process
2409
     * @param buildFile - buildfile level being processed
2410
     */
2411
    private void generateTarget(XmlBuilder xml, BuildFile buildEntry, Package p, int buildFile)
2412
    {
2413
        mLogger.debug("generateTarget");
2414
 
2415
        //---------------------------------------------------------------------
2416
        //  Generate the AbtData - common machine and email information
2417
        //  Only used by the daemon builds
2418
        //
2419
        if ( mDaemon && p.mBuildFile == 1 )
2420
        {
2421
            generateMachineInfo(xml, p );
2422
        }
2423
 
2424
        //-------------------------------------------------------------------------
2425
        //  Generate the <target name=... /> construct
2426
        //  There are two types
2427
        //      1) Simple dummy place holder. Just has the PackageName.PackageExt
2428
        //      2) Full target. Has all information to build the package including
2429
        //              AbtSetUp, AbtTearDown and AbtPublish targets
2430
        //
2431
 
2432
        if ( !mDaemon && ( p.mBuildFile < buildFile ) )
2433
        {
2434
            XmlBuilder target = xml.addNewElement("target");
2435
            target.addAttribute("name", p.mAlias);
2436
        }
2437
        else
2438
        {
2439
            if (!mDaemon) 
2440
            {
2441
                //  Escrow Only:
2442
                //  Generate the 'wrapper' target
2443
                //  This is used to ensure that the required dependencies have been built - I think
2444
                //
2445
                StringAppender dependList = new StringAppender(",");
2446
                if ( !p.mPackageDependencyCollection.isEmpty() )
2447
                {
2448
                    for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2449
                    {
2450
                        Package dependency = it.next();
2451
                        if ( !mDaemon && dependency.mBuildFile == -2 )
2452
                        {
2453
                            // ignore targets which build in foreign environments in escrow mode
2454
                            continue;
2455
                        }
2456
                        dependList.append(dependency.mAlias);
2457
                    }
2458
                }
2459
 
2460
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2461
                target.addAttribute("name", p.mAlias + ".wrap");
2462
 
2463
                if (dependList.length() > 0)
2464
                {
2465
                    target.addAttribute("depends", dependList.toString() );
2466
                }
2467
 
2468
                if ( !mDaemon )
2469
                {
2470
                    boolean hasDependenciesBuiltInThisIteration = false;
2471
                    if ( ( !p.mPackageDependencyCollection.isEmpty()) )
2472
                    {
2473
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2474
                        {
2475
                            Package dependency = it.next();
2476
 
2477
                            if ( dependency.mBuildFile == buildFile )
2478
                            {
2479
                                hasDependenciesBuiltInThisIteration = true;
2480
                                break;
2481
                            }
2482
                        }
2483
                    }
2484
 
2485
                    if ( hasDependenciesBuiltInThisIteration )
2486
                    {
2487
                        XmlBuilder condition = target.addNewElement("condition");
2488
                        condition.addAttribute("property",  p.mAlias + ".build");
2489
 
2490
                        XmlBuilder and = condition.addNewElement("and");
2491
 
2492
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2493
                        {
2494
                            Package dependency = it.next();
2495
 
2496
                            if ( dependency.mBuildFile == buildFile )
2497
                            {
2498
                                XmlBuilder or = and.addNewElement("or");
2499
 
2500
                                XmlBuilder equal1 = or.addNewElement("equals");
2501
                                equal1.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2502
                                equal1.addAttribute("arg2", "0");
2503
 
2504
                                XmlBuilder equal2 = or.addNewElement("equals");
2505
                                equal2.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2506
                                equal2.addAttribute("arg2", "257");
2507
                            }
2508
                        }
2509
                    }
2510
                    else
2511
                    {
2512
                        target.addProperty(p.mAlias + ".build", "");
2513
                    }
2514
                }
2515
            }
2516
 
2517
 
2518
            //
2519
            //  Generate the 'body' of the target package
2520
            //  Escrow Mode: Always
2521
            //  Daemon Mode: Only for the one target we are building
2522
            //                  Simplifies the XML
2523
            //                  Reduces noise in the logs
2524
            //              Don't add target dependencies. 
2525
            //                  We are only building one target and the 
2526
            //                  dependency management has been done way before now.
2527
            //                  All it does is makes the logs noisy.
2528
            //
2529
            if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
2530
            {
2531
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2532
                target.addAttribute("name", p.mAlias);
2533
 
2534
                if ( !mDaemon )
2535
                {
2536
                    target.addAttribute("depends",  p.mAlias + ".wrap");
2537
                    target.addAttribute("if",p.mAlias + ".build");
2538
                }
2539
 
2540
                if ( mDaemon && p.mBuildFile == 1 )
2541
                {
2542
                    target.addProperty(p.mAlias + "pkg_id",p.mPid);
2543
                    target.addProperty(p.mAlias + "pv_id",p.mId);
2544
                }
2545
 
2546
                target.addProperty(p.mAlias + "packagename",p.mName);        		
2547
                target.addProperty(p.mAlias + "packageversion",p.mVersion);
2548
                target.addProperty(p.mAlias + "packageextension",p.mExtension);
2549
                target.addProperty(p.mAlias + "packagevcstag",p.mVcsTag);
2550
 
2551
                target.makePropertyTag(p.mAlias + "directchange", p.mDirectlyPlanned); 
2552
                target.makePropertyTag(p.mAlias + "doesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2553
 
2554
                buildEntry.state = BuildFile.BuildFileState.NonGeneric;
2555
                if ( p.isGeneric() )
2556
                {
2557
                    buildEntry.state = BuildFile.BuildFileState.Generic;
2558
                    target.makePropertyTag(p.mAlias + "generic", true); 
2559
                }
2560
 
2561
                target.addProperty(p.mAlias + "loc", getBuildLocation(p));
2562
                target.makePropertyTag(p.mAlias + "unittests", p.mHasAutomatedUnitTests && mDaemon);
2563
 
2564
                //    Add our own task and associated information
2565
                //
2566
                XmlBuilder abt = target.addNewElement("abt").isExpanded();
2567
 
2568
                for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2569
                {
2570
                    Package dependency = it.next();
2571
                    XmlBuilder depend = abt.addNewElement("depend");
2572
                    depend.addAttribute("package_alias", "${" + dependency.mAlias + "}");
2573
                }
2574
 
2575
                buildInfo(abt,p);
2576
 
2577
                if ( mDaemon && p.mBuildFile == 1 )
2578
                {
2579
                    //    AbtTestPath
2580
                    target = xml.addNewElement("target").isExpanded();
2581
                    target.addAttribute("name", "AbtTestPath");
2582
                    target.addProperty("AbtTestPathpackagevcstag", p.mVcsTag);
2583
                    target.addProperty("AbtTestPathpackagename", p.mName);
2584
                    abt = target.addNewElement("abt").isExpanded();
2585
                    buildInfo(abt, p);
2586
 
2587
 
2588
                    //    AbtSetUp
2589
                    target = xml.addNewElement("target").isExpanded();
2590
                    target.addAttribute("name", "AbtSetUp");
2591
                    target.addProperty("AbtSetUppackagevcstag", p.mVcsTag);
2592
                    target.addProperty("AbtSetUppackagename", p.mName);
2593
 
2594
                    abt = target.addNewElement("abt").isExpanded();
2595
                    buildInfo(abt, p);
2596
 
2597
                    //    AbtTearDown
2598
                    target = xml.addNewElement("target").isExpanded();
2599
                    target.addAttribute("name", "AbtTearDown");
2600
                    target.addProperty("AbtTearDownpackagevcstag", p.mVcsTag);
2601
                    target.addProperty("AbtTearDownpackagename", p.mName);
2602
                    target.addProperty("AbtTearDownpackageversion", p.mVersion);
2603
                    target.addProperty("AbtTearDownpackageextension", p.mExtension);
2604
                    target.makePropertyTag(p.mAlias + "generic", p.isGeneric());
2605
 
2606
                    abt = target.addNewElement("abt").isExpanded();
2607
                    buildInfo(abt, p);
2608
 
2609
 
2610
                    //  AbtPublish
2611
                    target = xml.addNewElement("target").isExpanded();
2612
                    target.addAttribute("name", "AbtPublish");
2613
 
2614
                    target.addProperty("AbtPublishpackagevcstag", p.mVcsTag);
2615
                    target.addProperty("AbtPublishpackagename", p.mName);
2616
                    target.addProperty("AbtPublishpackageversion", p.mVersion);
2617
                    target.addProperty("AbtPublishpackageextension", p.mExtension);
2618
                    target.makePropertyTag("AbtPublishdirectchange", p.mDirectlyPlanned);
2619
                    target.makePropertyTag("AbtPublishdoesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2620
                    target.makePropertyTag("AbtPublishgeneric", p.isGeneric());
2621
                    target.addProperty("AbtPublishloc", getBuildLocation(p));
2622
 
2623
                    abt = target.addNewElement("abt").isExpanded();
2624
                    buildInfo(abt, p);
2625
 
2626
                }
2627
            }
2628
        }
2629
    }
2630
 
2631
    /** Extends the xml object. Adds ant default target for the current build iteration
2632
     * @param xml - The XmlBuilder Object to extend
2633
     * @param buildFile - The current build file level. This differs for Daemon and Escrow mode. In Daemon mode it will not be a '1' 
2634
     */
2635
    private void generateDefaultTarget(XmlBuilder xml, int buildFile)
2636
    {
2637
        mLogger.debug("generateDefaultTarget");
2638
 
2639
        XmlBuilder target = xml.addNewElement("target").isExpanded();
2640
        target.addAttribute("name", "fullstart");
2641
 
2642
        if (buildFile == 1)
2643
        {
2644
            antEcho(target, "${line.separator}" + mAnyBuildPlatforms + "${line.separator}${line.separator}");
7082 dpurdie 2645
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2646
            {
2647
                Package p = it.next();
2648
 
2649
                if ( p.mBuildFile == -1 )
2650
                {
2651
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2652
                }
2653
            }
2654
 
2655
            antEcho(target, "${line.separator}" + mAssocBuildPlatforms + "${line.separator}${line.separator}");
7082 dpurdie 2656
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2657
            {
2658
                Package p = it.next();
2659
 
2660
                if ( p.mBuildFile == -2 )
2661
                {
2662
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2663
                }
2664
            }
2665
 
2666
            antEcho(target, "${line.separator}" + mNotInBaseline + "${line.separator}${line.separator}");
7082 dpurdie 2667
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2668
            {
2669
                Package p = it.next();
2670
 
2671
                if ( p.mBuildFile == -4 )
2672
                {
2673
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2674
                }
2675
            }
2676
 
2677
            antEcho(target, "${line.separator}" + mDependent + "${line.separator}${line.separator}");
7082 dpurdie 2678
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2679
            {
2680
                Package p = it.next();
2681
 
2682
                if ( p.mBuildFile == -5 )
2683
                {
2684
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2685
                }
2686
            }
2687
        }
2688
 
2689
        if ( !mDaemon )
2690
        {
2691
            antEcho(target, "${line.separator}Build Started:${line.separator}${line.separator}");
2692
        }
2693
 
2694
        //
2695
        //	Create a comma separated list of all the required targets
2696
        //      Escrow : All packages
2697
        //      Daemon : Just the package being built
2698
        //
2699
        StringAppender dependList = new StringAppender(",");
2700
        dependList.append("fullstart");
7082 dpurdie 2701
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2702
        {
2703
            Package p = it.next();
2704
 
2705
            if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
2706
            {
2707
                if ((mDaemon && p.mBuildFile == 1) || !mDaemon)
2708
                {
2709
                    dependList.append(p.mAlias);                    
2710
                }
2711
            }
2712
        }
2713
 
2714
        target = xml.addNewElement("target").isExpanded();
2715
        target.addAttribute("name", "full");
2716
        target.addAttribute("depends", dependList.toString());
2717
 
2718
        if ( !mDaemon )
2719
        {
2720
            antEcho(target, "${line.separator}Build Finished${line.separator}");
2721
        }
2722
    }
2723
 
2724
    /** Internal helper function to create an ant 'echo statement
2725
     *  Many of the parameters are fixed
2726
     */
2727
    private void antEcho( XmlBuilder xml, String message)
2728
    {
2729
        XmlBuilder msg = xml.addNewElement("echo");
2730
        msg.addAttribute("message", message);
2731
        msg.addAttribute("file", "publish.log");
2732
        msg.addAttribute("append", "true");
2733
    }
2734
 
2735
    /**sets the mIndirectlyPlanned true for the package and all dependent packages
2736
     */
2737
    private void rippleIndirectlyPlanned(Package p)
2738
    {
2739
        mLogger.debug("rippleIndirectlyPlanned");
2740
        if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
2741
        {
2742
            p.mIndirectlyPlanned = true;
2743
 
7082 dpurdie 2744
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2745
            {
2746
                Package pkg = it.next();
2747
 
2748
                if ( pkg != p )
2749
                {
2750
                    for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
2751
                    {
2752
                        Package dependency = it2.next();
2753
 
2754
                        if ( dependency == p )
2755
                        {
2756
                            rippleIndirectlyPlanned( pkg );
2757
                            break;
2758
                        }
2759
                    }
2760
                }
2761
            }
2762
        }
7044 dpurdie 2763
        mLogger.info("rippleIndirectlyPlanned set {} {}", p.mName, p.mIndirectlyPlanned);    
6914 dpurdie 2764
    }
2765
 
2766
    /**accessor method
2767
     */
2768
    public String getEscrowSetUp()
2769
    {
2770
        mLogger.debug("getEscrowSetUp");
2771
        String retVal = mEscrowSetup;
2772
 
7044 dpurdie 2773
        mLogger.debug("getEscrowSetUp returned {}", retVal);
6914 dpurdie 2774
        return retVal;
2775
    }
2776
 
2777
    /**accessor method
2778
     */
2779
    public String getRawData()
2780
    {
2781
        mLogger.debug("getRawData");
2782
        String retVal = mEscrowRawData;
2783
 
7044 dpurdie 2784
        mLogger.debug("getRawData returned {}", retVal);
6914 dpurdie 2785
        return retVal;
2786
    }
2787
 
2788
    /**Get the build loc (location)
2789
     * This is package specific and will depend on the build mode (Escrow/Daemon)
2790
     * 
2791
     * @param	p - Package being built
2792
     * @return A string that describes the build location
2793
     */
2794
    private String getBuildLocation(Package p)
2795
    {
2796
        mLogger.debug("locationProperty");
2797
        String location = "";
2798
 
2799
        if (mDaemon)
2800
        {
2801
            // Daemon: Start in root of view/workspace
2802
            location += mBaseline;
2803
        }
2804
        else
2805
        {
2806
            // Escrow: mAlias used with jats -extractfiles -view
2807
            location += p.mAlias;
2808
        }
2809
 
2810
        //
2811
        //  Always use '/' as a path separator - even if user has specified '\'
2812
        //  Ant can handle it.
2813
        //
2814
        location = location.replace('\\', '/');
2815
        return location;
2816
    }
2817
 
2818
    /**Adds package build into as XML elements 
2819
     * @param	  xml 	- Xml element to extend
2820
     * @param   p       - Package to process
2821
     */
2822
    private void buildInfo(XmlBuilder xml, Package p)
2823
    {
2824
        mLogger.debug("buildInfo");
2825
 
2826
        //
2827
        // Create the xml build information
2828
        // <platform gbe_machtype="linux_i386" type="jats" arg="all"/>
2829
        //
2830
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext();)
2831
        {
2832
            BuildStandard bs = it.next();
2833
            bs.getBuildStandardXml(xml);
2834
        }
2835
    }
2836
 
2837
    /**returns the buildInfo as a single line of text
2838
     * Used for reporting purposes only
2839
     * @param   p       - Package to process
2840
     * 
2841
     */
2842
    public String buildInfoText(Package p)
2843
    {
2844
        mLogger.debug("buildInfoText");
2845
 
2846
        StringAppender result = new StringAppender (";");
2847
 
2848
        //
2849
        //  Create platform:standards
2850
        //      
2851
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
2852
        {
2853
            BuildStandard bs = it.next();
2854
 
2855
            if ( bs.isActive() )
2856
            {
2857
                String info = bs.getBuildStandardText();
2858
                result.append(info);
2859
            }
2860
        }
2861
 
7044 dpurdie 2862
        mLogger.info("buildInfoText returned {}", result);
6914 dpurdie 2863
        return result.toString();
2864
    }
2865
 
2866
    /**prints to standard out in escrow mode only
2867
     * <br>Prints a title and information. The title is only printed once.
2868
     * 
2869
     * @param header - The message title to display, if printMessage is true
2870
     * @param text - A package name. Really just the 2nd line of the message
2871
     * @param printHeader -  Controls the printing of the message argument
2872
     */
2873
    private void standardOut(final String header, final String text, boolean printHeader)
2874
    {
2875
        mLogger.debug("standardOut");
2876
        if (!mDaemon)
2877
        {
2878
            if ( printHeader )
2879
            {
2880
                System.out.println(header);
2881
            }
2882
 
2883
            System.out.println(text);
2884
        }
2885
    }
2886
 
2887
 
2888
    /**
2889
     *  Email users about a rejected daemon instruction
2890
     *  @param  reason  - Reason for the rejection
2891
     *  @param  pkg     - Package to be affected by the instruction
2892
     *  
2893
     */
2894
    public void emailRejectedDaemonInstruction(String reason, Package p)
2895
    {
2896
        mLogger.debug("emailRejectedDaemonInstruction");
2897
 
2898
        //  Email Subject
2899
        String subject = "BUILD FAILURE of Daemon Instruction on package " + p.mAlias;
2900
 
2901
        // Email Body
2902
        String mailBody = "The build system reject the the Daemon Instruction";
2903
        mailBody += "<br>Reason: " + reason; 
2904
 
2905
        mailBody += "<p>Release: " + mBaselineName 
2906
                +  "<br>Package: " + p.mAlias 
2907
                +  "<br>Rm Ref: " + CreateUrls.generateRmUrl(getRtagId(), p.mId); 
2908
 
2909
        mailBody += "<p><hr>";
2910
 
2911
        String target = p.emailInfoNonAntTask(this);
2912
 
7044 dpurdie 2913
        mLogger.error("emailRejectedDaemonInstruction Server: {}", getMailServer());
2914
        mLogger.error("emailRejectedDaemonInstruction Sender: {}", getMailSender());
2915
        mLogger.error("emailRejectedDaemonInstruction Target: {}", target);
6914 dpurdie 2916
 
2917
        try
2918
        {
2919
            //    
7082 dpurdie 2920
            Smtpsend.send(getMailServer(),  // mailServer
2921
                    getMailSender(),        // source
2922
                    target,                 // target
2923
                    getMailSender(),        // cc
2924
                    null,                   // bcc
2925
                    subject,                // subject
2926
                    mailBody,               // body
2927
                    null                    // attachment
6914 dpurdie 2928
                    );
2929
        } catch (Exception e)
2930
        {
7044 dpurdie 2931
            mLogger.warn("Email Failure: emailRejectedDaemonInstruction:{}", e.getMessage());
6914 dpurdie 2932
        }
2933
    }
2934
 
2935
    /**
2936
     * @return the mMailServer
2937
     */
2938
    public String getMailServer() {
2939
        return mMailServer;
2940
    }
2941
 
2942
    /**
2943
     * @param mMailServer the mMailServer to set
2944
     */
2945
    public void setMailServer(String mMailServer) {
2946
        this.mMailServer = mMailServer;
2947
    }
2948
 
2949
    /**
2950
     * @return the mMailSender
2951
     */
2952
    public String getMailSender() {
2953
        return mMailSender;
2954
    }
2955
 
2956
    /**
2957
     * @param mMailSender the mMailSender to set
2958
     */
2959
    public void setMailSender(String mMailSender) {
2960
        this.mMailSender = mMailSender;
2961
    }
2962
 
2963
    /**
2964
     * @return the mMailGlobalTarget
2965
     */
2966
    public String getMailGlobalTarget() {
2967
        return mMailGlobalTarget;
2968
    }
2969
 
2970
    /**
2971
     * @param mMailGlobalTarget the mMailGlobalTarget to set
2972
     */
2973
    public void setMailGlobalTarget(String mMailGlobalTarget) {
2974
        this.mMailGlobalTarget = mMailGlobalTarget;
2975
    }
2976
 
2977
}