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
                }
753
                else
754
                if ( pvApplied == 2 )
755
                {
756
                  // max 50 chars
900 mhunt 757
                  rippleBuildExclude(p, p.mId, "Package has reached ripple field limitations", null, null);
898 mhunt 758
                }
759
                else
760
                {
761
                  buildFile = 2;
908 mhunt 762
 
763
                  if ( p.mForcedRippleInstruction > 0 )
764
                  {
765
                    mReleaseManager.markDaemonInstCompleted( p.mForcedRippleInstruction );
766
                  }
767
 
768
                  if ( p.mTestBuildInstruction > 0 )
769
                  {
770
                    mReleaseManager.markDaemonInstInProgress( p.mTestBuildInstruction );
771
                  }
898 mhunt 772
                }
874 mhunt 773
              }
774
              else
775
              {
898 mhunt 776
                mLogger.info("planRelease package has future (downgraded) build requirement " + p.mName + " " + buildFile);              
874 mhunt 777
              }
814 mhunt 778
            }
898 mhunt 779
          }
780
        }
781
 
782
        // are more build files required
783
        allProcessed = true;
784
 
785
        if (mDaemon)
786
        {
787
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
788
          {
789
            Package p = it.next();
790
 
791
            if ( p.mBuildFile < 0 || ( !p.mDirectlyPlanned && !p.mIndirectlyPlanned ) )
814 mhunt 792
            {
898 mhunt 793
              // at this point...
794
              // only 1 package with a build requirement has a mBuildFile of 1,
795
              // all other packages with a build requirement have an mBuildFile of 2
796
              // give packages with no build requirement, reproducible or not, an mBuildFile of 3
797
              p.mBuildFile = 3;
798
              mLogger.info("planRelease 1 set mBuildFile to 3 for package " + p.mAlias );
814 mhunt 799
            }
800
          }
801
        }
898 mhunt 802
        else
803
        {
804
          // this is escrow mode centric
805
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
806
          {
807
            Package p = it.next();
808
 
809
            if ( p.mBuildFile == 0 )
810
            {
811
              // more build files are required
812
              allProcessed = false;
813
              mLogger.info("planRelease more build files are required for " + p.mName);
814
              break;
815
            }
816
          }
817
 
818
          buildFile++;
819
        }
820
      } while( !allProcessed );
814 mhunt 821
 
898 mhunt 822
      // persist the build files
823
      allProcessed = false;
824
      buildFile = 1;
4123 dpurdie 825
mLogger.warn("planRelease process Remaining-3");
814 mhunt 826
 
898 mhunt 827
      if ( mDaemon )
814 mhunt 828
      {
898 mhunt 829
        // all interesting packages in daemon mode match the following filter
830
        buildFile = 3;
831
      }
832
 
833
      mTimestamp = System.currentTimeMillis();
834
 
835
      if ( !ReleaseManager.mUseDatabase )
836
      {
837
        mTimestamp = 123456789;
838
      }
839
 
840
      do
841
      {
842
        String buildFileContent = new String( generateBuildFileHeader() );
843
 
864 mhunt 844
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 845
        {
864 mhunt 846
          Package p = it.next();
906 mhunt 847
 
848
          // DEVI 54816
849
          // now set a packages mBuildFile to -2 in escrow mode, but do not ripple this through
850
          // its consumers need dependency package property info
851
          if ( ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) ) || ( !mDaemon && p.mBuildFile == -2 ) )
814 mhunt 852
          {
898 mhunt 853
            buildFileContent += generatePackageProperty(p);
814 mhunt 854
          }
855
        }
898 mhunt 856
 
857
        buildFileContent += generateTaskdef();
858
 
859
        String set_up = new String("");
860
        boolean daemonHasTarget = false;
861
 
864 mhunt 862
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 863
        {
864 mhunt 864
          Package p = it.next();
898 mhunt 865
 
866
          if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
814 mhunt 867
          {
898 mhunt 868
            buildFileContent += generateTarget(p, buildFile);
869
 
870
            if ( p.mBuildFile == 1 )
871
            {
872
              daemonHasTarget = true;
873
            }
814 mhunt 874
          }
866 mhunt 875
 
898 mhunt 876
          if ( !mDaemon && buildFile == 1 )
866 mhunt 877
          {
924 dpurdie 878
        	  set_up += "jats jats_vcsrelease -extractfiles"
879
                      + " \"-label=" + p.mVcsTag + "\""
898 mhunt 880
                      + " \"-view=" + p.mAlias + "\""
881
                      + " -root=. -noprefix"
882
                      + lf;
866 mhunt 883
          }
814 mhunt 884
        }
898 mhunt 885
 
886
        if ( mDaemon && !daemonHasTarget )
887
        {
888
          // must have AbtSetUp, AbtTearDown, and AbtPublish targets
889
          buildFileContent += "<target name=\"AbtSetUp\"/>" + lf +
890
                              "<target name=\"AbtTearDown\"/>" + lf +
891
                              "<target name=\"AbtPublish\"/>" + lf;
892
        }
814 mhunt 893
 
894
        if ( !mDaemon && buildFile == 1 )
895
        {
924 dpurdie 896
          mEscrowSupportCollection.add(set_up);
897
          mEscrowSupportCollection.add(raw_data);
898 mhunt 898
        }
899
 
900
        buildFileContent += generateDefaultTarget( buildFile);
901
        buildFileContent += generateBuildFileFooter();
902
 
903
        mBuildCollection.add(buildFileContent);
904
 
905
        // are more build files required
906
        allProcessed = true;
907
 
908
        if (!mDaemon)
