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
      {
1217
       for (Iterator it = p.mBuildFailureEmailCollection.iterator(); it.hasNext(); )
1218
       {
1219
         String email = (String)it.next();
1220
         retVal +=
1221
         "  <owner email=\"" + email +"\"/>" + lf;
1222
       }
1223
      }
1224
 
1225
      retVal += "</abt>" + lf +
1226
      "</target>" + lf;
1227
 
1228
      if ( mDaemon && p.mBuildFile == 1 )
1229
      {
1230
        retVal +=
1231
        "<target name=\"AbtSetUp\">" + lf +
1232
        "<property name=\"AbtSetUppackagelabel\" value=\"" + p.mLabel + "\"/>" + lf;
1233
 
1234
        retVal += loc(p, "AbtSetUppackagelocation", lf);
1235
 
1236
        retVal +=
1237
        "<abt>" + lf +
1238
        "</abt>" + lf +
1239
        "</target>" + lf +
1240
        "<target name=\"AbtTearDown\">" + lf +
1241
        "<property name=\"AbtTearDownpackagelabel\" value=\"" + p.mLabel + "\"/>" + lf +
1242
        "<property name=\"AbtTearDownpackagename\" value=\"" + p.mName + "\"/>" + lf +
1243
        "<property name=\"AbtTearDownpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1244
        "<property name=\"AbtTearDownpackageextension\" value=\"";
1245
 
1246
        if ( p.mExtension.length() > 0 )
1247
        {
1248
          // drop the .
1249
          retVal += p.mExtension.substring(1);
1250
        }
1251
        else
1252
        {
1253
          retVal += p.mExtension;
1254
        }
1255
 
1256
        retVal += "\"/>" + lf;
1257
 
1258
        if ( p.isGeneric() )
1259
        {
1260
          retVal += "<property name=\"" + p.mAlias + "generic\" value=\"\"/>" + lf;
1261
        }
1262
 
1263
        retVal +=        
1264
        "<abt>" + lf +
836 mhunt 1265
        buildInfo(p, lf, false) +
814 mhunt 1266
        "</abt>" + lf +
1267
        "</target>" + lf +
1268
        "<target name=\"AbtPublish\">" + lf +
1269
        "<property name=\"AbtPublishpackagelabel\" value=\"" + p.mLabel + "\"/>" + lf +
1270
        "<property name=\"AbtPublishpackagename\" value=\"" + p.mName + "\"/>" + lf +
1271
        "<property name=\"AbtPublishpackageversion\" value=\"" + p.mVersion + "\"/>" + lf +
1272
        "<property name=\"AbtPublishpackageextension\" value=\"";
1273
 
1274
        if ( p.mExtension.length() > 0 )
1275
        {
1276
          // drop the .
1277
          retVal += p.mExtension.substring(1);
1278
        }
1279
        else
1280
        {
1281
          retVal += p.mExtension;
1282
        }
1283
 
1284
        retVal += "\"/>" + lf;
1285
 
1286
        if ( p.mDirectlyPlanned )
1287
        {
1288
          retVal += "<property name=\"AbtPublishdirectchange\" value=\"\"/>" + lf;
1289
        }
1290
 
852 mhunt 1291
        if ( ! p.mRequiresSourceControlInteraction )
1292
        {
1293
          retVal += "<property name=\"AbtPublishdoesnotrequiresourcecontrolinteraction\" value=\"\"/>" + lf;
1294
        }
1295
 
814 mhunt 1296
        if ( p.isGeneric() )
1297
        {
1298
          retVal += "<property name=\"AbtPublishgeneric\" value=\"\"/>" + lf;
1299
        }
1300
 
1301
        retVal += loc(p, "AbtPublishloc", lf);
1302
        retVal +=
816 mhunt 1303
        "<abt>" + lf +
836 mhunt 1304
        buildInfo(p, lf, true);
1305
 
1306
        for (Iterator it = p.mBuildFailureEmailCollection.iterator(); it.hasNext(); )
1307
        {
1308
          String email = (String)it.next();
1309
          retVal +=
1310
          "  <owner email=\"" + email +"\"/>" + lf;
1311
        }
1312
 
1313
        retVal +=
814 mhunt 1314
        "</abt>" + lf +
1315
        "</target>" + lf;
1316
      }
