Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.io.File;
4
 
5
import java.sql.SQLException;
6
 
7
import java.util.Iterator;
866 mhunt 8
import java.util.ListIterator;
814 mhunt 9
import java.util.Vector;
4123 dpurdie 10
import java.lang.Exception;
814 mhunt 11
 
12
import org.apache.log4j.Logger;
13
 
14
/**Plans release impact by generating a set of Strings containing build file content.
15
 */
16
public class RippleEngine
17
{
18
  /**collection of gbemachtypes in String form associated with the baseline
19
   * limited to the following items "win32", "sparc", "solaris10_sparc32", "solaris10_x86", "linux_i386"
20
   * accessed by Package::isLinuxBuilt, isSolarisBuilt, isWin32Built
21
   * @attribute
22
   */
864 mhunt 23
  Vector<String> mGbeMachtypeCollection = new Vector<String>();
866 mhunt 24
 
814 mhunt 25
  /**configured mail server
26
   * @attribute
27
   */
868 mhunt 28
  public String mMailServer = new String();
814 mhunt 29
 
30
  /**configured mail sender user
31
   * @attribute
32
   */
868 mhunt 33
  public String mMailSender = new String();
814 mhunt 34
 
868 mhunt 35
  /**configured global email target
36
   * @attribute
37
   */
38
  public String mGlobalTarget = new String();
39
 
814 mhunt 40
  /**name associated with the baseline
41
   * @attribute
42
   */
868 mhunt 43
  public String mBaselineName = new String();
814 mhunt 44
 
45
  /**collection of released pv_ids associated with the release
46
   * @attribute
47
   */
864 mhunt 48
  Vector<Integer> mReleasedPvIDCollection = new Vector<Integer>();
814 mhunt 49
 
50
  /**timestamp associated with build file generation
51
   * @attribute
52
   */
53
  long mTimestamp = 0;
54
 
55
  /**set to "non generic", "generic" or "dummy" to indicate the nature of the package in the build file in daemon mode
56
   * @attribute
57
   */
58
  String mAddendum = new String("dummy");
59
 
866 mhunt 60
  /**collection of build exceptions associated with the baseline
61
  /* used to determine (and report) what change in build exceptions happens as part of planRelease
62
   * deamon centric
63
   * @aggregation shared
64
   * @attribute
65
   */
66
  Vector<BuildExclusion> mBuildExclusionCollection = new Vector<BuildExclusion>();
67
 
814 mhunt 68
  /**Logger
69
   * @attribute
70
   */
71
  private static final Logger mLogger = Logger.getLogger(RippleEngine.class);
72
 
924 dpurdie 73
  /**collection of escrow support file content in String form, set_up
814 mhunt 74
   * @attribute
75
   */
924 dpurdie 76
  private Vector<String> mEscrowSupportCollection = new Vector<String>();
814 mhunt 77
 
78
  /**package versions representing the baseline
866 mhunt 79
   * escrow centric
814 mhunt 80
   * @aggregation shared
81
   * @attribute
82
   */
864 mhunt 83
  private Vector<Package> mPackageCollection = new Vector<Package>();
814 mhunt 84
 
85
  /**index to current String item
86
   * @attribute
87
   */
88
  private int mBuildIndex;
89
 
90
  /**Database abstraction
91
   * @attribute
92
   */
93
  private ReleaseManager mReleaseManager;
94
 
95
  /**Baseline identifier (rtag_id for a release manager baseline, bom_id for deployment manager baseline)
96
   * @attribute
97
   */
98
  private int mBaseline;
99
 
100
  /**When true, mBuildCollection contains one item based on a release manager rtag_id and contains a daemon property
101
   * When false, mBuildCollection contains at least one item based on a deployment manager bom_id
102
   * Will be accessed by the Package class to calculate its mAlias
103
   * @attribute
104
   */
105
  boolean mDaemon;
106
 
107
  /**collection of build file content in String form
108
   * @attribute
109
   */
864 mhunt 110
  private Vector<String> mBuildCollection = new Vector<String>();
814 mhunt 111
 
906 mhunt 112
  /**Warning message
113
   * @attribute
114
   */
115
  private static final String mAnyBuildPlatforms = new String("Warning. The following package versions are not reproducible on any build platform: ");
116
 
117
  /**Flag to control output to standard out
118
   * @attribute
119
   */
120
  private boolean mAnyBuildPlatformsFlag = true;
121
 
122
  /**Warning message
123
   * @attribute
124
   */
125
  private static final String mAssocBuildPlatforms = new String("Warning. The following package versions are not reproducible on the build platforms associated with this baseline: ");
126
 
127
  /**Flag to control output to standard out
128
   * @attribute
129
   */
130
  private boolean mAssocBuildPlatformsFlag = true;
131
 
132
  /**Warning message
133
   * @attribute
134
   */
135
  private static final String mNotInBaseline = new String("Warning. The following package versions are not reproducible as they are directly dependent upon package versions not in the baseline: ");
136
 
137
  /**Flag to control output to standard out
138
   * @attribute
139
   */
140
  private boolean mNotInBaselineFlag = true;
141
 
142
  /**Warning message
143
   * @attribute
144
   */
145
  private static final String mDependent = new String("Warning. The following package versions are not reproducible as they are directly/indirectly dependent upon not reproducible package versions: ");
146
 
147
  /**Flag to control output to standard out
148
   * @attribute
149
   */
150
  private boolean mDependentFlag = true;
151
 
910 mhunt 152
  /**Warning message
153
   * @attribute
154
   */
155
  private static final String mCircularDependency = new String("Warning. The following package versions are not reproducible as they have circular dependencies: ");
156
 
157
  /**Flag to control output to standard out
158
   * @attribute
159
   */
160
  private boolean mCircularDependencyFlag = true;
161
 
814 mhunt 162
  /**constructor
163
   */
164
  public RippleEngine(ReleaseManager releaseManager, int rtag_id, 
165
                      boolean isDaemon)
166
  {
167
    mLogger.debug("RippleEngine rtag_id " + rtag_id + " isDaemon " + isDaemon);
168
    mReleaseManager = releaseManager;
169
    mBaseline = rtag_id;
170
    mDaemon = isDaemon;
171
  }
172
 
173
  /**discards all build file content
174
   * plans new build file content
175
   */
176
  public void planRelease() throws SQLException, Exception
177
  {
178
    mLogger.warn("planRelease mDaemon " + mDaemon);
918 mhunt 179
    boolean highProbabilityBuildRequirement = true;
180
 
181
    if ( mAddendum.compareTo("dummy") == 0 )
182
    {
183
      // the last planning session had no build requirement
184
      highProbabilityBuildRequirement = false;
185
    }
186
 
814 mhunt 187
    mAddendum = "dummy";
188
    mBuildCollection.removeAllElements();
189
    mPackageCollection.removeAllElements();
190
    mReleasedPvIDCollection.removeAllElements();
191
 
192
    if ( !mDaemon )
193
    {
924 dpurdie 194
      mEscrowSupportCollection.removeAllElements();  
814 mhunt 195
    }
196
 
898 mhunt 197
    // use finally block in planRelease to ensure releaseMutex is called
198
    try
199
    {
918 mhunt 200
      mReleaseManager.connectForPlanning(highProbabilityBuildRequirement);
814 mhunt 201
 
898 mhunt 202
      if ( mDaemon )
866 mhunt 203
      {
898 mhunt 204
        // claim the mutex
4123 dpurdie 205
mLogger.warn("planRelease claimMutex");
206
 
898 mhunt 207
        mReleaseManager.claimMutex();
208
        mBuildExclusionCollection.removeAllElements();
209
        Vector<BuildExclusion> tempBuildExclusionCollection = new Vector<BuildExclusion>();
866 mhunt 210
 
4123 dpurdie 211
mLogger.warn("planRelease queryBuildExclusions");
898 mhunt 212
        mReleaseManager.queryBuildExclusions(tempBuildExclusionCollection, mBaseline);
4123 dpurdie 213
 
898 mhunt 214
        // only populate mBuildExclusionCollection with tempBuildExclusionCollection entries which have a relevant root_pv_id
215
        // ie the root_pv_id is ONLY relevant if it is null (-1) or it points to a pv_id in the collection
216
        // the package with a pv_id which is a root_pv_id may be removed ie when fixing a build issue
217
        for (Iterator<BuildExclusion> it = tempBuildExclusionCollection.iterator(); it.hasNext(); )
866 mhunt 218
        {
898 mhunt 219
          BuildExclusion buildExclusion = it.next();
220
 
221
          if ( buildExclusion.isRelevant(tempBuildExclusionCollection) )
222
          {
223
            mBuildExclusionCollection.add(buildExclusion);
224
          }
225
          else
226
          {
227
            // this is just a cosmetic step
228
            // it includes package versions which have been indirectly excluded
229
            // the build daemon ignores this information, but it serves to clarify this point to users
230
            buildExclusion.includeToBuild(mReleaseManager, mBaseline);
231
          }
866 mhunt 232
        }
233
      }
898 mhunt 234
 
4123 dpurdie 235
mLogger.warn("planRelease queryPackageVersions");
898 mhunt 236
      mReleaseManager.queryPackageVersions(this, mPackageCollection, mDaemon, mBaseline);
237
 
908 mhunt 238
      // must deal with test builds here as they may impact upon package attributes
239
      // eg dependency collection and build standard differences
240
      // this gives test builds preferential treatment
241
      if ( mDaemon )
242
      {
243
        // process test builds
244
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
245
        {
246
          Package p = it.next();
247
 
248
          if (p.mBuildFile == 0)
249
          {
250
            // package has yet to be processed
251
            if (  p.mTestBuildInstruction > 0 )
252
            {
253
              mLogger.info("planRelease package test build " + p.mName);
254
 
255
              // force patch for test build numbering
256
              p.mDirectlyPlanned = true;
257
              p.mChangeType.setPatch();
258
              p.mRequiresSourceControlInteraction = false;
259
              rippleIndirectlyPlanned(p);
260
 
261
              // put the mTestBuildAttributes to work
924 dpurdie 262
              p.mVcsTag = p.mTestBuildVcsTag;
908 mhunt 263
              p.setEmail();
264
              p.setDependencyCollection();
265
              p.setBuildStandardCollection();
266
            }
267
          }
268
        }
269
      }
270
 
898 mhunt 271
      // set up mPackageDependencyCollection
4123 dpurdie 272
mLogger.warn("planRelease setup mPackageDependencyCollection");
898 mhunt 273
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 274
      {
898 mhunt 275
        Package p = it.next();
276
 
277
        for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 278
        {
898 mhunt 279
          String alias = it2.next();
280
          Package dependency = findPackage(alias);
281
 
902 mhunt 282
          p.mPackageDependencyCollection.add(dependency);
283
        }
284
      }
910 mhunt 285
 
286
      // DEVI 56479 detect and deal with circular dependencies
4123 dpurdie 287
mLogger.warn("planRelease deal with circular dependencies");
910 mhunt 288
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
289
      {
290
        Package p = it.next();
291
 
292
        if ( p.hasCircularDependency( this ) )
293
        {
294
          mLogger.info("planRelease circular dependency detected " + p.mAlias);
295
          // exclude all dependent packages
296
          // max 50 chars
297
          rippleBuildExclude(p, p.mId, "Package has circular dependency", null, null);
298
 
299
          // take the package out of the build
300
          p.mBuildFile = -6;
301
          mLogger.info("planRelease set mBuildFile to -6 for package " + p.mAlias );
302
          standardOut(mCircularDependency, p.mAlias, mCircularDependencyFlag);
303
        }
304
      }
902 mhunt 305
 
306
      // DEVI 55483 now use the fully built mPackageDependencyCollection (in rippleBuildExclude)
4123 dpurdie 307
mLogger.warn("planRelease use the fully built mPackageDependencyCollection");
902 mhunt 308
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
309
      {
310
        Package p = it.next();
311
 
312
        for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
313
        {
314
          String alias = it2.next();
315
          Package dependency = findPackage(alias);
316
 
898 mhunt 317
          if (dependency == ReleaseManager.NULL_PACKAGE)
318
          {
319
            mLogger.info("planRelease dependency is not in the baseline " + alias);
320
            // exclude all dependent packages
321
            // max 50 chars
900 mhunt 322
            rippleBuildExclude(p, p.mId, "Package build dependency not in the release", null, null);
898 mhunt 323
 
324
            // take the package out of the build
325
            p.mBuildFile = -4;
326
            mLogger.info("planRelease set mBuildFile to -4 for package " + p.mAlias );
906 mhunt 327
            standardOut(mNotInBaseline, p.mAlias, mNotInBaselineFlag);
898 mhunt 328
            break;
329
          }
814 mhunt 330
        }
331
      }
902 mhunt 332
 
898 mhunt 333
      // process packages which are not reproducible, and all packages dependent upon them      
4123 dpurdie 334
mLogger.warn("planRelease process packages which are not reproducible");
898 mhunt 335
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 336
      {
898 mhunt 337
        Package p = it.next();
338
 
339
        if (p.mBuildFile == 0)
814 mhunt 340
        {
898 mhunt 341
          // package has yet to be processed
342
          if (!p.isReproducible())
343
          {
344
            // for escrow build purposes, exclude all dependent package versions
345
            mLogger.info("planRelease package not reproducible " + p.mName);
346
            // max 50 chars
900 mhunt 347
            rippleBuildExclude(p, p.mId, "Package has no build environment", null, null);
898 mhunt 348
 
349
            // package is not reproducible, discard
350
            p.mBuildFile = -1;
351
            mLogger.info("planRelease set mBuildFile to -1 for package " + p.mAlias );
906 mhunt 352
            standardOut(mAnyBuildPlatforms, p.mAlias, mAnyBuildPlatformsFlag);
898 mhunt 353
          }
814 mhunt 354
        }
355
      }
898 mhunt 356
 
357
      // process packages which are not reproducible on the build platforms configured for this baseline
4123 dpurdie 358
mLogger.warn("planRelease process packages which are not reproducible2");
898 mhunt 359
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 360
      {
898 mhunt 361
        Package p = it.next();
858 mhunt 362
 
898 mhunt 363
        if (p.mBuildFile == 0)
814 mhunt 364
        {
898 mhunt 365
          // package has yet to be processed
366
          // assume it does not need to be reproduced for this baseline
367
          boolean reproduce = false;
368
 
369
          for (Iterator<String> it2 = mGbeMachtypeCollection.iterator(); it2.hasNext(); )
814 mhunt 370
          {
898 mhunt 371
            String machtype = it2.next();
372
 
373
            if ( machtype.compareTo("linux_i386") == 0 )
814 mhunt 374
            {
898 mhunt 375
              if ( p.isLinuxBuilt() )
376
              {
377
                reproduce = true;
378
                mLogger.info("planRelease package built on linux " + p.mAlias );
379
                break;
380
              }
814 mhunt 381
            }
898 mhunt 382
            else if ( machtype.compareTo("win32") == 0 )
814 mhunt 383
            {
898 mhunt 384
              if ( p.isWin32Built() )
385
              {
386
                reproduce = true;
387
                mLogger.info("planRelease package built on win32 " + p.mAlias );
388
                break;
389
              }
814 mhunt 390
            }
898 mhunt 391
            else if ( machtype.compareTo("sparc") == 0
392
                   || machtype.compareTo("solaris10_x86") == 0
393
                   || machtype.compareTo("solaris10_sparc32") == 0 )
814 mhunt 394
            {
898 mhunt 395
              if ( p.isSolarisBuilt() )
396
              {
397
                reproduce = true;
398
                mLogger.info("planRelease package built on solaris " + p.mAlias );
399
                break;
400
              }
814 mhunt 401
            }
402
          }
898 mhunt 403
 
404
          if ( !reproduce )
405
          {
406
            mLogger.info("planRelease package not reproducible on the build platforms configured for this baseline " + p.mName);
407
 
906 mhunt 408
            if (mDaemon)
409
            {
410
              // DEVI 54816
411
              // for escrow build purposes, do not exclude all dependent package versions
412
              // max 50 chars
413
              rippleBuildExclude(p, p.mId, "Package not built for configured platforms", null, null);
414
            }
415
 
898 mhunt 416
            // package is not reproducible on the build platforms configured for this baseline, discard
417
            p.mBuildFile = -2;
418
            mLogger.info("planRelease set mBuildFile to -2 for package " + p.mAlias );
906 mhunt 419
            standardOut(mAssocBuildPlatforms, p.mAlias, mAssocBuildPlatformsFlag);
898 mhunt 420
          }
858 mhunt 421
        }
898 mhunt 422
      }      
423
 
424
      if (mDaemon)
814 mhunt 425
      {
898 mhunt 426
        // process packages which are not ripple buildable, and all packages dependent upon them
4123 dpurdie 427
mLogger.warn("planRelease process packages which are not ripple buildable");
898 mhunt 428
        for (ListIterator<BuildExclusion> it = mBuildExclusionCollection.listIterator(); it.hasNext(); )
814 mhunt 429
        {
898 mhunt 430
          BuildExclusion be = it.next();
866 mhunt 431
 
898 mhunt 432
          for (Iterator<Package> it1 = mPackageCollection.iterator(); it1.hasNext(); )
814 mhunt 433
          {
898 mhunt 434
            Package p = it1.next();
435
 
908 mhunt 436
            // ensure only root cause, non test build, build exclusions are excluded
900 mhunt 437
            // mBuildExclusionCollection is at this point based on
438
            // relevant (direct and indirect) excluded pv's in the database
908 mhunt 439
            if ( be.compare(p.mId) && be.isARootCause() && p.mTestBuildInstruction == 0 )
866 mhunt 440
            {
900 mhunt 441
              // package is not reproducible, discard
442
              rippleBuildExclude( p, p.mId, null, it, be );
443
              p.mBuildFile = -3;
444
              mLogger.info("planRelease set mBuildFile to -3 for package " + p.mAlias );
898 mhunt 445
              break;
866 mhunt 446
            }
814 mhunt 447
          }
448
        }
898 mhunt 449
 
450
        // process packages which need to be ripple built
4123 dpurdie 451
mLogger.warn("planRelease process packages which need to be ripple built");
898 mhunt 452
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 453
        {
898 mhunt 454
          Package p = it.next();
455
 
456
          if (p.mBuildFile == 0)
814 mhunt 457
          {
898 mhunt 458
            // package has yet to be processed
459
            if (p.mDirectlyPlanned)
814 mhunt 460
            {
898 mhunt 461
              // a WIP exists on the package
462
              // exclude all dependent package versions
463
              mLogger.info("planRelease package has WIP " + p.mName);
464
              rippleIndirectlyPlanned(p);
465
            }
466
            else
467
            {
468
              Iterator<Integer> it2 = p.mDependencyIDCollection.iterator();
469
              Iterator<Package> it3 = p.mPackageDependencyCollection.iterator();
470
              for ( ; it2.hasNext() && it3.hasNext(); )
814 mhunt 471
              {
898 mhunt 472
                Integer dpv_id = it2.next();
473
                Package dependency = it3.next();
474
 
475
                if ( !dependency.mAdvisoryRipple )
814 mhunt 476
                {
898 mhunt 477
                  // not advisory, ie has ripple build impact
478
                  boolean found = false;
479
 
480
                  for ( Iterator<Integer> it4 = mReleasedPvIDCollection.iterator(); it4.hasNext(); )
814 mhunt 481
                  {
898 mhunt 482
                    Integer pv_id = it4.next();
483
 
484
                    if ( pv_id.compareTo(dpv_id) == 0 )
485
                    {
486
                      found = true;
487
                      break;
488
                    }
489
                  }
490
 
491
                  if ( !found )
492
                  {
493
                    // the package is out of date
494
                    // exclude all dependent package versions
495
                    mLogger.info("planRelease package out of date " + p.mName);
496
                    rippleIndirectlyPlanned(p);                 
814 mhunt 497
                    break;
498
                  }
499
                }
500
              }
501
            }
502
          }
503
        }
898 mhunt 504
 
505
        // process packages which do not exist in the archive
4123 dpurdie 506
mLogger.warn("planRelease process packages which do not exist in the archive");
898 mhunt 507
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 508
        {
898 mhunt 509
          Package p = it.next();
510
 
511
          if (p.mBuildFile == 0)
814 mhunt 512
          {
898 mhunt 513
            // package has yet to be processed
514
            // for unit test purposes, assume all packages exist in the archive if released
515
            if ( ReleaseManager.mUseDatabase )
814 mhunt 516
            {
898 mhunt 517
              // only check existence outside the unit test
518
              if (!p.mDirectlyPlanned && !p.mIndirectlyPlanned)
814 mhunt 519
              {
898 mhunt 520
                // check package version archive existence
521
                if (!p.exists())
522
                {
523
                  mLogger.info("planRelease package not found in archive " + p.mName);
524
                  // DEVI 47395 the cause of this build is not WIP or ripple induced,
525
                  // it simply does not exist in the archive (has been removed)
526
                  // prevent source control interaction
527
                  p.mRequiresSourceControlInteraction = false;
528
                  rippleIndirectlyPlanned(p);
529
                }
814 mhunt 530
              }
531
            }
532
          }
533
        }
908 mhunt 534
 
535
        // process forced ripples
4123 dpurdie 536
mLogger.warn("planRelease process forced ripples");
908 mhunt 537
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
538
        {
539
          Package p = it.next();
540
 
541
          if (p.mBuildFile == 0)
542
          {
543
            // package has yet to be processed
544
            if ( p.mForcedRippleInstruction > 0 )
545
            {
546
              mLogger.info("planRelease package forced ripple " + p.mName);
547
              rippleIndirectlyPlanned(p);
548
            }
549
          }
550
        }
814 mhunt 551
      }
906 mhunt 552
      else
553
      {
554
        // escrow reporting only     
555
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
556
        {
557
          Package p = it.next();
558
 
559
          if (p.mBuildFile == -3)
560
          {
561
            standardOut(mDependent, p.mAlias, mDependentFlag);
562
          }
563
        }
564
      }
826 mhunt 565
 
898 mhunt 566
      // process remaining packages which need to be reproduced for this baseline
567
      // determine the build file for each package
568
      // for daemon builds, determine the first package that can be built now, this means the first package not dependent upon packages also to be built
569
      // set its mBuildNumber to 1, all remaining reproducible packages to 2
570
      // for escrow builds, determine the package versions that can be built in the build iteration
571
      // set their mBuildNumber to the build iteration
572
      // increment the build iteration and repeat until all package versions that need to be reproduced have been assigned a build iteration
573
      boolean allProcessed = false;
574
      int buildFile = 1;
575
 
576
      // delete the file <rtagId>official
577
      Integer rtag = new Integer(mBaseline);
578
      File rtagIdOfficial = new File(rtag + "official");
579
 
4123 dpurdie 580
mLogger.warn("planRelease process Remaining-1");
898 mhunt 581
      if (rtagIdOfficial.exists())
826 mhunt 582
      {
898 mhunt 583
        boolean del = rtagIdOfficial.delete();
584
 
826 mhunt 585
        if ( !del )
586
        {
898 mhunt 587
          // the delete failed
588
          // some literature suggests a forced garbage collection may free up resources associated with file handles
589
          // nothing to lose since the file "must" be deleted
590
          System.gc();
591
          del = rtagIdOfficial.delete();
592
 
593
          if ( !del )
594
          {
595
            mLogger.fatal("rtagIdOfficial.delete() returned " + del);
596
          }
826 mhunt 597
        }
598
      }
814 mhunt 599
 
898 mhunt 600
      String raw_data = new String("");
601
      String lf = new String( System.getProperty("line.separator") );
602
 
4123 dpurdie 603
mLogger.warn("planRelease process Remaining-2");
814 mhunt 604
      do
605
      {
898 mhunt 606
        boolean allDependenciesProcessed = true;
814 mhunt 607
 
898 mhunt 608
        do
814 mhunt 609
        {
898 mhunt 610
          // assume all dependencies have been processed
611
          allDependenciesProcessed = true;
814 mhunt 612
 
898 mhunt 613
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 614
          {
898 mhunt 615
            Package p = it.next();
616
 
906 mhunt 617
            if ( ( mDaemon && ( ( !p.mDirectlyPlanned && !p.mIndirectlyPlanned ) || p.mBuildFile < 0 ) ) ||
618
                 ( !mDaemon && p.mBuildFile == -2 ) )
814 mhunt 619
            {
898 mhunt 620
              // flag packages with no build requirement as processed in daemon mode
906 mhunt 621
              // DEVI 54816 flag packages with a foreign build environment as processed in escrow mode
898 mhunt 622
              p.mProcessed = true;
623
              mLogger.info("planRelease package has no build requirement " + p.mName);            
624
            }
906 mhunt 625
            else if ( ( p.mBuildFile == 0 ) && ( (mDaemon && ( p.mDirectlyPlanned || p.mIndirectlyPlanned ) ) || ( !mDaemon ) ) )
898 mhunt 626
            {
906 mhunt 627
              // package yet to be processed and
628
              // in daemon mode has a build requirement or
629
              // in escrow mode
630
              boolean canBeBuiltNow = true;
631
              boolean allDependenciesForThisPackageProcessed = true;
632
 
633
              for ( Iterator<Package> it2 = p.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 634
              {
906 mhunt 635
                Package dependency = it2.next();
814 mhunt 636
 
906 mhunt 637
                if ( !dependency.mProcessed )
814 mhunt 638
                {
906 mhunt 639
                  // cannot determine canBeBuiltNow until this dependency has been processed
640
                  allDependenciesForThisPackageProcessed = false;
641
                  allDependenciesProcessed = false;
642
                }
643
                else if ( ( mDaemon && ( dependency.mDirectlyPlanned ) || ( dependency.mIndirectlyPlanned ) ) || 
644
                          ( !mDaemon &&
645
                            ( ( dependency.mBuildFile == 0 ) ||
646
                              ( dependency.mBuildFile == buildFile &&
647
                                ( ( p.isLinuxBuilt() && !dependency.isLinuxBuilt() ) ||
648
                                  ( p.isWin32Built() && !dependency.isWin32Built() ) ||
649
                                  ( p.isSolarisBuilt() && !dependency.isSolarisBuilt() ) ||
650
                                  ( !p.isLinuxBuilt() && dependency.isLinuxBuilt() ) ||
651
                                  ( !p.isWin32Built() && dependency.isWin32Built() ) ||
652
                                  ( !p.isSolarisBuilt() && dependency.isSolarisBuilt() ) ) ) ) ) )
653
                {
654
                  // in daemon mode this processed dependency has a build requirement or
655
                  // in escrow mode...
656
                  // this processed dependency has not been assigned to a build iteration or
657
                  // this processed dependency has been assigned to this build iteration and does not build on this platform
658
                  canBeBuiltNow = false;
659
                  mLogger.info("planRelease package cannot be built in this iteration " + p.mName);
660
                  break;
661
                }
662
              }
663
 
664
              if (allDependenciesForThisPackageProcessed)
665
              {
666
                p.mProcessed = true;
667
 
668
                if ( mDaemon )
669
                {
670
                  if ( canBeBuiltNow )
814 mhunt 671
                  {
906 mhunt 672
                    // flag package with build requirement, may get downgraded to future build requirement
673
                    p.mBuildFile = 1;
674
                    mLogger.info("planRelease set mBuildFile to 1 for package " + p.mAlias );
814 mhunt 675
                  }
906 mhunt 676
                  else
814 mhunt 677
                  {
906 mhunt 678
                    // flag package with future build requirement
679
                    p.mBuildFile = 2;
680
                    mLogger.info("planRelease set mBuildFile to 2 for package " + p.mAlias );
814 mhunt 681
                  }
682
                }
906 mhunt 683
                else
814 mhunt 684
                {
906 mhunt 685
                  if ( canBeBuiltNow )
814 mhunt 686
                  {
906 mhunt 687
                    String isWin32Built = new String("");
688
 
689
                    if ( p.isWin32Built() )
848 dpurdie 690
                    {
906 mhunt 691
                      isWin32Built = "W";
898 mhunt 692
                    }
906 mhunt 693
 
694
                    String isLinuxBuilt = new String("");
695
 
696
                    if ( p.isLinuxBuilt() )
898 mhunt 697
                    {
906 mhunt 698
                      isLinuxBuilt = "L";
898 mhunt 699
                    }
906 mhunt 700
 
701
                    String isSolarisBuilt = new String("");
702
 
703
                    if ( p.isSolarisBuilt() )
898 mhunt 704
                    {
906 mhunt 705
                      isSolarisBuilt = "S";
848 dpurdie 706
                    }
906 mhunt 707
 
708
                    String isGeneric = new String("");
709
 
710
                    if ( p.isGeneric() )
711
                    {
712
                      isGeneric = "G";
713
                    }
714
 
715
                    raw_data += p.mAlias + "," +
716
                                isWin32Built + "," +
717
                                isLinuxBuilt + "," +
718
                                isSolarisBuilt + "," +
719
                                isGeneric + "," +
720
                                buildFile +
721
                                lf;
722
 
723
                    // not daemon
724
                    p.mBuildFile = buildFile;
725
                    mLogger.info("planRelease set mBuildFile to " + buildFile + " for package " + p.mAlias );
814 mhunt 726
                  }
727
                }
728
              }
729
            }
730
          }
898 mhunt 731
        } while( !allDependenciesProcessed );
732
 
733
        if ( mDaemon )
814 mhunt 734
        {
898 mhunt 735
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 736
          {
898 mhunt 737
            Package p = it.next();
738
 
739
            if ( p.mProcessed && p.mBuildFile == 1 )
814 mhunt 740
            {
898 mhunt 741
              p.mBuildFile = buildFile;
742
              mLogger.info("planRelease 2 set mBuildFile to " + buildFile + " for package " + p.mAlias );
743
 
744
              if ( buildFile == 1 )
874 mhunt 745
              {
898 mhunt 746
                int pvApplied = p.applyPV(mReleaseManager, mBaseline);
747
 
748
                if ( pvApplied == 1 )
749
                {
750
                  // max 50 chars
900 mhunt 751
                  rippleBuildExclude(p, p.mId, "Package has non standard versioning", null, null);
898 mhunt 752
                }
4212 dpurdie 753
                else if ( pvApplied == 2 )
898 mhunt 754
                {
755
                  // max 50 chars
900 mhunt 756
                  rippleBuildExclude(p, p.mId, "Package has reached ripple field limitations", null, null);
898 mhunt 757
                }
4212 dpurdie 758
                else if ( pvApplied == 3 )
759
                {
760
                  // max 50 chars
761
                  rippleBuildExclude(p, p.mId, "Package has invalid change type", null, null);
762
                }
898 mhunt 763
                else
764
                {
765
                  buildFile = 2;
908 mhunt 766
 
767
                  if ( p.mForcedRippleInstruction > 0 )
768
                  {
769
                    mReleaseManager.markDaemonInstCompleted( p.mForcedRippleInstruction );
770
                  }
771
 
772
                  if ( p.mTestBuildInstruction > 0 )
773
                  {
774
                    mReleaseManager.markDaemonInstInProgress( p.mTestBuildInstruction );
775
                  }
898 mhunt 776
                }
874 mhunt 777
              }
778
              else
779
              {
898 mhunt 780
                mLogger.info("planRelease package has future (downgraded) build requirement " + p.mName + " " + buildFile);              
874 mhunt 781
              }
814 mhunt 782
            }
898 mhunt 783
          }
784
        }
785
 
786
        // are more build files required
787
        allProcessed = true;
788
 
789
        if (mDaemon)
790
        {
791
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
792
          {
793
            Package p = it.next();
794
 
795
            if ( p.mBuildFile < 0 || ( !p.mDirectlyPlanned && !p.mIndirectlyPlanned ) )
814 mhunt 796
            {
898 mhunt 797
              // at this point...
798
              // only 1 package with a build requirement has a mBuildFile of 1,
799
              // all other packages with a build requirement have an mBuildFile of 2
800
              // give packages with no build requirement, reproducible or not, an mBuildFile of 3
801
              p.mBuildFile = 3;
802
              mLogger.info("planRelease 1 set mBuildFile to 3 for package " + p.mAlias );
814 mhunt 803
            }
804
          }
805
        }
898 mhunt 806
        else
807
        {
808
          // this is escrow mode centric
809
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
810
          {
811
            Package p = it.next();
812
 
813
            if ( p.mBuildFile == 0 )
814
            {
815
              // more build files are required
816
              allProcessed = false;
817
              mLogger.info("planRelease more build files are required for " + p.mName);
818
              break;
819
            }
820
          }
821
 
822
          buildFile++;
823
        }
824
      } while( !allProcessed );
814 mhunt 825
 
898 mhunt 826
      // persist the build files
827
      allProcessed = false;
828
      buildFile = 1;
4123 dpurdie 829
mLogger.warn("planRelease process Remaining-3");
814 mhunt 830
 
898 mhunt 831
      if ( mDaemon )
814 mhunt 832
      {
898 mhunt 833
        // all interesting packages in daemon mode match the following filter
834
        buildFile = 3;
835
      }
836
 
837
      mTimestamp = System.currentTimeMillis();
838
 
839
      if ( !ReleaseManager.mUseDatabase )
840
      {
841
        mTimestamp = 123456789;
842
      }
843
 
4280 dpurdie 844
      //-----------------------------------------------------------------------
845
      //    Generate the build file
898 mhunt 846
      do
847
      {
848
        String buildFileContent = new String( generateBuildFileHeader() );
849
 
864 mhunt 850
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 851
        {
864 mhunt 852
          Package p = it.next();
906 mhunt 853
 
854
          // DEVI 54816
855
          // now set a packages mBuildFile to -2 in escrow mode, but do not ripple this through
856
          // its consumers need dependency package property info
857
          if ( ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) ) || ( !mDaemon && p.mBuildFile == -2 ) )
814 mhunt 858
          {
898 mhunt 859
            buildFileContent += generatePackageProperty(p);
814 mhunt 860
          }
861
        }
898 mhunt 862
 
863
        buildFileContent += generateTaskdef();
4280 dpurdie 864
 
898 mhunt 865
        String set_up = new String("");
866
        boolean daemonHasTarget = false;
867
 
864 mhunt 868
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 869
        {
864 mhunt 870
          Package p = it.next();
898 mhunt 871
 
872
          if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
814 mhunt 873
          {
898 mhunt 874
            buildFileContent += generateTarget(p, buildFile);
875
 
876
            if ( p.mBuildFile == 1 )
877
            {
878
              daemonHasTarget = true;
879
            }
814 mhunt 880
          }
866 mhunt 881
 
898 mhunt 882
          if ( !mDaemon && buildFile == 1 )
866 mhunt 883
          {
924 dpurdie 884
        	  set_up += "jats jats_vcsrelease -extractfiles"
885
                      + " \"-label=" + p.mVcsTag + "\""
898 mhunt 886
                      + " \"-view=" + p.mAlias + "\""
887
                      + " -root=. -noprefix"
888
                      + lf;
866 mhunt 889
          }
814 mhunt 890
        }
898 mhunt 891
 
892
        if ( mDaemon && !daemonHasTarget )
893
        {
894
          // must have AbtSetUp, AbtTearDown, and AbtPublish targets
895
          buildFileContent += "<target name=\"AbtSetUp\"/>" + lf +
896
                              "<target name=\"AbtTearDown\"/>" + lf +
897
                              "<target name=\"AbtPublish\"/>" + lf;
898
        }
814 mhunt 899
 
900
        if ( !mDaemon && buildFile == 1 )
901
        {
924 dpurdie 902
          mEscrowSupportCollection.add(set_up);
903
          mEscrowSupportCollection.add(raw_data);
898 mhunt 904
        }
905
 
906
        buildFileContent += generateDefaultTarget( buildFile);
907
        buildFileContent += generateBuildFileFooter();
908
 
909
        mBuildCollection.add(buildFileContent);
910
 
911
        // are more build files required
912
        allProcessed = true;
913
 
914
        if (!mDaemon)
915
        {
916
          // this is escrow mode centric
917
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
848 dpurdie 918
          {
898 mhunt 919
            Package p = it.next();
920
 
921
            if ( p.mBuildFile > buildFile )
922
            {
923
              // more build files are required
924
              allProcessed = false;
925
              mLogger.info("planRelease reiterating package has no build requirement " + p.mName + " " + p.mBuildFile + " " + buildFile);
926
              break;
927
            }
928
          } 
929
 
930
          buildFile++;
814 mhunt 931
        }
898 mhunt 932
      } while( !allProcessed );
933
    }
934
    finally
866 mhunt 935
    {
4123 dpurdie 936
mLogger.warn("planRelease finally");
898 mhunt 937
      // this block is executed regardless of what happens in the try block
938
      // even if an exception is thrown
939
      // ensure the SELECT FOR UPDATE is released
940
      if ( mDaemon )
866 mhunt 941
      {
898 mhunt 942
        // attempt to release the SELECT FOR UPDATE through a commit
943
        // a commit must be done in the normal case
944
        // a commit may as well be done in the Exception case
945
        // in the case of a SQLException indicating database connectivity has been lost
946
        // having a go at the commit is superfluous
947
        // as the SELECT FOR UPDATE will have been released upon disconnection
948
        mReleaseManager.releaseMutex();
4123 dpurdie 949
mLogger.warn("planRelease finally-1");
866 mhunt 950
      }
898 mhunt 951
 
952
      // ensure disconnect
918 mhunt 953
      mReleaseManager.disconnectForPlanning(highProbabilityBuildRequirement);
4123 dpurdie 954
mLogger.warn("planRelease finally-2");
866 mhunt 955
    }
956
 
814 mhunt 957
    mLogger.warn("planRelease mDaemon " + mDaemon + " returned");
958
  }
