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.daemon;
2
 
3
import com.erggroup.buildtool.daemon.ResumeTimerTask;
4
import com.erggroup.buildtool.ripple.ReleaseManager;
868 mhunt 5
import com.erggroup.buildtool.smtp.Smtpsend;
6
import com.erggroup.buildtool.ripple.RippleEngine;
896 mhunt 7
import com.erggroup.buildtool.ripple.MutableString;
814 mhunt 8
 
9
import java.io.BufferedReader;
10
import java.io.File;
11
import java.io.FileNotFoundException;
12
import java.io.FileOutputStream;
13
import java.io.FileWriter;
14
import java.io.FilenameFilter;
15
 
16
import java.io.IOException;
17
import java.io.PrintStream;
18
import java.io.StringReader;
19
 
20
import java.sql.SQLException;
21
 
22
import java.util.Date;
23
import java.util.Timer;
24
 
25
import org.apache.log4j.Logger;
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.DefaultLogger;
28
import org.apache.tools.ant.Project;
29
import org.apache.tools.ant.ProjectHelper;
30
 
31
/**Build Thread sub component
32
 */
33
public abstract class BuildThread
34
  extends Thread
35
{
36
  /**baseline identifier (which release manager release this BuildThread is dealing with)
37
   * @attribute
38
   */
39
  protected int mRtagId = 0;
40
 
41
  /**unique identifier of this BuildThread
42
   * @attribute
43
   */
44
  protected int mRconId = 0;
45
 
46
  /**
47
   * @aggregation composite
48
   */
49
  protected RunLevel mRunLevel;
50
 
51
  /**
52
   * @aggregation composite
53
   */
54
  protected ReleaseManager mReleaseManager;
55
 
56
  /**configured GBEBUILDFILTER for this BuildThread
57
   * @attribute
58
   */
896 mhunt 59
  protected String mGbebuildfilter = null;
814 mhunt 60
 
896 mhunt 61
  /**unit test support
62
   * @attribute
63
   */
64
  protected String mUnitTest = "";
65
 
814 mhunt 66
  /**
67
   * @aggregation composite
68
   */
69
  protected static ResumeTimerTask mResumeTimerTask;
70
 
71
  /**
72
   * @aggregation composite
73
   */
74
  private static Timer mTimer;
75
 
76
  /**Synchroniser object
77
   * Use to Synchronize on by multiple threads
78
   * @attribute
79
   */
80
  static final Object mSynchroniser = new Object();
81
 
82
  /**BuildThread group
83
   * @attribute
84
   */
85
  public static final ThreadGroup mThreadGroup = new ThreadGroup("BuildThread");
86
 
87
  /**the advertised build file content when either
88
   * a) no package in the baseline has a build requirement
89
   * b) the next package in the baseline with a build requirement is generic
90
   * @attribute
91
   */
92
  protected static final String mDummyBuildFileContent = new String("<dummy/>");
93
 
94
  /**Set true when last build cycle was benign.
95
   * @attribute
96
   */
97
  protected boolean mSleep;
98
 
886 mhunt 99
  /**Set true when last build cycle caught SQLException or Exception.
100
   * @attribute
101
   */
102
  protected boolean mException;
103
 
854 mhunt 104
  /**Set true when ant error reported on any target.
105
   * @attribute
106
   */
107
  private boolean mErrorReported;
108
 
866 mhunt 109
  /**Logger
854 mhunt 110
   * @attribute
111
   */
866 mhunt 112
  private static final Logger mLogger = Logger.getLogger(BuildThread.class);
854 mhunt 113
 
866 mhunt 114
  /**Package name for reporting purposes.
814 mhunt 115
   * @attribute
116
   */
866 mhunt 117
  protected String mReportingPackageName;
814 mhunt 118
 
866 mhunt 119
  /**Package version for reporting purposes.
120
   * @attribute
121
   */
122
  protected String mReportingPackageVersion;
123
 
124
  /**Package extension for reporting purposes.
125
   * @attribute
126
   */
127
  protected String mReportingPackageExtension;
128
 
129
  /**Package location for reporting purposes.
130
   * @attribute
131
   */
132
  protected String mReportingPackageLocation;
133
 
134
  /**Package dependencies for reporting purposes.
135
   * @attribute
136
   */
137
  protected String mReportingPackageDepends;
138
 
139
  /**Is ripple flag for reporting purposes.
140
   * @attribute
141
   */
142
  protected String mReportingIsRipple;
143
 
144
  /**Package version identifier for reporting purposes.
145
   * @attribute
146
   */
147
  protected String mReportingPackageVersionId;
148
 
149
  /**Fully published flag for reporting purposes.
150
   * @attribute
151
   */
152
  protected String mReportingFullyPublished;
153
 
154
  /**New label for reporting purposes.
155
   * @attribute
156
   */
157
  protected String mReportingNewLabel;
158
 
159
  /**Source control interaction for reporting purposes.
160
   * @attribute
161
   */
162
  protected String mReportingDoesNotRequireSourceControlInteraction;
163
 
164
  /**Log file location for reporting purposes.
165
   * @attribute
166
   */
167
  protected String mReportingBuildFailureLogFile;
168
 
868 mhunt 169
  /**Non null determines to only gather metrics
170
   * @attribute
171
   */
172
  protected static final String mGbeGatherMetricsOnly = System.getenv("GBE_GATHER_METRICS");
173
 
896 mhunt 174
  /**Non null determines to only gather metrics
175
   * @attribute
176
   */
177
  protected boolean mRecoverable;
178
 
814 mhunt 179
  /**constructor
180
   */
181
  BuildThread()
182
  {
183
    super(mThreadGroup, "");
184
    mLogger.debug("BuildThread");
185
    mSleep = false;
886 mhunt 186
    mException = false;
854 mhunt 187
    mErrorReported = false;
814 mhunt 188
    mReleaseManager = new ReleaseManager();
896 mhunt 189
    mRecoverable = false;
814 mhunt 190
 
191
    // no need to be synchronized - BuildThreads are instantiated in a single thread
192
    if ( mResumeTimerTask == null )
193
    {
194
      mResumeTimerTask = new ResumeTimerTask();
195
      mTimer = new Timer();
196
      mResumeTimerTask.setTimer(mTimer);
197
    }
198
  }
199
 
886 mhunt 200
  /**sleeps when mException is set
201
   */
202
  protected void sleepCheck()
203
  {
204
    if (mException)
205
    {
206
      try
207
      {
208
        Integer sleepTime = 300000;
209
        mLogger.warn("sleepCheck sleep " + sleepTime.toString() + " secs");
210
        Thread.sleep(sleepTime);
211
        mLogger.info("sleepCheck sleep returned");
212
      }
213
      catch(InterruptedException e)
214
      {
215
        mLogger.warn("sleepCheck sleep caught InterruptedException");
216
      }
217
 
218
    }
219
    mException = false;
220
  }
221
 
814 mhunt 222
  /**initially changes the run level to IDLE
223
   * determines if the BuildThread is still configured
224
   * a) determines if the BuildThread is running in scheduled downtime
225
   * b) determines if the BuildThread is directed to pause
226
   * changes the run level to PAUSED if a) or b) are true
227
   * throws ExitException when not configured
228
   * implements the sequence diagrams allowed to proceed, not allowed to proceed, exit
229
   */
868 mhunt 230
  protected void allowedToProceed(boolean master) throws ExitException, SQLException, Exception
814 mhunt 231
  {
232
    mLogger.debug("allowedToProceed");
886 mhunt 233
 
234
    try
235
    {
236
      mRunLevel = RunLevel.IDLE;
237
      mLogger.warn("allowedToProceed changing run level to IDLE for rcon_id " + mRconId);
238
      mRunLevel.persist(mReleaseManager, mRconId);
896 mhunt 239
      if ( master )
240
      {
241
        mReleaseManager.discardVersion();
242
      }
886 mhunt 243
      mReleaseManager.clearCurrentPackageBeingBuilt(mRconId);      
244
    }
245
    catch(SQLException e)
246
    {
247
      mLogger.warn("allowedToProceed caught SQLException");
248
    }
814 mhunt 249
 
250
    if (mSleep)
251
    {
252
      try
253
      {
868 mhunt 254
        Integer sleepTime = 300000;
255
 
256
        if ( !master )
257
        {
258
          // sleep only 3 secs on slave
259
          sleepTime = 3000;
260
        }
261
        mLogger.warn("allowedToProceed sleep " + sleepTime.toString() + " secs no build requirement");
262
        Thread.sleep(sleepTime);
814 mhunt 263
        mLogger.info("allowedToProceed sleep returned");
264
      }
265
      catch(InterruptedException e)
266
      {
267
        mLogger.warn("allowedToProceed sleep caught InterruptedException");
268
      }
269
    }
270
 
271
    boolean proceed = false;
272
 
273
    while ( !proceed )
274
    {
275
      mReleaseManager.connect();
896 mhunt 276
      if ( !mReleaseManager.queryReleaseConfig(mRtagId, mRconId, BuildDaemon.mHostname, getMode()) )
814 mhunt 277
      {
278
        mReleaseManager.disconnect();
858 mhunt 279
        mLogger.warn("allowedToProceed queryReleaseConfig failed");
814 mhunt 280
        throw new ExitException();
281
      }
282
 
283
      Date resumeTime = new Date( 0 );
896 mhunt 284
      if ( !mReleaseManager.queryRunLevelSchedule(resumeTime, mRecoverable) )
814 mhunt 285
      {
286
        mLogger.info("allowedToProceed scheduled downtime");
287
        mReleaseManager.disconnect();
288
        mRunLevel = RunLevel.PAUSED;
816 mhunt 289
        mLogger.warn("allowedToProceed changing run level to PAUSED for rcon_id " + mRconId);
814 mhunt 290
        mRunLevel.persist(mReleaseManager, mRconId);
291
 
292
        synchronized(mSynchroniser)
293
        {
294
          // contain the schedule and wait in the same synchronized block to prevent a deadlock
295
          // eg this thread calls schedule, timer thread calls notifyall, this thread calls wait (forever)
296
          try
297
          {
298
            if (mResumeTimerTask.isCancelled())
299
            {
300
              mResumeTimerTask = new ResumeTimerTask();
301
              mTimer = new Timer();
302
              mResumeTimerTask.setTimer(mTimer);
303
            }
304
            mLogger.warn("allowedToProceed schedule passed " + resumeTime.getTime());
305
            mTimer.schedule(mResumeTimerTask, resumeTime);
306
          }
307
          catch( IllegalStateException e )
308
          {
309
            // this may be thrown by schedule if already scheduled
310
            // it signifies another BuildThread has already scheduled the ResumeTimerTask
311
             mLogger.warn("allowedToProceed already scheduled");
312
          }
313
 
314
          try
315
          {
316
            mLogger.warn("allowedToProceed wait");
317
            mSynchroniser.wait();
318
            mLogger.warn("allowedToProceed wait returned");
319
 
896 mhunt 320
            if ( mUnitTest.compareTo("unit test not allowed to proceed") == 0 )
814 mhunt 321
            {
322
              throw new ExitException();
323
            }
324
          }
325
          catch( InterruptedException e )
326
          {
327
            mLogger.warn("allowedToProceed caught InterruptedException");
328
          }
329
        }
330
 
331
      }
332
      else
333
      {
334
        if ( !mReleaseManager.queryDirectedRunLevel(mRconId) )
335
        {
336
          mLogger.info("allowedToProceed downtime");
337
          mReleaseManager.disconnect();
832 mhunt 338
          mRunLevel = RunLevel.PAUSED;
339
          mLogger.warn("allowedToProceed changing run level to PAUSED for rcon_id " + mRconId);
340
          mRunLevel.persist(mReleaseManager, mRconId);
814 mhunt 341
          try
342
          {
343
            // to do, sleep for periodicMs
344
            mLogger.warn("allowedToProceed sleep 5 mins directed downtime");
345
            Thread.sleep(300000);
346
            mLogger.info("allowedToProceed sleep returned");
347
          }
348
          catch (InterruptedException e)
349
          {
350
            mLogger.warn("allowedToProceed caught InterruptedException");
351
          }
352
        }
353
        else
354
        {
355
          mReleaseManager.disconnect();
356
          proceed = true;
357
        }
358
      }
359
    }
896 mhunt 360
 
361
    mRecoverable = false;
814 mhunt 362
  }
363
 
364
  /**periodically 
365
   * a) performs disk housekeeping
366
   * b) determines if a minimum threshold of disk space is available
894 mhunt 367
   * c) determines if a file can be touched
814 mhunt 368
   * changes the run level to CANNOT_CONTINUE if insufficient disk space
369
   * otherwise changes the run level to ACTIVE and returns
370
   * implements the sequence diagram check environment
371
   */
372
  protected void checkEnvironment() throws Exception
373
  {
374
    mLogger.debug("checkEnvironment");
375
    boolean exit = false;
376
 
377
    while( !exit )
378
    {
379
      housekeep();
380
 
381
      // attempt to exit
382
      exit = true;
383
 
894 mhunt 384
      if ( !hasSufficientDiskSpace() || !touch() )
814 mhunt 385
      {
894 mhunt 386
        mLogger.warn("checkEnvironment below disk free threshold or read only file system detected");
814 mhunt 387
        exit = false;
388
        mRunLevel = RunLevel.CANNOT_CONTINUE;
816 mhunt 389
        mLogger.warn("checkEnvironment changing run level to CANNOT_CONTINUE for rcon_id " + mRconId);
814 mhunt 390
        mRunLevel.persist(mReleaseManager, mRconId);
391
        try
392
        {
393
          // to do, sleep for periodicMs
896 mhunt 394
          if ( mUnitTest.compareTo("unit test check environment") != 0 )
814 mhunt 395
          {
396
            mLogger.warn("checkEnvironment sleep 5 mins below disk free threshold");
397
            Thread.sleep(300000);
398
            mLogger.info("checkEnvironment sleep returned");
399
          }
400
        }
401
        catch (InterruptedException e)
402
        {
403
          mLogger.warn("checkEnvironment caught InterruptedException");
404
        }
405
      }
406
    }
407
 
408
    mRunLevel = RunLevel.ACTIVE;    
816 mhunt 409
    mLogger.warn("checkEnvironment changing run level to ACTIVE for rcon_id " + mRconId);
814 mhunt 410
    mRunLevel.persist(mReleaseManager, mRconId);
411
  }
412
 
413
  /**performs disk housekeeping which involves deleting build directories > 5 days old
414
   * refer to the sequence diagram check environment
415
   */
416
  private void housekeep()
417
  {
418
    mLogger.debug("housekeep");
419
    FilenameFilter filter = new FilenameFilter()
420
    {
421
      public boolean accept(File file, String name)
422
      {
423
        mLogger.debug("accept " + name);
424
        boolean retVal = false;
425
 
426
        if ( file.isDirectory() && !name.startsWith( "." ) )
427
        {
428
          retVal = true;
429
        }
430
 
431
        mLogger.info("accept returned " + retVal);
432
        return retVal;
433
      }
434
    };
435
 
436
    try
437
    {
842 mhunt 438
      // DEVI 46729, 46730, solaris 10 core dumps implicate deleteDirectory
439
      // let each BuildThread look after its own housekeeping
854 mhunt 440
      File ocwd = new File( BuildDaemon.mGbeLog );
441
      File hcwd = new File( ocwd, BuildDaemon.mHostname );
442
      File cwd = new File( hcwd, String.valueOf( mRtagId ) );
842 mhunt 443
 
814 mhunt 444
      File[] children = cwd.listFiles( filter );
445
 
446
      if ( children != null )
447
      {
448
        for ( int child=0; child < children.length; child++ )
449
        {
854 mhunt 450
          // child is named uniquely to encapsulate a build
451
          // 5 days = 432,000,000 milliseconds
452
          if ( ( System.currentTimeMillis() - children[ child ].lastModified() ) > 432000000 )
814 mhunt 453
          {
854 mhunt 454
            // the directory is over 5 days old
455
            mLogger.warn("housekeep deleting directory " + children[ child ].getName());
896 mhunt 456
            if ( mUnitTest.compareTo("unit test check environment") != 0 )
814 mhunt 457
            {
854 mhunt 458
              deleteDirectory( children[ child ] );
814 mhunt 459
            }
460
          }
461
        }
462
      }
463
    }
464
    catch( SecurityException e )
465
    {
466
      // this can be thrown by lastModified
894 mhunt 467
      mLogger.warn("housekeep caught SecurityException");
814 mhunt 468
    }
469
 
470
  }
471
 
894 mhunt 472
  /**returns true if a file exists and can be deleted,
473
   * created and exists in the file system
474
   * this is to guard against read-only file systems
475
   */
476
  private boolean touch()
477
  {
478
    mLogger.debug("touch");
479
    boolean retVal = true;
480
 
481
    try
482
    {
483
      File touch = new File( String.valueOf( mRtagId ) + "touch" );
484
 
485
      if ( touch.exists() )
486
      {
487
        // delete it
488
        retVal = touch.delete();
489
      }
490
 
491
      if ( retVal )
492
      {
493
        // file does not exist
494
        retVal = touch.createNewFile();
495
      }
496
    }
497
    catch( SecurityException e )
498
    {
499
      // this can be thrown by exists, delete, createNewFile
500
      retVal = false;
501
      mLogger.warn("touch caught SecurityException");
502
    }
503
    catch( IOException e )
504
    {
505
      // this can be thrown by createNewFile
506
      retVal = false;
507
      mLogger.warn("touch caught IOException");
508
    }
509
 
510
    mLogger.info("touch returned " + retVal);
511
    return retVal;
512
  }
513
 
814 mhunt 514
  /**returns true if free disk space > 10G
515
   * this may become configurable if the need arises
516
   * refer to the sequence diagram check environment
517
   */
518
  private boolean hasSufficientDiskSpace()
519
  {
520
    mLogger.debug("hasSufficientDiskSpace");
521
    boolean retVal = true;
522
    long freeSpace = 0;
523
 
524
    try
525
    {
526
      File cwd = new File( "." );
527
 
528
      // 5G = 5368709120 bytes
886 mhunt 529
      // 1G = 1073741824 bytes - useful for testing
896 mhunt 530
      if ( mUnitTest.compareTo("unit test check environment") == 0 )
814 mhunt 531
      {
864 mhunt 532
        if ( ReleaseManager.mPersistedRunLevelCollection.size() == 0 )
814 mhunt 533
        {
534
          retVal = false;
535
        }
536
        else
537
        {
538
          retVal = true;
539
        }
540
      }
541
      else
542
      {
816 mhunt 543
        freeSpace = cwd.getUsableSpace();
814 mhunt 544
 
545
        if ( freeSpace < 5368709120L )
546
        {
816 mhunt 547
          mLogger.warn("hasSufficientDiskSpace on " + cwd.getAbsolutePath() + " freeSpace " + freeSpace);
814 mhunt 548
          retVal = false;
549
        }
550
      }
551
    }
552
    catch( SecurityException e )
553
    {
554
      // this can be thrown by getFreeSpace
555
       mLogger.warn("hasSufficientDiskSpace caught SecurityException");
556
    }
557
 
558
    mLogger.info("hasSufficientDiskSpace returned " + retVal + " " + freeSpace);
559
    return retVal;
560
  }
561
 
562
  /**abstract method
563
   */
564
  public abstract void run();
565
 
566
  /**deletes directory and all its files
567
   */
568
  protected void deleteDirectory(File directory)
569
  {
570
    mLogger.debug("deleteDirectory " + directory.getName());
571
    try
572
    {
573
      if ( directory.exists() )
574
      {
575
        FilenameFilter filter = new FilenameFilter()
576
        {
577
          public boolean accept(File file, String name)
578
          {
579
            mLogger.debug("accept " + name);
580
            boolean retVal = false;
581
 
840 mhunt 582
            if ( name.compareTo(".") != 0 && ( name.compareTo("..") != 0 ) )
814 mhunt 583
            {
584
              retVal = true;
585
            }
586
 
587
            mLogger.info("accept returned " + retVal);
588
            return retVal;
589
          }
590
        };
591
 
592
        File[] children = directory.listFiles( filter );
593
 
594
        if ( children != null )
595
        {
596
          for ( int child=0; child < children.length; child++ )
597
          {
598
            if ( children[ child ].isDirectory() )
599
            {
600
              deleteDirectory( children[ child ] );
601
            }
602
            else
603
            {
604
              children[ child ].delete();
605
            }
606
          }
607
        }
608
        directory.delete();
609
      }
610
    }
611
    catch( SecurityException e )
612
    {
613
      // this can be thrown by exists and delete
614
       mLogger.warn("deleteDirectory caught SecurityException");
615
    }
616
  }
617
 
618
  /**abstract method
619
   */
620
  protected abstract char getMode();
621
 
622
  /**injects GBE_BUILDFILTER into the passed buildFileContent
623
   * builds a buildFile from the buildFileContent
624
   * triggers ant to operate on the buildFile
625
   */
854 mhunt 626
  protected void deliverChange(String buildFileContent, String target, boolean master)
814 mhunt 627
  {
628
    mLogger.debug("deliverChange");
854 mhunt 629
 
866 mhunt 630
    // always perform a AbtSetUp, AbtPublish (master only), and AbtTearDown
631
    if ( target == null && mErrorReported )
854 mhunt 632
    {
866 mhunt 633
      // AbtSetUp failed
634
      // the default target will inevitably fail and will generate further email if allowed to proceed
635
      // do not mask the root cause
854 mhunt 636
      return;
637
    }
638
 
814 mhunt 639
    File buildFile = new File(mRtagId + "build.xml");
862 mhunt 640
    boolean logError = true;
866 mhunt 641
    Project p = new Project();
814 mhunt 642
 
643
    try
644
    {
645
      // clear the file contents
646
      if ( buildFileContent != null && target != null && target.compareTo("AbtSetUp") == 0 )
647
      {
648
        FileOutputStream buildFileOutputStream = new FileOutputStream(buildFile, false);
649
        buildFileOutputStream.close();
650
 
651
        StringReader buildFileContentStringReader = new StringReader(buildFileContent);
652
        BufferedReader buildFileBufferedReader = new BufferedReader(buildFileContentStringReader);
653
 
654
        // sanitise the buildFileContent
655
        // it may contain line.separators of "\n", "\r", or "\r\n" variety, depending on the location of the ripple engine
656
        String sanitisedBFC = new String();
657
        String lf = new String( System.getProperty("line.separator") );
658
        int lineCount = 0;
659
        String line = new String();
660
 
661
        while( ( line = buildFileBufferedReader.readLine() ) != null)
662
        {
663
          sanitisedBFC += line + lf;
664
          lineCount++;
665
 
666
          if ( lineCount == 2 )
667
          {
668
            // have read the first two lines
862 mhunt 669
            String inject = "<property name=\"abt_MASTER\" value=\"";
814 mhunt 670
 
671
            if ( master )
672
            {
673
              inject += "yes\"/>" + lf;
674
            }
675
            else
676
            {
677
              inject += "no\"/>" + lf;
678
            }
896 mhunt 679
 
814 mhunt 680
            // insert a GBE_BUILDFILTER property if necessary
896 mhunt 681
            if ( mGbebuildfilter != null && mGbebuildfilter.length() > 0 )
814 mhunt 682
            {
862 mhunt 683
              inject += "<property name=\"abt_GBE_BUILDFILTER\" value=\"" + mGbebuildfilter + "\"/>" + lf;
814 mhunt 684
            }
685
 
686
            mLogger.info("deliverChange injecting " + inject);
687
            sanitisedBFC += inject;
688
          }
689
        }
690
        buildFileBufferedReader.close();
691
        FileWriter buildFileWriter = new FileWriter(buildFile);
692
        buildFileWriter.write(sanitisedBFC);
693
        buildFileWriter.close();
694
      }
695
 
866 mhunt 696
      mReportingPackageName = null;
697
      mReportingPackageVersion = null;
698
      mReportingPackageExtension = null;
699
      mReportingPackageLocation = null;
700
      mReportingPackageDepends = null;
701
      mReportingIsRipple = null;
702
      mReportingPackageVersionId = null;
703
      mReportingDoesNotRequireSourceControlInteraction = null;
704
      mReportingFullyPublished = null;
705
      mReportingNewLabel = null;
706
 
707
      if ( buildFile.exists() )
814 mhunt 708
      {
866 mhunt 709
        p.setProperty("ant.file", buildFile.getAbsolutePath());
710
        DefaultLogger dl = new DefaultLogger();
711
        PrintStream ps = new PrintStream(mRtagId + ".log");
712
        dl.setOutputPrintStream(ps);
713
        dl.setMessageOutputLevel(Project.MSG_INFO);
714
        p.addBuildListener(dl);
715
        p.init();
716
        ProjectHelper pH = ProjectHelper.getProjectHelper();
717
        p.addReference("ant.projectHelper", pH);
718
 
719
        // parse can throw BuildException, this is serious
720
        pH.parse(p, buildFile);
721
        mLogger.warn("deliverChange ant launched on " + buildFile.getAbsolutePath());
722
 
723
        if ( target == null )
724
        {
725
          target = p.getDefaultTarget();
726
        }
727
        mLogger.warn("deliverChange ant launched against target " + target);
728
 
729
        // executeTarget can throw BuildException, this is not serious
730
        logError = false;
731
        // set up project properties for reporting purposes
732
        // this first group are hard coded in the build file
733
        mReportingPackageName = p.getProperty("abt_package_name");
734
        mReportingPackageVersion = p.getProperty("abt_package_version");
735
        mReportingPackageExtension = p.getProperty("abt_package_extension");
736
        mReportingPackageLocation = p.getProperty("basedir") + p.getProperty("abt_package_location");
737
        mReportingPackageDepends = p.getProperty("abt_package_depends");
738
        mReportingIsRipple = p.getProperty("abt_is_ripple");
739
        mReportingPackageVersionId = p.getProperty("abt_package_version_id");
740
        mReportingDoesNotRequireSourceControlInteraction = p.getProperty("abt_does_not_require_source_control_interaction");
741
 
742
        p.executeTarget(target);
743
        mLogger.warn("deliverChange ant returned");
744
 
814 mhunt 745
      }
746
    }
747
    catch( BuildException e )
748
    {
862 mhunt 749
      if ( logError )
750
      {
751
        mLogger.error("deliverChange caught BuildException, the build failed " + e.getMessage());
752
      }
753
      else
754
      {
866 mhunt 755
        if ( mReportingBuildFailureLogFile == null )
756
        {
757
          mReportingBuildFailureLogFile = e.getMessage();
758
        }
759
        mLogger.debug("deliverChange caught BuildException, big deal, the build failed " + mReportingBuildFailureLogFile);
862 mhunt 760
      }
854 mhunt 761
 
762
      mErrorReported = true;
814 mhunt 763
    }
764
    catch( FileNotFoundException e )
765
    {
766
      mLogger.error("deliverChange caught FileNotFoundException");
767
    }
768
    catch( IOException e )
769
    {
770
      mLogger.error("deliverChange caught IOException");
771
    }
772
 
866 mhunt 773
    // this group are set at run time (by the AbtPublish target only)
774
    // they will be null for every other target,
775
    // and null if an error occurs in the AbtPublish target
776
    mReportingFullyPublished = p.getProperty("abt_fully_published");
777
    mReportingNewLabel = p.getProperty("abt_new_label");
778
 
814 mhunt 779
  }
780
 
781
  /**sets up a ClearCase static view
782
   */
896 mhunt 783
  protected void setViewUp(String content, boolean master) throws SQLException, Exception
814 mhunt 784
  {
785
    mLogger.debug("setViewUp");
866 mhunt 786
    mReportingBuildFailureLogFile = null;
854 mhunt 787
    mErrorReported = false;
868 mhunt 788
 
789
    if ( !master && mGbeGatherMetricsOnly != null )
790
    {
791
      // do not run AbtSetUp on slave in metrics gathering mode
792
      return;
793
    }
794
 
896 mhunt 795
    MutableString buildFilter = new MutableString();
796
    mReleaseManager.connect();
797
    mReleaseManager.queryBuildFilter(mRconId, buildFilter);
798
    mReleaseManager.disconnect();
799
    mGbebuildfilter = buildFilter.value;
800
 
814 mhunt 801
    // run ant on the AbtSetUp target
802
    deliverChange(content, "AbtSetUp", master);
803
  }
804
 
805
  /**Checks the archive for the <packageName>/<packageVersion>/built.<machtype> existence
806
   */
807
  protected boolean published(String archive, String packageName, 
808
                            String packageVersion, String machtype,
809
                            String generic)
810
  {
811
    mLogger.debug("published");
812
    boolean retVal = false;
813
 
814
    String fs = System.getProperty( "file.separator" );
815
    String destination = archive + fs + packageName + fs + packageVersion;
816
 
817
    mLogger.debug("published " + destination);
818
    String filename = "built.";
819
 
820
    if ( generic.compareTo("generic") == 0 )
821
    {
822
      filename += "generic";
823
    }
824
    else
825
    {
826
      filename += machtype;
827
    }
828
 
829
    mLogger.debug("published " + filename);
830
    File flag = new File( destination, filename );
831
 
832
    if ( flag.exists() )
833
    {
834
      retVal = true;
835
    }
836
    mLogger.debug("published returned " + retVal);
837
    return retVal;
838
  }
868 mhunt 839
 
840
  /**
841
   * indefinite pause notification
842
  */
843
   protected void indefinitePause(RippleEngine rippleEngine, String cause)
844
   {
845
     mLogger.debug("indefinitePause");
846
 
847
     String body =
848
     "Hostname: " + BuildDaemon.mHostname + "<p>" +
849
     "Release: " + rippleEngine.mBaselineName + "<p>" +
850
     cause;
851
 
852
     try
853
     {
854
       Smtpsend.send(
855
       rippleEngine.mMailServer, // mailServer
856
       rippleEngine.mMailSender, // source
857
       rippleEngine.mGlobalTarget, // target
858
       null, // cc
859
       null, // bcc
860
       "BUILD DAEMON INDEFINITE PAUSE", // subject
861
       body, // body
862
       null // attachment
863
       );
864
     }
865
     catch( Exception e )
866
     {
867
     }
868
   }
869
 
814 mhunt 870
}