909
        {
910
          // this is escrow mode centric
911
          for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
848 dpurdie 912
          {
898 mhunt 913
            Package p = it.next();
914
 
915
            if ( p.mBuildFile > buildFile )
916
            {
917
              // more build files are required
918
              allProcessed = false;
919
              mLogger.info("planRelease reiterating package has no build requirement " + p.mName + " " + p.mBuildFile + " " + buildFile);
920
              break;
921
            }
922
          } 
923
 
924
          buildFile++;
814 mhunt 925
        }
898 mhunt 926
      } while( !allProcessed );
927
    }
928
    finally
866 mhunt 929
    {
4123 dpurdie 930
mLogger.warn("planRelease finally");
898 mhunt 931
      // this block is executed regardless of what happens in the try block
932
      // even if an exception is thrown
933
      // ensure the SELECT FOR UPDATE is released
934
      if ( mDaemon )
866 mhunt 935
      {
898 mhunt 936
        // attempt to release the SELECT FOR UPDATE through a commit
937
        // a commit must be done in the normal case
938
        // a commit may as well be done in the Exception case
939
        // in the case of a SQLException indicating database connectivity has been lost
940
        // having a go at the commit is superfluous
941
        // as the SELECT FOR UPDATE will have been released upon disconnection
942
        mReleaseManager.releaseMutex();
4123 dpurdie 943
mLogger.warn("planRelease finally-1");
866 mhunt 944
      }
898 mhunt 945
 
946
      // ensure disconnect
918 mhunt 947
      mReleaseManager.disconnectForPlanning(highProbabilityBuildRequirement);
4123 dpurdie 948
mLogger.warn("planRelease finally-2");
866 mhunt 949
    }
950
 
814 mhunt 951
    mLogger.warn("planRelease mDaemon " + mDaemon + " returned");
952
  }
953
 
908 mhunt 954
  /**reports what change in build exceptions happens as part of planRelease
955
   */
956
  public void reportChange() throws SQLException, Exception
957
  {
958
    for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
959
    {
960
      BuildExclusion buildExclusion = it.next();
961
 
962
      if ( !buildExclusion.isProcessed() )
963
      {
964
        // notify
965
        buildExclusion.excludeFromBuild(mReleaseManager, mBaseline);
966
        buildExclusion.email(mPackageCollection, mMailServer, mMailSender, mBaselineName, mReleaseManager);
967
      }
968
    }
969
  }
970
 
814 mhunt 971
  /**returns first build file content
972
   * returns false if no build file content exists
973
   */
974
  public boolean getFirstBuildFileContent(MutableString content)
975
  {
976
    mLogger.debug("getFirstBuildFileContent");
977
    boolean retVal = true;
978
 
979
    try
980
    {
981
      mBuildIndex = 0;
982
      content.value = (String)mBuildCollection.get( mBuildIndex );
983
    }
984
    catch( ArrayIndexOutOfBoundsException e )
985
    {
986
      retVal = false;
987
    }
988
 
989
    mLogger.info("getFirstBuildFileContent returned " + retVal);
990
    return retVal;
991
  }
992
 
993
  /**returns next build file content
994
   * returns false if no next build file content exists
995
   */
996
  public boolean getNextBuildFileContent(MutableString content)
997
  {
998
    mLogger.debug("getNextBuildFileContent");
999
    boolean retVal = true;
1000
 
1001
    try
1002
    {
1003
      mBuildIndex++;
1004
      content.value = (String)mBuildCollection.get( mBuildIndex );
1005
    }
1006
    catch( ArrayIndexOutOfBoundsException e )
1007
    {
1008
      retVal = false;
1009
    }
1010
 
1011
    mLogger.debug("getNextBuildFileContent returned " + retVal);
1012
    return retVal;
1013
  }
1014
 
1015
  /**collects meta data associated with the baseline
868 mhunt 1016
   * this is sufficient to send an indefinite pause email notification
814 mhunt 1017
   */
868 mhunt 1018
  public void collectMetaData() throws SQLException, Exception
814 mhunt 1019
  {
1020
    mLogger.debug("collectMetaData mDaemon " + mDaemon);
1021
    mGbeMachtypeCollection.removeAllElements();
898 mhunt 1022
 
1023
    try
814 mhunt 1024
    {
898 mhunt 1025
      mReleaseManager.connect();
1026
      mReleaseManager.queryMachtypes(mGbeMachtypeCollection, mDaemon, mBaseline);
1027
 
1028
      if (mDaemon)
1029
      {
1030
        mMailServer = mReleaseManager.queryMailServer();
1031
        mMailSender = mReleaseManager.queryMailSender();
1032
        mGlobalTarget = mReleaseManager.queryGlobalAddresses();
1033
      }
1034
      mBaselineName = mReleaseManager.queryBaselineName(mDaemon, mBaseline);
814 mhunt 1035
    }
898 mhunt 1036
    finally
1037
    {
1038
      // this block is executed regardless of what happens in the try block
1039
      // even if an exception is thrown
1040
      // ensure disconnect
1041
      mReleaseManager.disconnect();
1042
    }
814 mhunt 1043
  }
1044
 
1045
  /**returns the Package with the matching mAlias or NULL_PACKAGE if no package has the mID
1046
   */
908 mhunt 1047
  public Package findPackage(String alias)
814 mhunt 1048
  {
1049
    mLogger.debug("findPackage");
1050
    Package retVal = ReleaseManager.NULL_PACKAGE;
1051
 
864 mhunt 1052
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1053
    {
864 mhunt 1054
      Package p = it.next();
814 mhunt 1055
 
1056
      if ( p.mAlias.compareTo( alias ) == 0 )
1057
      {
1058
        retVal = p;
1059
        break;
1060
      }
1061
    }
1062
 
1063
    mLogger.info("findPackage returned " + retVal.mName);
1064
    return retVal;
1065
  }
