Subversion Repositories DevTools

Rev

Rev 7133 | Rev 7141 | 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
7137 dpurdie 1391
            //  Generate the ripplePlan - collection of packages that we need to build inthe current ripple
1392
            //
7133 dpurdie 1393
            //  Determine if we have a reason to build anything in this collection of buildable packages
1394
            //      Reset the mCheckedCircularDependency - it will be used to detect  that we have processed a package
7082 dpurdie 1395
 
1396
            for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
1397
            {
1398
                Package p = it.next();
7133 dpurdie 1399
                if (!p.mIsProcessed) {
1400
                    PlannedPackage pPkg = new PlannedPackage(p); 
1401
 
1402
                    results.planCollection.add(pPkg);
1403
                    pPkg.mPkg.mCheckedCircularDependency = false;
1404
 
1405
                    if (p.mBuildReason != null) {
1406
                        if (mode || ( !mode && p.mBuildReason != BuildReason.Ripple )) {
1407
                            toBuild.add(pPkg);
1408
                        }
6914 dpurdie 1409
                    }
1410
                }
1411
            }
7082 dpurdie 1412
 
1413
            //  Need (would like to) build stuff
1414
            //  Determine the packages that we need to build and the time that it will take
1415
            //
1416
            if ( !toBuild.isEmpty() )
6914 dpurdie 1417
            {
7099 dpurdie 1418
                //  Locate the packages that we need to build
1419
                //  The build order cannot be correctly determined at this time
1420
                //      Need to add elements to the end of the list while processing
1421
                //      Sum the buildTimes of the packages that we add to the list
7082 dpurdie 1422
                while ( ! toBuild.isEmpty())
6914 dpurdie 1423
                {
7082 dpurdie 1424
                    PlannedPackage pkg = toBuild.remove(0);
1425
 
7099 dpurdie 1426
                    if (pkg.mBuildLevel > 400 ) {
7082 dpurdie 1427
                        mLogger.error("Circular dependency detected - not handled well");
1428
                        break;
1429
                    }
1430
 
7099 dpurdie 1431
                    if ( ! pkg.mPkg.mCheckedCircularDependency )
6914 dpurdie 1432
                    {
7082 dpurdie 1433
                        ripplePlan.add(pkg);
1434
                        results.planTime += pkg.mPkg.mBuildTime;
7099 dpurdie 1435
                        pkg.mPkg.mCheckedCircularDependency = true;
1436
 
1437
                        ArrayList<PlannedPackage> usedBy = usedByPackages(pkg, results.planCollection);
1438
                        toBuild.addAll(usedBy);
6914 dpurdie 1439
                    }
1440
                }
7133 dpurdie 1441
            }
1442
        }
1443
        else
1444
        {
1445
            //  Escrow
1446
            //      Add all (not excluded) packages directly to the ripplePlan
1447
            for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
1448
            {
1449
                Package p = it.next();
1450
                if (!p.mIsProcessed) {
1451
                    ripplePlan.add(new PlannedPackage(p));
1452
                }
1453
            }  
1454
        }
1455
 
1456
        //
1457
        //  Now we have a collection of packages to build (and only the packages to build)
1458
        //  Need to determine the order in which it can be done and assign build levels
1459
        //  Basically:
1460
        //      Scan the collection looking for any package whose dependencies do not exist in the collection
1461
        //      or they have been allocated a build level.
1462
        //
1463
        //      Need to do this in waves so that we can correctly determine the build level.
1464
        //  
1465
        //
1466
        for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1467
        {
1468
            PlannedPackage p = it.next();
1469
            p.mPkg.mCheckedCircularDependency = true;
1470
            p.mBuildLevel = 0;
1471
        }
1472
 
1473
        int buildLevel = 0;
1474
        boolean more = true;
1475
        do  {
1476
            ArrayList<PlannedPackage> thisLevel = new ArrayList<PlannedPackage>();
1477
            for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1478
            {
1479
                PlannedPackage p = it.next();
1480
                if ( p.mPkg.mCheckedCircularDependency )
7099 dpurdie 1481
                {
7133 dpurdie 1482
                    boolean found = false;
1483
                    for (Iterator<String> it2 = p.mPkg.mDependencyCollection.iterator(); !found && it2.hasNext(); )
7099 dpurdie 1484
                    {
7133 dpurdie 1485
                        String alias = it2.next();
1486
                        for (Iterator<PlannedPackage> it3 = ripplePlan.iterator(); !found && it3.hasNext(); )
7099 dpurdie 1487
                        {
7133 dpurdie 1488
                            PlannedPackage pkg = it3.next();
1489
                            if (pkg.mPkg.mAlias.compareTo( alias ) == 0)
7099 dpurdie 1490
                            {
7133 dpurdie 1491
                                found = pkg.mPkg.mCheckedCircularDependency ;
1492
                                break;
7099 dpurdie 1493
                            }
1494
                        }
1495
                    }
1496
 
7133 dpurdie 1497
                    if (!found)
7099 dpurdie 1498
                    {
7133 dpurdie 1499
                        //  None of this packages dependencies can be found in the collection of packages to build
1500
                        //  Thus we can build it - at the current level
1501
                        p.mBuildLevel = buildLevel;
1502
                        thisLevel.add(p);
7099 dpurdie 1503
                    }
7082 dpurdie 1504
                }
1505
            }
1506
 
7133 dpurdie 1507
            //  Mark all the packages at this level as have been processed
1508
            //  Cannot do this while we are determining the packages in the level 
1509
            for (Iterator<PlannedPackage> it = thisLevel.iterator(); it.hasNext(); )
1510
            {
1511
                PlannedPackage p = it.next();
1512
                p.mPkg.mCheckedCircularDependency = false;
1513
            }
1514
 
7137 dpurdie 1515
            //
1516
            //  If any packages needed to be build at this level, then there might be a higher level
1517
            //  If no packages needed to be build at this level, then there is nothing to do.
7133 dpurdie 1518
            more = !thisLevel.isEmpty(); 
1519
            buildLevel++;
1520
 
1521
        } while (more);
1522
 
1523
        //  Sort the packages by buildOrder and buildTime
1524
        phase.setPhase("Sort Plan");
1525
        Collections.sort(ripplePlan, PlannedPackage.BuildOrderComparitor);
1526
 
7137 dpurdie 1527
        //  Optionally - Display the calculated plan
1528
        //      It will fill the log, but ...
7133 dpurdie 1529
        if (mLogger.isInfoEnabled() )
1530
        {
1531
            phase.setPhase("Display Build Order");
1532
            mLogger.info("Plan Build {} Time: {}", name, results.planTime);
1533
            for (Iterator<PlannedPackage> it = ripplePlan.iterator(); it.hasNext(); )
1534
            {
1535
                PlannedPackage p = it.next();
1536
                mLogger.info("Plan: {} {} t:{}", p.mBuildLevel, p.mPkg.mAlias, p.mPkg.mBuildTime);
1537
            }
7082 dpurdie 1538
        }
7133 dpurdie 1539
 
1540
        results.planCollection = ripplePlan;
7137 dpurdie 1541
 
7099 dpurdie 1542
        phase.setPhase("EndPlanCollection");
7082 dpurdie 1543
        return results;
1544
    }
6914 dpurdie 1545
 
7082 dpurdie 1546
    /** Generate a plan based on a modified set of packages
1547
     * 
1548
     * @param name      - Name of the plan
1549
     * @param basicPlan - basicPlan
1550
     * @param mode      - True: Include natural ripples and WIPS/RIPPLES that would have been done
1551
     *                          as a part of the basic plan
1552
     * @return
1553
     */