959
 
908 mhunt 960
  /**reports what change in build exceptions happens as part of planRelease
961
   */
962
  public void reportChange() throws SQLException, Exception
963
  {
964
    for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
965
    {
966
      BuildExclusion buildExclusion = it.next();
967
 
968
      if ( !buildExclusion.isProcessed() )
969
      {
970
        // notify
971
        buildExclusion.excludeFromBuild(mReleaseManager, mBaseline);
972
        buildExclusion.email(mPackageCollection, mMailServer, mMailSender, mBaselineName, mReleaseManager);
973
      }
974
    }
975
  }
976
 
814 mhunt 977
  /**returns first build file content
978
   * returns false if no build file content exists
979
   */
980
  public boolean getFirstBuildFileContent(MutableString content)
981
  {
982
    mLogger.debug("getFirstBuildFileContent");
983
    boolean retVal = true;
984
 
985
    try
986
    {
987
      mBuildIndex = 0;
988
      content.value = (String)mBuildCollection.get( mBuildIndex );
989
    }
990
    catch( ArrayIndexOutOfBoundsException e )
991
    {
992
      retVal = false;
993
    }
994
 
995
    mLogger.info("getFirstBuildFileContent returned " + retVal);
996
    return retVal;
997
  }
998
 
999
  /**returns next build file content
1000
   * returns false if no next build file content exists
1001
   */
