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.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
   */
47
  Vector mBuildStandardCollection = new Vector();
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
   */
59
  Vector mDependencyCollection = new Vector();
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
   */
79
  Vector mBuildFailureEmailCollection = new Vector();
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 include in a build in daemon mode
87
   * @attribute
88
   */
89
  boolean mDoNotRipple = false;
90
 
91
  /**when true, do not ripple this package through packages which are dependent upon it in daemon mode
92
   * @attribute
93
   */
94
  boolean mAdvisoryRipple = false;
95
 
96
  /**determines the build file the package is built in, or not
97
   *  1 buildfile 1 etc
98
   *  0 not yet processed (initial value)
99
   * -1 not reproducible
100
   * -2 not reproducible on the build platforms configured for this release
101
   * -3 do not ripple
102
   * -4 directly dependent on package versions not in the baseline
103
   * -5 indirectly dependent on package versions which are not reproducible
104
   *    because of -1, -2 (escrow), -3 (daemon), -4
105
   * @attribute
106
   */
107
  int mBuildFile = 0;
108
 
109
  /**build dependencies by package
110
   * @attribute
111
   */
112
  Vector mPackageDependencyCollection = new Vector();
113
 
114
  /**used for escrow build purposes
115
   * set true when a package has been processed
116
   * @attribute
117
   */
118
  boolean mProcessed = false;
119
 
120
  /**set true for WIP package versions
121
   * only used in daemon mode
122
   * @attribute
123
   */
124
  boolean mDirectlyPlanned = false;
125
 
126
  /**set true when it is determined to be ripple built
127
   * @attribute
128
   */
129
  boolean mIndirectlyPlanned = false;
130
 
131
  /**build dependencies by pv_id (-1 or not used for planned dependencies)
132
   * @attribute
133
   */
134
  Vector mDependencyIDCollection = new Vector();
135
 
136
  /**unique pkg_id in the database
137
   * used for querying package version existence in the database in daemon mode
138
   * @attribute
139
   */
140
  int mPid;
141
 
142
  /**Logger
143
   * @attribute
144
   */
145
  private static final Logger mLogger = Logger.getLogger(Package.class);
146
 
147
  /**dpkg archive location
148
   * @attribute
149
   */
150
  public static final String mGbeDpkg = System.getenv("GBE_DPKG");
151
 
152
  /**deploy archive location
153
   * @attribute
154
   */
155
  public static final String mGbeDply = System.getenv("GBE_DPLY");
156
 
157
  /**true if the package exists in the dpkg or deploy archive
158
   * @attribute
159
   */
160
  private boolean mArchivalExistence = true;
161
 
162
  /**constructor
163
   */
164
  Package(int pv_id, String pkg_name, String v_ext, String alias, 
165
          String pkg_label, String src_path, char change_type)
166
  {
167
    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);
168
    mId = pv_id;
169
    mName = pkg_name;
170
    mVersion = "0.0.0000";
171
    mExtension = v_ext;
172
    mAlias = alias;
173
    mLabel = pkg_label;
174
    mLocation = src_path;
175
 
176
    if (change_type == 'M')
177
    {
178
      mChangeType.setMajor();
179
    }
180
    else if (change_type == 'N')
181
    {
182
      mChangeType.setMinor();
183
    }
184
    else
185
    {
186
      mChangeType.setPatch();
187
    }
188
  }
189
 
190
  /**constructor
191
   */
192
  Package(int pv_id, String pkg_name, String pkg_version, String v_ext, 
193
          String alias, String pkg_label, String src_path, 
194
          char ripple_field)
195
  {
196
    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);
197
    mId = pv_id;
198
    mName = pkg_name;
199
    mVersion = pkg_version;
200
    int endindex = mVersion.length() - v_ext.length();
201
 
202
    if ( endindex > 0 )
203
    {
204
      mVersion = mVersion.substring(0, endindex);
205
    }
206
 
207
    mExtension = v_ext;
208
    mAlias = alias;
209
    mLabel = pkg_label;
210
    mLocation = src_path;
211
 
212
    if (ripple_field == 'M')
213
    {
214
      mRippleField.setMajor();
215
    }
216
    else if (ripple_field == 'm')
217
    {
218
      mRippleField.setMinor();
219
    }
220
    else if (ripple_field == 'p')
221
    {
222
      mRippleField.setPatch();
223
    }