1066
 
1067
  /**sets the mBuildFile to -5 for the package and all dependent packages
1068
   */
900 mhunt 1069
  private void rippleBuildExclude(Package p, int root_pv_id, String root_cause, ListIterator<BuildExclusion> list, BuildExclusion be )
814 mhunt 1070
  {
1071
    mLogger.debug("rippleBuildExclude");
874 mhunt 1072
    if ( p.mBuildFile == 0 || p.mBuildFile == 1 )
814 mhunt 1073
    {
1074
      p.mBuildFile = -5;
894 mhunt 1075
      mLogger.info("rippleBuildExclude set mBuildFile to -5 for package " + p.mAlias );
866 mhunt 1076
 
900 mhunt 1077
      if ( be != null )
866 mhunt 1078
      {
900 mhunt 1079
        be.process();
866 mhunt 1080
      }
900 mhunt 1081
      else
866 mhunt 1082
      {
900 mhunt 1083
        // if found, process it, else add it (unprocessed)
1084
        boolean found = false;
866 mhunt 1085
        for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
1086
        {
1087
          BuildExclusion buildExclusion = it.next();
836 mhunt 1088
 
900 mhunt 1089
          if ( buildExclusion.compare(p.mId, root_pv_id, root_cause))
866 mhunt 1090
          {
900 mhunt 1091
            found = true;
866 mhunt 1092
            buildExclusion.process();
900 mhunt 1093
            break;
866 mhunt 1094
          }
1095
        }
1096
 
900 mhunt 1097
        if (!found)
866 mhunt 1098
        {
900 mhunt 1099
          // process all occurrences for this package
1100
          // these will be superceded by a new build exclusion entry
1101
          for (Iterator<BuildExclusion> it = mBuildExclusionCollection.iterator(); it.hasNext(); )
814 mhunt 1102
          {
900 mhunt 1103
            BuildExclusion buildExclusion = it.next();
814 mhunt 1104
 
900 mhunt 1105
            if ( buildExclusion.compare(p.mId))
814 mhunt 1106
            {
900 mhunt 1107
              buildExclusion.process();
814 mhunt 1108
            }
1109
          }
900 mhunt 1110
 
908 mhunt 1111
          BuildExclusion buildExclusion = new BuildExclusion(p.mId, root_pv_id, root_cause, p.mTestBuildInstruction);
900 mhunt 1112
 
1113
          if ( list == null )
1114
          {
1115
            mBuildExclusionCollection.add(buildExclusion);
1116
          }
1117
          else
1118
          {
1119
            // must use the ListIterator interface to add to the collection whilst iterating through it
1120
            list.add(buildExclusion);
1121
          }
814 mhunt 1122
        }
1123
      }
1124
 
908 mhunt 1125
      // only ripple a test build failure through for non test builds
1126
      if ( p.mTestBuildInstruction == 0 )
866 mhunt 1127
      {
908 mhunt 1128
        // non test build
1129
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
866 mhunt 1130
        {
908 mhunt 1131
          Package pkg = it.next();
1132
 
1133
          if ( pkg != p )
866 mhunt 1134
          {
908 mhunt 1135
            for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
866 mhunt 1136
            {
908 mhunt 1137
              Package dependency = it2.next();
1138
 
1139
              if ( dependency == p )
1140
              {
1141
                rippleBuildExclude( pkg, root_pv_id, null, list, null );
1142
                break;
1143
              }
866 mhunt 1144
            }
1145
          }
1146
        }
1147
      }
1148
    }
1149
    mLogger.info("rippleBuildExclude set " + p.mName + " " + p.mBuildFile);
1150
  }
1151
 
924 dpurdie 1152
  public String escapeXml( String xml )
1153
  {
1154
    xml = xml.replaceAll("&", "&amp;");
1155
    xml = xml.replaceAll("<", "&lt;");
1156
    xml = xml.replaceAll(">", "&gt;");
1157
    xml = xml.replaceAll("\"","&quot;");
1158
    xml = xml.replaceAll("'", "&apos;");
1159
    xml = xml.replaceAll("\\$", "\\$\\$");
1160
 
1161
    return xml;
1162
  }
1163
 
814 mhunt 1164
  /**returns a build file header for the mBaseline
1165
   */
1166
  private String generateBuildFileHeader()