1554
    private PlanResults postRipplePlan(String name, PlanResults basicPlan, boolean mode) {
6914 dpurdie 1555
 
7082 dpurdie 1556
        ArrayList<Package> fullPlanCollection = new ArrayList<Package>(mPackageCollection);
1557
        ArrayList<Package> buildCandidates = new ArrayList<Package>();
1558
        buildCandidates.addAll(mPackageCollectionWip);
1559
        buildCandidates.addAll(mPackageCollectionRipple);
1560
 
1561
        if ( !buildCandidates.isEmpty() )
1562
        {
1563
            for (Iterator<Package> it = buildCandidates.iterator(); it.hasNext(); )
1564
            {
1565
                Package p = it.next();
1566
                if (p.mBuildFile >= 0)
6914 dpurdie 1567
                {
7082 dpurdie 1568
                    if (!mode)
6914 dpurdie 1569
                    {
7088 dpurdie 1570
                        //  Exclude packages that would have been processed in the basicPlan
1571
                        for (Iterator<PlannedPackage> it1 = basicPlan.planCollection.iterator(); it1.hasNext(); )
1572
                        {
1573
                            PlannedPackage pkg = it1.next();
1574
                            if (pkg.mPkg == p)
1575
                            {
7099 dpurdie 1576
                                mLogger.error("Test Plan without {}", p.mAlias);
7088 dpurdie 1577
                                continue;
1578
                            }
1579
                        }
6914 dpurdie 1580
                    }
7082 dpurdie 1581
 
7099 dpurdie 1582
                    mLogger.error("Test Plan with {}", p.mAlias);
7082 dpurdie 1583
                    Package foundInRelease = mReleaseManager.findPackage(p.mAlias, fullPlanCollection);
1584
                    int foundIndex = mReleaseManager.findPackageLastIndex;
1585
                    if (foundInRelease == ReleaseManager.NULL_PACKAGE)
1586
                    {
1587
                        fullPlanCollection.add(p);
1588
                    }
1589
                    else
1590
                    {
1591
                        fullPlanCollection.set(foundIndex, p);
1592
                    }
1593
 
1594
                    Package.resetCircularDependency (fullPlanCollection);
1595
                    if ( p.hasCircularDependency( fullPlanCollection ) )
1596
                    {
1597
                        mLogger.info("planRelease circular dependency detected {}", p.mAlias);
1598
 
1599
                        //  Force this package to be marked as having a circular dependency - even if its been excluded
1600
                        p.mBuildFile = 0;
1601
 
1602
                        // Exclude the package
1603
                        // max 50 chars
1604
                        rippleBuildExclude(p, p.mId, "Package has circular dependency", -6);
1605
                    }
6914 dpurdie 1606
                }
1607
            }
7082 dpurdie 1608
 
1609
        }
1610
        return planCollection(name, fullPlanCollection, mode);
1611
    }
1612
 
1613
    /** 
1614
     *  Calculate a collection of packages that actively use the named package
1615
     *  A consumer package does NOT use the named package,
1616
     *      If the consumer is an SDK or is Pegged
1617
     *      If the consumer is marked as advisoryRipple
1618
     *      If the consumer cannot be built
1619
     *   
1620
     * @param pkg - Package to process
1621
     * @param planCollection - collection of packages to scan
1622
     *
1623
     * @return A collection of packages that actively 'use' the specified package
1624
 
1625
     */
7099 dpurdie 1626
    private ArrayList<PlannedPackage> usedByPackages(PlannedPackage pkg, ArrayList<PlannedPackage> planCollection) {
7082 dpurdie 1627
 
1628
        ArrayList<PlannedPackage> usedBy = new ArrayList<PlannedPackage>();
1629
 
1630
        for (Iterator<PlannedPackage> it = planCollection.iterator(); it.hasNext(); )
1631
        {
1632
            PlannedPackage p = it.next();
1633
 
1634
            //  Is this package 'actively used' in the current build
1635
            if (p.mPkg.mBuildFile >= 0)
6914 dpurdie 1636
            {
7082 dpurdie 1637
                for (Iterator<String> it2 = p.mPkg.mDependencyCollection.iterator(); it2.hasNext(); )
6914 dpurdie 1638
                {
7088 dpurdie 1639
                    String alias = it2.next();
1640
                    if (  pkg.mPkg.mAlias.compareTo( alias ) == 0  ) {
1641
                        //  Have found a consumer of 'pkg'
1642
                        usedBy.add(p);
6914 dpurdie 1643
                        break;
1644
                    }
1645
                }
7082 dpurdie 1646
            }
1647
        }
1648
 
1649
        return usedBy;
1650
    }
1651
 
1652
    /** 
1653
     *  Calculate a collection of packages that use the named package
1654
     *   
1655
     * @param pkg - Package to process
1656
     * @param pkgCollection - collection of packages to scan
1657
     *
1658
     * @return A collection of packages that actively 'use' the specified package
6914 dpurdie 1659
 
7082 dpurdie 1660
     */
1661
    private ArrayList<Package> usedByAnyPackages(Package pkg, ArrayList<Package> pkgCollection) {
1662
 
1663
        ArrayList<Package> usedBy = new ArrayList<Package>();
1664
 
1665
        for (Iterator<Package> it = pkgCollection.iterator(); it.hasNext(); )
1666
        {
1667
            Package p = it.next();
1668
 
1669
            for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
1670
            {
1671
                String alias = it2.next();
1672
                if (  pkg.mAlias.compareTo( alias ) == 0  ) {
1673
                    usedBy.add(p);
1674
                    break;
1675
                }
6914 dpurdie 1676
            }
7082 dpurdie 1677
        }
1678
 
1679
        return usedBy;
6914 dpurdie 1680
    }
1681
 
1682
    /** Determine if a given PVID is a member of the current release.
1683
     *  Used to determine if a package dependency is out of date
1684
     * 
1685
     * @param dpvId
1686
     * @return true - specified pvid is a full member of the Release
1687
     */