224
  }
225
 
226
  /**constructor
227
   */
228
  Package()
229
  {
230
    mLogger.debug("Package 3");
231
    mId = 0;
232
    mName = "null";
233
    mExtension = "null";
234
    mAlias = "null";
235
    mLabel = "null";
236
    mLocation = "null";
237
  }
238
 
239
  /**returns true if mBuildStandardCollection is not empty
240
   */
241
  boolean isReproducible()
242
  {
243
    mLogger.debug("isReproducible on Package " + mName);
244
    boolean retVal = false;
245
 
246
    if ( mBuildStandardCollection.size() > 0 )
247
    {
248
      retVal = true;
249
    }
250
 
251
    mLogger.info("isReproducible returned " + retVal);
252
    return retVal;
253
  }
254
 
255
  /**returns true if at least one of its BuildStandards has mWin32 or mGeneric true
256
   */
257
  boolean isWin32Built()
258
  {
259
    mLogger.debug("isWin32Built on Package " + mName);
260
    boolean retVal = false;
261
    for (Iterator it = mBuildStandardCollection.iterator(); it.hasNext(); )
262
    {
263
      BuildStandard buildStandard = (BuildStandard) it.next();
264
 
265
      if (buildStandard.getWin32() || buildStandard.getGeneric())
266
      {
267
        retVal = true;
268
        break;
269
      }
270
    }
271
 
272
    mLogger.info("isWin32Built returned " + retVal);
273
    return retVal;
274
  }
275
 
276
  /**returns true if at least one of its BuildStandards has mSolaris or mGeneric true
277
   */
278
  boolean isSolarisBuilt()
279
  {
280
    mLogger.debug("isSolarisBuilt on Package " + mName);
281
    boolean retVal = false;
282
    for (Iterator it = mBuildStandardCollection.iterator(); it.hasNext(); )
283
    {
284
      BuildStandard buildStandard = (BuildStandard) it.next();
285
 
286
      if (buildStandard.getSolaris() || buildStandard.getGeneric())
287
      {
288
        retVal = true;
289
        break;
290
      }
291
    }
292
 
293
    mLogger.info("isSolarisBuilt returned " + retVal);
294
    return retVal;
295
  }
296
 
297
  /**returns true if at least one of its BuildStandards has mLinux or mGeneric true
298
   */
299
  boolean isLinuxBuilt()
300
  {
301
    mLogger.debug("isLinuxBuilt on Package " + mName);
302
    boolean retVal = false;
303
    for (Iterator it = mBuildStandardCollection.iterator(); it.hasNext(); )
304
    {
305
      BuildStandard buildStandard = (BuildStandard) it.next();
306
 
307
      if (buildStandard.getLinux() || buildStandard.getGeneric())
308
      {
309
        retVal = true;
310
        break;
311
      }
312
    }
313
 
314
    mLogger.info("isLinuxBuilt returned " + retVal);
315
    return retVal;
316
  }
317
 
318
  /**returns true if at least one of its BuildStandards has mGeneric true
319
   */
320
  boolean isGeneric()
321
  {
322
    mLogger.debug("isGeneric on Package " + mName);
323
    boolean retVal = false;
324
    for (Iterator it = mBuildStandardCollection.iterator(); it.hasNext(); )
325
    {
326
      BuildStandard buildStandard = (BuildStandard) it.next();
327
 
328
      if (buildStandard.getGeneric())
329
      {
330
        retVal = true;
331
        break;
332
      }
333
    }
334
 
335
    mLogger.info("isGeneric returned " + retVal);
336
    return retVal;
337
  }
338
 
339
  /**applies the required version number change
340
   */
341
  void applyPV(ReleaseManager releaseManager, int rtag_id) throws Exception