1002
  public boolean getNextBuildFileContent(MutableString content)
1003
  {
1004
    mLogger.debug("getNextBuildFileContent");
1005
    boolean retVal = true;
1006
 
1007
    try
1008
    {
1009
      mBuildIndex++;
1010
      content.value = (String)mBuildCollection.get( mBuildIndex );
1011
    }
1012
    catch( ArrayIndexOutOfBoundsException e )
1013
    {
1014
      retVal = false;
1015
    }
1016
 
1017
    mLogger.debug("getNextBuildFileContent returned " + retVal);
1018
    return retVal;
1019
  }
1020
 
1021
  /**collects meta data associated with the baseline
868 mhunt 1022
   * this is sufficient to send an indefinite pause email notification
814 mhunt 1023
   */
868 mhunt 1024
  public void collectMetaData() throws SQLException, Exception
814 mhunt 1025
  {
1026
    mLogger.debug("collectMetaData mDaemon " + mDaemon);
1027
    mGbeMachtypeCollection.removeAllElements();
898 mhunt 1028
 
1029
    try
814 mhunt 1030
    {
898 mhunt 1031
      mReleaseManager.connect();
1032
      mReleaseManager.queryMachtypes(mGbeMachtypeCollection, mDaemon, mBaseline);
1033
 
1034
      if (mDaemon)
1035
      {
1036
        mMailServer = mReleaseManager.queryMailServer();
1037
        mMailSender = mReleaseManager.queryMailSender();
1038
        mGlobalTarget = mReleaseManager.queryGlobalAddresses();
1039
      }
1040
      mBaselineName = mReleaseManager.queryBaselineName(mDaemon, mBaseline);
814 mhunt 1041
    }
898 mhunt 1042
    finally
1043
    {
1044
      // this block is executed regardless of what happens in the try block
1045
      // even if an exception is thrown
1046
      // ensure disconnect
1047
      mReleaseManager.disconnect();
1048
    }
814 mhunt 1049
  }