1167
  {
1168
    mLogger.debug("generateBuildFileHeader");
1169
    String lf = new String( System.getProperty("line.separator") );
1170
    String retVal = new String("");
1171
    retVal +=
862 mhunt 1172
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + lf +
814 mhunt 1173
    "<project name=\"mass\" default=\"full\" basedir=\".\">" + lf;
1174
 
1175
    if ( mDaemon )
1176
    {
1177
      retVal +=
1178
      "<property name=\"abt_mail_server\" value=\"" + mMailServer + "\"/>" + lf +
1179
      "<property name=\"abt_mail_sender\" value=\"" + mMailSender + "\"/>" + lf +
1180
      "<property name=\"abt_rtag_id\" value=\"" + mBaseline + "\"/>" + lf +
1181
      "<property name=\"abt_daemon\" value=\"" + mTimestamp + "\"/>" + lf;
866 mhunt 1182
 
1183
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
1184
      {
1185
        Package p = it.next();
1186
 
1187
        if ( p.mBuildFile == 1 )
1188
        {
1189
          retVal +=
1190
          "<property name=\"abt_package_name\" value=\"" + p.mName + "\"/>" + lf +
1191
          "<property name=\"abt_package_version\" value=\"" + p.mVersion + p.mExtension + "\"/>" + lf +
1192
          "<property name=\"abt_package_extension\" value=\"" + p.mExtension + "\"/>" + lf +
1193
          loc(p, "abt_package_location", lf) +
1194
          "<property name=\"abt_package_depends\" value=\"";
1195
 
1196
          // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
1197
          String depends = new String();
1198
 
1199
          for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
1200
          {
1201
            Package depend = it3.next();
1202
 
1203
            if ( depends.compareTo( "" ) != 0 )
1204
            {
1205
              depends += ";";
1206
            }
1207
            depends += "\'" + depend.mName + "\'";
1208
            depends += ",";
1209
            String dependsExtension = depend.mExtension;
1210
            String dependsVersion = depend.mVersion;
1211
 
1212
            if ( dependsExtension.length() > 0 )
1213
            {
1214
              dependsVersion += dependsExtension;
1215
            }
1216
            else
1217
            {
1218
              dependsExtension = ".";
1219
            }
1220
            depends += "\'" + dependsVersion + "\'";
1221
          }
1222
 
1223
          retVal += depends + "\"/>" + lf +
1224
          "<property name=\"abt_is_ripple\" value=\"";
1225
 
1226
          if ( p.mDirectlyPlanned )
1227
          {
1228
            retVal += "0";
1229
          }
1230
          else
1231
          {
1232
            retVal += "1";
1233
          }
1234
 
1235
          retVal += "\"/>" + lf +
1236
          "<property name=\"abt_package_version_id\" value=\"" + p.mId + "\"/>" + lf +
1237
          "<property name=\"abt_does_not_require_source_control_interaction\" value=\"";
1238
 
1239
          if ( ! p.mRequiresSourceControlInteraction )
1240
          {
1241
            retVal += "true";
1242
          }
1243
          else
1244
          {
1245
            retVal += "false";
1246
          }
1247
 
908 mhunt 1248
          retVal += "\"/>" + lf +
1249
          "<property name=\"abt_test_build_instruction\" value=\"" + p.mTestBuildInstruction + "\"/>" + lf;
866 mhunt 1250
        }
1251
      }
814 mhunt 1252
    }
1253
    else
1254
    {
1255
      retVal +=
1256
      "<property name=\"abt_rtag_id\" value=\"-1\"/>" + lf;
1257
    }
1258
 
822 mhunt 1259
    String majorVersionNumber = this.getClass().getPackage().getSpecificationVersion();
1260
 
864 mhunt 1261
    if ( !ReleaseManager.mUseDatabase )
822 mhunt 1262
    {
1263
        // hard code 11 for unit test purposes
1264
         majorVersionNumber = "11";
1265
    }
1266
 
814 mhunt 1267
    retVal +=
924 dpurdie 1268
    "<property name=\"abt_release\" value=\"" + escapeXml(mBaselineName) + "\"/>" + lf +
822 mhunt 1269
    "<property name=\"abt_buildtool_version\" value=\""+ majorVersionNumber + "\"/>" + lf +
814 mhunt 1270
    "<condition property=\"abt_family\" value=\"windows\">" + lf +
1271
    "  <os family=\"windows\"/>" + lf +
1272
    "</condition>" + lf +
1273
    "<property name=\"abt_family\" value=\"unix\"/>" + lf;
1274
    mLogger.info("generateBuildFileHeader returned " + retVal);
1275
    return retVal;
1276
  }
1277
 
1278
  /**returns an ant property for the passed Package
1279
   */
1280
  private String generatePackageProperty(Package p)
1281
  {
1282
    mLogger.debug("generatePackageProperty");
1283
    String lf = new String( System.getProperty("line.separator") );
1284
    String retVal = new String("");
1285
    retVal +=
1286
    "<property name=\"" + p.mAlias + "\" value=\"" + p.mName + " " + p.mVersion + p.mExtension + "\"/>" + lf;
1287
    mLogger.info("generatePackageProperty returned " + retVal);
1288
    return retVal;
1289
  }
1290
 
1291
  /**returns an ant taskdef for the abt ant task
1292
   */
1293
  private String generateTaskdef()
1294
  {
1295
    mLogger.debug("generateTaskdef");
1296
    String lf = new String( System.getProperty("line.separator") );
1297
    String retVal = new String("");
1298
    retVal +=
866 mhunt 1299
    "<taskdef name=\"abt\" classname=\"com.erggroup.buildtool.abt.ABT\"/>" + lf;
814 mhunt 1300
    return retVal;
1301
  }
1302
 
1303
  /**returns an ant target for the passed Package
1304
   * in daemon mode:
1305
   *  packages are categorised with one of three mBuildFile values:
1306
   *   1 the package to be built by this buildfile
1307
   *   2 the packages with a future build requirement
1308
   *   3 the packages with no build requirement
1309
   *  the returned target depends on this categorisation and will have
1310
   *   1 full abt info
1311
   *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
1312
   *   3 only a name attribute (will not build this package)
1313
   * in escrow mode:
1314
   *  if the passed Package's mBuildFile is different (less than) the passed build file,
1315
   *  the returned target have only a name attribute (will not build this package) 
1316
   */
1317
  private String generateTarget(Package p, int buildFile)