1688
    private boolean isInRelease(Integer dpvId) {
1689
 
7082 dpurdie 1690
        boolean inRelease = false;
6914 dpurdie 1691
 
7082 dpurdie 1692
        for ( Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
6914 dpurdie 1693
        {
7082 dpurdie 1694
            Package p = it.next();
6914 dpurdie 1695
 
7082 dpurdie 1696
            if ( p.mId == dpvId )
6914 dpurdie 1697
            {
7082 dpurdie 1698
                inRelease = ! p.mIsNotReleased;
6914 dpurdie 1699
                break;
1700
            }
1701
        }
7082 dpurdie 1702
        return inRelease;
6914 dpurdie 1703
    }
1704
 
1705
 
7082 dpurdie 1706
    /** Reports what change in build exceptions happens as part of planRelease
1707
     * 
1708
     *  There are three types of exceptions
1709
     *      PlanError - These may be removed, if the error was not seen in the last plan
1710
     *      BuildErrors - These we persist
1711
     *      IndirectErrors - Packages that depend on a Plan or Build errors
6914 dpurdie 1712
     */
1713
    public void reportChange() throws SQLException, Exception
1714
    {
1715
        int counter = 0;
1716
        for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1717
        {
1718
            BuildExclusion buildExclusion = it.next();
1719
 
7082 dpurdie 1720
            //  Skip 'Processed' entries
1721
            //  These will be the result of a PlanError that we have seen again
1722
            //
1723
            //  PlanErrors - Add/Remove as detected
1724
            //  BuildErrors - Persist. 
1725
            //  IndirectErrors - Add/Remove as detected
1726
            //  
1727
 
1728
            if ( !buildExclusion.isABuildError() )
6914 dpurdie 1729
            {
7088 dpurdie 1730
                if ( !buildExclusion.isProcessed() )
1731
                {
1732
                    if (buildExclusion.isImported() && !buildExclusion.isARootCause() ) {
1733
                        // Remove from the exclusion list
1734
                        buildExclusion.includeToBuild(mReleaseManager, mBaseline);
1735
                        mLogger.error("reportChange remove unused exclusion: {}", buildExclusion );
1736
                    } else {
1737
                        // Exclude and notify
1738
                        buildExclusion.excludeFromBuild(mReleaseManager, mBaseline);
1739
                        buildExclusion.email(this, mPackageCollectionAll);
1740
                        counter++;
1741
                    }
7032 dpurdie 1742
                }
6914 dpurdie 1743
            }
1744
        }
7044 dpurdie 1745
        mLogger.error("reportChange exclusion count: {}", counter);
6914 dpurdie 1746
    }
1747
 
1748
    /**reports the build plan
1749
     */
1750
    public void reportPlan() throws SQLException, Exception
1751
    {
1752
        mReleaseManager.reportPlan(mRtagId, mBuildOrder);
1753
    }
1754
 
1755
    /**Returns the first build file from the collection
1756
     * The build file will be flagged as empty if none exists
1757
     */
1758
    public BuildFile getFirstBuildFileContent()
1759
    {
1760
        mLogger.debug("getFirstBuildFileContent");
1761
 
1762
        mBuildIndex = -1;
1763
        return getNextBuildFileContent();
1764
    }
1765
 
1766
    /**Returns next build file from the collection
1767
     * The build file will be flagged as empty if none exists
1768
     */
1769
    public BuildFile getNextBuildFileContent()
1770
    {
1771
        mLogger.debug("getNextBuildFileContent");
1772
        BuildFile retVal = null;
1773
 
1774
        try
1775
        {
1776
            mBuildIndex++;
1777
            retVal = mBuildCollection.get( mBuildIndex );
1778
        }
1779
        catch( IndexOutOfBoundsException e )
1780
        {
1781
            // Ignore exception. retVal is still null.
1782
        }
1783
 
1784
        if (retVal == null)
1785
        {
1786
            retVal = new BuildFile();
1787
        }
1788
 
7044 dpurdie 1789
        mLogger.debug("getNextBuildFileContent returned {}", retVal.state.name() );
6914 dpurdie 1790
        return retVal;
1791
    }
1792
 
1793
 
1794
    /**collects meta data associated with the baseline
1795
     * this is sufficient to send an indefinite pause email notification 
1796
     *  
1797
     * Escrow: Used once to collect information about the SBOM and associated Release 
1798
     *         mBaseline is an SBOMID 
1799
     * Daemon: Used each build cycle to refresh the information 
1800
     *          mBaseline is an RTAGID
1801
     */
1802
    public void collectMetaData() throws SQLException, Exception
1803
    {
1804
        Phase phase = new Phase("cmd");
7044 dpurdie 1805
        mLogger.debug("collectMetaData mDaemon {}", mDaemon);
6914 dpurdie 1806
 
1807
        try
1808
        {
1809
            phase.setPhase("connect");
1810
            mReleaseManager.connect();
1811
 
1812
            if (! mDaemon)
1813
            {
1814
                mSbomId = mBaseline;
1815
                phase.setPhase("queryRtagIdForSbom");
1816
                mRtagId = mReleaseManager.queryRtagIdForSbom(mBaseline);
1817
                if (mRtagId == 0)
1818
                {
7033 dpurdie 1819
                    mLogger.error("SBOM does not have a matching Release. Cannot be used as a base for an Escrow"); 
6914 dpurdie 1820
                    throw new Exception("rtagIdForSbom show stopper. SBOM does not have an associated Release");
1821
                }
1822
            }
1823
 
1824
            phase.setPhase("queryReleaseConfig");
1825
            mReleaseManager.queryReleaseConfig(mRtagId);
1826
 
1827
            if (mDaemon)
1828
            {
1829
                phase.setPhase("queryMailServer");
1830
                setMailServer(mReleaseManager.queryMailServer());
1831
                phase.setPhase("queryMailSender");
1832
                setMailSender(mReleaseManager.queryMailSender());
1833
                phase.setPhase("queryGlobalAddresses");
1834
                setMailGlobalTarget(mReleaseManager.queryGlobalAddresses());
1835
                phase.setPhase("queryProjectEmail");
1836
                mMailGlobalCollection = mReleaseManager.queryProjectEmail(mBaseline);
1837
                phase.setPhase("mMailGlobalTarget");
1838
                mMailGlobalCollection.add(0,getMailGlobalTarget());
1839
            }
1840
            phase.setPhase("queryBaselineName");
1841
            mBaselineName = mReleaseManager.queryBaselineName(mBaseline);
1842
            phase.setPhase("Done");
1843
        }
1844
        finally
1845
        {
1846
            // this block is executed regardless of what happens in the try block
1847
            // even if an exception is thrown
1848
            // ensure disconnect
1849
            mReleaseManager.disconnect();
1850
        }
1851
    }
1852
 
1853
    /**
1854
     * Find Package by package alias
7082 dpurdie 1855
     * Searches the released package collection
6914 dpurdie 1856
     * @param   alias               - alias of package to locate
1857
     * @return  Package with the matching mAlias or NULL_PACKAGE if no package has the mAlias
1858
     */
1859
    public Package findPackage(String alias)
1860
    {
1861
        mLogger.debug("findPackage");
1862
 
1863
        Package retVal = mReleaseManager.findPackage(alias, mPackageCollection);
1864
 
7044 dpurdie 1865
        mLogger.info("findPackage returned {}", retVal.mName);
6914 dpurdie 1866
        return retVal;
1867
    }
7082 dpurdie 1868
 
6914 dpurdie 1869
    /**
7082 dpurdie 1870
     * Sets the mBuildFile to the specified value for the package
1871
     * Does not handle dependent packages - this will be done later  
1872
     *  
7032 dpurdie 1873
     * @param p             The package being excluded 
1874
     * @param rootPvId      The PVID of the package that is causing the exclusion. Null or -ve values are special
1875
     *                      This package is the root cause, -2: Excluded by Ripple Stop 
1876
     * @param rootCause     Text message. Max 50 characters imposed by RM database 
7082 dpurdie 1877
     * @param reason        New value for mBuildFile
6914 dpurdie 1878
     */
7082 dpurdie 1879
    private void rippleBuildExclude(Package p, int rootPvId, String rootCause, int reason )
6914 dpurdie 1880
    {
1881
        mLogger.debug("rippleBuildExclude");
7082 dpurdie 1882
 
7099 dpurdie 1883
        if ( p.mBuildFile >= 0 )
6914 dpurdie 1884
        {
7088 dpurdie 1885
            p.mBuildFile = reason;
7099 dpurdie 1886
            mLogger.info("rippleBuildExclude set mBuildFile to {} for package {}", reason, p.mAlias );
7088 dpurdie 1887
 
1888
            //  Scan the complete collection looking for a matching item
1889
            //  If found then assume that this error is a a PlanError that is still present
1890
            //      Mark it as Processed to indicate that its still present
1891
            //  If found, process it, else add it (unprocessed)
1892
            boolean found = false;
1893
            for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1894
            {
1895
                BuildExclusion buildExclusion = it.next();
6914 dpurdie 1896
 
7082 dpurdie 1897
                if ( buildExclusion.compare(p.mId, rootPvId, rootCause))
1898
                {
1899
                    buildExclusion.setProcessed();
1900
                    found = true;
1901
                    break;
1902
                }
6914 dpurdie 1903
            }
7082 dpurdie 1904
 
1905
            if (!found)
6914 dpurdie 1906
            {
7082 dpurdie 1907
                // Entry not found in the mBuildExclusionCollection. Its a new error
1908
                // 
1909
                // Mark all occurrences for this package as processed
1910
                // These will be superseded by a new build exclusion entry
6914 dpurdie 1911
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1912
                {
1913
                    BuildExclusion buildExclusion = it.next();
1914
 
7082 dpurdie 1915
                    if ( buildExclusion.compare(p.mId))
6914 dpurdie 1916
                    {
7032 dpurdie 1917
                        buildExclusion.setProcessed();
6914 dpurdie 1918
                    }
1919
                }
1920
 
7082 dpurdie 1921
                //  Add the new build exclusion to a list
1922
                BuildExclusion buildExclusion = new BuildExclusion(p.mId, rootPvId, rootCause, p.mTestBuildInstruction);
1923
                mBuildExclusionCollection.add(buildExclusion);
6914 dpurdie 1924
            }
7082 dpurdie 1925
        }
6914 dpurdie 1926
 
7088 dpurdie 1927
        mLogger.info("rippleBuildExclude set {} {}", p.mAlias, p.mBuildFile);
6914 dpurdie 1928
    }
1929
 
1930
    /**Simple XML string escaping
1931
     * 
1932
     * @param xml		- String to escape
1933
     * @return		- A copy of the string with XML-unfriendly characters escaped 
1934
     */
1935
    public static String escapeXml( String xml )
1936
    {
1937
        xml = xml.replaceAll("&", "&amp;");
1938
        xml = xml.replaceAll("<", "&lt;");
1939
        xml = xml.replaceAll(">", "&gt;");
1940
        xml = xml.replaceAll("\"","&quot;");
1941
        xml = xml.replaceAll("'", "&apos;");
1942
        xml = xml.replaceAll("\\$", "\\$\\$");
1943
 
1944
        return xml;
1945
    }
1946
 
1947
    /** Quote a string or a string pair
1948
     *  If two strings are provided, then they will be joined with a comma.
1949
     *   
1950
     * @param text		- First string to quote
1951
     * @param text2		- Optional, second string
1952
     * @return A string of the form 'text','text2'
1953
     */
1954
    public static String quoteString(String text, String text2)
1955
    {
1956
        String result;
1957
        result =  "\'" + text + "\'";
1958
        if (text2 != null )
1959
        {
1960
            result +=  ",\'" + text2 + "\'";  
1961
        }
1962
        return result;
1963
    }
1964
 
1965
    /** Generate build file information
1966
     * 
1967
     */
1968
    private void generateBuildFiles() 
1969
    {
1970
 
1971
        // persist the build files
1972
        boolean allProcessed = false;
1973
        int buildFile = 1;
1974
        StringBuilder rawData = new StringBuilder();
1975
        StringBuilder setUp = new StringBuilder();
1976
 
1977
        mLogger.debug("generateBuildFiles");
1978
 
1979
        if ( mDaemon )
1980
        {
1981
            // all interesting packages in daemon mode match the following filter
1982
            buildFile = 3;
1983
        }
1984
 
1985
        //-----------------------------------------------------------------------
1986
        //    Generate the build file
1987
        do
1988
        {
1989
            BuildFile buildEntry = new  BuildFile();
1990
            buildEntry.state = BuildFileState.Dummy;
1991
            XmlBuilder xml = generateBuildFileHeader();
1992
 
1993
 
1994
            //	Generate properties for each package in this build level or lower build levels
1995
            //	The properties link the packageAlias to the PackageName and PackageVersion
1996
            //
1997
            //	[DEVI 54816] In escrow mode all unreproducible packages are included 
1998
            for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
1999
            {
2000
                Package p = it.next();
2001
 
2002
                if ( ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) ) || ( !mDaemon && p.mBuildFile == -2 ) )
2003
                {
2004
                    xml.addProperty(p.mAlias, p.mName + " " + p.mVersion + p.mExtension);
2005
                }
2006
            }
2007
 
2008
            //	UTF Support
2009
            //	Insert additional info into the build file to provide extra checking
2010
            //
7046 dpurdie 2011
            if ( ! mReleaseManager.mUseDatabase )
6914 dpurdie 2012
            {
2013
                // UTF Support
2014
                // Insert per-package planning information
2015
                //
2016
                xml.addComment("mPackageCollection");
2017
                for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
2018
                {
2019
                    Package p = it.next();
2020
                    generatePackageInfo(xml, p);
2021
                }
2022
 
7082 dpurdie 2023
                xml.addComment("mPackageCollectionWip");
2024
                for (Iterator<Package> it = mPackageCollectionWip.iterator(); it.hasNext(); )
2025
                {
2026
                    Package p = it.next();
2027
                    if (p.mIsNotReleased )
2028
                        generatePackageInfo(xml, p);
2029
                }
2030
 
2031
                xml.addComment("mPackageCollectionTest");
2032
                for (Iterator<Package> it = mPackageCollectionTest.iterator(); it.hasNext(); )
2033
                {
2034
                    Package p = it.next();
2035
                    if (p.mIsNotReleased )
2036
                        generatePackageInfo(xml, p);
2037
                }
2038
 
2039
                xml.addComment("mPackageCollectionTestRipple");
2040
                for (Iterator<Package> it = mPackageCollectionRipple.iterator(); it.hasNext(); )
2041
                {
2042
                    Package p = it.next();
2043
                    if (p.mIsNotReleased )
2044
                        generatePackageInfo(xml, p);
2045
                }
2046
 
6914 dpurdie 2047
                // UTF Support
2048
                // Insert build exclusion information
2049
                xml.addComment("mBuildExclusionCollection");
2050
                for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
2051
                {
2052
                    BuildExclusion buildExclusion = it.next();
2053
                    {
7082 dpurdie 2054
                        xml.addComment(buildExclusion.toString());
6914 dpurdie 2055
                    }
2056
                }
7082 dpurdie 2057
            }
2058
 
7137 dpurdie 2059
            // UTF Support (Also while trialing the changes)
7082 dpurdie 2060
            // Insert build Plan
2061
            if (mDaemon)
2062
            {
2063
                xml.addComment("mBuildOrder");
2064
                for (Iterator<PlannedPackage> it = mBuildOrder.iterator(); it.hasNext(); )
6914 dpurdie 2065
                {
7082 dpurdie 2066
                    PlannedPackage p = it.next();
2067
                    String comment =
2068
                            "pvid="+ p.mPkg.mId +
2069
                            " order=" + p.mBuildLevel +
2070
                            " time=" + p.mPkg.mBuildTime +
2071
                            " name=\"" + p.mPkg.mAlias + "\"";
2072
                    xml.addComment(comment);
6914 dpurdie 2073
                }
2074
            }
2075
 
2076
            //  Generate Taskdef information
2077
            generateTaskdef(xml);
2078
 
2079
            //
2080
            //  Insert known Machine Information
2081
            //  Escrow usage: 
2082
            //      Map machType to machClass
2083
            //  Also serves as a snapshot of the required build configuration
2084
            //  ie: machine types and buildfilters
2085
            //
2086
            if (!mDaemon)
2087
            {
2088
                generateMachineInfo(xml, null);
2089
            }
2090
 
2091
            //
2092
            //	Generate target rules for each package to be built within the current build file
2093
            //
2094
            boolean daemonHasTarget = false;
2095
 
7082 dpurdie 2096
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2097
            {
2098
                Package p = it.next();
2099
 
2100
                if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
2101
                {
2102
                    generateTarget(xml, buildEntry, p, buildFile);
2103
 
2104
                    if ( p.mBuildFile == 1 )
2105
                    {
2106
                        daemonHasTarget = true;
2107
 
2108
                        // Retain information about the target package
2109
                        buildEntry.mPkgId = p.mPid;
2110
                        buildEntry.mPvId = p.mId;
2111
                    }
2112
                }
2113
 
2114
                //	Generate escrow extraction commands
2115
                //	Only done on the first pass though the packages
2116
                //
2117
                if ( !mDaemon && buildFile == 1 )
2118
                {
2119
                    setUp.append("jats jats_vcsrelease -extractfiles"
2120
                                + " \"-label=" + p.mVcsTag + "\""
2121
                                + " \"-view=" + p.mAlias + "\""
2122
                                + " -root=. -noprefix"
2123
                                + mlf );
2124
                }
2125
 
2126
                //	Generate escrow raw CSV data
2127
                //	Note: I don't think this data is used at all
2128
 
2129
                if ( !mDaemon && ( p.mBuildFile == buildFile))
2130
                {
2131
                    StringAppender machines = new StringAppender(",");
2132
                    for (Iterator<BuildStandard> it1 = p.mBuildStandardCollection.iterator(); it1.hasNext();)
2133
                    {
2134
                        BuildStandard bs = it1.next();
2135
                        machines.append(bs.mMachClass);
2136
                    }
2137
 
2138
                    rawData.append(p.mAlias + "," +
2139
                                    buildFile + "," +
2140
                                    machines +
2141
                                    mlf);
2142
                }
2143
            }
2144
 
2145
            if ( mDaemon && !daemonHasTarget )
2146
            {
2147
                // must have AbtTestPath, AbtSetUp, AbtTearDown, and AbtPublish targets
2148
                XmlBuilder target = xml.addNewElement("target");
2149
                target.addAttribute("name", "AbtTestPath");
2150
 
2151
                target = xml.addNewElement("target");
2152
                target.addAttribute("name", "AbtSetUp");
2153
 
2154
                target = xml.addNewElement("target");
2155
                target.addAttribute("name", "AbtTearDown");
2156
 
2157
                target = xml.addNewElement("target");
2158
                target.addAttribute("name", "AbtPublish");
2159
            }
2160
 
2161
            generateDefaultTarget( xml, buildFile);
2162
 
2163
            //	Convert the Xml structure into text and save it in the build file
2164
            //	Add this build file to the mBuildCollection
2165
            buildEntry.content = mXmlHeader + xml.toString();
2166
            mBuildCollection.add(buildEntry);
2167
 
2168
            // are more build files required
2169
            allProcessed = true;
2170
 
2171
            if (!mDaemon)
2172
            {
2173
                // this is escrow mode centric
7082 dpurdie 2174
                for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2175
                {
2176
                    Package p = it.next();
2177
 
2178
                    if ( p.mBuildFile > buildFile )
2179
                    {
2180
                        // more build files are required
2181
                        allProcessed = false;
7044 dpurdie 2182
                        mLogger.info("planRelease reiterating package has no build requirement {} {} {}",p.mName, p.mBuildFile,  buildFile);
6914 dpurdie 2183
                        break;
2184
                    }
2185
                } 
2186
 
2187
                buildFile++;
2188
            }
2189
 
2190
        } while( !allProcessed );