1050
 
1051
  /**returns the Package with the matching mAlias or NULL_PACKAGE if no package has the mID
1052
   */
908 mhunt 1053
  public Package findPackage(String alias)
814 mhunt 1054
  {
1055
    mLogger.debug("findPackage");
1056
    Package retVal = ReleaseManager.NULL_PACKAGE;
1057
 
864 mhunt 1058
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1059
    {
864 mhunt 1060
      Package p = it.next();
814 mhunt 1061
 
1062
      if ( p.mAlias.compareTo( alias ) == 0 )
1063
      {
1064
        retVal = p;
1065
        break;
1066
      }
1067
    }
1068
 
1069
    mLogger.info("findPackage returned " + retVal.mName);
1070
    return retVal;
1071
  }
1072
 
1073
  /**sets the mBuildFile to -5 for the package and all dependent packages
1074
   */
900 mhunt 1075
  private void rippleBuildExclude(Package p, int root_pv_id, String root_cause, ListIterator<BuildExclusion> list, BuildExclusion be )
814 mhunt 1076
  {
1077
    mLogger.debug("rippleBuildExclude");
874 mhunt 1078
    if ( p.mBuildFile == 0 || p.mBuildFile == 1 )
814 mhunt 1079
    {
1080
      p.mBuildFile = -5;
894 mhunt 1081
      mLogger.info("rippleBuildExclude set mBuildFile to -5 for package " + p.mAlias );
866 mhunt 1082
 
900 mhunt 1083
      if ( be != null )
866 mhunt 1084
      {
900 mhunt 1085
        be.process();
866 mhunt 1086
      }
900 mhunt 1087
      else
866 mhunt 1088
      {
900 mhunt 1089
        // if found, process it, else add it (unprocessed)
1090
        boolean found = false;
866 mhunt 1091
        for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1092
        {
1093
          BuildExclusion buildExclusion = it.next();
836 mhunt 1094
 
900 mhunt 1095
          if ( buildExclusion.compare(p.mId, root_pv_id, root_cause))
866 mhunt 1096
          {
900 mhunt 1097
            found = true;
866 mhunt 1098
            buildExclusion.process();
900 mhunt 1099
            break;
866 mhunt 1100
          }
1101
        }
1102
 
900 mhunt 1103
        if (!found)
866 mhunt 1104
        {
900 mhunt 1105
          // process all occurrences for this package
1106
          // these will be superceded by a new build exclusion entry
1107
          for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
814 mhunt 1108
          {
900 mhunt 1109
            BuildExclusion buildExclusion = it.next();
814 mhunt 1110
 
900 mhunt 1111
            if ( buildExclusion.compare(p.mId))
814 mhunt 1112
            {
900 mhunt 1113
              buildExclusion.process();
814 mhunt 1114
            }
1115
          }
900 mhunt 1116
 
908 mhunt 1117
          BuildExclusion buildExclusion = new BuildExclusion(p.mId, root_pv_id, root_cause, p.mTestBuildInstruction);
900 mhunt 1118
 
1119
          if ( list == null )
1120
          {
1121
            mBuildExclusionCollection.add(buildExclusion);
1122
          }
1123
          else
1124
          {
1125
            // must use the ListIterator interface to add to the collection whilst iterating through it
1126
            list.add(buildExclusion);
1127
          }
814 mhunt 1128
        }
1129
      }
1130
 
908 mhunt 1131
      // only ripple a test build failure through for non test builds
1132
      if ( p.mTestBuildInstruction == 0 )
866 mhunt 1133
      {
908 mhunt 1134
        // non test build
1135
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
866 mhunt 1136
        {
908 mhunt 1137
          Package pkg = it.next();
1138
 
1139
          if ( pkg != p )
866 mhunt 1140
          {
908 mhunt 1141
            for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
866 mhunt 1142
            {
908 mhunt 1143
              Package dependency = it2.next();
1144
 
1145
              if ( dependency == p )
1146
              {
1147
                rippleBuildExclude( pkg, root_pv_id, null, list, null );
1148
                break;
1149
              }
866 mhunt 1150
            }
1151
          }
1152
        }
1153
      }
1154
    }
1155
    mLogger.info("rippleBuildExclude set " + p.mName + " " + p.mBuildFile);
1156
  }