342
  {
343
    mLogger.debug("applyPV on Package " + mName);
344
    // three scenarios, only applyPV for 2 of them
345
    // WIP exists:                      mDirectlyPlanned == true;   mIndirectlyPlanned == true; mArchivalExistence don't care - applyPV
346
    // Package version is out of date:  mDirectlyPlanned == false;  mIndirectlyPlanned == true; mArchivalExistence == true    - applyPV
347
    // Package version does not exist:  mDirectlyPlanned == false;  mIndirectlyPlanned == true; mArchivalExistence == false   - do not applyPV
348
    if ( !mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence )
349
    {
350
      // the package has an mIndirectlyPlanned flag set true in daemon mode because the package does not exist in an archive
351
      // do not apply a different package version
352
      mLogger.info("applyPV !mDirectlyPlanned && mIndirectlyPlanned && !mArchivalExistence on Package " + mName);
353
      return;
354
    }
355
 
356
    int major = 0;
357
    int minor = 0;
358
    int patch = 1000;
359
 
360
    String field[] = mVersion.split("\\D");
361
 
362
    if ( field.length == 3 )
363
    {
364
      major = Integer.parseInt(field[0]);
365
      minor = Integer.parseInt(field[1]);
366
      patch = Integer.parseInt(field[2]);
367
    }
368
    else
369
    {
370
      // cannot work with non standard versioning
371
      mLogger.error("applyPV cannot work with non standard versioning");
372
      return;
373
    }
374
 
375
    if ( patch < 1000 && field[2].substring(0, 1).compareTo("0") != 0 )
376
    {
377
      mLogger.info("applyPV accomodate old style mVersion of the form 1.0.1");
378
      patch = patch * 1000;
379
    }
380
 
381
    // mChangeType overrides mRippleField
382
    do
383
    {
384
      if ( mChangeType.mMajor )
385
      {
386
        major++;
387
        mLogger.info("applyPV mChangeType.mMajor " + major);
388
        minor = 0;
389
        patch = 0;
390
      }
391
      else if ( mChangeType.mMinor )
392
      {
393
        minor++;
394
        mLogger.info("applyPV mChangeType.mMinor " + minor);
395
        patch = 0;
396
      }
397
      else if ( mChangeType.mPatch )
398
      {
399
        do
400
        {
401
          patch++;
402
        } while ( ( patch / 1000 ) * 1000 != patch );
403
        mLogger.info("applyPV mChangeType.mPatch " + patch);
404
      }
405
      else
406
      {
407
        if ( mRippleField.mMajor )
408
        {
409
          major++;
410
          mLogger.info("applyPV mRippleField.mMajor " + major);
411
          minor = 0;
412
          patch = 0;
413
        }
414
        else if ( mRippleField.mMinor )
415
        {
416
          minor++;
417
          mLogger.info("applyPV mRippleField.mMinor " + minor);
418
          patch = 0;
419
        }
420
        else if ( mRippleField.mPatch )
421
        {
422
          do
423
          {
424
            patch++;
425
          } while ( ( patch / 1000 ) * 1000 != patch );
426
          mLogger.info("applyPV mRippleField.mPatch " + patch);
427
        }
428
        else
429
        {
430
          patch++;
431
          mLogger.info("applyPV ripple field default " + patch);
432
        }
433
      }
434
 
435
      mVersion = String.valueOf(major) + "." + String.valueOf(minor) + ".";
436
 
437
      if ( patch < 10 )
438
      {
439
        mVersion += "000";
440
      }
441
      else if ( patch < 100 )
442
      {
443
        mVersion += "00";
444
      }
445
      else if ( patch < 1000 )
446
      {
447
        mVersion += "0";
448
      }
449
 
450
      mVersion += String.valueOf(patch);
451
    } while ( exists(releaseManager, rtag_id) );
452
 
453
    releaseManager.claimVersion(mPid, mVersion + mExtension, rtag_id);
454
  }
455
 
456
  /**returns true if the version exists in the dpkg_archive, deploy_archive or release manager database
457
   * claims the version in the release manager database
458
   */
459
  private boolean exists(ReleaseManager releaseManager, int rtag_id) throws Exception
460
  {
461
    mLogger.debug("exists 1 on Package " + mName + " version " + mVersion + " extension " + mExtension);
462
    boolean retVal = false;
463
 
464
    if ( !releaseManager.mUseDatabase )
465
    {
466
      mLogger.info("exists 1 !releaseManager.mUseDatabase");
467
    }
468
    else
469
    {
470
      retVal = exists();
471
 
472
      if ( !retVal )
473
      {
474
        String pkg_version = new String(mVersion);
475
 
476
        if ( mExtension.length() > 0 )
477
        {
478
          pkg_version += mExtension;
479
        }
480
 
481
        retVal = releaseManager.queryPackageVersions(mPid, pkg_version);
482
      }
483
    }
484
 
485
    mLogger.info("exists 1 returned " + retVal);
486
    return retVal;
487
  }