1318
  {
1319
    mLogger.debug("generateTarget");
1320
 
832 mhunt 1321
    if ( ( mDaemon && p.mBuildFile == 1 ) || ( !mDaemon && !p.isGeneric() ) )
814 mhunt 1322
    {
1323
      // populate 'missing' BuildStandards
1324
      boolean solaris = false;
1325
      boolean linux = false;
1326
      boolean win32 = false;
1327
      boolean jats = false;
1328
      boolean determinedBuildStandard = false;
1329
 
864 mhunt 1330
      for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 1331
      {
864 mhunt 1332
        BuildStandard bs = it.next();
814 mhunt 1333
 
1334
        if ( bs.getSolaris() )
1335
        {
1336
          solaris = true;
1337
        }
1338
        else
1339
        if ( bs.getLinux() )
1340
        {
1341
          linux = true;
1342
        }
1343
        else
1344
        if ( bs.getWin32() )
1345
        {
1346
          win32 = true;
1347
        }
1348
 
908 mhunt 1349
        if ( !determinedBuildStandard && bs.getBuildStandard(!ReleaseManager.mUseDatabase, true).contains("<jats") )
814 mhunt 1350
        {
1351
          jats = true;
1352
          determinedBuildStandard = true;
1353
        }
1354
      }
1355
 
1356
      if ( !solaris )
1357
      {
1358
        BuildStandard bs = new BuildStandard(this);
1359
        bs.setSolaris();
1360
 
1361
        if ( jats )
1362
        {
1363
          bs.setJatsNone();
1364
        }
1365
        else
1366
        {
1367
          bs.setAntNone();
1368
        }
1369
 
1370
        p.mBuildStandardCollection.add(bs);
1371
      }
1372
 
1373
      if ( !linux )
1374
      {
1375
        BuildStandard bs = new BuildStandard(this);
1376
        bs.setLinux();
1377
 
1378
        if ( jats )
1379
        {
1380
          bs.setJatsNone();
1381
        }
1382
        else
1383
        {
1384
          bs.setAntNone();
1385
        }
1386
 
1387
        p.mBuildStandardCollection.add(bs);
1388
      }
1389
 
1390
      if ( !win32 )
1391
      {
1392
        BuildStandard bs = new BuildStandard(this);
1393
        bs.setWin32();
1394
 
1395
        if ( jats )
1396
        {
1397
          bs.setJatsNone();
1398
        }
1399
        else
1400
        {
1401
          bs.setAntNone();
1402
        }
1403
 
1404
        p.mBuildStandardCollection.add(bs);
1405
      }
1406
    }
1407
 
1408
    String lf = new String( System.getProperty("line.separator") );
1409
    String retVal = new String("");
1410
 
1411
    if ( ( mDaemon && p.mBuildFile == 3 ) ||
1412
         ( !mDaemon && ( p.mBuildFile < buildFile ) ) )
1413
    {
1414
      retVal +=
1415
      "<target name=\"" + p.mAlias + "\"/>" + lf;
1416
    }
1417
    else
1418
    {
848 dpurdie 1419
      retVal +=
814 mhunt 1420
      "<target name=\"" + p.mAlias + ".wrap\"";
1421
 
1422
      if ( p.mPackageDependencyCollection.size() > 0 )
1423
      {
1424
        retVal +=" depends=\"";
1425
        boolean comma = false;
1426
 
864 mhunt 1427
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1428
        {
906 mhunt 1429
          Package dependency = it.next();
1430
          // DEVI 54816
1431
          if ( !mDaemon && dependency.mBuildFile == -2 )
1432
          {
1433
            // ignore targets which build in foreign environments in escrow mode
1434
            continue;
1435
          }
814 mhunt 1436
          if (comma)
1437
          {
1438
            retVal += ",";
1439
          }
1440
          comma = true;
1441
 
1442
          retVal += dependency.mAlias;
1443
        }
1444
 
1445
        retVal += "\"";
1446
      }
1447
      retVal += ">" + lf;
1448
 
1449
      if ( !mDaemon )
1450
      {
1451
        boolean hasDependenciesBuiltInThisIteration = false;
1452
        if ( ( p.mPackageDependencyCollection.size() > 0 ) )
1453
        {
864 mhunt 1454
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1455
          {
864 mhunt 1456
            Package dependency = it.next();
814 mhunt 1457
 
1458
            if ( dependency.mBuildFile == buildFile )
1459
            {
1460
              hasDependenciesBuiltInThisIteration = true;
1461
              break;
1462
            }
1463
          }
1464
        }
1465
 
1466
        if ( hasDependenciesBuiltInThisIteration )
1467
        {
1468
          retVal +=
1469
          "  <condition property=\"" + p.mAlias + ".build\">" + lf +
1470
          "    <and>" + lf;
1471
 
864 mhunt 1472
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1473
          {
864 mhunt 1474
            Package dependency = it.next();
814 mhunt 1475
 
1476
            if ( dependency.mBuildFile == buildFile )
1477
            {
1478
              retVal +=
1479
              "      <or>" + lf +
1480
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"0\"/>" + lf +
1481
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"257\"/>" + lf +
1482
              "      </or>" + lf;
1483
            }
1484
          }
1485
 
1486
          retVal +=
1487
          "    </and>" + lf +
1488
          "  </condition>" + lf;
1489
        }
1490
        else
1491
        {
1492
          retVal += "  <property name=\"" + p.mAlias + ".build\" value=\"\"/>" + lf;
1493
        }
1494
      }
1495
 
1496
      retVal +=
1497
      "</target>" + lf +
1498
      "<target name=\"" + p.mAlias + "\" depends=\"" + p.mAlias + ".wrap\"";
1499
 
1500
      if ( !mDaemon )
1501
      {
1502
        retVal += " if=\"" + p.mAlias + ".build\"";
1503
      }
1504
 
1505
      retVal += ">" + lf;
1506
 
1507
      if ( mDaemon && p.mBuildFile == 1 )
1508
      {
1509
        retVal +=
1510
        "<property name=\"" + p.mAlias + "pkg_id\" value=\"" + p.mPid + "\"/>" + lf +
1511
        "<property name=\"" + p.mAlias + "pv_id\" value=\"" + p.mId + "\"/>" + lf;
1512
      }
1513
 
1514
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1515
      {
1516
        retVal +=
1517
        "<property name=\"" + p.mAlias + "packagename\" value=\"" + p.mName + "\"/>" + lf +
1518
        "<property name=\"" + p.mAlias + "packageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1519
        "<property name=\"" + p.mAlias + "packageextension\" value=\"";
1520
 
1521
        if ( p.mExtension.length() > 0 )
1522
        {
1523
          // drop the .
1524
          retVal += p.mExtension.substring(1);
1525
        }
1526
        else
1527
        {
1528
          retVal += p.mExtension;
1529
        }
1530
 
1531
        retVal += "\"/>" + lf +
924 dpurdie 1532
        "<property name=\"" + p.mAlias + "packagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf;
814 mhunt 1533
 
1534
        if ( p.mDirectlyPlanned )
1535
        {
1536
          retVal += "<property name=\"" + p.mAlias + "directchange\" value=\"\"/>" + lf;
1537
        }
1538
 
852 mhunt 1539
        if ( ! p.mRequiresSourceControlInteraction )
1540
        {
1541
          retVal += "<property name=\"" + p.mAlias + "doesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
1542
        }
1543
 
814 mhunt 1544
        mAddendum = "non generic";
1545
 
1546
        if ( p.isGeneric() )
1547
        {
1548
          mAddendum = "generic";
1549
          retVal += "<property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
1550
        }
1551
 
1552
        retVal += loc(p, p.mAlias + "loc", lf);
1553
 
830 mhunt 1554
        if ( p.mHasAutomatedUnitTests && mDaemon )
814 mhunt 1555
        {
1556
          retVal += 
1557
          "<property name=\"" + p.mAlias + "unittests\" value=\"\"/>" + lf;
1558
        }
1559
      }
1560
 
1561
      retVal += "<abt>" + lf;
1562
 
1563
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1564
      {
864 mhunt 1565
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1566
        {
864 mhunt 1567
          Package dependency = it.next();
814 mhunt 1568
          retVal +=
1569
          "  <depend package_alias=\"${" + dependency.mAlias + "}\"/>" + lf;
1570
        }
1571
 
836 mhunt 1572
        retVal += buildInfo(p, lf, false);
814 mhunt 1573
      }
1574
 
1575
      if ( mDaemon && p.mBuildFile == 1 )
1576
      {
854 mhunt 1577
        retVal += p.emailInfo( lf );
814 mhunt 1578
      }
1579
 
1580
      retVal += "</abt>" + lf +
1581
      "</target>" + lf;
1582
 
1583
      if ( mDaemon && p.mBuildFile == 1 )
1584
      {
1585
        retVal +=
1586
        "<target name=\"AbtSetUp\">" + lf +
924 dpurdie 1587
        "<property name=\"AbtSetUppackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
1588
        "<property name=\"AbtSetUppackagename\" value=\"" + p.mName + "\"/>" + lf;
814 mhunt 1589
 
1590
        retVal +=
1591
        "<abt>" + lf +
854 mhunt 1592
        p.emailInfo( lf ) +
814 mhunt 1593
        "</abt>" + lf +
872 dpurdie 1594
        "</target>" + lf;
1595
 
1596
        retVal +=
814 mhunt 1597
        "<target name=\"AbtTearDown\">" + lf +
924 dpurdie 1598
        "<property name=\"AbtTearDownpackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
814 mhunt 1599
        "<property name=\"AbtTearDownpackagename\" value=\"" + p.mName + "\"/>" + lf +
1600
        "<property name=\"AbtTearDownpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1601
        "<property name=\"AbtTearDownpackageextension\" value=\"";
1602
 
1603
        if ( p.mExtension.length() > 0 )
1604
        {
1605
          // drop the .
1606
          retVal += p.mExtension.substring(1);
1607
        }
1608
        else
1609
        {
1610
          retVal += p.mExtension;
1611
        }
1612
 
1613
        retVal += "\"/>" + lf;
1614
 
1615
        if ( p.isGeneric() )
1616
        {
1617
          retVal += "<property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
1618
        }
1619
 
1620
        retVal +=        
1621
        "<abt>" + lf +
836 mhunt 1622
        buildInfo(p, lf, false) +
854 mhunt 1623
        p.emailInfo( lf ) +
814 mhunt 1624
        "</abt>" + lf +
1625
        "</target>" + lf +
1626
        "<target name=\"AbtPublish\">" + lf +
924 dpurdie 1627
        "<property name=\"AbtPublishpackagevcstag\" value=\"" + p.mVcsTag + "\"/>" + lf +
814 mhunt 1628
        "<property name=\"AbtPublishpackagename\" value=\"" + p.mName + "\"/>" + lf +
1629
        "<property name=\"AbtPublishpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1630
        "<property name=\"AbtPublishpackageextension\" value=\"";
1631
 
1632
        if ( p.mExtension.length() > 0 )
1633
        {
1634
          // drop the .
1635
          retVal += p.mExtension.substring(1);
1636
        }
1637
        else
1638
        {
1639
          retVal += p.mExtension;
1640
        }
1641
 
1642
        retVal += "\"/>" + lf;
1643
 
1644
        if ( p.mDirectlyPlanned )
1645
        {
1646
          retVal += "<property name=\"AbtPublishdirectchange\" value=\"\"/>" + lf;
1647
        }
1648
 
852 mhunt 1649
        if ( ! p.mRequiresSourceControlInteraction )
1650
        {
1651
          retVal += "<property name=\"AbtPublishdoesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
1652
        }
1653
 
814 mhunt 1654
        if ( p.isGeneric() )
1655
        {
1656
          retVal += "<property name=\"AbtPublishgeneric\" value=\"\"/>" + lf;
1657
        }
1658
 
1659
        retVal += loc(p, "AbtPublishloc", lf);
1660
        retVal +=
816 mhunt 1661
        "<abt>" + lf +
854 mhunt 1662
        buildInfo(p, lf, true) +
1663
        p.emailInfo( lf ) +
814 mhunt 1664
        "</abt>" + lf +
1665
        "</target>" + lf;
1666
      }
1667
    }
1668
    mLogger.info("generateTarget returned " + retVal);
1669
    return retVal;
1670
  }