1157
 
924 dpurdie 1158
  public String escapeXml( String xml )
1159
  {
1160
    xml = xml.replaceAll("&", "&amp;");
1161
    xml = xml.replaceAll("<", "&lt;");
1162
    xml = xml.replaceAll(">", "&gt;");
1163
    xml = xml.replaceAll("\"","&quot;");
1164
    xml = xml.replaceAll("'", "&apos;");
1165
    xml = xml.replaceAll("\\$", "\\$\\$");
1166
 
1167
    return xml;
1168
  }
1169
 
814 mhunt 1170
  /**returns a build file header for the mBaseline
1171
   */
1172
  private String generateBuildFileHeader()
1173
  {
1174
    mLogger.debug("generateBuildFileHeader");
1175
    String lf = new String( System.getProperty("line.separator") );
1176
    String retVal = new String("");
1177
    retVal +=
862 mhunt 1178
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + lf +
814 mhunt 1179
    "<project name=\"mass\" default=\"full\" basedir=\".\">" + lf;
1180
 
1181
    if ( mDaemon )
1182
    {
1183
      retVal +=
1184
      "<property name=\"abt_mail_server\" value=\"" + mMailServer + "\"/>" + lf +
1185
      "<property name=\"abt_mail_sender\" value=\"" + mMailSender + "\"/>" + lf +
1186
      "<property name=\"abt_rtag_id\" value=\"" + mBaseline + "\"/>" + lf +
1187
      "<property name=\"abt_daemon\" value=\"" + mTimestamp + "\"/>" + lf;
866 mhunt 1188
 
1189
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
1190
      {
1191
        Package p = it.next();
1192
 
1193
        if ( p.mBuildFile == 1 )
1194
        {
1195
          retVal +=
1196
          "<property name=\"abt_package_name\" value=\"" + p.mName + "\"/>" + lf +
1197
          "<property name=\"abt_package_version\" value=\"" + p.mVersion + p.mExtension + "\"/>" + lf +
1198
          "<property name=\"abt_package_extension\" value=\"" + p.mExtension + "\"/>" + lf +
1199
          loc(p, "abt_package_location", lf) +
1200
          "<property name=\"abt_package_depends\" value=\"";
1201
 
1202
          // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
1203
          String depends = new String();
1204
 
1205
          for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
1206
          {
1207
            Package depend = it3.next();
1208
 
1209
            if ( depends.compareTo( "" ) != 0 )
1210
            {
1211
              depends += ";";
1212
            }
1213
            depends += "\'" + depend.mName + "\'";
1214
            depends += ",";
1215
            String dependsExtension = depend.mExtension;
1216
            String dependsVersion = depend.mVersion;
1217
 
1218
            if ( dependsExtension.length() > 0 )
1219
            {
1220
              dependsVersion += dependsExtension;
1221
            }
1222
            else
1223
            {
1224
              dependsExtension = ".";
1225
            }
1226
            depends += "\'" + dependsVersion + "\'";
1227
          }
1228
 
1229
          retVal += depends + "\"/>" + lf +
1230
          "<property name=\"abt_is_ripple\" value=\"";
1231
 
1232
          if ( p.mDirectlyPlanned )
1233
          {
1234
            retVal += "0";
1235
          }
1236
          else
1237
          {
1238
            retVal += "1";
1239
          }
1240
 
1241
          retVal += "\"/>" + lf +
1242
          "<property name=\"abt_package_version_id\" value=\"" + p.mId + "\"/>" + lf +
1243
          "<property name=\"abt_does_not_require_source_control_interaction\" value=\"";
1244
 
1245
          if ( ! p.mRequiresSourceControlInteraction )
1246
          {
1247
            retVal += "true";
1248
          }
1249
          else
1250
          {
1251
            retVal += "false";
1252
          }
1253
 
908 mhunt 1254
          retVal += "\"/>" + lf +
1255
          "<property name=\"abt_test_build_instruction\" value=\"" + p.mTestBuildInstruction + "\"/>" + lf;
866 mhunt 1256
        }
1257
      }
814 mhunt 1258
    }
1259
    else
1260
    {
1261
      retVal +=
1262
      "<property name=\"abt_rtag_id\" value=\"-1\"/>" + lf;
1263
    }
1264
 
822 mhunt 1265
    String majorVersionNumber = this.getClass().getPackage().getSpecificationVersion();
1266
 
864 mhunt 1267
    if ( !ReleaseManager.mUseDatabase )
822 mhunt 1268
    {
1269
        // hard code 11 for unit test purposes
1270
         majorVersionNumber = "11";
1271
    }
1272
 
814 mhunt 1273
    retVal +=
924 dpurdie 1274
    "<property name=\"abt_release\" value=\"" + escapeXml(mBaselineName) + "\"/>" + lf +
822 mhunt 1275
    "<property name=\"abt_buildtool_version\" value=\""+ majorVersionNumber + "\"/>" + lf +
814 mhunt 1276
    "<condition property=\"abt_family\" value=\"windows\">" + lf +
1277
    "  <os family=\"windows\"/>" + lf +
1278
    "</condition>" + lf +
1279
    "<property name=\"abt_family\" value=\"unix\"/>" + lf;
1280
    mLogger.info("generateBuildFileHeader returned " + retVal);
1281
    return retVal;
1282
  }