488
 
489
  /**returns true if the version exists in the dpkg_archive or deploy_archive
490
   */
491
  boolean exists()
492
    throws Exception
493
  {
494
    mLogger.debug("exists 2 on Package " + mName);
495
    boolean retVal = false;
496
 
497
    String Release = mGbeDpkg;
498
    String Deploy = mGbeDply;
499
 
500
    if (Release == null || Deploy == null)
501
    {
502
      mLogger.error("exists 2 Release == null || Deploy == null");
503
      throw new Exception();
504
    }
505
 
506
    String fs = System.getProperty( "file.separator" );
507
    String name = new String(Release);
508
    name += fs + mName + fs + mVersion + mExtension;
509
    File release = new File(name);
510
 
511
    if (release.exists())
512
    {
513
      mLogger.info("exists 2 release.exists()");
514
      retVal = true;
515
    }
516
 
517
    if (!retVal && (Release != Deploy))
518
    {
519
      name = Deploy + fs + mName + fs + mVersion + mExtension;
520
 
521
      File deploy = new File(name);
522
 
523
      if (deploy.exists())
524
      {
525
        mLogger.info("exists 2 deploy.exists()");
526
        retVal = true;
527
      }
528
    }
529
 
530
    mArchivalExistence = retVal;
531
    mLogger.info("exists 2 returned " + retVal);
532
    return retVal;
533
  }
534
 
535
  /**entity class supporting the ERG version numbering standard:
536
   * <major>.<minor>.<patch/build>
537
   * patch/build is at least a 4 digit number whose last 3 digits represent the build
538
   */
539
  public class VersionNumberingStandard
540
  {
541
    /**in terms of the mChangeType Package field,
542
     * when true indicates the contract of the package has changed in a non backwardly compatible manner
543
     * in terms of the mRippleField Package field,
544
     * when true indicates the major version number will be incremented
545
     * @attribute
546
     */
547
    private boolean mMajor = false;
548
 
549
    /**in terms of the mChangeType Package field,
550
     * when true indicates the contract of the package has changed in a backwardly compatible manner
551
     * in terms of the mRippleField Package field,
552
     * when true indicates the minor version number will be incremented
553
     * @attribute
554
     */
555
    private boolean mMinor = false;
556
 
557
    /**in terms of the mChangeType Package field,
558
     * when true indicates the contract of the package has not changed, but the package has changed internally
559
     * in terms of the mRippleField Package field,
560
     * when true indicates the minor version number will be incremented
561
     * @attribute
562
     */
563
    private boolean mPatch = false;
564
 
565
    /**in terms of the mChangeType Package field,
566
     * when true indicates the package has not changed, its dependencies potentially have
567
     * in terms of the mRippleField Package field,
568
     * when true indicates the build number will be incremented
569
     * @attribute
570
     */
571
    private boolean mBuild = true;
572
 
573
    /**constructor
574
     */
575
    private VersionNumberingStandard()
576
    {
577
      mLogger.debug("VersionNumberingStandard");
578
    }
579
 
580
    /**sets mBuild true, mMajor false, mMinor false, mPatch false
581
     */
582
    void setBuild()
583
    {
584
      mLogger.debug("setBuild");
585
      mBuild = true;
586
      mMajor = false;
587
      mMinor = false;
588
      mPatch = false;
589
    }
590
 
591
    /**sets mBuild false, mMajor true, mMinor false, mPatch false
592
     */
593
    void setMajor()
594
    {
595
      mLogger.debug("setMajor");
596
      mBuild = false;
597
      mMajor = true;
598
      mMinor = false;
599
      mPatch = false;
600
    }
601
 
602
    /**sets mBuild false, mMajor false, mMinor true, mPatch false
603
     */
604
    void setMinor()
605
    {
606
      mLogger.debug("setMinor");
607
      mBuild = false;
608
      mMajor = false;
609
      mMinor = true;
610
      mPatch = false;
611
    }
612
 
613
    /**sets mBuild false, mMajor false, mMinor false, mPatch true
614
     */
615
    void setPatch()
616
    {
617
      mLogger.debug("setPatch");
618
      mBuild = false;
619
      mMajor = false;
620
      mMinor = false;
621
      mPatch = true;
622
    }
623
 
624
  }
625
 
626
}