1671
 
1672
  /**returns an ant default target for the current build iteration
1673
   */
1674
  private String generateDefaultTarget(int buildFile)
1675
  {
1676
    mLogger.debug("generateDefaultTarget");
1677
    String lf = new String( System.getProperty("line.separator") );
1678
    String retVal = new String("");
1679
    retVal +=
1680
    "<target name=\"fullstart\">" + lf;
1681
 
1682
    if (buildFile == 1)
1683
    {
1684
      retVal +=
906 mhunt 1685
      "<echo message=\"${line.separator}" + mAnyBuildPlatforms + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1686
 
864 mhunt 1687
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1688
      {
864 mhunt 1689
        Package p = it.next();
814 mhunt 1690
 
1691
        if ( p.mBuildFile == -1 )
1692
        {
1693
          retVal +=
1694
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1695
        }
1696
      }
1697
 
1698
      retVal +=
906 mhunt 1699
      "<echo message=\"${line.separator}" + mAssocBuildPlatforms + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1700
 
864 mhunt 1701
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1702
      {
864 mhunt 1703
        Package p = it.next();
814 mhunt 1704
 
1705
        if ( p.mBuildFile == -2 )
1706
        {
1707
          retVal +=
1708
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1709
        }
1710
      }
1711
 
1712
      retVal +=
906 mhunt 1713
      "<echo message=\"${line.separator}" + mNotInBaseline + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1714
 
864 mhunt 1715
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1716
      {
864 mhunt 1717
        Package p = it.next();
814 mhunt 1718
 
1719
        if ( p.mBuildFile == -4 )
1720
        {
1721
          retVal +=
1722
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1723
        }
1724
      }
1725
 
1726
      retVal +=
906 mhunt 1727
      "<echo message=\"${line.separator}" + mDependent + "${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
814 mhunt 1728
 
864 mhunt 1729
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1730
      {
864 mhunt 1731
        Package p = it.next();
814 mhunt 1732
 
1733
        if ( p.mBuildFile == -5 )
1734
        {
1735
          retVal +=
1736
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1737
        }
1738
      }
1739
    }
1740
    if ( !mDaemon )
1741
    {
1742
      retVal +=
1743
      "<echo message=\"${line.separator}Build Started:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1744
    }
1745
 
1746
    retVal +=
1747
    "</target>" + lf +
1748
    "<target name=\"full\" depends=\"fullstart";
1749
 
864 mhunt 1750
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1751
    {
864 mhunt 1752
      Package p = it.next();
814 mhunt 1753
 
1754
      if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
1755
      {
1756
        retVal += "," + p.mAlias;
1757
      }
1758
    }
1759
 
1760
    retVal +=
1761
    "\">" + lf;
1762
 
1763
    if ( !mDaemon )
1764
    {
1765
      retVal +=
1766
      "<echo message=\"${line.separator}Build Finished${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1767
    }
1768
 
1769
    retVal +=
1770
    "</target>" + lf;
1771
    return retVal;
1772
  }