1283
 
1284
  /**returns an ant property for the passed Package
1285
   */
1286
  private String generatePackageProperty(Package p)
1287
  {
1288
    mLogger.debug("generatePackageProperty");
1289
    String lf = new String( System.getProperty("line.separator") );
1290
    String retVal = new String("");
1291
    retVal +=
4280 dpurdie 1292
    "  <property name=\"" + p.mAlias + "\" value=\"" + p.mName + " " + p.mVersion + p.mExtension + "\"/>" + lf;
814 mhunt 1293
    mLogger.info("generatePackageProperty returned " + retVal);
1294
    return retVal;
1295
  }
1296
 
1297
  /**returns an ant taskdef for the abt ant task
1298
   */
1299
  private String generateTaskdef()
1300
  {
1301
    mLogger.debug("generateTaskdef");
1302
    String lf = new String( System.getProperty("line.separator") );
1303
    String retVal = new String("");
4280 dpurdie 1304
    retVal += "<taskdef name=\"abt\" classname=\"com.erggroup.buildtool.abt.ABT\"/>" + lf;
1305
 
1306
    //  The ABTData class is only used in Daemon Mode
1307
    if ( mDaemon ) {
1308
      retVal += "<taskdef name=\"abtdata\" classname=\"com.erggroup.buildtool.abt.ABTData\"/>" + lf;
1309
    }
814 mhunt 1310
    return retVal;
1311
  }
1312
 
4280 dpurdie 1313
  /** returns the command abtdata items
1314
   *  Common machine information
1315
   *  Common email address
1316
   */
1317
  private String generateMachineInfo(Package p, String lf)
1318
  {
1319
    String  retVal = new String("");
1320
    retVal += "<abtdata>" + lf;
1321
 
1322
    //
1323
    //  Iterate over all the machines and create a nice entry
1324
    //
1325
    for (Iterator<ReleaseConfig> it = mReleaseManager.mReleaseConfigCollection.iterator(); it.hasNext(); )
1326
    {
1327
      ReleaseConfig rc = it.next();
1328
      retVal += "  " + rc.getMachineEntry() + lf;
1329
    }
1330
 
1331
    //
1332
    //  Now the email information
1333
    //
1334
    retVal += p.emailInfo( lf );
1335
 
1336
    // End of this element
1337
    retVal += "</abtdata>" + lf;
1338
    return retVal;
1339
  }
1340
 
814 mhunt 1341
  /**returns an ant target for the passed Package
1342
   * in daemon mode:
1343
   *  packages are categorised with one of three mBuildFile values:
1344
   *   1 the package to be built by this buildfile
1345
   *   2 the packages with a future build requirement
1346
   *   3 the packages with no build requirement
1347
   *  the returned target depends on this categorisation and will have
1348
   *   1 full abt info
1349
   *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
1350
   *   3 only a name attribute (will not build this package)
1351
   * in escrow mode:
1352
   *  if the passed Package's mBuildFile is different (less than) the passed build file,
1353
   *  the returned target have only a name attribute (will not build this package) 
1354
   */
1355
  private String generateTarget(Package p, int buildFile)
