Subversion Repositories DevTools

Rev

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