1773
 
1774
  /**returns a build file footer
1775
   */
1776
  private String generateBuildFileFooter()
1777
  {
1778
    mLogger.debug("generateBuildFileFooter");
1779
    String retVal = new String("</project>");
1780
    return retVal;
1781
  }
1782
 
1783
  /**sets the mIndirectlyPlanned true for the package and all dependent packages
1784
   */
1785
  private void rippleIndirectlyPlanned(Package p)
1786
  {
1787
    mLogger.debug("rippleIndirectlyPlanned");
1788
    if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
1789
    {
1790
      p.mIndirectlyPlanned = true;
1791
 
864 mhunt 1792
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1793
      {
864 mhunt 1794
        Package pkg = it.next();
814 mhunt 1795
 
1796
        if ( pkg != p )
1797
        {
864 mhunt 1798
          for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 1799
          {
864 mhunt 1800
            Package dependency = it2.next();
814 mhunt 1801
 
1802
            if ( dependency == p )
1803
            {
1804
              rippleIndirectlyPlanned( pkg );
1805
              break;
1806
            }
1807
          }
1808
        }
1809
      }
1810
    }
1811
    mLogger.info("rippleIndirectlyPlanned set " + p.mName + " " + p.mIndirectlyPlanned);    
1812
  }
1813
 
1814
  /**accessor method
1815
   */
830 mhunt 1816
  public String getESCROWSetUp()
814 mhunt 1817
  {
830 mhunt 1818
    mLogger.debug("getESCROWSetUp");
814 mhunt 1819
    String retVal = new String("");
1820
 
1821
    try
1822
    {
924 dpurdie 1823
      if ( mEscrowSupportCollection.size() >= 1 )
814 mhunt 1824
      {
924 dpurdie 1825
        retVal = (String)mEscrowSupportCollection.get(0);
814 mhunt 1826
      }
1827
    }
1828
    catch( ArrayIndexOutOfBoundsException e )
1829
    {
1830
    }
1831
 
830 mhunt 1832
    mLogger.info("getESCROWSetUp returned " + retVal);
814 mhunt 1833
    return retVal;
1834
  }