1356
  {
1357
    mLogger.debug("generateTarget");
4280 dpurdie 1358
    String lf = new String( System.getProperty("line.separator") );
1359
    String retVal = new String("");
814 mhunt 1360
 
4280 dpurdie 1361
    //-------------------------------------------------------------------------
1362
    //  Generate a collection of 'BuildStandard's
1363
    //
832 mhunt 1364
    if ( ( mDaemon && p.mBuildFile == 1 ) || ( !mDaemon && !p.isGeneric() ) )
814 mhunt 1365
    {
1366
      // populate 'missing' BuildStandards
1367
      boolean solaris = false;
1368
      boolean linux = false;
1369
      boolean win32 = false;
1370
      boolean jats = false;
1371
      boolean determinedBuildStandard = false;
1372
 
864 mhunt 1373
      for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 1374
      {
864 mhunt 1375
        BuildStandard bs = it.next();
814 mhunt 1376
 
1377
        if ( bs.getSolaris() )
1378
        {
1379
          solaris = true;
1380
        }
4280 dpurdie 1381
        else if ( bs.getLinux() )
814 mhunt 1382
        {
1383
          linux = true;
1384
        }
4280 dpurdie 1385
        else if ( bs.getWin32() )
814 mhunt 1386
        {
1387
          win32 = true;
1388
        }
1389
 
908 mhunt 1390
        if ( !determinedBuildStandard && bs.getBuildStandard(!ReleaseManager.mUseDatabase, true).contains("<jats") )
814 mhunt 1391
        {
1392
          jats = true;
1393
          determinedBuildStandard = true;
1394
        }
1395
      }
1396
 
1397
      if ( !solaris )
1398
      {
1399
        BuildStandard bs = new BuildStandard(this);
1400
        bs.setSolaris();
1401
 
1402
        if ( jats )
1403
        {
1404
          bs.setJatsNone();
1405
        }
1406
        else
1407
        {
1408
          bs.setAntNone();
1409
        }
1410
 
1411
        p.mBuildStandardCollection.add(bs);
1412
      }
1413
 
1414
      if ( !linux )
1415
      {
1416
        BuildStandard bs = new BuildStandard(this);
1417
        bs.setLinux();
1418
 
1419
        if ( jats )
1420
        {
1421
          bs.setJatsNone();
1422
        }
1423
        else
1424
        {
1425
          bs.setAntNone();
1426
        }
1427
 
1428
        p.mBuildStandardCollection.add(bs);
1429
      }
1430
 
1431
      if ( !win32 )
1432
      {
1433
        BuildStandard bs = new BuildStandard(this);
1434
        bs.setWin32();
1435
 
1436
        if ( jats )
1437
        {
1438
          bs.setJatsNone();
1439
        }
1440
        else
1441
        {
1442
          bs.setAntNone();
1443
        }
1444
 
1445
        p.mBuildStandardCollection.add(bs);
1446
      }
1447
    }
4280 dpurdie 1448
 
1449
    //---------------------------------------------------------------------
1450
    //  Generate the AbtData - common machine and email information
1451
    //  Only used by the daemon builds
1452
    //
1453
    if ( mDaemon && p.mBuildFile == 1 )
1454
    {
1455
      retVal += generateMachineInfo(p, lf);
1456
    }
814 mhunt 1457
 
4280 dpurdie 1458
    //-------------------------------------------------------------------------
1459
    //  Generate the <target name=... /> construct
1460
    //  There are two types
1461
    //      1) Simple dummy place holder. Just has the PackageName.PackageExt
1462
    //      2) Full target. Has all information to build the package including
1463
    //              AbtSetUp, AbtTearDown and AbtPublish targets
1464
    //
814 mhunt 1465
 
1466
    if ( ( mDaemon && p.mBuildFile == 3 ) ||
1467
         ( !mDaemon && ( p.mBuildFile < buildFile ) ) )
1468
    {
1469
      retVal +=
1470
      "<target name=\"" + p.mAlias + "\"/>" + lf;
1471
    }
1472
    else
1473
    {
848 dpurdie 1474
      retVal +=
814 mhunt 1475
      "<target name=\"" + p.mAlias + ".wrap\"";
1476
 
1477
      if ( p.mPackageDependencyCollection.size() > 0 )
1478
      {
1479
        retVal +=" depends=\"";
1480
        boolean comma = false;
1481
 
864 mhunt 1482
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1483
        {
906 mhunt 1484
          Package dependency = it.next();
1485
          // DEVI 54816
1486
          if ( !mDaemon && dependency.mBuildFile == -2 )
1487
          {
1488
            // ignore targets which build in foreign environments in escrow mode
1489
            continue;
1490
          }
814 mhunt 1491
          if (comma)
1492
          {
1493
            retVal += ",";
1494
          }
1495
          comma = true;
1496
 
1497
          retVal += dependency.mAlias;
1498
        }
1499
 
1500
        retVal += "\"";
1501
      }
1502
      retVal += ">" + lf;
1503
 
1504
      if ( !mDaemon )
1505
      {
1506
        boolean hasDependenciesBuiltInThisIteration = false;
1507
        if ( ( p.mPackageDependencyCollection.size() > 0 ) )
1508
        {
864 mhunt 1509
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1510
          {
864 mhunt 1511
            Package dependency = it.next();
814 mhunt 1512
 
1513
            if ( dependency.mBuildFile == buildFile )
1514
            {
1515
              hasDependenciesBuiltInThisIteration = true;
1516
              break;
1517
            }
1518
          }
1519
        }
1520
 
1521
        if ( hasDependenciesBuiltInThisIteration )
1522
        {
1523
          retVal +=
1524
          "  <condition property=\"" + p.mAlias + ".build\">" + lf +
1525
          "    <and>" + lf;
1526
 
864 mhunt 1527
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1528
          {
864 mhunt 1529
            Package dependency = it.next();
814 mhunt 1530
 
1531
            if ( dependency.mBuildFile == buildFile )
1532
            {
1533
              retVal +=
1534
              "      <or>" + lf +
1535
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"0\"/>" + lf +
1536
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"257\"/>" + lf +
1537
              "      </or>" + lf;
1538
            }
1539
          }
1540
 
1541
          retVal +=
1542
          "    </and>" + lf +
1543
          "  </condition>" + lf;
1544
        }
1545
        else
1546
        {
4280 dpurdie 1547
          retVal += "    <property name=\"" + p.mAlias + ".build\" value=\"\"/>" + lf;
814 mhunt 1548
        }
1549
      }
1550
 
1551
      retVal +=
1552
      "</target>" + lf +
1553
      "<target name=\"" + p.mAlias + "\" depends=\"" + p.mAlias + ".wrap\"";
1554
 
1555
      if ( !mDaemon )
1556
      {
1557
        retVal += " if=\"" + p.mAlias + ".build\"";
1558
      }
1559
 
1560
      retVal += ">" + lf;
1561
 
1562
      if ( mDaemon && p.mBuildFile == 1 )
1563
      {
1564
        retVal +=
4280 dpurdie 1565
        "  <property name=\"" + p.mAlias + "pkg_id\" value=\"" + p.mPid + "\"/>" + lf +
1566
        "  <property name=\"" + p.mAlias + "pv_id\" value=\"" + p.mId + "\"/>" + lf;
814 mhunt 1567
      }
1568
 
1569
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1570
      {
1571
        retVal +=
4280 dpurdie 1572
        "  <property name=\"" + p.mAlias + "packagename\" value=\"" + p.mName + "\"/>" + lf +
1573
        "  <property name=\"" + p.mAlias + "packageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1574
        "  <property name=\"" + p.mAlias + "packageextension\" value=\"" + p.mExtension + "\"/>" + lf +
1575
        "  <property name=\"" + p.mAlias + "packagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf;
814 mhunt 1576
 
1577
        if ( p.mDirectlyPlanned )
1578
        {
4280 dpurdie 1579
          retVal += "  <property name=\"" + p.mAlias + "directchange\" value=\"\"/>" + lf;
814 mhunt 1580
        }
1581
 
852 mhunt 1582
        if ( ! p.mRequiresSourceControlInteraction )
1583
        {
4280 dpurdie 1584
          retVal += "  <property name=\"" + p.mAlias + "doesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
852 mhunt 1585
        }
1586
 
814 mhunt 1587
        mAddendum = "non generic";
1588
 
1589
        if ( p.isGeneric() )
1590
        {
1591
          mAddendum = "generic";
4280 dpurdie 1592
          retVal += "  <property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
814 mhunt 1593
        }
1594
 
4280 dpurdie 1595
        retVal += "  " + loc(p, p.mAlias + "loc", lf);
814 mhunt 1596
 
830 mhunt 1597
        if ( p.mHasAutomatedUnitTests && mDaemon )
814 mhunt 1598
        {
1599
          retVal += 
4280 dpurdie 1600
          "  <property name=\"" + p.mAlias + "unittests\" value=\"\"/>" + lf;
814 mhunt 1601
        }
1602
      }
1603
 
4280 dpurdie 1604
      //    Add our own task and associated information
1605
      //
1606
      retVal += "  <abt>" + lf;
814 mhunt 1607
 
1608
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1609
      {
864 mhunt 1610
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1611
        {
864 mhunt 1612
          Package dependency = it.next();
814 mhunt 1613
          retVal +=
4280 dpurdie 1614
          "    <depend package_alias=\"${" + dependency.mAlias + "}\"/>" + lf;
814 mhunt 1615
        }
1616
 
836 mhunt 1617
        retVal += buildInfo(p, lf, false);
814 mhunt 1618
      }
1619
 
4280 dpurdie 1620
      retVal += "  </abt>" + lf +
814 mhunt 1621
      "</target>" + lf;
1622
 
1623
      if ( mDaemon && p.mBuildFile == 1 )
1624
      {
4280 dpurdie 1625
        //    AbtSetUp
814 mhunt 1626
        retVal +=
4280 dpurdie 1627
            "<target name=\"AbtSetUp\">" + lf +
1628
            "  <property name=\"AbtSetUppackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
1629
            "  <property name=\"AbtSetUppackagename\" value=\"" + p.mName + "\"/>" + lf;
814 mhunt 1630
 
1631
        retVal +=
4280 dpurdie 1632
            "  <abt>" + lf +
1633
            "  </abt>" + lf +
1634
            "  </target>" + lf;
872 dpurdie 1635
 
4280 dpurdie 1636
        //    AbtTearDown
872 dpurdie 1637
        retVal +=
4280 dpurdie 1638
            "<target name=\"AbtTearDown\">" + lf +
1639
            "  <property name=\"AbtTearDownpackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
1640
            "  <property name=\"AbtTearDownpackagename\" value=\"" + p.mName + "\"/>" + lf +
1641
            "  <property name=\"AbtTearDownpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1642
            "  <property name=\"AbtTearDownpackageextension\" value=\"" + p.mExtension + "\"/>" + lf;
814 mhunt 1643
 
1644
        if ( p.isGeneric() )
1645
        {
4280 dpurdie 1646
          retVal += "  <property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
814 mhunt 1647
        }
1648
 
1649
        retVal +=        
4280 dpurdie 1650
            "  <abt>" + lf +
1651
            buildInfo(p, lf, false) +
1652
            "  </abt>" + lf +
1653
            "</target>" + lf;
1654
 
1655
        //  AbtPublish  
1656
        retVal +=        
1657
            "<target name=\"AbtPublish\">" + lf +
1658
            "  <property name=\"AbtPublishpackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
1659
            "  <property name=\"AbtPublishpackagename\" value=\"" + p.mName + "\"/>" + lf +
1660
            "  <property name=\"AbtPublishpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1661
            "  <property name=\"AbtPublishpackageextension\" value=\"" + p.mExtension + "\"/>" + lf;
814 mhunt 1662
 
4280 dpurdie 1663
 
814 mhunt 1664
        if ( p.mDirectlyPlanned )
1665
        {
4280 dpurdie 1666
          retVal += "  <property name=\"AbtPublishdirectchange\" value=\"\"/>" + lf;
814 mhunt 1667
        }
1668
 
852 mhunt 1669
        if ( ! p.mRequiresSourceControlInteraction )
1670
        {
4280 dpurdie 1671
          retVal += "  <property name=\"AbtPublishdoesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
852 mhunt 1672
        }
1673
 
814 mhunt 1674
        if ( p.isGeneric() )
1675
        {
4280 dpurdie 1676
          retVal += "  <property name=\"AbtPublishgeneric\" value=\"\"/>" + lf;
814 mhunt 1677
        }
1678
 
4280 dpurdie 1679
        retVal += "  " + loc(p, "AbtPublishloc", lf);
814 mhunt 1680
        retVal +=
4280 dpurdie 1681
            "  <abt>" + lf +
1682
            buildInfo(p, lf, true) +
1683
            "  </abt>" + lf +
1684
            "</target>" + lf;
814 mhunt 1685
      }
1686
    }
1687
    mLogger.info("generateTarget returned " + retVal);
1688
    return retVal;
1689
  }
1690
 
1691
  /**returns an ant default target for the current build iteration
1692
   */
1693
  private String generateDefaultTarget(int buildFile)