2191
 
2192
        //	Save additional escrow data
2193
        if ( !mDaemon )
2194
        {
2195
            mEscrowSetup = setUp.toString();
2196
            mEscrowRawData = rawData.toString();
2197
        }
2198
    }
2199
 
2200
    /**returns a build file header for the mBaseline
2201
     */
2202
    private XmlBuilder generateBuildFileHeader()
2203
    {
2204
        mLogger.debug("generateBuildFileHeader");
2205
        XmlBuilder element = new XmlBuilder("project");
2206
 
2207
        element.addAttribute("name", "mass");
2208
        element.addAttribute("default", "full");
2209
        element.addAttribute("basedir", ".");
2210
 
2211
        if ( mDaemon )
2212
        {
2213
            element.addProperty("abt_mail_server", getMailServer());
2214
            element.addProperty("abt_mail_sender", getMailSender()); 
2215
            element.addProperty("abt_rtag_id", mBaseline);
2216
            element.addProperty("abt_daemon", mReleaseManager.currentTimeMillis());
2217
            element.makePropertyTag("abt_packagetarball", true);
2218
            element.makePropertyTag("abt_usetestarchive", !ReleaseManager.getUseMutex());
2219
 
7082 dpurdie 2220
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2221
            {
2222
                Package p = it.next();
2223
 
2224
                if ( p.mBuildFile == 1 )
2225
                {
2226
                    element.addProperty("abt_package_name", p.mName);
2227
                    element.addProperty("abt_package_version", p.mVersion + p.mExtension);
2228
                    element.addProperty("abt_package_extension", p.mExtension);
2229
                    element.addProperty("abt_package_location", getBuildLocation(p));
2230
                    element.addProperty("abt_package_ownerlist", p.emailInfoNonAntTask(this));
2231
                    element.addProperty("abt_package_build_info", buildInfoText(p));
2232
 
2233
                    // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
2234
                    StringAppender depends = new StringAppender(";");
2235
 
2236
                    for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
2237
                    {
2238
                        Package depend = it3.next();
2239
                        depends.append( quoteString(depend.mName, depend.mVersion + depend.mExtension) );
2240
                    }
2241
 
2242
                    element.addProperty("abt_package_depends", depends.toString());
2243
                    element.addProperty("abt_is_ripple", p.mDirectlyPlanned ? "0" : "1");
2244
                    element.addProperty("abt_build_reason", p.mBuildReason.toString());
2245
                    element.addProperty("abt_package_version_id", p.mId);
2246
                    element.addProperty("abt_does_not_require_source_control_interaction", ! p.mRequiresSourceControlInteraction ? "true" : "false" );
2247
                    element.addProperty("abt_test_build_instruction", p.mTestBuildInstruction);
2248
                }
2249
            }
2250
        }
2251
        else
2252
        {
2253
            //    Escrow Mode
2254
            element.addProperty("abt_rtag_id", mRtagId);
2255
            element.addProperty("abt_sbom_id", mSbomId);
2256
        }
2257
 
2258
        element.addProperty("abt_release", escapeXml(mBaselineName));
2259
        element.addProperty("abt_buildtool_version", mReleaseManager.getMajorVersionNumber() );
2260
 
2261
        element.addNewElement("condition")
2262
        .addAttribute("property", "abt_family")
2263
        .addAttribute("value", "windows")
2264
        .addNewElement("os")
2265
        .addAttribute("family", "windows");
2266
        element.addProperty("abt_family", "unix");
2267
 
2268
        return element;
2269
    }
