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