Subversion Repositories DevTools

Rev

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.io.FileWriter;
6
 
7
import java.sql.SQLException;
8
 
9
import java.util.Iterator;
10
import java.util.Vector;
11
 
12
import org.apache.log4j.Logger;
13
 
830 mhunt 14
import java.util.regex.PatternSyntaxException;
15
 
814 mhunt 16
/**Plans release impact by generating a set of Strings containing build file content.
17
 */
18
public class RippleEngine
19
{
20
  /**collection of gbemachtypes in String form associated with the baseline
21
   * limited to the following items "win32", "sparc", "solaris10_sparc32", "solaris10_x86", "linux_i386"
22
   * accessed by Package::isLinuxBuilt, isSolarisBuilt, isWin32Built
23
   * @attribute
24
   */
864 mhunt 25
  Vector<String> mGbeMachtypeCollection = new Vector<String>();
814 mhunt 26
 
27
  /**configured mail server
28
   * @attribute
29
   */
30
  String mMailServer = new String();
31
 
32
  /**configured mail sender user
33
   * @attribute
34
   */
35
  String mMailSender = new String();
36
 
37
  /**name associated with the baseline
38
   * @attribute
39
   */
40
  String mBaselineName = new String();
41
 
42
  /**collection of released pv_ids associated with the release
43
   * @attribute
44
   */
864 mhunt 45
  Vector<Integer> mReleasedPvIDCollection = new Vector<Integer>();
814 mhunt 46
 
47
  /**timestamp associated with build file generation
48
   * @attribute
49
   */
50
  long mTimestamp = 0;
51
 
52
  /**set to "non generic", "generic" or "dummy" to indicate the nature of the package in the build file in daemon mode
53
   * @attribute
54
   */
55
  String mAddendum = new String("dummy");
56
 
57
  /**Logger
58
   * @attribute
59
   */
60
  private static final Logger mLogger = Logger.getLogger(RippleEngine.class);
61
 
830 mhunt 62
  /**collection of escrow clearcase support file content in String form, set_up
814 mhunt 63
   * @attribute
64
   */
864 mhunt 65
  private Vector<String> mEscrowClearcaseSupportCollection = new Vector<String>();
814 mhunt 66
 
67
  /**package versions representing the baseline
68
   * @aggregation shared
69
   * @attribute
70
   */
864 mhunt 71
  private Vector<Package> mPackageCollection = new Vector<Package>();
814 mhunt 72
 
73
  /**index to current String item
74
   * @attribute
75
   */
76
  private int mBuildIndex;
77
 
78
  /**Database abstraction
79
   * @attribute
80
   */
81
  private ReleaseManager mReleaseManager;
82
 
83
  /**Baseline identifier (rtag_id for a release manager baseline, bom_id for deployment manager baseline)
84
   * @attribute
85
   */
86
  private int mBaseline;
87
 
88
  /**When true, mBuildCollection contains one item based on a release manager rtag_id and contains a daemon property
89
   * When false, mBuildCollection contains at least one item based on a deployment manager bom_id
90
   * Will be accessed by the Package class to calculate its mAlias
91
   * @attribute
92
   */
93
  boolean mDaemon;
94
 
95
  /**collection of build file content in String form
96
   * @attribute
97
   */
864 mhunt 98
  private Vector<String> mBuildCollection = new Vector<String>();
814 mhunt 99
 
100
  /**constructor
101
   */
102
  public RippleEngine(ReleaseManager releaseManager, int rtag_id, 
103
                      boolean isDaemon)
104
  {
105
    mLogger.debug("RippleEngine rtag_id " + rtag_id + " isDaemon " + isDaemon);
106
    mReleaseManager = releaseManager;
107
    mBaseline = rtag_id;
108
    mDaemon = isDaemon;
109
  }
110
 
111
  /**discards all build file content
112
   * plans new build file content
113
   */
114
  public void planRelease() throws SQLException, Exception
115
  {
116
    mLogger.warn("planRelease mDaemon " + mDaemon);
117
    mAddendum = "dummy";
118
    mBuildCollection.removeAllElements();
119
    mPackageCollection.removeAllElements();
120
    mReleasedPvIDCollection.removeAllElements();
121
 
122
    if ( !mDaemon )
123
    {
124
      mEscrowClearcaseSupportCollection.removeAllElements();  
125
    }
126
 
127
    mReleaseManager.connect();
128
 
129
    if ( mDaemon )
130
    {
131
      // claim the mutex
132
      mReleaseManager.claimMutex();
133
    }
134
 
135
    collectMetaData();
136
 
137
    mReleaseManager.queryPackageVersions(this, mPackageCollection, mDaemon, mBaseline);
138
 
139
    // set up mPackageDependencyCollection
864 mhunt 140
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 141
    {
864 mhunt 142
      Package p = it.next();
814 mhunt 143
 
864 mhunt 144
      for (Iterator<String> it2 = p.mDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 145
      {
864 mhunt 146
        String alias = it2.next();
814 mhunt 147
        Package dependency = findPackage(alias);
148
 
149
        if (dependency == ReleaseManager.NULL_PACKAGE)
150
        {
151
          mLogger.info("planRelease dependency is not in the baseline " + alias);
152
          // exclude all dependent packages
153
          rippleBuildExclude(p);
154
 
155
          // take the package out of the build
156
          p.mBuildFile = -4;
858 mhunt 157
          mLogger.warn("planRelease set mBuildFile to -4 for package " + p.mAlias );
814 mhunt 158
          break;
159
        }
160
 
161
        p.mPackageDependencyCollection.add(dependency);
162
      }
163
    }
164
 
165
    // process packages which are not reproducible, and all packages dependent upon them      
864 mhunt 166
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 167
    {
864 mhunt 168
      Package p = it.next();
814 mhunt 169
 
170
      if (p.mBuildFile == 0)
171
      {
172
        // package has yet to be processed
173
        if (!p.isReproducible())
174
        {
175
          if ( !mDaemon )
176
          {
177
            // for escrow build purposes, exclude all dependent package versions
178
            mLogger.info("planRelease package not reproducible " + p.mName);
179
            rippleBuildExclude(p);
180
          }
181
 
182
          // package is not reproducible, discard
183
          p.mBuildFile = -1;
858 mhunt 184
          mLogger.warn("planRelease set mBuildFile to -1 for package " + p.mAlias );
814 mhunt 185
        }
186
      }
187
    }
188
 
189
    // process packages which are not reproducible on the build platforms configured for this baseline
864 mhunt 190
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 191
    {
864 mhunt 192
      Package p = it.next();
814 mhunt 193
 
194
      if (p.mBuildFile == 0)
195
      {
196
        // package has yet to be processed
858 mhunt 197
        // assume it does not need to be reproduced for this baseline
198
        boolean reproduce = false;
199
 
864 mhunt 200
        for (Iterator<String> it2 = mGbeMachtypeCollection.iterator(); it2.hasNext(); )
814 mhunt 201
        {
864 mhunt 202
          String machtype = it2.next();
858 mhunt 203
 
204
          if ( machtype.compareTo("linux_i386") == 0 )
814 mhunt 205
          {
858 mhunt 206
            if ( p.isLinuxBuilt() )
814 mhunt 207
            {
858 mhunt 208
              reproduce = true;
209
              mLogger.info("planRelease package built on linux " + p.mAlias );
210
              break;
814 mhunt 211
            }
858 mhunt 212
          }
213
          else if ( machtype.compareTo("win32") == 0 )
214
          {
215
            if ( p.isWin32Built() )
814 mhunt 216
            {
858 mhunt 217
              reproduce = true;
218
              mLogger.info("planRelease package built on win32 " + p.mAlias );
219
              break;
814 mhunt 220
            }
858 mhunt 221
          }
222
          else if ( machtype.compareTo("sparc") == 0
223
                 || machtype.compareTo("solaris10_x86") == 0
224
                 || machtype.compareTo("solaris10_sparc32") == 0 )
225
          {
226
            if ( p.isSolarisBuilt() )
814 mhunt 227
            {
858 mhunt 228
              reproduce = true;
229
              mLogger.info("planRelease package built on solaris " + p.mAlias );
230
              break;
814 mhunt 231
            }
232
          }
858 mhunt 233
        }
814 mhunt 234
 
858 mhunt 235
        if ( !reproduce )
236
        {
237
          if ( !mDaemon )
814 mhunt 238
          {
858 mhunt 239
            // for escrow build purposes, exclude all dependent package versions
240
            mLogger.info("planRelease package not reproducible on the build platforms configured for this baseline " + p.mName);
241
            rippleBuildExclude(p);
814 mhunt 242
          }
858 mhunt 243
 
244
          // package is not reproducible on the build platforms configured for this baseline, discard
245
          p.mBuildFile = -2;
246
          mLogger.warn("planRelease set mBuildFile to -2 for package " + p.mAlias );
814 mhunt 247
        }
248
      }
249
    }      
250
 
251
    if (mDaemon)
252
    {
253
      // process packages which are not ripple buildable, and all packages dependent upon them      
864 mhunt 254
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 255
      {
864 mhunt 256
        Package p = it.next();
814 mhunt 257
 
258
        if (p.mBuildFile == 0)
259
        {
260
          // package has yet to be processed
261
          if (p.mDoNotRipple)
262
          {
263
            // exclude all dependent package versions
264
            mLogger.info("planRelease do not ripple " + p.mName);
265
            rippleBuildExclude(p);
266
 
267
            // package is not reproducible, discard
268
            p.mBuildFile = -3;
858 mhunt 269
            mLogger.warn("planRelease set mBuildFile to -3 for package " + p.mAlias );
814 mhunt 270
          }
271
        }
272
      }
273
 
274
      // process packages which need to be ripple built
864 mhunt 275
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 276
      {
864 mhunt 277
        Package p = it.next();
814 mhunt 278
 
279
        if (p.mBuildFile == 0)
280
        {
281
          // package has yet to be processed
282
          if (p.mDirectlyPlanned)
283
          {
284
            // a WIP exists on the package
285
            // exclude all dependent package versions
286
            mLogger.info("planRelease package has WIP " + p.mName);
287
            rippleIndirectlyPlanned(p);
288
          }
289
          else
290
          {
864 mhunt 291
            Iterator<Integer> it2 = p.mDependencyIDCollection.iterator();
292
            Iterator<Package> it3 = p.mPackageDependencyCollection.iterator();
814 mhunt 293
            for ( ; it2.hasNext() && it3.hasNext(); )
294
            {
864 mhunt 295
              Integer dpv_id = it2.next();
296
              Package dependency = it3.next();
814 mhunt 297
 
298
              if ( !dependency.mAdvisoryRipple )
299
              {
300
                // not advisory, ie has ripple build impact
301
                boolean found = false;
302
 
864 mhunt 303
                for ( Iterator<Integer> it4 = mReleasedPvIDCollection.iterator(); it4.hasNext(); )
814 mhunt 304
                {
864 mhunt 305
                  Integer pv_id = it4.next();
836 mhunt 306
 
814 mhunt 307
                  if ( pv_id.compareTo(dpv_id) == 0 )
308
                  {
309
                    found = true;
310
                    break;
311
                  }
312
                }
313
 
314
                if ( !found )
315
                {
316
                  // the package is out of date
317
                  // exclude all dependent package versions
318
                  mLogger.info("planRelease package out of date " + p.mName);
319
                  rippleIndirectlyPlanned(p);                 
320
                  break;
321
                }
322
              }
323
            }
324
          }
325
        }
326
      }
327
 
328
      // process packages which do not exist in the archive
864 mhunt 329
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 330
      {
864 mhunt 331
        Package p = it.next();
814 mhunt 332
 
333
        if (p.mBuildFile == 0)
334
        {
335
          // package has yet to be processed
336
          // for unit test purposes, assume all packages exist in the archive if released
864 mhunt 337
          if ( ReleaseManager.mUseDatabase )
814 mhunt 338
          {
339
            // only check existence outside the unit test
340
            if (!p.mDirectlyPlanned && !p.mIndirectlyPlanned)
341
            {
342
              // check package version archive existence
343
              if (!p.exists())
344
              {
345
                mLogger.info("planRelease package not found in archive " + p.mName);
852 mhunt 346
                // DEVI 47395 the cause of this build is not WIP or ripple induced,
347
                // it simply does not exist in the archive (has been removed)
348
                // prevent source control interaction
349
                p.mRequiresSourceControlInteraction = false;
814 mhunt 350
                rippleIndirectlyPlanned(p);
351
              }
352
            }
353
          }
354
        }
355
      }
356
    }
357
 
358
    // process remaining packages which need to be reproduced for this baseline
359
    // determine the build file for each package
360
    // 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
361
    // set its mBuildNumber to 1, all remaining reproducible packages to 2
362
    // for escrow builds, determine the package versions that can be built in the build iteration
363
    // set their mBuildNumber to the build iteration
364
    // increment the build iteration and repeat until all package versions that need to be reproduced have been assigned a build iteration
365
    boolean allProcessed = false;
366
    int buildFile = 1;
367
 
368
    // delete the file <rtagId>official
369
    Integer rtag = new Integer(mBaseline);
370
    File rtagIdOfficial = new File(rtag + "official");
371
 
372
    if (rtagIdOfficial.exists())
373
    {
826 mhunt 374
      boolean del = rtagIdOfficial.delete();
375
 
376
      if ( !del )
377
      {
378
        // the delete failed
379
        // some literature suggests a forced garbage collection may free up resources associated with file handles
380
        // nothing to lose since the file "must" be deleted
381
        System.gc();
382
        del = rtagIdOfficial.delete();
383
 
384
        if ( !del )
385
        {
386
          mLogger.fatal("rtagIdOfficial.delete() returned " + del);
387
        }
388
      }
814 mhunt 389
    }
390
 
830 mhunt 391
    String raw_data = new String("");
392
    String lf = new String( System.getProperty("line.separator") );
393
 
814 mhunt 394
    do
395
    {
396
      boolean allDependenciesProcessed = true;
397
 
398
      do
399
      {
400
        // assume all dependencies have been processed
401
        allDependenciesProcessed = true;
402
 
864 mhunt 403
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 404
        {
864 mhunt 405
          Package p = it.next();
814 mhunt 406
 
407
          if ( mDaemon && ( ( !p.mDirectlyPlanned && !p.mIndirectlyPlanned ) || p.mBuildFile < 0 ) )
408
          {
409
            // flag packages with no build requirement as processed in daemon mode
410
            p.mProcessed = true;
411
            mLogger.info("planRelease package has no build requirement " + p.mName);            
412
          }
413
          else
414
          {
415
            if ( ( p.mBuildFile == 0 ) && ( (mDaemon && ( p.mDirectlyPlanned || p.mIndirectlyPlanned ) ) || ( !mDaemon ) ) )
416
            {
417
              // package yet to be processed and
418
              // in daemon mode has a build requirement or
419
              // in escrow mode
420
              boolean canBeBuiltNow = true;
421
              boolean allDependenciesForThisPackageProcessed = true;
422
 
864 mhunt 423
              for ( Iterator<Package> it2 = p.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 424
              {
864 mhunt 425
                Package dependency = it2.next();
814 mhunt 426
 
427
                if ( !dependency.mProcessed )
428
                {
429
                  // cannot determine canBeBuiltNow until this dependency has been processed
430
                  allDependenciesForThisPackageProcessed = false;
431
                  allDependenciesProcessed = false;
432
                }
433
                else if ( ( mDaemon && ( dependency.mDirectlyPlanned ) || ( dependency.mIndirectlyPlanned ) ) || 
434
                          ( !mDaemon &&
435
                            ( ( dependency.mBuildFile == 0 ) ||
436
                              ( dependency.mBuildFile == buildFile &&
437
                                ( ( p.isLinuxBuilt() && !dependency.isLinuxBuilt() ) ||
438
                                  ( p.isWin32Built() && !dependency.isWin32Built() ) ||
834 mhunt 439
                                  ( p.isSolarisBuilt() && !dependency.isSolarisBuilt() ) ||
440
                                  ( !p.isLinuxBuilt() && dependency.isLinuxBuilt() ) ||
441
                                  ( !p.isWin32Built() && dependency.isWin32Built() ) ||
442
                                  ( !p.isSolarisBuilt() && dependency.isSolarisBuilt() ) ) ) ) ) )
814 mhunt 443
                {
444
                  // in daemon mode this processed dependency has a build requirement or
445
                  // in escrow mode...
446
                  // this processed dependency has not been assigned to a build iteration or
447
                  // this processed dependency has been assigned to this build iteration and does not build on this platform
448
                  canBeBuiltNow = false;
449
                  mLogger.info("planRelease package cannot be built in this iteration " + p.mName);
450
                  break;
451
                }
452
              }
453
 
454
              if (allDependenciesForThisPackageProcessed)
455
              {
456
                p.mProcessed = true;
457
 
458
                if ( mDaemon )
459
                {
460
                  if ( canBeBuiltNow )
461
                  {
462
                    // flag package with build requirement, may get downgraded to future build requirement
463
                    p.mBuildFile = 1;
858 mhunt 464
                    mLogger.warn("planRelease set mBuildFile to 1 for package " + p.mAlias );
814 mhunt 465
                  }
466
                  else
467
                  {
468
                    // flag package with future build requirement
469
                    p.mBuildFile = 2;
858 mhunt 470
                    mLogger.warn("planRelease set mBuildFile to 2 for package " + p.mAlias );
814 mhunt 471
                  }
472
                }
473
                else
474
                {
475
                  if ( canBeBuiltNow )
476
                  {
848 dpurdie 477
                    if ( !mDaemon )
478
                    {
479
                      String isWin32Built = new String("");
480
 
481
                      if ( p.isWin32Built() )
482
                      {
483
                        isWin32Built = "W";
484
                      }
485
 
486
                      String isLinuxBuilt = new String("");
487
 
488
                      if ( p.isLinuxBuilt() )
489
                      {
490
                        isLinuxBuilt = "L";
491
                      }
492
 
493
                      String isSolarisBuilt = new String("");
494
 
495
                      if ( p.isSolarisBuilt() )
496
                      {
497
                        isSolarisBuilt = "S";
498
                      }
499
 
500
                      String isGeneric = new String("");
501
 
502
                      if ( p.isGeneric() )
503
                      {
504
                        isGeneric = "G";
505
                      }
506
 
507
                      raw_data += p.mAlias + "," +
508
                                  isWin32Built + "," +
509
                                  isLinuxBuilt + "," +
510
                                  isSolarisBuilt + "," +
511
                                  isGeneric + "," +
512
                                  buildFile +
513
                                  lf;
514
                    }
515
 
858 mhunt 516
                    // not daemon
814 mhunt 517
                    p.mBuildFile = buildFile;
858 mhunt 518
                    mLogger.info("planRelease set mBuildFile to " + buildFile + " for package " + p.mAlias );
814 mhunt 519
                  }
520
                }
521
              }
522
            }
523
          }
524
        }
525
      } while( !allDependenciesProcessed );
526
 
527
      if ( mDaemon )
528
      {
864 mhunt 529
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 530
        {
864 mhunt 531
          Package p = it.next();
814 mhunt 532
 
533
          if ( p.mProcessed && p.mBuildFile == 1 )
534
          {
535
            p.mBuildFile = buildFile;
858 mhunt 536
            mLogger.warn("planRelease 2 set mBuildFile to " + buildFile + " for package " + p.mAlias );
836 mhunt 537
 
814 mhunt 538
            if ( buildFile == 1 )
539
            {
540
              p.applyPV(mReleaseManager, mBaseline);
541
              // write <rtagId>offical
826 mhunt 542
              boolean createNewFile = rtagIdOfficial.createNewFile();
814 mhunt 543
 
826 mhunt 544
              if ( createNewFile )
814 mhunt 545
              {
826 mhunt 546
                  FileWriter rtagIdOfficialFileWriter = new FileWriter(rtagIdOfficial);
547
                  rtagIdOfficialFileWriter.append("packageName=" + p.mName + lf);
548
                  String extension = p.mExtension;
549
                  String version = p.mVersion;
550
 
551
                  if ( extension.length() > 0 )
552
                  {
553
                    version += extension;
554
                  }
555
 
556
                  rtagIdOfficialFileWriter.append("packageExtension=" + extension + lf);
557
                  rtagIdOfficialFileWriter.append("packageVersion=" + version + lf);
558
 
559
                  // depends in the form 'cs','25.1.0000.cr';'Dinkumware_STL','1.0.0.cots'
560
                  String depends = new String();
561
 
864 mhunt 562
                  for (Iterator<Package> it3 = p.mPackageDependencyCollection.iterator(); it3.hasNext(); )
826 mhunt 563
                  {
864 mhunt 564
                    Package depend = it3.next();
826 mhunt 565
 
566
                    if ( depends.compareTo( "" ) != 0 )
567
                    {
568
                      depends += ";";
569
                    }
570
                    depends += "\'" + depend.mName + "\'";
571
                    depends += ",";
572
                    String dependsExtension = depend.mExtension;
573
                    String dependsVersion = depend.mVersion;
574
 
575
                    if ( dependsExtension.length() > 0 )
576
                    {
577
                      dependsVersion += dependsExtension;
578
                    }
579
                    else
580
                    {
581
                      dependsExtension = ".";
582
                    }
583
                    depends += "\'" + dependsVersion + "\'";
584
                  }
585
 
586
                  rtagIdOfficialFileWriter.append("packageDepends=" + depends + lf);
587
 
588
                  if ( p.mDirectlyPlanned )
589
                  {
590
                    // a WIP
591
                    rtagIdOfficialFileWriter.append("packageRipple=0" + lf);
592
                  }
593
                  else
594
                  {
595
                    // a ripple
596
                    rtagIdOfficialFileWriter.append("packageRipple=1" + lf);
597
                  }
598
 
599
                  rtagIdOfficialFileWriter.append("packageVersionID=" + p.mId);
600
 
601
                  rtagIdOfficialFileWriter.close();
814 mhunt 602
              }
603
              else
604
              {
826 mhunt 605
                  mLogger.fatal("rtagIdOfficial.createNewFile() returned false");                  
814 mhunt 606
              }
607
            }
608
            else
609
            {
610
              mLogger.info("planRelease package has future (downgraded) build requirement " + p.mName + " " + buildFile);              
611
            }
612
 
613
            buildFile = 2;
614
          }
615
        }
616
      }
617
 
618
      // are more build files required
619
      allProcessed = true;
620
 
621
      if (mDaemon)
622
      {
864 mhunt 623
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 624
        {
864 mhunt 625
          Package p = it.next();
814 mhunt 626
 
627
          if ( p.mBuildFile < 0 || ( !p.mDirectlyPlanned && !p.mIndirectlyPlanned ) )
628
          {
629
            // at this point...
630
            // only 1 package with a build requirement has a mBuildFile of 1,
631
            // all other packages with a build requirement have an mBuildFile of 2
632
            // give packages with no build requirement, reproducible or not, an mBuildFile of 3
633
            p.mBuildFile = 3;
858 mhunt 634
            mLogger.warn("planRelease 1 set mBuildFile to 3 for package " + p.mAlias );
814 mhunt 635
          }
636
        }
637
      }
638
      else
639
      {
640
        // this is escrow mode centric
864 mhunt 641
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 642
        {
864 mhunt 643
          Package p = it.next();
814 mhunt 644
 
645
          if ( p.mBuildFile == 0 )
646
          {
647
            // more build files are required
648
            allProcessed = false;
649
            mLogger.info("planRelease more build files are required for " + p.mName);
650
            break;
651
          }
652
        }
653
 
654
        buildFile++;
655
      }
656
    } while( !allProcessed );
657
 
658
    // persist the build files
659
    allProcessed = false;
660
    buildFile = 1;
661
 
662
    if ( mDaemon )
663
    {
664
      // all interesting packages in daemon mode match the following filter
665
      buildFile = 3;
666
    }
667
 
668
    mTimestamp = System.currentTimeMillis();
669
 
864 mhunt 670
    if ( !ReleaseManager.mUseDatabase )
814 mhunt 671
    {
672
      mTimestamp = 123456789;
673
    }
674
 
675
    do
676
    {
677
      String buildFileContent = new String( generateBuildFileHeader() );
678
 
864 mhunt 679
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 680
      {
864 mhunt 681
        Package p = it.next();
814 mhunt 682
 
683
        if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
684
        {
685
          buildFileContent += generatePackageProperty(p);
686
        }
687
      }
688
 
689
      buildFileContent += generateTaskdef();
690
 
830 mhunt 691
      String set_up = new String("");
814 mhunt 692
 
864 mhunt 693
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 694
      {
864 mhunt 695
        Package p = it.next();
814 mhunt 696
 
697
        if ( p.mBuildFile > 0 && p.mBuildFile <= buildFile )
698
        {
699
          buildFileContent += generateTarget(p, buildFile);
700
        }
701
 
702
        if ( !mDaemon && buildFile == 1 )
703
        {
848 dpurdie 704
          // for the purposes of the set up, use /
705
          String loc = new String("");
706
          try
707
          {
708
            // The regular expression "\\\\" matches an escape character "\\" and a single backslash "\\"
709
            loc = p.mLocation.replaceAll("\\\\", "/");
710
          }
711
          catch( PatternSyntaxException e )
712
          {
713
          }
714
 
715
          set_up += "jats release -extractfiles"
716
                    + " \"-label=" + p.mLabel + "\""
717
                    + " \"-path=" + loc + "\""
718
                    + " \"-view=" + p.mAlias + "\""
719
                    + " -root=. -noprefix"
720
                    + lf;
814 mhunt 721
        }
722
      }
848 dpurdie 723
 
724
      if ( !mDaemon && buildFile == 1 )
725
      {
830 mhunt 726
        mEscrowClearcaseSupportCollection.add(set_up);
727
        mEscrowClearcaseSupportCollection.add(raw_data);
814 mhunt 728
      }
729
 
730
      buildFileContent += generateDefaultTarget( buildFile);
731
      buildFileContent += generateBuildFileFooter();
732
 
733
      mBuildCollection.add(buildFileContent);
734
 
735
      // are more build files required
736
      allProcessed = true;
737
 
738
      if (!mDaemon)
739
      {
740
        // this is escrow mode centric
864 mhunt 741
        for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 742
        {
864 mhunt 743
          Package p = it.next();
814 mhunt 744
 
745
          if ( p.mBuildFile > buildFile )
746
          {
747
            // more build files are required
748
            allProcessed = false;
749
            mLogger.info("planRelease reiterating package has no build requirement " + p.mName + " " + p.mBuildFile + " " + buildFile);
750
            break;
751
          }
752
        } 
753
 
754
        buildFile++;
755
      }
756
    } while( !allProcessed );
757
 
758
    mReleaseManager.disconnect();
759
    mLogger.warn("planRelease mDaemon " + mDaemon + " returned");
760
  }
761
 
762
  /**returns first build file content
763
   * returns false if no build file content exists
764
   */
765
  public boolean getFirstBuildFileContent(MutableString content)
766
  {
767
    mLogger.debug("getFirstBuildFileContent");
768
    boolean retVal = true;
769
 
770
    try
771
    {
772
      mBuildIndex = 0;
773
      content.value = (String)mBuildCollection.get( mBuildIndex );
774
    }
775
    catch( ArrayIndexOutOfBoundsException e )
776
    {
777
      retVal = false;
778
    }
779
 
780
    mLogger.info("getFirstBuildFileContent returned " + retVal);
781
    return retVal;
782
  }
783
 
784
  /**returns next build file content
785
   * returns false if no next build file content exists
786
   */
787
  public boolean getNextBuildFileContent(MutableString content)
788
  {
789
    mLogger.debug("getNextBuildFileContent");
790
    boolean retVal = true;
791
 
792
    try
793
    {
794
      mBuildIndex++;
795
      content.value = (String)mBuildCollection.get( mBuildIndex );
796
    }
797
    catch( ArrayIndexOutOfBoundsException e )
798
    {
799
      retVal = false;
800
    }
801
 
802
    mLogger.debug("getNextBuildFileContent returned " + retVal);
803
    return retVal;
804
  }
805
 
806
  /**collects meta data associated with the baseline
807
   */
808
  private void collectMetaData() throws SQLException, Exception
809
  {
810
    mLogger.debug("collectMetaData mDaemon " + mDaemon);
811
    mGbeMachtypeCollection.removeAllElements();
812
    mReleaseManager.queryMachtypes(mGbeMachtypeCollection, mDaemon, mBaseline);
813
 
814
    if (mDaemon)
815
    {
816
      mMailServer = mReleaseManager.queryMailServer();
817
      mMailSender = mReleaseManager.queryMailSender();
818
    }
819
    mBaselineName = mReleaseManager.queryBaselineName(mDaemon, mBaseline);
820
  }
821
 
822
  /**returns the Package with the matching mAlias or NULL_PACKAGE if no package has the mID
823
   */
824
  private Package findPackage(String alias)
825
  {
826
    mLogger.debug("findPackage");
827
    Package retVal = ReleaseManager.NULL_PACKAGE;
828
 
864 mhunt 829
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 830
    {
864 mhunt 831
      Package p = it.next();
814 mhunt 832
 
833
      if ( p.mAlias.compareTo( alias ) == 0 )
834
      {
835
        retVal = p;
836
        break;
837
      }
838
    }
839
 
840
    mLogger.info("findPackage returned " + retVal.mName);
841
    return retVal;
842
  }
843
 
844
  /**sets the mBuildFile to -5 for the package and all dependent packages
845
   */
846
  private void rippleBuildExclude(Package p)
847
  {
848
    mLogger.debug("rippleBuildExclude");
849
    if ( p.mBuildFile == 0 )
850
    {
851
      p.mBuildFile = -5;
858 mhunt 852
      mLogger.warn("rippleBuildExclude set mBuildFile to -5 for package " + p.mAlias );
836 mhunt 853
 
864 mhunt 854
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 855
      {
864 mhunt 856
        Package pkg = it.next();
814 mhunt 857
 
858
        if ( pkg != p )
859
        {
864 mhunt 860
          for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 861
          {
864 mhunt 862
            Package dependency = it2.next();
814 mhunt 863
 
864
            if ( dependency == p )
865
            {
866
              rippleBuildExclude( pkg );
867
              break;
868
            }
869
          }
870
        }
871
      }
872
    }
873
    mLogger.info("rippleBuildExclude set " + p.mName + " " + p.mBuildFile);
874
  }
875
 
876
  /**returns a build file header for the mBaseline
877
   */
878
  private String generateBuildFileHeader()
879
  {
880
    mLogger.debug("generateBuildFileHeader");
881
    String lf = new String( System.getProperty("line.separator") );
882
    String retVal = new String("");
883
    retVal +=
862 mhunt 884
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + lf +
814 mhunt 885
    "<project name=\"mass\" default=\"full\" basedir=\".\">" + lf;
886
 
887
    if ( mDaemon )
888
    {
889
      retVal +=
890
      "<property name=\"abt_mail_server\" value=\"" + mMailServer + "\"/>" + lf +
891
      "<property name=\"abt_mail_sender\" value=\"" + mMailSender + "\"/>" + lf +
892
      "<property name=\"abt_rtag_id\" value=\"" + mBaseline + "\"/>" + lf +
893
      "<property name=\"abt_daemon\" value=\"" + mTimestamp + "\"/>" + lf;
894
    }
895
    else
896
    {
897
      retVal +=
898
      "<property name=\"abt_rtag_id\" value=\"-1\"/>" + lf;
899
    }
900
 
822 mhunt 901
    String majorVersionNumber = this.getClass().getPackage().getSpecificationVersion();
902
 
864 mhunt 903
    if ( !ReleaseManager.mUseDatabase )
822 mhunt 904
    {
905
        // hard code 11 for unit test purposes
906
         majorVersionNumber = "11";
907
    }
908
 
814 mhunt 909
    retVal +=
910
    "<property name=\"abt_release\" value=\"" + mBaselineName + "\"/>" + lf +
822 mhunt 911
    "<property name=\"abt_buildtool_version\" value=\""+ majorVersionNumber + "\"/>" + lf +
814 mhunt 912
    "<condition property=\"abt_family\" value=\"windows\">" + lf +
913
    "  <os family=\"windows\"/>" + lf +
914
    "</condition>" + lf +
915
    "<property name=\"abt_family\" value=\"unix\"/>" + lf;
916
    mLogger.info("generateBuildFileHeader returned " + retVal);
917
    return retVal;
918
  }
919
 
920
  /**returns an ant property for the passed Package
921
   */
922
  private String generatePackageProperty(Package p)
923
  {
924
    mLogger.debug("generatePackageProperty");
925
    String lf = new String( System.getProperty("line.separator") );
926
    String retVal = new String("");
927
    retVal +=
928
    "<property name=\"" + p.mAlias + "\" value=\"" + p.mName + " " + p.mVersion + p.mExtension + "\"/>" + lf;
929
    mLogger.info("generatePackageProperty returned " + retVal);
930
    return retVal;
931
  }
932
 
933
  /**returns an ant taskdef for the abt ant task
934
   */
935
  private String generateTaskdef()
936
  {
937
    mLogger.debug("generateTaskdef");
938
    String lf = new String( System.getProperty("line.separator") );
939
    String retVal = new String("");
940
    retVal +=
941
    "<taskdef name=\"abt\" classname=\"com.erggroup.buildtool.ABT\"/>" + lf;
942
    return retVal;
943
  }
944
 
945
  /**returns an ant target for the passed Package
946
   * in daemon mode:
947
   *  packages are categorised with one of three mBuildFile values:
948
   *   1 the package to be built by this buildfile
949
   *   2 the packages with a future build requirement
950
   *   3 the packages with no build requirement
951
   *  the returned target depends on this categorisation and will have
952
   *   1 full abt info
953
   *   2 full dependency info to determine future build ordering but no abt info (will not build this package)
954
   *   3 only a name attribute (will not build this package)
955
   * in escrow mode:
956
   *  if the passed Package's mBuildFile is different (less than) the passed build file,
957
   *  the returned target have only a name attribute (will not build this package) 
958
   */
959
  private String generateTarget(Package p, int buildFile)
960
  {
961
    mLogger.debug("generateTarget");
962
 
832 mhunt 963
    if ( ( mDaemon && p.mBuildFile == 1 ) || ( !mDaemon && !p.isGeneric() ) )
814 mhunt 964
    {
965
      // populate 'missing' BuildStandards
966
      boolean solaris = false;
967
      boolean linux = false;
968
      boolean win32 = false;
969
      boolean jats = false;
970
      boolean determinedBuildStandard = false;
971
 
864 mhunt 972
      for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 973
      {
864 mhunt 974
        BuildStandard bs = it.next();
814 mhunt 975
 
976
        if ( bs.getSolaris() )
977
        {
978
          solaris = true;
979
        }
980
        else
981
        if ( bs.getLinux() )
982
        {
983
          linux = true;
984
        }
985
        else
986
        if ( bs.getWin32() )
987
        {
988
          win32 = true;
989
        }
990
 
864 mhunt 991
        if ( !determinedBuildStandard && bs.getBuildStandard(!ReleaseManager.mUseDatabase).contains("<jats") )
814 mhunt 992
        {
993
          jats = true;
994
          determinedBuildStandard = true;
995
        }
996
      }
997
 
998
      if ( !solaris )
999
      {
1000
        BuildStandard bs = new BuildStandard(this);
1001
        bs.setSolaris();
1002
 
1003
        if ( jats )
1004
        {
1005
          bs.setJatsNone();
1006
        }
1007
        else
1008
        {
1009
          bs.setAntNone();
1010
        }
1011
 
1012
        p.mBuildStandardCollection.add(bs);
1013
      }
1014
 
1015
      if ( !linux )
1016
      {
1017
        BuildStandard bs = new BuildStandard(this);
1018
        bs.setLinux();
1019
 
1020
        if ( jats )
1021
        {
1022
          bs.setJatsNone();
1023
        }
1024
        else
1025
        {
1026
          bs.setAntNone();
1027
        }
1028
 
1029
        p.mBuildStandardCollection.add(bs);
1030
      }
1031
 
1032
      if ( !win32 )
1033
      {
1034
        BuildStandard bs = new BuildStandard(this);
1035
        bs.setWin32();
1036
 
1037
        if ( jats )
1038
        {
1039
          bs.setJatsNone();
1040
        }
1041
        else
1042
        {
1043
          bs.setAntNone();
1044
        }
1045
 
1046
        p.mBuildStandardCollection.add(bs);
1047
      }
1048
    }
1049
 
1050
    String lf = new String( System.getProperty("line.separator") );
1051
    String retVal = new String("");
1052
 
1053
    if ( ( mDaemon && p.mBuildFile == 3 ) ||
1054
         ( !mDaemon && ( p.mBuildFile < buildFile ) ) )
1055
    {
1056
      retVal +=
1057
      "<target name=\"" + p.mAlias + "\"/>" + lf;
1058
    }
1059
    else
1060
    {
848 dpurdie 1061
      retVal +=
814 mhunt 1062
      "<target name=\"" + p.mAlias + ".wrap\"";
1063
 
1064
      if ( p.mPackageDependencyCollection.size() > 0 )
1065
      {
1066
        retVal +=" depends=\"";
1067
        boolean comma = false;
1068
 
864 mhunt 1069
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1070
        {
1071
          if (comma)
1072
          {
1073
            retVal += ",";
1074
          }
1075
          comma = true;
1076
 
864 mhunt 1077
          Package dependency = it.next();
814 mhunt 1078
          retVal += dependency.mAlias;
1079
        }
1080
 
1081
        retVal += "\"";
1082
      }
1083
      retVal += ">" + lf;
1084
 
1085
      if ( !mDaemon )
1086
      {
1087
        boolean hasDependenciesBuiltInThisIteration = false;
1088
        if ( ( p.mPackageDependencyCollection.size() > 0 ) )
1089
        {
864 mhunt 1090
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1091
          {
864 mhunt 1092
            Package dependency = it.next();
814 mhunt 1093
 
1094
            if ( dependency.mBuildFile == buildFile )
1095
            {
1096
              hasDependenciesBuiltInThisIteration = true;
1097
              break;
1098
            }
1099
          }
1100
        }
1101
 
1102
        if ( hasDependenciesBuiltInThisIteration )
1103
        {
1104
          retVal +=
1105
          "  <condition property=\"" + p.mAlias + ".build\">" + lf +
1106
          "    <and>" + lf;
1107
 
864 mhunt 1108
          for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1109
          {
864 mhunt 1110
            Package dependency = it.next();
814 mhunt 1111
 
1112
            if ( dependency.mBuildFile == buildFile )
1113
            {
1114
              retVal +=
1115
              "      <or>" + lf +
1116
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"0\"/>" + lf +
1117
              "        <equals arg1=\"${" + dependency.mAlias + ".res}\" arg2=\"257\"/>" + lf +
1118
              "      </or>" + lf;
1119
            }
1120
          }
1121
 
1122
          retVal +=
1123
          "    </and>" + lf +
1124
          "  </condition>" + lf;
1125
        }
1126
        else
1127
        {
1128
          retVal += "  <property name=\"" + p.mAlias + ".build\" value=\"\"/>" + lf;
1129
        }
1130
      }
1131
 
1132
      retVal +=
1133
      "</target>" + lf +
1134
      "<target name=\"" + p.mAlias + "\" depends=\"" + p.mAlias + ".wrap\"";
1135
 
1136
      if ( !mDaemon )
1137
      {
1138
        retVal += " if=\"" + p.mAlias + ".build\"";
1139
      }
1140
 
1141
      retVal += ">" + lf;
1142
 
1143
      if ( mDaemon && p.mBuildFile == 1 )
1144
      {
1145
        retVal +=
1146
        "<property name=\"" + p.mAlias + "pkg_id\" value=\"" + p.mPid + "\"/>" + lf +
1147
        "<property name=\"" + p.mAlias + "pv_id\" value=\"" + p.mId + "\"/>" + lf;
1148
      }
1149
 
1150
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1151
      {
1152
        retVal +=
1153
        "<property name=\"" + p.mAlias + "packagename\" value=\"" + p.mName + "\"/>" + lf +
1154
        "<property name=\"" + p.mAlias + "packageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1155
        "<property name=\"" + p.mAlias + "packageextension\" value=\"";
1156
 
1157
        if ( p.mExtension.length() > 0 )
1158
        {
1159
          // drop the .
1160
          retVal += p.mExtension.substring(1);
1161
        }
1162
        else
1163
        {
1164
          retVal += p.mExtension;
1165
        }
1166
 
1167
        retVal += "\"/>" + lf +
1168
        "<property name=\"" + p.mAlias + "packagelabel\" value=\"" + p.mLabel + "\"/>" + lf;
1169
 
1170
        if ( p.mDirectlyPlanned )
1171
        {
1172
          retVal += "<property name=\"" + p.mAlias + "directchange\" value=\"\"/>" + lf;
1173
        }
1174
 
852 mhunt 1175
        if ( ! p.mRequiresSourceControlInteraction )
1176
        {
1177
          retVal += "<property name=\"" + p.mAlias + "doesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
1178
        }
1179
 
814 mhunt 1180
        mAddendum = "non generic";
1181
 
1182
        if ( p.isGeneric() )
1183
        {
1184
          mAddendum = "generic";
1185
          retVal += "<property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
1186
        }
1187
 
1188
        retVal += loc(p, p.mAlias + "loc", lf);
1189
 
830 mhunt 1190
        if ( p.mHasAutomatedUnitTests && mDaemon )
814 mhunt 1191
        {
1192
          retVal += 
1193
          "<property name=\"" + p.mAlias + "unittests\" value=\"\"/>" + lf;
1194
        }
1195
      }
1196
 
1197
      retVal += "<abt>" + lf;
1198
 
1199
      if ( ( mDaemon && p.mBuildFile == 1 ) || !mDaemon )
1200
      {
864 mhunt 1201
        for (Iterator<Package> it = p.mPackageDependencyCollection.iterator(); it.hasNext(); )
814 mhunt 1202
        {
864 mhunt 1203
          Package dependency = it.next();
814 mhunt 1204
          retVal +=
1205
          "  <depend package_alias=\"${" + dependency.mAlias + "}\"/>" + lf;
1206
        }
1207
 
836 mhunt 1208
        retVal += buildInfo(p, lf, false);
814 mhunt 1209
      }
1210
 
1211
      if ( mDaemon && p.mBuildFile == 1 )
1212
      {
854 mhunt 1213
        retVal += p.emailInfo( lf );
814 mhunt 1214
      }
1215
 
1216
      retVal += "</abt>" + lf +
1217
      "</target>" + lf;
1218
 
1219
      if ( mDaemon && p.mBuildFile == 1 )
1220
      {
1221
        retVal +=
1222
        "<target name=\"AbtSetUp\">" + lf +
854 mhunt 1223
        "<property name=\"AbtSetUppackagelabel\" value=\"" + p.mLabel + "\"/>" + lf +
1224
        "<property name=\"AbtSetUppackagename\" value=\"" + p.mName + "\"/>" + lf;
814 mhunt 1225
 
1226
        retVal += loc(p, "AbtSetUppackagelocation", lf);
1227
 
1228
        retVal +=
1229
        "<abt>" + lf +
854 mhunt 1230
        p.emailInfo( lf ) +
814 mhunt 1231
        "</abt>" + lf +
1232
        "</target>" + lf +
1233
        "<target name=\"AbtTearDown\">" + lf +
1234
        "<property name=\"AbtTearDownpackagelabel\" value=\"" + p.mLabel + "\"/>" + lf +
1235
        "<property name=\"AbtTearDownpackagename\" value=\"" + p.mName + "\"/>" + lf +
1236
        "<property name=\"AbtTearDownpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1237
        "<property name=\"AbtTearDownpackageextension\" value=\"";
1238
 
1239
        if ( p.mExtension.length() > 0 )
1240
        {
1241
          // drop the .
1242
          retVal += p.mExtension.substring(1);
1243
        }
1244
        else
1245
        {
1246
          retVal += p.mExtension;
1247
        }
1248
 
1249
        retVal += "\"/>" + lf;
1250
 
1251
        if ( p.isGeneric() )
1252
        {
1253
          retVal += "<property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
1254
        }
1255
 
1256
        retVal +=        
1257
        "<abt>" + lf +
836 mhunt 1258
        buildInfo(p, lf, false) +
854 mhunt 1259
        p.emailInfo( lf ) +
814 mhunt 1260
        "</abt>" + lf +
1261
        "</target>" + lf +
1262
        "<target name=\"AbtPublish\">" + lf +
1263
        "<property name=\"AbtPublishpackagelabel\" value=\"" + p.mLabel + "\"/>" + lf +
1264
        "<property name=\"AbtPublishpackagename\" value=\"" + p.mName + "\"/>" + lf +
1265
        "<property name=\"AbtPublishpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1266
        "<property name=\"AbtPublishpackageextension\" value=\"";
1267
 
1268
        if ( p.mExtension.length() > 0 )
1269
        {
1270
          // drop the .
1271
          retVal += p.mExtension.substring(1);
1272
        }
1273
        else
1274
        {
1275
          retVal += p.mExtension;
1276
        }
1277
 
1278
        retVal += "\"/>" + lf;
1279
 
1280
        if ( p.mDirectlyPlanned )
1281
        {
1282
          retVal += "<property name=\"AbtPublishdirectchange\" value=\"\"/>" + lf;
1283
        }
1284
 
852 mhunt 1285
        if ( ! p.mRequiresSourceControlInteraction )
1286
        {
1287
          retVal += "<property name=\"AbtPublishdoesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
1288
        }
1289
 
814 mhunt 1290
        if ( p.isGeneric() )
1291
        {
1292
          retVal += "<property name=\"AbtPublishgeneric\" value=\"\"/>" + lf;
1293
        }
1294
 
1295
        retVal += loc(p, "AbtPublishloc", lf);
1296
        retVal +=
816 mhunt 1297
        "<abt>" + lf +
854 mhunt 1298
        buildInfo(p, lf, true) +
1299
        p.emailInfo( lf ) +
814 mhunt 1300
        "</abt>" + lf +
1301
        "</target>" + lf;
1302
      }
1303
    }
1304
    mLogger.info("generateTarget returned " + retVal);
1305
    return retVal;
1306
  }
1307
 
1308
  /**returns an ant default target for the current build iteration
1309
   */
1310
  private String generateDefaultTarget(int buildFile)
1311
  {
1312
    mLogger.debug("generateDefaultTarget");
1313
    String lf = new String( System.getProperty("line.separator") );
1314
    String retVal = new String("");
1315
    retVal +=
1316
    "<target name=\"fullstart\">" + lf;
1317
 
1318
    if (buildFile == 1)
1319
    {
1320
      retVal +=
1321
      "<echo message=\"${line.separator}The following package versions are not reproducible on any build platform:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1322
 
864 mhunt 1323
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1324
      {
864 mhunt 1325
        Package p = it.next();
814 mhunt 1326
 
1327
        if ( p.mBuildFile == -1 )
1328
        {
1329
          retVal +=
1330
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1331
        }
1332
      }
1333
 
1334
      retVal +=
1335
      "<echo message=\"${line.separator}The following package versions are not reproducible on the build platforms associated with this baseline:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1336
 
864 mhunt 1337
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1338
      {
864 mhunt 1339
        Package p = it.next();
814 mhunt 1340
 
1341
        if ( p.mBuildFile == -2 )
1342
        {
1343
          retVal +=
1344
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1345
        }
1346
      }
1347
 
1348
      retVal +=
1349
      "<echo message=\"${line.separator}The following package versions are not reproducible as they are directly dependent upon package versions not in the baseline:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1350
 
864 mhunt 1351
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1352
      {
864 mhunt 1353
        Package p = it.next();
814 mhunt 1354
 
1355
        if ( p.mBuildFile == -4 )
1356
        {
1357
          retVal +=
1358
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1359
        }
1360
      }
1361
 
1362
      retVal +=
1363
      "<echo message=\"${line.separator}The following package versions are not reproducible as they are directly/indirectly dependent upon not reproducible package versions:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1364
 
864 mhunt 1365
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1366
      {
864 mhunt 1367
        Package p = it.next();
814 mhunt 1368
 
1369
        if ( p.mBuildFile == -5 )
1370
        {
1371
          retVal +=
1372
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1373
        }
1374
      }
1375
    }
1376
    if ( !mDaemon )
1377
    {
1378
      retVal +=
1379
      "<echo message=\"${line.separator}Build Started:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1380
    }
1381
 
1382
    retVal +=
1383
    "</target>" + lf +
1384
    "<target name=\"full\" depends=\"fullstart";
1385
 
864 mhunt 1386
    for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1387
    {
864 mhunt 1388
      Package p = it.next();
814 mhunt 1389
 
1390
      if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
1391
      {
1392
        retVal += "," + p.mAlias;
1393
      }
1394
    }
1395
 
1396
    retVal +=
1397
    "\">" + lf;
1398
 
1399
    if ( !mDaemon )
1400
    {
1401
      retVal +=
1402
      "<echo message=\"${line.separator}Build Finished${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1403
    }
1404
 
1405
    retVal +=
1406
    "</target>" + lf;
1407
    return retVal;
1408
  }
1409
 
1410
  /**returns a build file footer
1411
   */
1412
  private String generateBuildFileFooter()
1413
  {
1414
    mLogger.debug("generateBuildFileFooter");
1415
    String retVal = new String("</project>");
1416
    return retVal;
1417
  }
1418
 
1419
  /**sets the mIndirectlyPlanned true for the package and all dependent packages
1420
   */
1421
  private void rippleIndirectlyPlanned(Package p)
1422
  {
1423
    mLogger.debug("rippleIndirectlyPlanned");
1424
    if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
1425
    {
1426
      p.mIndirectlyPlanned = true;
1427
 
864 mhunt 1428
      for (Iterator<Package> it = mPackageCollection.iterator(); it.hasNext(); )
814 mhunt 1429
      {
864 mhunt 1430
        Package pkg = it.next();
814 mhunt 1431
 
1432
        if ( pkg != p )
1433
        {
864 mhunt 1434
          for (Iterator<Package> it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
814 mhunt 1435
          {
864 mhunt 1436
            Package dependency = it2.next();
814 mhunt 1437
 
1438
            if ( dependency == p )
1439
            {
1440
              rippleIndirectlyPlanned( pkg );
1441
              break;
1442
            }
1443
          }
1444
        }
1445
      }
1446
    }
1447
    mLogger.info("rippleIndirectlyPlanned set " + p.mName + " " + p.mIndirectlyPlanned);    
1448
  }
1449
 
1450
  /**accessor method
1451
   */
830 mhunt 1452
  public String getESCROWSetUp()
814 mhunt 1453
  {
830 mhunt 1454
    mLogger.debug("getESCROWSetUp");
814 mhunt 1455
    String retVal = new String("");
1456
 
1457
    try
1458
    {
830 mhunt 1459
      if ( mEscrowClearcaseSupportCollection.size() >= 1 )
814 mhunt 1460
      {
1461
        retVal = (String)mEscrowClearcaseSupportCollection.get(0);
1462
      }
1463
    }
1464
    catch( ArrayIndexOutOfBoundsException e )
1465
    {
1466
    }
1467
 
830 mhunt 1468
    mLogger.info("getESCROWSetUp returned " + retVal);
814 mhunt 1469
    return retVal;
1470
  }
1471
 
1472
  /**accessor method
1473
   */
830 mhunt 1474
  public String getRawData()
814 mhunt 1475
  {
830 mhunt 1476
    mLogger.debug("getRawData");
814 mhunt 1477
    String retVal = new String("");
1478
 
1479
    try
1480
    {
830 mhunt 1481
      if ( mEscrowClearcaseSupportCollection.size() >= 2 )
814 mhunt 1482
      {
1483
        retVal = (String)mEscrowClearcaseSupportCollection.get(1);
1484
      }
1485
    }
1486
    catch( ArrayIndexOutOfBoundsException e )
1487
    {
1488
    }
1489
 
830 mhunt 1490
    mLogger.info("getRawData returned " + retVal);
814 mhunt 1491
    return retVal;
1492
  }
1493
 
1494
  /**returns first build file content and addendum
1495
   * the addendum value is one of "non generic", "generic" or "dummy"
1496
   */
1497
  public void getFirstBuildFileContent(MutableString content, 
1498
                                MutableString addendum)
1499
  {
1500
    mLogger.debug("getFirstBuildFileContent");
1501
    try
1502
    {
1503
      mBuildIndex = 0;
1504
      content.value = (String)mBuildCollection.get( mBuildIndex );
1505
      addendum.value = mAddendum;
1506
    }
1507
    catch( ArrayIndexOutOfBoundsException e )
1508
    {
1509
    }
1510
    mLogger.info("getFirstBuildFileContent passed " + content.value + addendum.value);
1511
  }
1512
 
1513
  /**returns the built loc
1514
   */
1515
  private String loc(Package p, String target, String lf)
1516
  {
1517
    mLogger.debug("loc");
1518
    String retVal = new String();
1519
    String loc = new String("\\");
1520
 
864 mhunt 1521
    for (Iterator<String> it = mGbeMachtypeCollection.iterator(); it.hasNext(); )
814 mhunt 1522
    {
864 mhunt 1523
      String machtype = it.next();
814 mhunt 1524
 
1525
      if ( machtype.compareTo("win32") == 0 )
1526
      {
816 mhunt 1527
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1528
        {
816 mhunt 1529
          if (mDaemon)
814 mhunt 1530
          {
832 mhunt 1531
            loc += mBaseline + "\\" + mTimestamp + "\\" + p.mLabel;
814 mhunt 1532
          }
832 mhunt 1533
          else
1534
          {
848 dpurdie 1535
            // mAlias used with jats -extractfiles -view
1536
            loc += p.mAlias;
832 mhunt 1537
          }
1538
 
1539
          loc += p.mLocation;
814 mhunt 1540
        }
816 mhunt 1541
        else
1542
        {
1543
          loc = p.mLocation;
1544
        }
1545
        break;
814 mhunt 1546
      }
1547
    }
1548
 
1549
    loc = loc.replace('/', '\\');
1550
    retVal =
1551
    "<condition property=\"" + target + "\" value=\"" + loc + "\">" + lf +
1552
    "  <os family=\"windows\"/>" + lf +
1553
    "</condition>" + lf;
1554
 
1555
    loc = "/";
1556
 
864 mhunt 1557
    for (Iterator<String> it = mGbeMachtypeCollection.iterator(); it.hasNext(); )
814 mhunt 1558
    {
864 mhunt 1559
      String machtype = it.next();
814 mhunt 1560
 
1561
      if ( machtype.compareTo("linux_i386") == 0 )
1562
      {
816 mhunt 1563
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1564
        {
816 mhunt 1565
          if (mDaemon)
814 mhunt 1566
          {
816 mhunt 1567
            loc += mBaseline + "/" + mTimestamp + "/";
814 mhunt 1568
          }
832 mhunt 1569
 
1570
          if (mDaemon)
1571
          {
1572
            loc += p.mLabel;
848 dpurdie 1573
            // no vobs in escrow_set_up ie jats -extractfiles
1574
            loc += "/vobs";
832 mhunt 1575
          }
1576
          else
1577
          {
848 dpurdie 1578
            // mAlias used with jats -extractfiles -view
1579
            loc += p.mAlias;
832 mhunt 1580
          }
1581
 
1582
          loc += p.mLocation;
814 mhunt 1583
        }
816 mhunt 1584
        else
1585
        {
1586
          loc = p.mLocation;
1587
        }
1588
        break;
814 mhunt 1589
      }
1590
      else if ( machtype.compareTo("sparc") == 0
1591
             || machtype.compareTo("solaris10_x86") == 0
1592
             || machtype.compareTo("solaris10_sparc32") == 0 )
1593
      {
816 mhunt 1594
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1595
        {
816 mhunt 1596
          if (mDaemon)
814 mhunt 1597
          {
816 mhunt 1598
            loc += mBaseline + "/" + mTimestamp + "/";
1599
          }
814 mhunt 1600
 
832 mhunt 1601
          if (mDaemon)
1602
          {
1603
            loc += p.mLabel;
848 dpurdie 1604
            // no vobs in escrow_set_up ie jats -extractfiles
1605
            loc += "/vobs";
832 mhunt 1606
          }
1607
          else
1608
          {
848 dpurdie 1609
            // mAlias used with jats -extractfiles -view
1610
            loc += p.mAlias;
832 mhunt 1611
          }
1612
 
1613
          loc += p.mLocation;
816 mhunt 1614
        }
1615
        else
1616
        {
1617
          loc = p.mLocation;
1618
        }
1619
        break;
814 mhunt 1620
      }
1621
    }
1622
    loc = loc.replace('\\', '/');
1623
    retVal += 
1624
    "<property name=\"" + target + "\" value=\"" + loc + "\"/>" + lf;
1625
 
1626
    mLogger.info("loc returned " + retVal);
1627
    return retVal;
1628
  }
816 mhunt 1629
 
1630
  /**returns the buildInfo
1631
   */
836 mhunt 1632
  private String buildInfo(Package p, String lf, boolean filter)
816 mhunt 1633
  {
1634
    mLogger.debug("buildInfo");
1635
 
1636
    String platforms = new String();
1637
    String standards = new String();
1638
 
864 mhunt 1639
    for (Iterator<BuildStandard> it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
816 mhunt 1640
    {
864 mhunt 1641
      BuildStandard bs = it.next();
816 mhunt 1642
 
836 mhunt 1643
      if ( !filter )
816 mhunt 1644
      {
864 mhunt 1645
        String platform = bs.getPlatform(!ReleaseManager.mUseDatabase);
816 mhunt 1646
 
1647
        if ( platform.length() > 0 )
1648
        {
1649
          platforms += platform + lf;
1650
        }
1651
 
864 mhunt 1652
        String standard = bs.getBuildStandard(!ReleaseManager.mUseDatabase);
816 mhunt 1653
 
1654
        if ( standard.length() > 0 )
1655
        {
1656
          standards += standard + lf;
1657
        }
1658
      }
1659
      else
1660
      {
864 mhunt 1661
        if ( !bs.getBuildStandard(!ReleaseManager.mUseDatabase).contains("\"none\"") )
816 mhunt 1662
        {
864 mhunt 1663
          String platform = bs.getPlatform(!ReleaseManager.mUseDatabase);
816 mhunt 1664
 
1665
          if ( platform.length() > 0 )
1666
          {
1667
            platforms += platform + lf;
1668
          }
836 mhunt 1669
 
864 mhunt 1670
          String standard = bs.getBuildStandard(!ReleaseManager.mUseDatabase);
836 mhunt 1671
 
1672
          if ( standard.length() > 0 )
1673
          {
1674
            standards += standard + lf;
1675
          }
816 mhunt 1676
        }
1677
      }
1678
    }
1679
 
1680
    mLogger.info("buildInfo returned " + platforms + standards);
1681
    return platforms + standards;
1682
  }
814 mhunt 1683
}