2270
 
2271
    /** Add task def XML items taskdef for the abt ant task
2272
     * @param xml 	- xml item to extend
2273
     */
2274
    private void generateTaskdef(XmlBuilder xml)
2275
    {
2276
        mLogger.debug("generateTaskdef");
2277
        xml.addNewElement("taskdef")
2278
        .addAttribute("name", "abt")
2279
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABT");
2280
 
2281
        xml.addNewElement("taskdef")
2282
        .addAttribute("name", "abtdata")
2283
        .addAttribute("classname", "com.erggroup.buildtool.abt.ABTData");
2284
    }
2285
 
2286
    /** returns the command abtdata items
2287
     *  <br>Common machine information
2288
     *  <br>Common email address
2289
     *  
2290
     *  
2291
     *  @param	xml - Xml element to extend   
2292
     *  @param    p - Package (May be null)
2293
     */
2294
    private void generateMachineInfo(XmlBuilder xml, Package p)
2295
    {
2296
        XmlBuilder element = xml.addNewElement("abtdata");
2297
        element.addAttribute("id", "global-abt-data");
2298
 
2299
        //
2300
        //  Iterate over all the machines and create a nice entry
2301
        //
2302
        for (Iterator<ReleaseConfig> it = mReleaseManager.mReleaseConfigCollection.mReleaseConfig.iterator(); it.hasNext(); )
2303
        {
2304
            ReleaseConfig rc = it.next();
2305
            element.addElement(rc.getMachineEntry());
2306
        }
2307
 
2308
        //
2309
        //  Now the email information
2310
        //
2311
        if ( p != null)
2312
        {
2313
            p.emailInfo(this, element);
2314
        }
2315
    }