1694
  {
1695
    mLogger.debug("generateDefaultTarget");
1696
    String lf = new String( System.getProperty("line.separator") );
1697
    String retVal = new String("");
1698
    retVal +=
1699
    "<target name=\"fullstart\">" + lf;
1700
 
1701
    if (buildFile == 1)
1702
    {
1703
      retVal +=
906 mhunt 1704
      "<echo message=\"${line.separator}" + mAnyBuildPlatforms + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1705
 
864 mhunt 1706
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1707
      {
864 mhunt 1708
        Package p = it.next();
814 mhunt 1709
 
1710
        if ( p.mBuildFile == -1 )
1711
        {
1712
          retVal +=
1713
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1714
        }
1715
      }
1716
 
1717
      retVal +=
906 mhunt 1718
      "<echo message=\"${line.separator}" + mAssocBuildPlatforms + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1719
 
864 mhunt 1720
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1721
      {
864 mhunt 1722
        Package p = it.next();
814 mhunt 1723
 
1724
        if ( p.mBuildFile == -2 )
1725
        {
1726
          retVal +=
1727
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1728
        }
1729
      }
1730
 
1731
      retVal +=
906 mhunt 1732
      "<echo message=\"${line.separator}" + mNotInBaseline + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1733
 
864 mhunt 1734
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1735
      {
864 mhunt 1736
        Package p = it.next();
814 mhunt 1737
 
1738
        if ( p.mBuildFile == -4 )
1739
        {
1740
          retVal +=
1741
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1742
        }
1743
      }
1744
 
1745
      retVal +=
906 mhunt 1746
      "<echo message=\"${line.separator}" + mDependent + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1747
 
864 mhunt 1748
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1749
      {
864 mhunt 1750
        Package p = it.next();
814 mhunt 1751
 
1752
        if ( p.mBuildFile == -5 )
1753
        {
1754
          retVal +=
1755
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1756
        }
1757
      }
1758
    }
1759
    if ( !mDaemon )
1760
    {
1761
      retVal +=
1762
      "<echo message=\"${line.separator}Build Started:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1763
    }
1764
 
1765
    retVal +=
1766
    "</target>" + lf +
1767
    "<target name=\"full\" depends=\"fullstart";
1768
 
864 mhunt 1769
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1770
    {
864 mhunt 1771
      Package p = it.next();
814 mhunt 1772
 
1773
      if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
1774
      {
1775
        retVal += "," + p.mAlias;
1776
      }
1777
    }
1778
 
1779
    retVal +=
1780
    "\">" + lf;
1781
 
1782
    if ( !mDaemon )
1783
    {
1784
      retVal +=
1785
      "<echo message=\"${line.separator}Build Finished${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1786
    }
1787
 
1788
    retVal +=
1789
    "</target>" + lf;
1790
    return retVal;
1791
  }
1792
 
1793
  /**returns a build file footer
1794
   */
1795
  private String generateBuildFileFooter()
1796
  {
1797
    mLogger.debug("generateBuildFileFooter");
1798
    String retVal = new String("</project>");
1799
    return retVal;
1800
  }
1801
 
1802
  /**sets the mIndirectlyPlanned true for the package and all dependent packages
1803
   */
1804
  private void rippleIndirectlyPlanned(Package p)
1805
  {
1806
    mLogger.debug("rippleIndirectlyPlanned");
1807
    if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
1808
    {
1809
      p.mIndirectlyPlanned = true;
1810
 
864 mhunt 1811
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1812
      {
864 mhunt 1813
        Package pkg = it.next();
814 mhunt 1814
 
1815
        if ( pkg != p )
1816
        {
864 mhunt 1817
          for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 1818
          {
864 mhunt 1819
            Package dependency = it2.next();
814 mhunt 1820
 
1821
            if ( dependency == p )
1822
            {
1823
              rippleIndirectlyPlanned( pkg );
1824
              break;
1825
            }
1826
          }
1827
        }
1828
      }
1829
    }
1830
    mLogger.info("rippleIndirectlyPlanned set " + p.mName + " " + p.mIndirectlyPlanned);    
1831
  }
1832
 
1833
  /**accessor method
1834
   */
830 mhunt 1835
  public String getESCROWSetUp()
814 mhunt 1836
  {
830 mhunt 1837
    mLogger.debug("getESCROWSetUp");
814 mhunt 1838
    String retVal = new String("");
1839
 
1840
    try
1841
    {
924 dpurdie 1842
      if ( mEscrowSupportCollection.size() >= 1 )
814 mhunt 1843
      {
924 dpurdie 1844
        retVal = (String)mEscrowSupportCollection.get(0);
814 mhunt 1845
      }
1846
    }
1847
    catch( ArrayIndexOutOfBoundsException e )
1848
    {
1849
    }
1850
 
830 mhunt 1851
    mLogger.info("getESCROWSetUp returned " + retVal);
814 mhunt 1852
    return retVal;
1853
  }
1854
 
1855
  /**accessor method
1856
   */
830 mhunt 1857
  public String getRawData()
814 mhunt 1858
  {
830 mhunt 1859
    mLogger.debug("getRawData");
814 mhunt 1860
    String retVal = new String("");
1861
 
1862
    try
1863
    {
924 dpurdie 1864
      if ( mEscrowSupportCollection.size() >= 2 )
814 mhunt 1865
      {
924 dpurdie 1866
        retVal = (String)mEscrowSupportCollection.get(1);
814 mhunt 1867
      }
1868
    }
1869
    catch( ArrayIndexOutOfBoundsException e )
1870
    {
1871
    }
1872
 
830 mhunt 1873
    mLogger.info("getRawData returned " + retVal);
814 mhunt 1874
    return retVal;
1875
  }
1876
 
1877
  /**returns first build file content and addendum
1878
   * the addendum value is one of "non generic", "generic" or "dummy"
1879
   */
1880
  public void getFirstBuildFileContent(MutableString content, 
1881
                                MutableString addendum)
1882
  {
1883
    mLogger.debug("getFirstBuildFileContent");
1884
    try
1885
    {
1886
      mBuildIndex = 0;
1887
      content.value = (String)mBuildCollection.get( mBuildIndex );
1888
      addendum.value = mAddendum;
1889
    }
1890
    catch( ArrayIndexOutOfBoundsException e )
1891
    {
1892
    }
1893
    mLogger.info("getFirstBuildFileContent passed " + content.value + addendum.value);
1894
  }
1895
 
872 dpurdie 1896
  /**returns the build loc
814 mhunt 1897
   */
1898
  private String loc(Package p, String target, String lf)
1899
  {
1900
    mLogger.debug("loc");
1901
    String retVal = new String();
872 dpurdie 1902
    String loc = new String("/");
1903
 
1904
    if (mDaemon)
814 mhunt 1905
    {
872 dpurdie 1906
      // Daemon: Start in root of view/workspace
924 dpurdie 1907
      loc += mBaseline;
814 mhunt 1908
    }
872 dpurdie 1909
    else
814 mhunt 1910
    {
872 dpurdie 1911
      // mAlias used with jats -extractfiles -view
1912
      loc += p.mAlias;
1913
    }
814 mhunt 1914
 
872 dpurdie 1915
    //
1916
    //  Always use '/' as a path seperator - even if user has specified '\'
1917
    //  Ant can handle it.
1918
    //
814 mhunt 1919
    loc = loc.replace('\\', '/');
1920
    retVal += 
1921
    "<property name=\"" + target + "\" value=\"" + loc + "\"/>" + lf;
1922
 
1923
    mLogger.info("loc returned " + retVal);
1924
    return retVal;
1925
  }
816 mhunt 1926
 
4280 dpurdie 1927
  /**returns the buildInfo 
1928
   *    p       - Package to process
1929
   *    lf      - End of Line terminator
1930
   *    filter  - False: Include all build standards
1931
   *              True: Only include build standards relevent to the package
816 mhunt 1932
   */
836 mhunt 1933
  private String buildInfo(Package p, String lf, boolean filter)
816 mhunt 1934
  {
1935
    mLogger.debug("buildInfo");
1936
 
1937
    String platforms = new String();
1938
    String standards = new String();
1939
 
4280 dpurdie 1940
    //
1941
    //  Create two (related) xlm sequences
1942
    //      platforms - <platform gbe_machtype="linux_i386"/>
1943
    //      standards - <jats target="all"/>
1944
    //      
864 mhunt 1945
    for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
816 mhunt 1946
    {
864 mhunt 1947
      BuildStandard bs = it.next();
816 mhunt 1948
 
4280 dpurdie 1949
      if ( !filter  || !bs.getBuildStandard(!ReleaseManager.mUseDatabase, true).contains("\"none\"") )
816 mhunt 1950
      {
908 mhunt 1951
        String platform = bs.getPlatform(!ReleaseManager.mUseDatabase, true);
816 mhunt 1952
        if ( platform.length() > 0 )
1953
        {
1954
          platforms += platform + lf;
1955
        }
1956
 
908 mhunt 1957
        String standard = bs.getBuildStandard(!ReleaseManager.mUseDatabase, true);
816 mhunt 1958
        if ( standard.length() > 0 )
1959
        {
1960
          standards += standard + lf;
1961
        }
1962
      }
1963
    }
1964
 
1965
    mLogger.info("buildInfo returned " + platforms + standards);
1966
    return platforms + standards;
1967
  }
866 mhunt 1968
 
906 mhunt 1969
  /**prints to standard out in escrow mode only
1970
   */
1971
  private void standardOut(final String message, final String alias, boolean printMessage)
1972
  {
1973
    mLogger.debug("standardOut");
1974
    if (!mDaemon)
1975
    {
1976
      if ( printMessage )
1977
      {
1978
        System.out.println(message);
1979
        // switch the message off
1980
        printMessage = false;
1981
      }
1982
 
1983
      System.out.println(alias);
1984
    }
1985
  }
814 mhunt 1986
}