Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.io.File;
4
 
5
import java.util.Iterator;
6
import java.util.Vector;
7
 
8
import org.apache.log4j.Logger;
9
 
10
public class Package
11
{
12
  /**name of package, must not contain spaces
13
   * @attribute
14
   */
15
  String mName = new String();
16
 
17
  /**package scope
18
   * @attribute
19
   */
20
  String mExtension = new String();
21
 
22
  /**instance identifier
23
   * @attribute
24
   */
25
  String mVersion = new String();
26
 
27
  /**unique identifier
28
   * for daemon builds = mName + mExtension
29
   * for escrow builds = mName + mVersion + mExtension
30
   * @attribute
31
   */
32
  String mAlias = new String();
33
 
34
  /**clearcase vob location, must not contain spaces
35
   * @attribute
36
   */
37
  String mLocation = new String();
38
 
39
  /**clearcase source file instance identifier
40
   * @attribute
41
   */
42
  String mLabel = new String();
43
 
44
  /**build standards
45
   * @attribute
46
   */
864 mhunt 47
  Vector<BuildStandard> mBuildStandardCollection = new Vector<BuildStandard>();
814 mhunt 48
 
49
  /**GBE_MACHTYPE used to build generic packages for this baseline
50
   * only has meaning in the daemon build, not the escrow build
51
   * accessed by BuildStandard::getPlatform, getBuildStandard
52
   * @attribute
53
   */
54
  public static final String mGenericMachtype = System.getenv("GBE_MACHTYPE");
55
 
56
  /**build dependencies by package alias
57
   * @attribute
58
   */
864 mhunt 59
  Vector<String> mDependencyCollection = new Vector<String>();
814 mhunt 60
 
61
  /**primary package version key pv_id in database
62
   * @attribute
63
   */
64
  int mId;
65
 
66
  /**indication of the nature of change
67
   * @attribute
68
   */
69
  Package.VersionNumberingStandard mChangeType = new VersionNumberingStandard();
70
 
71
  /**determines what field is rippled on a package version whose dependencies have changed
72
   * @attribute
73
   */
74
  Package.VersionNumberingStandard mRippleField = new VersionNumberingStandard();
75
 
76
  /**interested owners
77
   * @attribute
78
   */
864 mhunt 79
  private Vector<String> mBuildFailureEmailCollection = new Vector<String>();
814 mhunt 80
 
81
  /**when true will trigger unit tests as part of the package build phase in daemon mode
82
   * @attribute
83
   */
84
  boolean mHasAutomatedUnitTests = false;
85
 
86
  /**when true, do not ripple this package through packages which are dependent upon it in daemon mode
87
   * @attribute
88
   */
89
  boolean mAdvisoryRipple = false;
90
 
91
  /**determines the build file the package is built in, or not
92
   *  1 buildfile 1 etc
93
   *  0 not yet processed (initial value)
94
   * -1 not reproducible
95
   * -2 not reproducible on the build platforms configured for this release
96
   * -3 do not ripple
97
   * -4 directly dependent on package versions not in the baseline
98
   * -5 indirectly dependent on package versions which are not reproducible
99
   *    because of -1, -2 (escrow), -3 (daemon), -4
100
   * @attribute
101
   */
102
  int mBuildFile = 0;
103
 
104
  /**build dependencies by package
105
   * @attribute
106
   */
864 mhunt 107
  Vector<Package> mPackageDependencyCollection = new Vector<Package>();
814 mhunt 108
 
109
  /**used for escrow build purposes
110
   * set true when a package has been processed
111
   * @attribute
112
   */
113
  boolean mProcessed = false;
114
 
115
  /**set true for WIP package versions
116
   * only used in daemon mode
117
   * @attribute
118
   */
119
  boolean mDirectlyPlanned = false;
120
 
121
  /**set true when it is determined to be ripple built
122
   * @attribute
123
   */
124
  boolean mIndirectlyPlanned = false;
125
 
126
  /**build dependencies by pv_id (-1 or not used for planned dependencies)
127
   * @attribute
128
   */
864 mhunt 129
  Vector<Integer> mDependencyIDCollection = new Vector<Integer>();
814 mhunt 130
 
131
  /**unique pkg_id in the database
132
   * used for querying package version existence in the database in daemon mode
133
   * @attribute
134
   */
135
  int mPid;
136
 
874 mhunt 137
  /**maximum major number supported for determining ripple number
138
   * @attribute
139
   */
140
  int mMajorLimit;
141
 
142
  /**maximum minor number supported for determining ripple number
143
   * @attribute
144
   */
145
  int mMinorLimit;
146
 
147
  /**maximum patch number supported for determining ripple number
148
   * @attribute
149
   */
150
  int mPatchLimit;
151
 
152
  /**maximum build number number supported for determining ripple number
153
   * @attribute
154
   */
155
  int mBuildLimit;
156
 
814 mhunt 157
  /**Logger
158
   * @attribute
159
   */
160
  private static final Logger mLogger = Logger.getLogger(Package.class);
161
 
162
  /**dpkg archive location
163
   * @attribute
164
   */
165
  public static final String mGbeDpkg = System.getenv("GBE_DPKG");
166
 
167
  /**deploy archive location
168
   * @attribute
169
   */
170
  public static final String mGbeDply = System.getenv("GBE_DPLY");
171
 
896 mhunt 172
  /**Exception message used upon detection an archive does not exist
173
   * Seems this is a rare but transient and recoverable scenario
174
   * @attribute
175
   */
176
  public static final String mRecoverable = "dpkg or deploy_archive do not exist, recovery will be attempted";
177
 
814 mhunt 178
  /**true if the package exists in the dpkg or deploy archive
179
   * @attribute
180
   */
181
  private boolean mArchivalExistence = true;
182
 
852 mhunt 183
  /**when true will trigger source control interaction eg labelling
184
   * @attribute
185
   */
186
  public boolean mRequiresSourceControlInteraction = true;
187
 
814 mhunt 188
  /**constructor
189
   */
190
  Package(int pv_id, String pkg_name, String v_ext, String alias, 
191
          String pkg_label, String src_path, char change_type)
192
  {
193
    mLogger.debug("Package 1: pv_id " + pv_id + " pkg_name " + pkg_name + " v_ext " + v_ext + " alias " + alias + " pkg_label " + pkg_label + " src_path " + src_path + " change_type " + change_type);
194
    mId = pv_id;
195
    mName = pkg_name;
196
    mVersion = "0.0.0000";
197
    mExtension = v_ext;
198
    mAlias = alias;
199
    mLabel = pkg_label;
200
    mLocation = src_path;
201
 
202
    if (change_type == 'M')
203
    {
204
      mChangeType.setMajor();
205
    }
206
    else if (change_type == 'N')
207
    {
208
      mChangeType.setMinor();
209
    }
210
    else
211
    {
212
      mChangeType.setPatch();
213
    }
214
  }
215
 
216
  /**constructor
217
   */
218
  Package(int pv_id, String pkg_name, String pkg_version, String v_ext, 
219
          String alias, String pkg_label, String src_path, 
220
          char ripple_field)
221
  {
222
    mLogger.debug("Package 2: pv_id " + pv_id + " pkg_name " + pkg_name + " pkg_version " + pkg_version + " v_ext " + v_ext + " alias " + alias + " pkg_label " + pkg_label + " src_path " + src_path + " ripple_field " + ripple_field);
223
    mId = pv_id;
224
    mName = pkg_name;
225
    mVersion = pkg_version;
226
    int endindex = mVersion.length() - v_ext.length();
227
 
228
    if ( endindex > 0 )
229
    {
230
      mVersion = mVersion.substring(0, endindex);
231
    }
232
 
233
    mExtension = v_ext;
234
    mAlias = alias;
235
    mLabel = pkg_label;
236
    mLocation = src_path;
237
 
874 mhunt 238
    // setBuild is the default
814 mhunt 239
    if (ripple_field == 'M')
240
    {
241
      mRippleField.setMajor();
242
    }
243
    else if (ripple_field == 'm')
244
    {
245
      mRippleField.setMinor();
246
    }
247
    else if (ripple_field == 'p')
248
    {
249
      mRippleField.setPatch();
250
    }
874 mhunt 251
    else if (ripple_field == 'L')
252
    {
253
      mRippleField.setLimit();
254
    }
814 mhunt 255
  }
256
 
257
  /**constructor
258
   */
259
  Package()
260
  {
261
    mLogger.debug("Package 3");
262
    mId = 0;
263
    mName = "null";
264
    mExtension = "null";
265
    mAlias = "null";
266
    mLabel = "null";
267
    mLocation = "null";
268
  }
269
 
874 mhunt 270
  /**constructor for unit test purposes
271
  */
272
  public Package(ReleaseManager rm, String version, int majorLimit, int minorLimit, int patchLimit, int buildNumberLimit)
273
  {
274
    mId = -1;
275
    mRippleField.setLimit();
276
    mVersion = version;
277
    mMajorLimit = majorLimit;
278
    mMinorLimit = minorLimit;
279
    mPatchLimit = patchLimit;
280
    mBuildLimit = buildNumberLimit;
281
    try
282
    {
283
      mId = applyPV( rm, 0 );
284
    }
285
    catch(Exception e)
286
    {
287
    }
288
  }
289
 
290
  /**accessor for unit test purposes
291
   */
292
  public int getId()
293
  {
294
    return mId;
295
  }
296
 
297
  /**accessor for unit test purposes
298
   */
299
  public String getVersion()
300
  {
301
    return mVersion;
302
  }
303
 
814 mhunt 304
  /**returns true if mBuildStandardCollection is not empty
305
   */
306
  boolean isReproducible()
307
  {
308
    mLogger.debug("isReproducible on Package " + mName);
309
    boolean retVal = false;
310
 
311
    if ( mBuildStandardCollection.size() > 0 )
312
    {
313
      retVal = true;
314
    }
315
 
316
    mLogger.info("isReproducible returned " + retVal);
317
    return retVal;
318
  }
319
 
320
  /**returns true if at least one of its BuildStandards has mWin32 or mGeneric true
321
   */
322
  boolean isWin32Built()
323
  {
324
    mLogger.debug("isWin32Built on Package " + mName);
325
    boolean retVal = false;
864 mhunt 326
    for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 327
    {
864 mhunt 328
      BuildStandard buildStandard = it.next();
814 mhunt 329
 
330
      if (buildStandard.getWin32() || buildStandard.getGeneric())
331
      {
332
        retVal = true;
333
        break;
334
      }
335
    }
336
 
337
    mLogger.info("isWin32Built returned " + retVal);
338
    return retVal;
339
  }
340
 
341
  /**returns true if at least one of its BuildStandards has mSolaris or mGeneric true
342
   */
343
  boolean isSolarisBuilt()
344
  {
345
    mLogger.debug("isSolarisBuilt on Package " + mName);
346
    boolean retVal = false;
864 mhunt 347
    for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 348
    {
864 mhunt 349
      BuildStandard buildStandard = it.next();
814 mhunt 350
 
351
      if (buildStandard.getSolaris() || buildStandard.getGeneric())
352
      {
353
        retVal = true;
354
        break;
355
      }
356
    }
357
 
358
    mLogger.info("isSolarisBuilt returned " + retVal);
359
    return retVal;
360
  }
361
 
362
  /**returns true if at least one of its BuildStandards has mLinux or mGeneric true
363
   */
364
  boolean isLinuxBuilt()
365
  {
366
    mLogger.debug("isLinuxBuilt on Package " + mName);
367
    boolean retVal = false;
864 mhunt 368
    for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 369
    {
864 mhunt 370
      BuildStandard buildStandard = it.next();
814 mhunt 371
 
372
      if (buildStandard.getLinux() || buildStandard.getGeneric())
373
      {
374
        retVal = true;
375
        break;
376
      }
377
    }
378
 
379
    mLogger.info("isLinuxBuilt returned " + retVal);
380
    return retVal;
381
  }
382
 
383
  /**returns true if at least one of its BuildStandards has mGeneric true
384
   */
385
  boolean isGeneric()
386
  {
387
    mLogger.debug("isGeneric on Package " + mName);
388
    boolean retVal = false;
864 mhunt 389
    for (Iterator<BuildStandard> it = mBuildStandardCollection.iterator(); it.hasNext(); )
814 mhunt 390
    {
864 mhunt 391
      BuildStandard buildStandard = it.next();
814 mhunt 392
 
393
      if (buildStandard.getGeneric())
394
      {
395
        retVal = true;
396
        break;
397
      }
398
    }
399
 
400
    mLogger.info("isGeneric returned " + retVal);
401
    return retVal;
402
  }
403
 
404
  /**applies the required version number change
874 mhunt 405
   * returns 0 on success
406
   *         1 on cannot work with non standard versioning
407
   *         2 on ripple field limitations prevent a ripple build
814 mhunt 408
   */
874 mhunt 409
  int applyPV(ReleaseManager releaseManager, int rtag_id) throws Exception
814 mhunt 410
  {
411
    mLogger.debug("applyPV on Package " + mName);
412
    // three scenarios, only applyPV for 2 of them
413
    // WIP exists:                      mDirectlyPlanned == true;   mIndirectlyPlanned == true; mArchivalExistence don't care - applyPV
414
    // Package version is out of date:  mDirectlyPlanned == false;  mIndirectlyPlanned == true; mArchivalExistence == true    - applyPV
415
    // Package version does not exist:  mDirectlyPlanned == false;  mIndirectlyPlanned == true; mArchivalExistence == false   - do not applyPV
416
    if ( !mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence )
417
    {
418
      // the package has an mIndirectlyPlanned flag set true in daemon mode because the package does not exist in an archive
419
      // do not apply a different package version
420
      mLogger.info("applyPV !mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence on Package " + mName);
836 mhunt 421
      releaseManager.claimVersion(mPid, mVersion + mExtension, rtag_id);
874 mhunt 422
      mLogger.info("applyPv returned 0");
423
      return 0;
814 mhunt 424
    }
425
 
892 mhunt 426
    MutableInt major = new MutableInt();
427
    major.value = 0;
428
    MutableInt minor = new MutableInt();
429
    minor.value = 0;
430
    MutableInt patch = new MutableInt();
431
    patch.value = 1000;
814 mhunt 432
 
433
    String field[] = mVersion.split("\\D");
888 mhunt 434
    String nonStandardCotsVersion = "";
435
 
814 mhunt 436
    if ( field.length == 3 )
437
    {
892 mhunt 438
      major.value = Integer.parseInt(field[0]);
439
      minor.value = Integer.parseInt(field[1]);
440
      patch.value = Integer.parseInt(field[2]);
814 mhunt 441
    }
442
    else
443
    {
888 mhunt 444
      if ( !mChangeType.mMajor &&
445
           !mChangeType.mMinor &&
446
           !mChangeType.mPatch &&
447
           mRippleField.mBuild &&
448
           mExtension.compareTo(".cots") == 0 &&
449
           field.length > 0 )
450
      {
451
        // DEVI 52782
452
        // allow and work with (ripple build) versions a.b.c.d....xxxx
453
        // where xxxx.length > 3
454
        String patchStr = field[field.length - 1];
455
        int patchLen = patchStr.length();
456
 
457
        // check patchStr is the last (at least 4) digits
458
        if ( patchLen > 3 && mVersion.substring( mVersion.length() - patchLen, mVersion.length() ).compareTo(patchStr) == 0 )
459
        {
892 mhunt 460
          patch.value = Integer.parseInt(patchStr);
888 mhunt 461
          nonStandardCotsVersion = mVersion.substring(0, mVersion.length() - patchLen );
462
        }
463
      }
464
 
465
      if ( nonStandardCotsVersion.length() == 0 )
466
      {
467
        // cannot work with non standard versioning
468
        mLogger.error("applyPV cannot work with non standard versioning");
469
        mLogger.info("applyPv returned 1");
470
        return 1;
471
      }
814 mhunt 472
    }
473
 
888 mhunt 474
    if ( nonStandardCotsVersion.length() == 0 &&
892 mhunt 475
         patch.value < 1000 && 
888 mhunt 476
         field[2].substring(0, 1).compareTo("0") != 0 )
814 mhunt 477
    {
478
      mLogger.info("applyPV accomodate old style mVersion of the form 1.0.1");
892 mhunt 479
      patch.value = patch.value * 1000;
814 mhunt 480
    }
481
 
482
    // mChangeType overrides mRippleField
483
    do
484
    {
485
      if ( mChangeType.mMajor )
486
      {
892 mhunt 487
        if ( !incrementFieldsAccordingToLimits(4, major, minor, patch) )
488
        {
489
          mLogger.info("applyPv returned 2");
490
          return 2;
491
        }
814 mhunt 492
      }
493
      else if ( mChangeType.mMinor )
494
      {
892 mhunt 495
        if ( !incrementFieldsAccordingToLimits(3, major, minor, patch) )
496
        {
497
          mLogger.info("applyPv returned 2");
498
          return 2;
499
        }
814 mhunt 500
      }
501
      else if ( mChangeType.mPatch )
502
      {
892 mhunt 503
        if ( !incrementFieldsAccordingToLimits(2, major, minor, patch) )
814 mhunt 504
        {
892 mhunt 505
          mLogger.info("applyPv returned 2");
506
          return 2;
507
        }
814 mhunt 508
      }
509
      else
510
      {
511
        if ( mRippleField.mMajor )
512
        {
892 mhunt 513
          major.value++;
514
          mLogger.info("applyPV mRippleField.mMajor " + major.value);
515
          minor.value = 0;
516
          patch.value = 0;
814 mhunt 517
        }
518
        else if ( mRippleField.mMinor )
519
        {
892 mhunt 520
          minor.value++;
521
          mLogger.info("applyPV mRippleField.mMinor " + minor.value);
522
          patch.value = 0;
814 mhunt 523
        }
524
        else if ( mRippleField.mPatch )
525
        {
526
          do
527
          {
892 mhunt 528
            patch.value++;
529
          } while ( ( patch.value / 1000 ) * 1000 != patch.value );
530
          mLogger.info("applyPV mRippleField.mPatch " + patch.value);
814 mhunt 531
        }
874 mhunt 532
        else if ( mRippleField.mBuild )
814 mhunt 533
        {
892 mhunt 534
          patch.value++;
535
          mLogger.info("applyPV mRippleField.mBuild " + patch.value);
814 mhunt 536
        }
874 mhunt 537
        else
538
        {
892 mhunt 539
          if ( !incrementFieldsAccordingToLimits(1, major, minor, patch) )
874 mhunt 540
          {
541
            mLogger.info("applyPv returned 2");
542
            return 2;
543
          }
544
        }
814 mhunt 545
      }
888 mhunt 546
 
547
      if ( nonStandardCotsVersion.length() == 0 )
548
      {
892 mhunt 549
        mVersion = String.valueOf(major.value) + "." + String.valueOf(minor.value) + ".";
888 mhunt 550
      }
551
      else
552
      {
553
        mVersion = nonStandardCotsVersion;
554
      }
814 mhunt 555
 
892 mhunt 556
      if ( patch.value < 10 )
814 mhunt 557
      {
558
        mVersion += "000";
559
      }
892 mhunt 560
      else if ( patch.value < 100 )
814 mhunt 561
      {
562
        mVersion += "00";
563
      }
892 mhunt 564
      else if ( patch.value < 1000 )
814 mhunt 565
      {
566
        mVersion += "0";
567
      }
568
 
892 mhunt 569
      mVersion += String.valueOf(patch.value);
814 mhunt 570
    } while ( exists(releaseManager, rtag_id) );
571
 
572
    releaseManager.claimVersion(mPid, mVersion + mExtension, rtag_id);
874 mhunt 573
    mLogger.info("applyPv returned 0");
574
    return 0;
814 mhunt 575
  }
576
 
892 mhunt 577
  /**increments fields according to mRippleField.mLimit if necessary
578
   * will apply it to the field passed as follows
579
   * 1 = build
580
   * 2 = patch
581
   * 3 = minor
582
   * other = major
583
   * returns true on success
584
   *         false on ripple field limitations prevent a ripple build
585
   */
586
  private boolean incrementFieldsAccordingToLimits(int field, MutableInt major, MutableInt minor, MutableInt patch)
587
  {
588
    boolean retVal = true;
589
 
590
    if (!mRippleField.mLimit)
591
    {
592
      // simple case
593
      // no need to take field limits into consideration
594
      switch (field)
595
      {
596
      case 1:
597
        // unreachable
598
        // the only scenario involving build number manipulation involves the mRippleField.mLimit being set
599
        retVal = false;
600
        break;
601
      case 2:
602
        do
603
        {
604
          patch.value++;
605
        } while ( ( patch.value / 1000 ) * 1000 != patch.value );
606
        mLogger.info("incrementFieldsAccordingToLimits patch " + patch.value);
607
        break;
608
      case 3:
609
        minor.value++;
610
        mLogger.info("incrementFieldsAccordingToLimits minor " + minor.value);
611
        patch.value = 0;
612
        break;
613
      default:
614
        major.value++;
615
        mLogger.info("incrementFieldsAccordingToLimits major " + major.value);
616
        minor.value = 0;
617
        patch.value = 0;
618
      }
619
    }
620
    else
621
    {
622
      // take field limits into consideration
623
      boolean changeOccurred = false;
624
      boolean incrementField = true;
625
 
626
      switch (field)
627
      {
628
      case 1:
629
        if ( mBuildLimit != 0 )
630
        {
631
          // increment or reset the patch build number
632
          int buildNumber = patch.value - (patch.value/1000) * 1000;
633
 
634
          if ( buildNumber < mBuildLimit )
635
          {
636
            // can increment the patch build number
637
            patch.value++;
638
            mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit build number " + patch.value);
639
            changeOccurred = true;
640
            incrementField = false;
641
          }
642
          else
643
          {
644
            if ( mPatchLimit == 0 )
645
            {
646
              // reset the patch number and patch build number
647
              patch.value = 0;
648
            }
649
          }
650
        }
651
        // no break by design
652
      case 2:
653
        if ( mPatchLimit != 0 && incrementField )
654
        {
655
          // increment or reset the patch number
656
          if ( ( patch.value / 1000 ) < mPatchLimit )
657
          {
658
            do
659
            {
660
              patch.value++;
661
            } while ( ( patch.value / 1000 ) * 1000 != patch.value );
662
 
663
            mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit patch " + patch.value);
664
            changeOccurred = true;
665
            incrementField = false;
666
          }
667
          else
668
          {
669
            // reset the patch number and patch build number
670
            patch.value = 0;
671
          }
672
        }
673
        // no break by design
674
      case 3:
675
        if ( mMinorLimit != 0 && incrementField )
676
        {
677
          // increment or reset the minor number
678
          if ( minor.value < mMinorLimit )
679
          {
680
            minor.value++;
681
            patch.value = 0;
682
            mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit minor " + minor.value);
683
            changeOccurred = true;
684
            incrementField = false;
685
          }
686
          else
687
          {
688
            // reset the minor number
689
            minor.value = 0;
690
          }
691
        }
692
        // no break by design
693
      default:
694
        if ( mMajorLimit != 0 && incrementField )
695
        {
696
          // increment or reset the major number
697
          if ( major.value < mMajorLimit )
698
          {
699
            // increment the major number
700
            changeOccurred = true;
701
            major.value++;
702
            minor.value = 0;
703
            patch.value = 0;
704
            mLogger.info("incrementFieldsAccordingToLimits mRippleField.mLimit major " + major.value);
705
          }
706
        }
707
      }
708
 
709
      if ( !changeOccurred )
710
      {
711
        // unable to increment a field due to field limitations
712
        mLogger.error("incrementFieldsAccordingToLimits ripple field limitations prevent a ripple build");
713
        mLogger.info("incrementFieldsAccordingToLimits returned false");
714
        retVal = false;
715
      }
716
    }
717
 
718
    return retVal;
719
  }
720
 
814 mhunt 721
  /**returns true if the version exists in the dpkg_archive, deploy_archive or release manager database
722
   * claims the version in the release manager database
723
   */
724
  private boolean exists(ReleaseManager releaseManager, int rtag_id) throws Exception
725
  {
726
    mLogger.debug("exists 1 on Package " + mName + " version " + mVersion + " extension " + mExtension);
727
    boolean retVal = false;
728
 
864 mhunt 729
    if ( !ReleaseManager.mUseDatabase )
814 mhunt 730
    {
731
      mLogger.info("exists 1 !releaseManager.mUseDatabase");
732
    }
733
    else
734
    {
735
      retVal = exists();
736
 
737
      if ( !retVal )
738
      {
739
        String pkg_version = new String(mVersion);
740
 
741
        if ( mExtension.length() > 0 )
742
        {
743
          pkg_version += mExtension;
744
        }
745
 
746
        retVal = releaseManager.queryPackageVersions(mPid, pkg_version);
747
      }
748
    }
749
 
750
    mLogger.info("exists 1 returned " + retVal);
751
    return retVal;
752
  }
753
 
896 mhunt 754
  /**returns true if the dpkg_archive and deploy_archive exist
755
   * attempt to recover from their transient loss 
756
   */
757
  public static boolean recover()
758
  {
759
    mLogger.debug("recover");
760
    boolean retVal = false;
761
 
762
    String Release = mGbeDpkg;
763
    String Deploy = mGbeDply;
764
 
765
    if (Release != null && Deploy != null)
766
    {
767
      File dpkg = new File(mGbeDpkg);
768
      File dply = new File(mGbeDply);
769
 
770
      if ( dpkg.exists() && dply.exists() )
771
      {
772
        retVal = true;
773
      }
774
    }
775
 
776
    mLogger.info("recover returned " + retVal);
777
    return retVal;
778
  }
779
 
814 mhunt 780
  /**returns true if the version exists in the dpkg_archive or deploy_archive
781
   */
782
  boolean exists()
783
    throws Exception
784
  {
785
    mLogger.debug("exists 2 on Package " + mName);
786
    boolean retVal = false;
787
 
788
    String Release = mGbeDpkg;
789
    String Deploy = mGbeDply;
790
 
791
    if (Release == null || Deploy == null)
792
    {
868 mhunt 793
      mLogger.fatal("exists 2 Release == null || Deploy == null");
794
      throw new Exception("exists 2 Release == null || Deploy == null");
814 mhunt 795
    }
896 mhunt 796
 
797
    File dpkg = new File(mGbeDpkg);
798
    File dply = new File(mGbeDply);
799
 
800
    if ( !dpkg.exists() || !dply.exists() )
801
    {
802
      mLogger.fatal("exists 2 " + mRecoverable);
803
      throw new Exception(mRecoverable);
804
    }
814 mhunt 805
 
806
    String fs = System.getProperty( "file.separator" );
807
    String name = new String(Release);
808
    name += fs + mName + fs + mVersion + mExtension;
809
    File release = new File(name);
810
 
811
    if (release.exists())
812
    {
813
      mLogger.info("exists 2 release.exists()");
814
      retVal = true;
815
    }
816
 
817
    if (!retVal && (Release != Deploy))
818
    {
819
      name = Deploy + fs + mName + fs + mVersion + mExtension;
820
 
821
      File deploy = new File(name);
822
 
823
      if (deploy.exists())
824
      {
825
        mLogger.info("exists 2 deploy.exists()");
826
        retVal = true;
827
      }
828
    }
829
 
830
    mArchivalExistence = retVal;
831
    mLogger.info("exists 2 returned " + retVal);
832
    return retVal;
833
  }
854 mhunt 834
 
835
  /**returns email information
836
   */
837
  String emailInfo( String lf )
838
  {
839
    String retVal = new String();
840
 
864 mhunt 841
    for (Iterator<String> it = mBuildFailureEmailCollection.iterator(); it.hasNext(); )
854 mhunt 842
    {
864 mhunt 843
      String email = it.next();
854 mhunt 844
      retVal +=
845
      "  <owner email=\"" + email +"\"/>" + lf;
846
    }
847
 
848
    return retVal;
849
  }
814 mhunt 850
 
866 mhunt 851
  /**returns email information
852
   */
853
  String emailInfoNonAntTask()
854
  {
855
    String retVal = null;
856
 
857
    for (Iterator<String> it = mBuildFailureEmailCollection.iterator(); it.hasNext(); )
858
    {
859
      String email = it.next();
860
 
861
      if ( retVal == null )
862
      {
863
        retVal = new String();
864
      }
865
      else
866
      {
867
        retVal += ",";
868
      }
869
      retVal += email;
870
    }
871
 
872
    return retVal;
873
  }
874
 
864 mhunt 875
  /**adds email to mBuildFailureEmailCollection if unique
876
   */
877
  void addEmail( String email )
878
  {
879
    boolean alreadyExists = false;
880
 
881
    for (Iterator<String> it = mBuildFailureEmailCollection.iterator(); it.hasNext(); )
882
    {
883
      String existingEmail = it.next();
884
 
885
      if ( existingEmail.compareTo(email) == 0 )
886
      {
887
        alreadyExists = true;
888
        break;
889
      }
890
    }
891
 
892
    if ( !alreadyExists )
893
    {
894
      mBuildFailureEmailCollection.add(email);
895
    }
896
  }
897
 
814 mhunt 898
  /**entity class supporting the ERG version numbering standard:
899
   * <major>.<minor>.<patch/build>
900
   * patch/build is at least a 4 digit number whose last 3 digits represent the build
901
   */
902
  public class VersionNumberingStandard
903
  {
904
    /**in terms of the mChangeType Package field,
905
     * when true indicates the contract of the package has changed in a non backwardly compatible manner
906
     * in terms of the mRippleField Package field,
907
     * when true indicates the major version number will be incremented
908
     * @attribute
909
     */
910
    private boolean mMajor = false;
911
 
912
    /**in terms of the mChangeType Package field,
913
     * when true indicates the contract of the package has changed in a backwardly compatible manner
914
     * in terms of the mRippleField Package field,
915
     * when true indicates the minor version number will be incremented
916
     * @attribute
917
     */
918
    private boolean mMinor = false;
919
 
920
    /**in terms of the mChangeType Package field,
921
     * when true indicates the contract of the package has not changed, but the package has changed internally
922
     * in terms of the mRippleField Package field,
923
     * when true indicates the minor version number will be incremented
924
     * @attribute
925
     */
926
    private boolean mPatch = false;
927
 
928
    /**in terms of the mChangeType Package field,
929
     * when true indicates the package has not changed, its dependencies potentially have
930
     * in terms of the mRippleField Package field,
931
     * when true indicates the build number will be incremented
932
     * @attribute
933
     */
934
    private boolean mBuild = true;
935
 
874 mhunt 936
    /**in terms of the mChangeType Package field,
937
     * always false, does not apply
938
     * in terms of the mRippleField Package field,
939
     * when true indicates the major, minor, patch and build number will be incremented according to field limits
940
     * @attribute
941
     */
942
    private boolean mLimit = false;
943
 
814 mhunt 944
    /**constructor
945
     */
946
    private VersionNumberingStandard()
947
    {
948
      mLogger.debug("VersionNumberingStandard");
949
    }
950
 
874 mhunt 951
    /**sets mBuild true, mMajor false, mMinor false, mPatch false, mLimit false
814 mhunt 952
     */
953
    void setBuild()
954
    {
955
      mLogger.debug("setBuild");
956
      mBuild = true;
957
      mMajor = false;
958
      mMinor = false;
959
      mPatch = false;
874 mhunt 960
      mLimit = false;
814 mhunt 961
    }
962
 
874 mhunt 963
    /**sets mBuild false, mMajor true, mMinor false, mPatch false, mLimit false
814 mhunt 964
     */
965
    void setMajor()
966
    {
967
      mLogger.debug("setMajor");
968
      mBuild = false;
969
      mMajor = true;
970
      mMinor = false;
971
      mPatch = false;
874 mhunt 972
      mLimit = false;
814 mhunt 973
    }
974
 
874 mhunt 975
    /**sets mBuild false, mMajor false, mMinor true, mPatch false, mLimit false
814 mhunt 976
     */
977
    void setMinor()
978
    {
979
      mLogger.debug("setMinor");
980
      mBuild = false;
981
      mMajor = false;
982
      mMinor = true;
983
      mPatch = false;
874 mhunt 984
      mLimit = false;
814 mhunt 985
    }
986
 
874 mhunt 987
    /**sets mBuild false, mMajor false, mMinor false, mPatch true, mLimit false
814 mhunt 988
     */
989
    void setPatch()
990
    {
991
      mLogger.debug("setPatch");
992
      mBuild = false;
993
      mMajor = false;
994
      mMinor = false;
995
      mPatch = true;
874 mhunt 996
      mLimit = false;
814 mhunt 997
    }
998
 
874 mhunt 999
    /**sets mBuild false, mMajor false, mMinor false, mPatch false, mLimit true
1000
     */
1001
    void setLimit()
1002
    {
1003
      mLogger.debug("setPatch");
1004
      mBuild = false;
1005
      mMajor = false;
1006
      mMinor = false;
1007
      mPatch = false;
1008
      mLimit = true;
1009
    }
1010
 
814 mhunt 1011
  }
1012
 
1013
}