2316
 
2317
    /** Generate package information
2318
     *  Only when running unit tests
2319
     *  
2320
     * @param xml	- An xml element to append data to
2321
     * @param p	- Package to process
2322
     */
2323
    private void generatePackageInfo (XmlBuilder xml, Package p)
2324
    {
7082 dpurdie 2325
        StringBuilder comment = new StringBuilder();
2326
        StringBuilder deps = new StringBuilder();
2327
 
2328
        String joiner = "";
2329
        for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
2330
        {
2331
            String alias = it2.next();
2332
            deps.append(joiner).append(alias); 
2333
            joiner = ",";
2334
        }
2335
 
2336
        comment.append("pvid=").append(p.mId);
2337
        comment.append(" name=").append('"').append(p.mAlias).append('"');
2338
        comment.append(" reason=").append(p.mNoBuildReason);
2339
        comment.append(" buildFile=").append(p.mBuildFile);
2340
        comment.append(" directlyPlanned=").append(p.mDirectlyPlanned);
2341
        comment.append(" indirectlyPlanned=").append(p.mIndirectlyPlanned);
2342
        comment.append(" depends=[").append(deps).append("]");
6914 dpurdie 2343
 
7082 dpurdie 2344
        xml.addComment(comment.toString());            
6914 dpurdie 2345
    }
2346
 
2347
    /**returns an ant target for the passed Package
2348
     * in daemon mode:
2349
     *  packages are categorized with one of three mBuildFile values:
2350
     *   1 the package to be built by this buildfile
2351
     *   2 the packages with a future build requirement
2352
     *   3 the packages with no build requirement
2353
     *  the returned target depends on this categorization and will have
2354
     *   1 full abt info
2355
     *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
2356
     *   3 only a name attribute (will not build this package)
2357
     * in escrow mode:
2358
     *  if the passed Package's mBuildFile is different (less than) the passed build file,
2359
     *  the returned target have only a name attribute (will not build this package)
2360
     *   
2361
     * @param xml - Xml element to extend
2362
     * @param buildEntry - Record build type (dummy/generic/not generic)
2363
     * @param p - Package to process
2364
     * @param buildFile - buildfile level being processed
2365
     */
2366
    private void generateTarget(XmlBuilder xml, BuildFile buildEntry, Package p, int buildFile)