1317
    }
1318
    mLogger.info("generateTarget returned " + retVal);
1319
    return retVal;
1320
  }
1321
 
1322
  /**returns an ant default target for the current build iteration
1323
   */
1324
  private String generateDefaultTarget(int buildFile)
1325
  {
1326
    mLogger.debug("generateDefaultTarget");
1327
    String lf = new String( System.getProperty("line.separator") );
1328
    String retVal = new String("");
1329
    retVal +=
1330
    "<target name=\"fullstart\">" + lf;
1331
 
1332
    if (buildFile == 1)
1333
    {
1334
      retVal +=
1335
      "<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;
1336
 
1337
      for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1338
      {
1339
        Package p = (Package)it.next();
1340
 
1341
        if ( p.mBuildFile == -1 )
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 on the build platforms associated with this baseline:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1350
 
1351
      for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1352
      {
1353
        Package p = (Package)it.next();
1354
 
1355
        if ( p.mBuildFile == -2 )
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 dependent upon package versions not in the baseline:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1364
 
1365
      for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1366
      {
1367
        Package p = (Package)it.next();
1368
 
1369
        if ( p.mBuildFile == -4 )
1370
        {
1371
          retVal +=
1372
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1373
        }
1374
      }
1375
 
1376
      retVal +=
1377
      "<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;
1378
 
1379
      for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1380
      {
1381
        Package p = (Package)it.next();
1382
 
1383
        if ( p.mBuildFile == -5 )
1384
        {
1385
          retVal +=
1386
          "<echo message=\"${line.separator}" + p.mAlias + "${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1387
        }
1388
      }
1389
    }
1390
    if ( !mDaemon )
1391
    {
1392
      retVal +=
1393
      "<echo message=\"${line.separator}Build Started:${line.separator}${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1394
    }
1395
 
1396
    retVal +=
1397
    "</target>" + lf +
1398
    "<target name=\"full\" depends=\"fullstart";
1399
 
1400
    for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1401
    {
1402
      Package p = (Package)it.next();
1403
 
1404
      if ( ( p.mBuildFile > 0 ) && ( p.mBuildFile <= buildFile ) )
1405
      {
1406
        retVal += "," + p.mAlias;
1407
      }
1408
    }
1409
 
1410
    retVal +=
1411
    "\">" + lf;
1412
 
1413
    if ( !mDaemon )
1414
    {
1415
      retVal +=
1416
      "<echo message=\"${line.separator}Build Finished${line.separator}\" file=\"publish.log\" append=\"true\"/>" + lf;
1417
    }
1418
 
1419
    retVal +=
1420
    "</target>" + lf;
1421
    return retVal;
1422
  }
1423
 
1424
  /**returns a build file footer
1425
   */
1426
  private String generateBuildFileFooter()
1427
  {
1428
    mLogger.debug("generateBuildFileFooter");
1429
    String retVal = new String("</project>");
1430
    return retVal;
1431
  }
1432
 
1433
  /**sets the mIndirectlyPlanned true for the package and all dependent packages
1434
   */
1435
  private void rippleIndirectlyPlanned(Package p)
1436
  {
1437
    mLogger.debug("rippleIndirectlyPlanned");
1438
    if ( !p.mIndirectlyPlanned && p.mBuildFile == 0 )
1439
    {
1440
      p.mIndirectlyPlanned = true;
1441
 
1442
      for (Iterator it = mPackageCollection.iterator(); it.hasNext(); )
1443
      {
1444
        Package pkg = (Package) it.next();
1445
 
1446
        if ( pkg != p )
1447
        {
1448
          for (Iterator it2 = pkg.mPackageDependencyCollection.iterator(); it2.hasNext(); )
1449
          {
1450
            Package dependency = (Package) it2.next();
1451
 
1452
            if ( dependency == p )
1453
            {
1454
              rippleIndirectlyPlanned( pkg );
1455
              break;
1456
            }
1457
          }
1458
        }
1459
      }
1460
    }
1461
    mLogger.info("rippleIndirectlyPlanned set " + p.mName + " " + p.mIndirectlyPlanned);    
1462
  }
1463
 
1464
  /**accessor method
1465
   */
830 mhunt 1466
  public String getESCROWSetUp()
814 mhunt 1467
  {
830 mhunt 1468
    mLogger.debug("getESCROWSetUp");
814 mhunt 1469
    String retVal = new String("");
1470
 
1471
    try
1472
    {
830 mhunt 1473
      if ( mEscrowClearcaseSupportCollection.size() >= 1 )
814 mhunt 1474
      {
1475
        retVal = (String)mEscrowClearcaseSupportCollection.get(0);
1476
      }
1477
    }
1478
    catch( ArrayIndexOutOfBoundsException e )
1479
    {
1480
    }
1481
 
830 mhunt 1482
    mLogger.info("getESCROWSetUp returned " + retVal);
814 mhunt 1483
    return retVal;
1484
  }
1485
 
1486
  /**accessor method
1487
   */
830 mhunt 1488
  public String getRawData()
814 mhunt 1489
  {
830 mhunt 1490
    mLogger.debug("getRawData");
814 mhunt 1491
    String retVal = new String("");
1492
 
1493
    try
1494
    {
830 mhunt 1495
      if ( mEscrowClearcaseSupportCollection.size() >= 2 )
814 mhunt 1496
      {
1497
        retVal = (String)mEscrowClearcaseSupportCollection.get(1);
1498
      }
1499
    }
1500
    catch( ArrayIndexOutOfBoundsException e )
1501
    {
1502
    }
1503
 
830 mhunt 1504
    mLogger.info("getRawData returned " + retVal);
814 mhunt 1505
    return retVal;
1506
  }
1507
 
1508
  /**returns first build file content and addendum
1509
   * the addendum value is one of "non generic", "generic" or "dummy"
1510
   */
1511
  public void getFirstBuildFileContent(MutableString content, 
1512
                                MutableString addendum)
1513
  {
1514
    mLogger.debug("getFirstBuildFileContent");
1515
    try
1516
    {
1517
      mBuildIndex = 0;
1518
      content.value = (String)mBuildCollection.get( mBuildIndex );
1519
      addendum.value = mAddendum;
1520
    }
1521
    catch( ArrayIndexOutOfBoundsException e )
1522
    {
1523
    }
1524
    mLogger.info("getFirstBuildFileContent passed " + content.value + addendum.value);
1525
  }
1526
 
1527
  /**returns the built loc
1528
   */
1529
  private String loc(Package p, String target, String lf)
1530
  {
1531
    mLogger.debug("loc");
1532
    String retVal = new String();
1533
    String loc = new String("\\");
1534
 
1535
    for (Iterator it = mGbeMachtypeCollection.iterator(); it.hasNext(); )
1536
    {
1537
      String machtype = (String) it.next();
1538
 
1539
      if ( machtype.compareTo("win32") == 0 )
1540
      {
816 mhunt 1541
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1542
        {
816 mhunt 1543
          if (mDaemon)
814 mhunt 1544
          {
832 mhunt 1545
            loc += mBaseline + "\\" + mTimestamp + "\\" + p.mLabel;
814 mhunt 1546
          }
832 mhunt 1547
          else
1548
          {
848 dpurdie 1549
            // mAlias used with jats -extractfiles -view
1550
            loc += p.mAlias;
832 mhunt 1551
          }
1552
 
1553
          loc += p.mLocation;
814 mhunt 1554
        }
816 mhunt 1555
        else
1556
        {
1557
          loc = p.mLocation;
1558
        }
1559
        break;
814 mhunt 1560
      }
1561
    }
1562
 
1563
    loc = loc.replace('/', '\\');
1564
    retVal =
1565
    "<condition property=\"" + target + "\" value=\"" + loc + "\">" + lf +
1566
    "  <os family=\"windows\"/>" + lf +
1567
    "</condition>" + lf;
1568
 
1569
    loc = "/";
1570
 
1571
    for (Iterator it = mGbeMachtypeCollection.iterator(); it.hasNext(); )
1572
    {
1573
      String machtype = (String) it.next();
1574
 
1575
      if ( machtype.compareTo("linux_i386") == 0 )
1576
      {
816 mhunt 1577
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1578
        {
816 mhunt 1579
          if (mDaemon)
814 mhunt 1580
          {
816 mhunt 1581
            loc += mBaseline + "/" + mTimestamp + "/";
814 mhunt 1582
          }
832 mhunt 1583
 
1584
          if (mDaemon)
1585
          {
1586
            loc += p.mLabel;
848 dpurdie 1587
            // no vobs in escrow_set_up ie jats -extractfiles
1588
            loc += "/vobs";
832 mhunt 1589
          }
1590
          else
1591
          {
848 dpurdie 1592
            // mAlias used with jats -extractfiles -view
1593
            loc += p.mAlias;
832 mhunt 1594
          }
1595
 
1596
          loc += p.mLocation;
814 mhunt 1597
        }
816 mhunt 1598
        else
1599
        {
1600
          loc = p.mLocation;
1601
        }
1602
        break;
814 mhunt 1603
      }
1604
      else if ( machtype.compareTo("sparc") == 0
1605
             || machtype.compareTo("solaris10_x86") == 0
1606
             || machtype.compareTo("solaris10_sparc32") == 0 )
1607
      {
816 mhunt 1608
        if ( target.compareTo("AbtSetUppackagelocation") != 0 )
814 mhunt 1609
        {
816 mhunt 1610
          if (mDaemon)
814 mhunt 1611
          {
816 mhunt 1612
            loc += mBaseline + "/" + mTimestamp + "/";
1613
          }
814 mhunt 1614
 
832 mhunt 1615
          if (mDaemon)
1616
          {
1617
            loc += p.mLabel;
848 dpurdie 1618
            // no vobs in escrow_set_up ie jats -extractfiles
1619
            loc += "/vobs";
832 mhunt 1620
          }
1621
          else
1622
          {
848 dpurdie 1623
            // mAlias used with jats -extractfiles -view
1624
            loc += p.mAlias;
832 mhunt 1625
          }
1626
 
1627
          loc += p.mLocation;
816 mhunt 1628
        }
1629
        else
1630
        {
1631
          loc = p.mLocation;
1632
        }
1633
        break;
814 mhunt 1634
      }
1635
    }
1636
    loc = loc.replace('\\', '/');
1637
    retVal += 
1638
    "<property name=\"" + target + "\" value=\"" + loc + "\"/>" + lf;
1639
 
1640
    mLogger.info("loc returned " + retVal);
1641
    return retVal;
1642
  }
816 mhunt 1643
 
1644
  /**returns the buildInfo
1645
   */
836 mhunt 1646
  private String buildInfo(Package p, String lf, boolean filter)
816 mhunt 1647
  {
1648
    mLogger.debug("buildInfo");
1649
 
1650
    String platforms = new String();
1651
    String standards = new String();
1652
 
1653
    for (Iterator it = p.mBuildStandardCollection.iterator(); it.hasNext(); )
1654
    {
1655
      BuildStandard bs = (BuildStandard)it.next();
1656
 
836 mhunt 1657
      if ( !filter )
816 mhunt 1658
      {
1659
        String platform = bs.getPlatform(!mReleaseManager.mUseDatabase);
1660
 
1661
        if ( platform.length() > 0 )
1662
        {
1663
          platforms += platform + lf;
1664
        }
1665
 
1666
        String standard = bs.getBuildStandard(!mReleaseManager.mUseDatabase);
1667
 
1668
        if ( standard.length() > 0 )
1669
        {
1670
          standards += standard + lf;
1671
        }
1672
      }
1673
      else
1674
      {
1675
        if ( !bs.getBuildStandard(!mReleaseManager.mUseDatabase).contains("\"none\"") )
1676
        {
1677
          String platform = bs.getPlatform(!mReleaseManager.mUseDatabase);
1678
 
1679
          if ( platform.length() > 0 )
1680
          {
1681
            platforms += platform + lf;
1682
          }
836 mhunt 1683
 
1684
          String standard = bs.getBuildStandard(!mReleaseManager.mUseDatabase);
1685
 
1686
          if ( standard.length() > 0 )
1687
          {
1688
            standards += standard + lf;
1689
          }
816 mhunt 1690
        }
1691
      }
1692
    }
1693
 
1694
    mLogger.info("buildInfo returned " + platforms + standards);
1695
    return platforms + standards;
1696
  }
814 mhunt 1697
}