1835
 
1836
  /**accessor method
1837
   */
830 mhunt 1838
  public String getRawData()
814 mhunt 1839
  {
830 mhunt 1840
    mLogger.debug("getRawData");
814 mhunt 1841
    String retVal = new String("");
1842
 
1843
    try
1844
    {
924 dpurdie 1845
      if ( mEscrowSupportCollection.size() >= 2 )
814 mhunt 1846
      {
924 dpurdie 1847
        retVal = (String)mEscrowSupportCollection.get(1);
814 mhunt 1848
      }
1849
    }
1850
    catch( ArrayIndexOutOfBoundsException e )
1851
    {
1852
    }
1853
 
830 mhunt 1854
    mLogger.info("getRawData returned " + retVal);
814 mhunt 1855
    return retVal;
1856
  }
1857
 
1858
  /**returns first build file content and addendum
1859
   * the addendum value is one of "non generic", "generic" or "dummy"
1860
   */
1861
  public void getFirstBuildFileContent(MutableString content, 
1862
                                MutableString addendum)
1863
  {
1864
    mLogger.debug("getFirstBuildFileContent");
1865
    try
1866
    {
1867
      mBuildIndex = 0;
1868
      content.value = (String)mBuildCollection.get( mBuildIndex );
1869
      addendum.value = mAddendum;
1870
    }
1871
    catch( ArrayIndexOutOfBoundsException e )
1872
    {
1873
    }
1874
    mLogger.info("getFirstBuildFileContent passed " + content.value + addendum.value);
1875
  }
1876
 
872 dpurdie 1877
  /**returns the build loc
814 mhunt 1878
   */
1879
  private String loc(Package p, String target, String lf)
1880
  {
1881
    mLogger.debug("loc");
1882
    String retVal = new String();
872 dpurdie 1883
    String loc = new String("/");
1884
 
1885
    if (mDaemon)
814 mhunt 1886
    {
872 dpurdie 1887
      // Daemon: Start in root of view/workspace
924 dpurdie 1888
      loc += mBaseline;
814 mhunt 1889
    }
872 dpurdie 1890
    else
814 mhunt 1891
    {
872 dpurdie 1892
      // mAlias used with jats -extractfiles -view
1893
      loc += p.mAlias;
1894
    }
814 mhunt 1895
 
872 dpurdie 1896
    //
1897
    //  Always use '/' as a path seperator - even if user has specified '\'
1898
    //  Ant can handle it.
1899
    //
814 mhunt 1900
    loc = loc.replace('\\', '/');
1901
    retVal += 
1902
    "<property name=\"" + target + "\" value=\"" + loc + "\"/>" + lf;
1903
 
1904
    mLogger.info("loc returned " + retVal);
1905
    return retVal;
1906
  }
816 mhunt 1907
 
1908
  /**returns the buildInfo
1909
   */
836 mhunt 1910
  private String buildInfo(Package p, String lf, boolean filter)
816 mhunt 1911
  {
1912
    mLogger.debug("buildInfo");
1913
 
1914
    String platforms = new String();
1915
    String standards = new String();
1916
 
864 mhunt 1917
    for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
816 mhunt 1918
    {
864 mhunt 1919
      BuildStandard bs = it.next();
816 mhunt 1920
 
836 mhunt 1921
      if ( !filter )
816 mhunt 1922
      {
908 mhunt 1923
        String platform = bs.getPlatform(!ReleaseManager.mUseDatabase, true);
816 mhunt 1924
 
1925
        if ( platform.length() > 0 )
1926
        {
1927
          platforms += platform + lf;
1928
        }
1929
 
908 mhunt 1930
        String standard = bs.getBuildStandard(!ReleaseManager.mUseDatabase, true);
816 mhunt 1931
 
1932
        if ( standard.length() > 0 )
1933
        {
1934
          standards += standard + lf;
1935
        }
1936
      }
1937
      else
1938
      {
908 mhunt 1939
        if ( !bs.getBuildStandard(!ReleaseManager.mUseDatabase, true).contains("\"none\"") )
816 mhunt 1940
        {
908 mhunt 1941
          String platform = bs.getPlatform(!ReleaseManager.mUseDatabase, true);
816 mhunt 1942
 
1943
          if ( platform.length() > 0 )
1944
          {
1945
            platforms += platform + lf;
1946
          }
836 mhunt 1947
 
908 mhunt 1948
          String standard = bs.getBuildStandard(!ReleaseManager.mUseDatabase, true);
836 mhunt 1949
 
1950
          if ( standard.length() > 0 )
1951
          {
1952
            standards += standard + lf;
1953
          }
816 mhunt 1954
        }
1955
      }
1956
    }
1957
 
1958
    mLogger.info("buildInfo returned " + platforms + standards);
1959
    return platforms + standards;
1960
  }
866 mhunt 1961
 
906 mhunt 1962
  /**prints to standard out in escrow mode only
1963
   */
1964
  private void standardOut(final String message, final String alias, boolean printMessage)
1965
  {
1966
    mLogger.debug("standardOut");
1967
    if (!mDaemon)
1968
    {
1969
      if ( printMessage )
1970
      {
1971
        System.out.println(message);
1972
        // switch the message off
1973
        printMessage = false;
1974
      }
1975
 
1976
      System.out.println(alias);
1977
    }
1978
  }
814 mhunt 1979
}