2367
    {
2368
        mLogger.debug("generateTarget");
2369
 
2370
        //---------------------------------------------------------------------
2371
        //  Generate the AbtData - common machine and email information
2372
        //  Only used by the daemon builds
2373
        //
2374
        if ( mDaemon && p.mBuildFile == 1 )
2375
        {
2376
            generateMachineInfo(xml, p );
2377
        }
2378
 
2379
        //-------------------------------------------------------------------------
2380
        //  Generate the <target name=... /> construct
2381
        //  There are two types
2382
        //      1) Simple dummy place holder. Just has the PackageName.PackageExt
2383
        //      2) Full target. Has all information to build the package including
2384
        //              AbtSetUp, AbtTearDown and AbtPublish targets
2385
        //
2386
 
2387
        if ( !mDaemon && ( p.mBuildFile < buildFile ) )
2388
        {
2389
            XmlBuilder target = xml.addNewElement("target");
2390
            target.addAttribute("name", p.mAlias);
2391
        }
2392
        else
2393
        {
2394
            if (!mDaemon) 
2395
            {
2396
                //  Escrow Only:
2397
                //  Generate the 'wrapper' target
2398
                //  This is used to ensure that the required dependencies have been built - I think
2399
                //
2400
                StringAppender dependList = new StringAppender(",");
2401
                if ( !p.mPackageDependencyCollection.isEmpty() )
2402
                {
2403
                    for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2404
                    {
2405
                        Package dependency = it.next();
2406
                        if ( !mDaemon && dependency.mBuildFile == -2 )
2407
                        {
2408
                            // ignore targets which build in foreign environments in escrow mode
2409
                            continue;
2410
                        }
2411
                        dependList.append(dependency.mAlias);
2412
                    }
2413
                }
2414
 
2415
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2416
                target.addAttribute("name", p.mAlias + ".wrap");
2417
 
2418
                if (dependList.length() > 0)
2419
                {
2420
                    target.addAttribute("depends", dependList.toString() );
2421
                }
2422
 
2423
                if ( !mDaemon )
2424
                {
2425
                    boolean hasDependenciesBuiltInThisIteration = false;
2426
                    if ( ( !p.mPackageDependencyCollection.isEmpty()) )
2427
                    {
2428
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2429
                        {
2430
                            Package dependency = it.next();
2431
 
2432
                            if ( dependency.mBuildFile == buildFile )
2433
                            {
2434
                                hasDependenciesBuiltInThisIteration = true;
2435
                                break;
2436
                            }
2437
                        }
2438
                    }
2439
 
2440
                    if ( hasDependenciesBuiltInThisIteration )
2441
                    {
2442
                        XmlBuilder condition = target.addNewElement("condition");
2443
                        condition.addAttribute("property",  p.mAlias + ".build");
2444
 
2445
                        XmlBuilder and = condition.addNewElement("and");
2446
 
2447
                        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2448
                        {
2449
                            Package dependency = it.next();
2450
 
2451
                            if ( dependency.mBuildFile == buildFile )
2452
                            {
2453
                                XmlBuilder or = and.addNewElement("or");
2454
 
2455
                                XmlBuilder equal1 = or.addNewElement("equals");
2456
                                equal1.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2457
                                equal1.addAttribute("arg2", "0");
2458
 
2459
                                XmlBuilder equal2 = or.addNewElement("equals");
2460
                                equal2.addAttribute("arg1", "${" + dependency.mAlias + ".res}");
2461
                                equal2.addAttribute("arg2", "257");
2462
                            }
2463
                        }
2464
                    }
2465
                    else
2466
                    {
2467
                        target.addProperty(p.mAlias + ".build", "");
2468
                    }
2469
                }
2470
            }
2471
 
2472
 
2473
            //
2474
            //  Generate the 'body' of the target package
2475
            //  Escrow Mode: Always
2476
            //  Daemon Mode: Only for the one target we are building
2477
            //                  Simplifies the XML
2478
            //                  Reduces noise in the logs
2479
            //              Don't add target dependencies. 
2480
            //                  We are only building one target and the 
2481
            //                  dependency management has been done way before now.
2482
            //                  All it does is makes the logs noisy.
2483
            //
2484
            if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
2485
            {
2486
                XmlBuilder target = xml.addNewElement("target").isExpanded();
2487
                target.addAttribute("name", p.mAlias);
2488
 
2489
                if ( !mDaemon )
2490
                {
2491
                    target.addAttribute("depends",  p.mAlias + ".wrap");
2492
                    target.addAttribute("if",p.mAlias + ".build");
2493
                }
2494
 
2495
                if ( mDaemon && p.mBuildFile == 1 )
2496
                {
2497
                    target.addProperty(p.mAlias + "pkg_id",p.mPid);
2498
                    target.addProperty(p.mAlias + "pv_id",p.mId);
2499
                }
2500
 
2501
                target.addProperty(p.mAlias + "packagename",p.mName);        		
2502
                target.addProperty(p.mAlias + "packageversion",p.mVersion);
2503
                target.addProperty(p.mAlias + "packageextension",p.mExtension);
2504
                target.addProperty(p.mAlias + "packagevcstag",p.mVcsTag);
2505
 
2506
                target.makePropertyTag(p.mAlias + "directchange", p.mDirectlyPlanned); 
2507
                target.makePropertyTag(p.mAlias + "doesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2508
 
2509
                buildEntry.state = BuildFile.BuildFileState.NonGeneric;
2510
                if ( p.isGeneric() )
2511
                {
2512
                    buildEntry.state = BuildFile.BuildFileState.Generic;
2513
                    target.makePropertyTag(p.mAlias + "generic", true); 
2514
                }
2515
 
2516
                target.addProperty(p.mAlias + "loc", getBuildLocation(p));
2517
                target.makePropertyTag(p.mAlias + "unittests", p.mHasAutomatedUnitTests && mDaemon);
2518
 
2519
                //    Add our own task and associated information
2520
                //
2521
                XmlBuilder abt = target.addNewElement("abt").isExpanded();
2522
 
2523
                for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
2524
                {
2525
                    Package dependency = it.next();
2526
                    XmlBuilder depend = abt.addNewElement("depend");
2527
                    depend.addAttribute("package_alias", "${" + dependency.mAlias + "}");
2528
                }
2529
 
2530
                buildInfo(abt,p);
2531
 
2532
                if ( mDaemon && p.mBuildFile == 1 )
2533
                {
2534
                    //    AbtTestPath
2535
                    target = xml.addNewElement("target").isExpanded();
2536
                    target.addAttribute("name", "AbtTestPath");
2537
                    target.addProperty("AbtTestPathpackagevcstag", p.mVcsTag);
2538
                    target.addProperty("AbtTestPathpackagename", p.mName);
2539
                    abt = target.addNewElement("abt").isExpanded();
2540
                    buildInfo(abt, p);
2541
 
2542
 
2543
                    //    AbtSetUp
2544
                    target = xml.addNewElement("target").isExpanded();
2545
                    target.addAttribute("name", "AbtSetUp");
2546
                    target.addProperty("AbtSetUppackagevcstag", p.mVcsTag);
2547
                    target.addProperty("AbtSetUppackagename", p.mName);
2548
 
2549
                    abt = target.addNewElement("abt").isExpanded();
2550
                    buildInfo(abt, p);
2551
 
2552
                    //    AbtTearDown
2553
                    target = xml.addNewElement("target").isExpanded();
2554
                    target.addAttribute("name", "AbtTearDown");
2555
                    target.addProperty("AbtTearDownpackagevcstag", p.mVcsTag);
2556
                    target.addProperty("AbtTearDownpackagename", p.mName);
2557
                    target.addProperty("AbtTearDownpackageversion", p.mVersion);
2558
                    target.addProperty("AbtTearDownpackageextension", p.mExtension);
2559
                    target.makePropertyTag(p.mAlias + "generic", p.isGeneric());
2560
 
2561
                    abt = target.addNewElement("abt").isExpanded();
2562
                    buildInfo(abt, p);
2563
 
2564
 
2565
                    //  AbtPublish
2566
                    target = xml.addNewElement("target").isExpanded();
2567
                    target.addAttribute("name", "AbtPublish");
2568
 
2569
                    target.addProperty("AbtPublishpackagevcstag", p.mVcsTag);
2570
                    target.addProperty("AbtPublishpackagename", p.mName);
2571
                    target.addProperty("AbtPublishpackageversion", p.mVersion);
2572
                    target.addProperty("AbtPublishpackageextension", p.mExtension);
2573
                    target.makePropertyTag("AbtPublishdirectchange", p.mDirectlyPlanned);
2574
                    target.makePropertyTag("AbtPublishdoesnotrequiresourcecontrolinteraction", ! p.mRequiresSourceControlInteraction);
2575
                    target.makePropertyTag("AbtPublishgeneric", p.isGeneric());
2576
                    target.addProperty("AbtPublishloc", getBuildLocation(p));
2577
 
2578
                    abt = target.addNewElement("abt").isExpanded();
2579
                    buildInfo(abt, p);
2580
 
2581
                }
2582
            }
2583
        }
2584
    }
2585
 
2586
    /** Extends the xml object. Adds ant default target for the current build iteration
2587
     * @param xml - The XmlBuilder Object to extend
2588
     * @param buildFile - The current build file level. This differs for Daemon and Escrow mode. In Daemon mode it will not be a '1' 
2589
     */
2590
    private void generateDefaultTarget(XmlBuilder xml, int buildFile)
2591
    {
2592
        mLogger.debug("generateDefaultTarget");
2593
 
2594
        XmlBuilder target = xml.addNewElement("target").isExpanded();
2595
        target.addAttribute("name", "fullstart");
2596
 
2597
        if (buildFile == 1)
2598
        {
2599
            antEcho(target, "${line.separator}" + mAnyBuildPlatforms + "${line.separator}${line.separator}");
7082 dpurdie 2600
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2601
            {
2602
                Package p = it.next();
2603
 
2604
                if ( p.mBuildFile == -1 )
2605
                {
2606
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2607
                }
2608
            }
2609
 
2610
            antEcho(target, "${line.separator}" + mAssocBuildPlatforms + "${line.separator}${line.separator}");
7082 dpurdie 2611
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2612
            {
2613
                Package p = it.next();
2614
 
2615
                if ( p.mBuildFile == -2 )
2616
                {
2617
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2618
                }
2619
            }
2620
 
2621
            antEcho(target, "${line.separator}" + mNotInBaseline + "${line.separator}${line.separator}");
7082 dpurdie 2622
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2623
            {
2624
                Package p = it.next();
2625
 
2626
                if ( p.mBuildFile == -4 )
2627
                {
2628
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2629
                }
2630
            }
2631
 
2632
            antEcho(target, "${line.separator}" + mDependent + "${line.separator}${line.separator}");
7082 dpurdie 2633
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2634
            {
2635
                Package p = it.next();
2636
 
2637
                if ( p.mBuildFile == -5 )
2638
                {
2639
                    antEcho(target, "${line.separator}" + p.mAlias + "${line.separator}");
2640
                }
2641
            }
2642
        }
2643
 
2644
        if ( !mDaemon )
2645
        {
2646
            antEcho(target, "${line.separator}Build Started:${line.separator}${line.separator}");
2647
        }
2648
 
2649
        //
2650
        //	Create a comma separated list of all the required targets
2651
        //      Escrow : All packages
2652
        //      Daemon : Just the package being built
2653
        //
2654
        StringAppender dependList = new StringAppender(",");
2655
        dependList.append("fullstart");
7082 dpurdie 2656
        for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2657
        {
2658
            Package p = it.next();
2659
 
2660
            if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
2661
            {
2662
                if ((mDaemon && p.mBuildFile == 1) || !mDaemon)
2663
                {
2664
                    dependList.append(p.mAlias);                    
2665
                }
2666
            }
2667
        }
2668
 
2669
        target = xml.addNewElement("target").isExpanded();
2670
        target.addAttribute("name", "full");
2671
        target.addAttribute("depends", dependList.toString());
2672
 
2673
        if ( !mDaemon )
2674
        {
2675
            antEcho(target, "${line.separator}Build Finished${line.separator}");
2676
        }
2677
    }
2678
 
2679
    /** Internal helper function to create an ant 'echo statement
2680
     *  Many of the parameters are fixed
2681
     */
2682
    private void antEcho( XmlBuilder xml, String message)
2683
    {
2684
        XmlBuilder msg = xml.addNewElement("echo");
2685
        msg.addAttribute("message", message);
2686
        msg.addAttribute("file", "publish.log");
2687
        msg.addAttribute("append", "true");
2688
    }
2689
 
2690
    /**sets the mIndirectlyPlanned true for the package and all dependent packages
2691
     */
2692
    private void rippleIndirectlyPlanned(Package p)
2693
    {
2694
        mLogger.debug("rippleIndirectlyPlanned");
2695
        if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
2696
        {
2697
            p.mIndirectlyPlanned = true;
2698
 
7082 dpurdie 2699
            for (Iterator<Package> it = mPackageCollectionAll.iterator(); it.hasNext(); )
6914 dpurdie 2700
            {
2701
                Package pkg = it.next();
2702
 
2703
                if ( pkg != p )
2704
                {
2705
                    for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
2706
                    {
2707
                        Package dependency = it2.next();
2708
 
2709
                        if ( dependency == p )
2710
                        {
2711
                            rippleIndirectlyPlanned( pkg );
2712
                            break;
2713
                        }
2714
                    }
2715
                }
2716
            }
2717
        }
7044 dpurdie 2718
        mLogger.info("rippleIndirectlyPlanned set {} {}", p.mName, p.mIndirectlyPlanned);    
6914 dpurdie 2719
    }
2720
 
2721
    /**accessor method
2722
     */
2723
    public String getEscrowSetUp()
2724
    {
2725
        mLogger.debug("getEscrowSetUp");
2726
        String retVal = mEscrowSetup;
2727
 
7044 dpurdie 2728
        mLogger.debug("getEscrowSetUp returned {}", retVal);
6914 dpurdie 2729
        return retVal;
2730
    }
2731
 
2732
    /**accessor method
2733
     */
2734
    public String getRawData()
2735
    {
2736
        mLogger.debug("getRawData");
2737
        String retVal = mEscrowRawData;
2738
 
7044 dpurdie 2739
        mLogger.debug("getRawData returned {}", retVal);
6914 dpurdie 2740
        return retVal;
2741
    }
2742
 
2743
    /**Get the build loc (location)
2744
     * This is package specific and will depend on the build mode (Escrow/Daemon)
2745
     * 
2746
     * @param	p - Package being built
2747
     * @return A string that describes the build location
2748
     */
2749
    private String getBuildLocation(Package p)
2750
    {
2751
        mLogger.debug("locationProperty");
2752
        String location = "";
2753
 
2754
        if (mDaemon)
2755
        {
2756
            // Daemon: Start in root of view/workspace
2757
            location += mBaseline;
2758
        }
2759
        else
2760
        {
2761
            // Escrow: mAlias used with jats -extractfiles -view
2762
            location += p.mAlias;
2763
        }
2764
 
2765
        //
2766
        //  Always use '/' as a path separator - even if user has specified '\'
2767
        //  Ant can handle it.
2768
        //
2769
        location = location.replace('\\', '/');
2770
        return location;
2771
    }
2772
 
2773
    /**Adds package build into as XML elements 
2774
     * @param	  xml 	- Xml element to extend
2775
     * @param   p       - Package to process
2776
     */
2777
    private void buildInfo(XmlBuilder xml, Package p)
2778
    {
2779
        mLogger.debug("buildInfo");
2780
 
2781
        //
2782
        // Create the xml build information
2783
        // <platform gbe_machtype="linux_i386" type="jats" arg="all"/>
2784
        //
2785
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext();)
2786
        {
2787
            BuildStandard bs = it.next();
2788
            bs.getBuildStandardXml(xml);
2789
        }
2790
    }
2791
 
2792
    /**returns the buildInfo as a single line of text
2793
     * Used for reporting purposes only
2794
     * @param   p       - Package to process
2795
     * 
2796
     */
2797
    public String buildInfoText(Package p)
2798
    {
2799
        mLogger.debug("buildInfoText");
2800
 
2801
        StringAppender result = new StringAppender (";");
2802
 
2803
        //
2804
        //  Create platform:standards
2805
        //      
2806
        for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
2807
        {
2808
            BuildStandard bs = it.next();
2809
 
2810
            if ( bs.isActive() )
2811
            {
2812
                String info = bs.getBuildStandardText();
2813
                result.append(info);
2814
            }
2815
        }
2816
 
7044 dpurdie 2817
        mLogger.info("buildInfoText returned {}", result);
6914 dpurdie 2818
        return result.toString();
2819
    }
2820
 
2821
    /**prints to standard out in escrow mode only
2822
     * <br>Prints a title and information. The title is only printed once.
2823
     * 
2824
     * @param header - The message title to display, if printMessage is true
2825
     * @param text - A package name. Really just the 2nd line of the message
2826
     * @param printHeader -  Controls the printing of the message argument
2827
     */
2828
    private void standardOut(final String header, final String text, boolean printHeader)
2829
    {
2830
        mLogger.debug("standardOut");
2831
        if (!mDaemon)
2832
        {
2833
            if ( printHeader )
2834
            {
2835
                System.out.println(header);
2836
            }
2837
 
2838
            System.out.println(text);
2839
        }
2840
    }
2841
 
2842
 
2843
    /**
2844
     *  Email users about a rejected daemon instruction
2845
     *  @param  reason  - Reason for the rejection
2846
     *  @param  pkg     - Package to be affected by the instruction
2847
     *  
2848
     */
2849
    public void emailRejectedDaemonInstruction(String reason, Package p)
2850
    {
2851
        mLogger.debug("emailRejectedDaemonInstruction");
2852
 
2853
        //  Email Subject
2854
        String subject = "BUILD FAILURE of Daemon Instruction on package " + p.mAlias;
2855
 
2856
        // Email Body
2857
        String mailBody = "The build system reject the the Daemon Instruction";
2858
        mailBody += "<br>Reason: " + reason; 
2859
 
2860
        mailBody += "<p>Release: " + mBaselineName 
2861
                +  "<br>Package: " + p.mAlias 
2862
                +  "<br>Rm Ref: " + CreateUrls.generateRmUrl(getRtagId(), p.mId); 
2863
 
2864
        mailBody += "<p><hr>";
2865
 
2866
        String target = p.emailInfoNonAntTask(this);
2867
 
7044 dpurdie 2868
        mLogger.error("emailRejectedDaemonInstruction Server: {}", getMailServer());
2869
        mLogger.error("emailRejectedDaemonInstruction Sender: {}", getMailSender());
2870
        mLogger.error("emailRejectedDaemonInstruction Target: {}", target);
6914 dpurdie 2871
 
2872
        try
2873
        {
2874
            //    
7082 dpurdie 2875
            Smtpsend.send(getMailServer(),  // mailServer
2876
                    getMailSender(),        // source
2877
                    target,                 // target
2878
                    getMailSender(),        // cc
2879
                    null,                   // bcc
2880
                    subject,                // subject
2881
                    mailBody,               // body
2882
                    null                    // attachment
6914 dpurdie 2883
                    );
2884
        } catch (Exception e)
2885
        {
7044 dpurdie 2886
            mLogger.warn("Email Failure: emailRejectedDaemonInstruction:{}", e.getMessage());
6914 dpurdie 2887
        }
2888
    }
2889
 
2890
    /**
2891
     * @return the mMailServer
2892
     */
2893
    public String getMailServer() {
2894
        return mMailServer;
2895
    }
2896
 
2897
    /**
2898
     * @param mMailServer the mMailServer to set
2899
     */
2900
    public void setMailServer(String mMailServer) {
2901
        this.mMailServer = mMailServer;
2902
    }
2903
 
2904
    /**
2905
     * @return the mMailSender
2906
     */
2907
    public String getMailSender() {
2908
        return mMailSender;
2909
    }
2910
 
2911
    /**
2912
     * @param mMailSender the mMailSender to set
2913
     */
2914
    public void setMailSender(String mMailSender) {
2915
        this.mMailSender = mMailSender;
2916
    }
2917
 
2918
    /**
2919
     * @return the mMailGlobalTarget
2920
     */
2921
    public String getMailGlobalTarget() {
2922
        return mMailGlobalTarget;
2923
    }
2924
 
2925
    /**
2926
     * @param mMailGlobalTarget the mMailGlobalTarget to set
2927
     */
2928
    public void setMailGlobalTarget(String mMailGlobalTarget) {
2929
        this.mMailGlobalTarget = mMailGlobalTarget;
2930
    }
2931
 
2932
}