Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.abt;
2
 
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
 
9
import java.net.InetAddress;
10
import java.net.UnknownHostException;
11
 
12
import java.util.Iterator;
13
import java.util.Vector;
872 dpurdie 14
import java.util.Properties;
866 mhunt 15
 
16
import org.apache.log4j.Logger;
17
import org.apache.tools.ant.Project;
18
import org.apache.tools.ant.Target;
19
import org.apache.tools.ant.Task;
20
import org.apache.tools.ant.taskdefs.Execute;
21
import org.apache.tools.ant.taskdefs.Redirector;
22
import org.apache.tools.ant.BuildException;
868 mhunt 23
 
866 mhunt 24
import com.erggroup.buildtool.smtp.Smtpsend;
25
 
26
public class ABT extends Task
27
{
28
  // static fields
29
  // public
30
  // protected
31
  // private
32
 
33
  // fields
34
  // public
35
  // protected
36
  // private
37
  // System
38
  private String fs = System.getProperty( "file.separator" );
39
  private String ls = System.getProperty( "line.separator" );
40
  private String gbeMachtype = System.getenv("GBE_MACHTYPE");
41
  private String dpkg_archive = System.getenv("GBE_DPKG");
42
  private String deploy_archive = System.getenv("GBE_DPLY");
43
  // ant built in
44
  private Project project;
45
  private String basedir;
46
  // global
47
  private boolean master;
48
  private String gbebuildfilter;
49
  private String mailServer;
50
  private String mailSender;
51
  // project related
52
  private String rtagId;
53
  private String daemon;
54
  private String release;
55
  private String buildtoolVersion;
56
  private String family;
57
  private String oldExtension;
58
  private String newExtension;
59
  // target related
60
  private Target target;
61
  private String packageVersionID;
62
  private String packageAlias;
63
  private String packageName;
64
  private String packageVersion;
65
  private String packageExtension;
66
  private String packageLoc;
67
  private String packageLabel;
68
  private String directChange;
69
  private String doesNotRequireSourceControlInteraction;
908 mhunt 70
  private String testBuildInstruction;
866 mhunt 71
  private String generic;
72
  private String loc;
73
  private String unittests;
74
  private Vector<Depend> dependCollection = new Vector<Depend>();
75
  private Vector<Platform> platformCollection = new Vector<Platform>();
76
  private Vector<Jats> jatsCollection = new Vector<Jats>();
77
  private Vector<Ant> antCollection = new Vector<Ant>();
78
  private Vector<Owner> ownerCollection = new Vector<Owner>();
79
  private String owners;
80
  // set up in execute
81
  private BuildStandards buildStandard = BuildStandards.JATS;
82
  private JavaVersions javaVersion = JavaVersions.NONE;
83
  private CompileTargets compileTarget = CompileTargets.NONE;
84
  // abt task result property
85
  private String propertyValue = "0";
86
  // output redirector
87
  private Redirector re;
88
  private File output;
89
  // exec thread
90
  private String[] command = new String[100];
91
  private int commandIndex = 0;
92
  private String cwd;
93
  private Execute thread;
94
  private File wd;
95
  private String newLabel;
96
  private static final Logger mLogger = Logger.getLogger(ABT.class);
97
  private String fullyPublished = "no";
98
  private String hostname = new String("unknown");
99
 
100
  private void Log(String message1, String message2)
101
  {
102
    Log( message1 + message2, info );
103
  }
104
 
105
  private static final char debug = 0;
106
  private static final char info = 1;
107
  private static final char warn = 2;
108
  private static final char error = 3;
109
  private static final char fatal = 4;
110
 
111
  private void Log(String message, char facility)
112
  {
113
    if ( daemon != null )
114
    {
115
	    if ( facility == debug)
116
	    {
117
	      mLogger.debug(message);
118
	    }
119
	    else
120
	    if ( facility == info)
121
	    {
122
	      mLogger.info(message);
123
	    }
124
	    else
125
	    if ( facility == warn)
126
	    {
127
	      mLogger.warn(message);
128
	    }
129
	    else
130
	    if ( facility == error)
131
	    {
132
	      mLogger.error(message);
133
	    }
134
	    else
135
	    {
136
	      mLogger.fatal(message);
137
	    }
138
    }
139
 
140
    log( message );
141
  }
142
 
143
  private void initCommand()
144
  {
145
    for( int i = 0; i < 100; i++ )
146
    {
147
      command[ i ] = null;
148
    }
149
    commandIndex = 0;
150
  }
151
 
152
  private void addCommand( String c )
153
  {
154
    command[ commandIndex ] = c;
155
    commandIndex++;
156
  }
157
 
158
  private String printCommand( String addendum, boolean log )
159
  {
160
    String commandToPrint = "";
161
 
162
    for( int i = 0; i < 100; i++ )
163
    {
164
      if ( command[ i ] != null )
165
      {
166
        commandToPrint += command[ i ] + " ";
167
      }
168
      else
169
      {
170
        break;
171
      }
172
    }
173
 
174
    if ( addendum != null )
175
    {
176
      commandToPrint += addendum;
177
    }
178
 
179
    if ( log )
180
    {
181
      Log( commandToPrint, warn );
182
    }
183
 
184
    return commandToPrint;
185
  }
186
 
187
  private int runCommand( String message ) throws Exception
188
  {
189
    String cmd[] = new String[commandIndex];
190
    for ( int i = 0; i < commandIndex; i++ )
191
    {
192
      cmd[i] = command[i];
193
    }
194
    thread.setCommandline(cmd);
195
    printCommand( null, true );
196
    int retVal = thread.execute();
197
 
198
    if ( retVal == Execute.INVALID )
199
    {
200
      reportErrorException( "Failure to execute thread, internal ABT problem", 256 );
201
    }
202
    else
203
    {
204
      printCommand( " returned " + String.valueOf( retVal ), true );
205
 
206
      if ( message != null && retVal != 0 )
207
      {
208
        reportErrorException( message + " : " + printCommand( " returned " + String.valueOf( retVal ), true ), retVal );
209
      }
210
    }
211
 
212
    return retVal;
213
  }
214
 
215
  private String published(String archive, String machtype) throws Exception
216
  {
217
    String retVal = "no";
218
 
219
    if (archive == null)
220
    {
221
      reportErrorException( "GBE_DPKG or GBE_DPLY environment variable not set", 256 );
222
    }
223
 
224
    String destination = archive + fs + packageName + fs + packageVersion;
225
 
226
    if ( packageExtension.length() > 0 )
227
    {
228
      destination += "." + packageExtension;
229
    }
230
 
231
    String filename = "built.";
232
 
233
    if ( generic != null )
234
    {
235
      filename += "generic";
236
    }
237
    else
238
    {
239
      filename += machtype;
240
    }
241
 
242
    File flag = new File( destination, filename );
243
 
244
    if ( flag.exists() )
245
    {
246
      retVal = "yes";
247
      Log("published " + flag.getName() + " exists", warn);
248
    }
249
    else
250
    {
251
      Log("published " + flag.getName() + " does not exist", warn);
252
    }
253
 
254
    return retVal;
255
  }
256
 
257
  private void printPackage( FileWriter file, String packageName, String packageVersion, String packageExtension ) throws IOException
258
  {
259
    String line = packageName;
260
 
261
    if ( packageVersion != null )
262
    {
263
      // packageName not in form name version.ext
264
      line += " " + packageVersion;
265
 
266
      if ( packageExtension != null  && packageExtension.length() > 0 )
267
      {
268
        line += "." + packageExtension;
269
      }
270
    }
271
 
272
    line += ls;
273
 
274
    file.write( line );
275
  }
276
 
277
  private void copyFile( File source, File copy )
278
  {
279
    if ( source.exists() )
280
    {
281
      try
282
      {
283
        FileInputStream fis = new FileInputStream(source);
284
        FileOutputStream fos = new FileOutputStream(copy);
285
        byte[] buf = new byte[1024];
286
        int i = 0;
287
        while( (i=fis.read(buf)) != -1)
288
        {
289
          fos.write(buf, 0, i);
290
        }
291
        fis.close();
292
        fos.close();
293
      }
294
      catch( Exception e )
295
      {
296
        Log( "copyFile caught Exception", error );
297
      }
298
    }
299
  }
300
 
301
  private void reportError(String error, int retVal)
302
  {
303
    propertyValue = String.valueOf( retVal );
304
 
305
    Log( error, ABT.error );
306
    Log( "reportError propertyValue = " + propertyValue.toString() + ", ", error);
307
 
308
    if ( daemon == null )
309
    {
310
      // do nothing more in escrow
311
      return;
312
    }
313
 
314
    // persist the failure log to GBE_LOG/hostname/rtagid/timestamp
315
    String log = System.getenv("GBE_LOG");
316
 
317
    if ( log == null )
318
    {
319
      // cannot happen, GBE_LOG is checked in BuildDaemon at startup
320
      return;
321
    }
322
 
323
    try
324
    {
325
      InetAddress local = InetAddress.getLocalHost();
326
      hostname = local.getHostName();
327
    }
328
    catch( UnknownHostException e )
329
    {
330
      // do nothing, shouldn't happen, but hostname will be "unknown" if it does
331
    }
332
 
333
    File destinationLog = new File( log );
334
    File destinationHostname = new File( destinationLog, hostname );
335
    File destinationRtagId = new File( destinationHostname, rtagId );
336
    // create directories
337
    new File( destinationRtagId, daemon).mkdirs();
338
 
339
    File destinationTimestamp = new File( destinationRtagId, daemon );
340
 
341
    if ( destinationTimestamp.exists() )
342
    {
343
      File buildsource = new File(rtagId + "build.xml");
344
      File logsource = new File(rtagId + ".log");
345
      File buildcopy = new File( destinationTimestamp, packageAlias + ".xml");
346
      copyFile( buildsource, buildcopy );
347
      File logcopy = new File( destinationTimestamp, packageAlias + ".log");
348
      copyFile( logsource, logcopy );
349
      Log("reportError persisting " + logcopy.getName(), warn);
350
    }
351
 
352
    if ( !ownerCollection.isEmpty() )
353
    {
354
      String unc = System.getenv("GBE_UNC");
355
 
356
      if ( unc == null )
357
      {
358
        // cannot happen, GBE_UNC is checked in BuildDaemon at startup
359
        return;
360
      }
361
 
922 dpurdie 362
      String href = hostname + "/" + rtagId + "/" + daemon + "/" + packageAlias + ".log";
363
      unc += "/" + href;
364
 
866 mhunt 365
      String body = new String();
366
      body = "Release: " + release + "<p>" +
367
             "Package: " + packageName + "<p>" + 
368
             "Build machine: " + hostname + "<p>" +
369
             "GBE_MACHTYPE: " + gbeMachtype + "<p>" +
922 dpurdie 370
             "Error: " + error + "<p>" +
371
             "Log File: <a href=\"" + unc + "\">" + href + "</a> ... URL expires in 5 working days time<p><hr>";
866 mhunt 372
 
373
      try
374
      {
922 dpurdie 375
        Smtpsend.send( mailServer,  // mailServer
376
                       mailSender,  // source
377
                       owners,      // target
378
                       null,        // cc
379
                       null,        // bcc
866 mhunt 380
                       "BUILD FAILURE on package " + packageName, // subject
922 dpurdie 381
                       body,        // body
382
                       null         // attachment
866 mhunt 383
                      );
384
      }
385
      catch( Exception e )
386
      {
387
        // not fatal
388
        Log( "reportError caught Exception", warn);
389
      }
390
    }
391
 
392
  }
393
 
394
  private void reportErrorException(String error, int retVal) throws Exception
395
  {
396
    reportError( error, retVal );
397
    throw new Exception( hostname );
398
  }
399
 
868 mhunt 400
  private void genbuild(String gatherMetricsOnly) throws Exception
866 mhunt 401
  {
402
    if ( master )
403
    {
404
      // gather metrics
886 mhunt 405
      // jats -locatefile=.jats.packageroot etool jats_metrics -mode=init -rootdir=.
406
      // -locate=.jats.packageroot causes jats to cd to the folder containing the file .jats.packageroot
407
      // this file is created in the -path folder by jats release -extract
408
      // DEVI 51370 it is essential for metrics branch calculation the metrics utility is started within a static view
866 mhunt 409
      initCommand();
410
      addCommand( "jats" );
886 mhunt 411
      addCommand( "-locatefile=.jats.packageroot" );
866 mhunt 412
      addCommand( "etool" );
413
      addCommand( "jats_metrics" );
414
      addCommand( "-mode=init" );
415
      addCommand( "-rootdir=." );
416
 
417
      runCommand( "Failure to collect metrics" );
418
    }
419
 
868 mhunt 420
    if ( gatherMetricsOnly != null )
421
    {
422
      return;
423
    }
872 dpurdie 424
 
425
    //
426
    //  Create build files with updated dependency information
427
    //  In escrow mode : No new dependency information
894 mhunt 428
    //  In daemon mode :
429
    //      Ripple     : New dependency information
430
    //      Verify     : Existing dependency information
872 dpurdie 431
    //
894 mhunt 432
    //  In all modes  : ANT builds need an auto.xml
872 dpurdie 433
    //
894 mhunt 434
    //  In order to create auto.xml/auto.pl with package dependencies need to
872 dpurdie 435
    //  create file with dependency data (auto.cfg) only because its
436
    //  needed by "jats_rewrite"
437
    //
438
    File cfg = null;
439
    boolean  create_file = false;
894 mhunt 440
    if ( daemon != null )
866 mhunt 441
    {
872 dpurdie 442
      create_file = true;
443
 
894 mhunt 444
      // always generate auto.cfg
872 dpurdie 445
      cfg = new File( cwd + fs + "auto.cfg" );
866 mhunt 446
      cfg.createNewFile();
447
 
448
      if ( !cfg.exists() || !cfg.canWrite() )
449
      {
450
        reportErrorException( "Failed to open auto.cfg", 263 );
451
      }
452
 
453
      try
454
      {
455
        FileWriter cfgfw = new FileWriter(cfg);
456
        printPackage( cfgfw, packageName, packageVersion, packageExtension );
457
 
458
        // provide releasemanager.projectname=<name[0]> and releasemanager.releasename=<name[1]>
459
        String[] name = release.split( " > ", 2 );
460
 
461
        if ( name.length == 2 )
462
        {
463
          printPackage( cfgfw, "releasemanager.projectname=" + name[0], null, null );
464
          printPackage( cfgfw, "releasemanager.releasename=" + name[1], null, null );
465
        }
466
 
467
        for (Iterator<Depend> it=dependCollection.iterator(); it.hasNext(); )
468
        {
469
          Depend depend = it.next();
470
          printPackage( cfgfw, depend.getPackage_Alias(), null, null );
471
        }
472
 
473
        cfgfw.close();
474
      }
475
      catch( IOException e )
476
      {
477
        reportErrorException( "Failure to write to auto.cfg", 263 );
478
      }
872 dpurdie 479
    }
480
    else
481
    if ( buildStandard == BuildStandards.ANT )
482
    {
483
      // Have not created an auto.xml with updated dependencies
484
      // Ant build still would like an auto.xml file
485
      //
486
      // ie packages with a line <import file="auto.xml" optional="true"/> are fine
487
      //    but in escrow and rebuild we still need an auto.xml to be kind
488
      //
489
      create_file = true;
490
    }
491
 
492
    //
493
    //  Create the auto.pl/auto.xml file if required
494
    //
495
    if ( create_file )
496
    {
866 mhunt 497
      initCommand();
498
      addCommand( "jats" );
872 dpurdie 499
 
866 mhunt 500
      if ( buildStandard == BuildStandards.ANT )
501
      {
872 dpurdie 502
        addCommand( "-locatefile=" + packageName + ".xml" );
866 mhunt 503
        addCommand( "etool" );
504
        addCommand( "jats_rewrite" );
505
        addCommand( "-infile=" + packageName + "depends.xml" );
506
        addCommand( "-outfile=auto.xml" );
507
      }
508
      else
509
      {
510
        addCommand( "-locatepkg=" + packageLoc );
511
        addCommand( "etool" );
512
        addCommand( "jats_rewrite" );
513
        addCommand( "-infile=build.pl" );
514
        addCommand( "-outfile=auto.pl" );
515
      }
872 dpurdie 516
 
517
      if ( cfg != null )
518
      {
519
        addCommand( "-config=" + cfg.getAbsolutePath() );
894 mhunt 520
 
908 mhunt 521
        if ( doesNotRequireSourceControlInteraction != null && testBuildInstruction.compareTo("0") == 0 )
894 mhunt 522
        {
523
            // Have a config file, but we are not rippling the package
524
            // just rebuilding it. Validate the versions in Release Manager
525
            // against those in the build files
526
            addCommand( "-validate");
527
        }
872 dpurdie 528
      }
529
      else
530
      {
531
        addCommand( "-noconfig");
532
      }
866 mhunt 533
 
534
      if ( oldExtension != null )
535
      {
536
        addCommand( "-oldproject=" + oldExtension );
537
        addCommand( "-newproject=" + newExtension );
538
      }
539
 
540
      runCommand( "Failure to generate auto.pl potentially caused by missing dependencies in the Release Manager database" );
541
    }
542
  }
543
 
544
  private void jwrap() throws Exception
545
  {
872 dpurdie 546
    //--------------------------------------------------------------------------
547
    //  Build Phase
548
    //  Create build environment
549
 
866 mhunt 550
    initCommand();
872 dpurdie 551
    addCommand( "jats" );
866 mhunt 552
 
872 dpurdie 553
    if ( gbebuildfilter != null )
554
    {
555
      addCommand( "-buildfilter" );
556
      addCommand( gbebuildfilter);
557
    }
558
 
866 mhunt 559
    if ( buildStandard == BuildStandards.ANT )
560
    {
872 dpurdie 561
      addCommand( "-locatefile=" + packageName + ".xml" );
562
      addCommand( "abt" );
563
      addCommand( "-java=" + javaVersion.getJavaVersion() );
564
      addCommand( "-buildfile=" + packageName + ".xml" );
866 mhunt 565
      addCommand( "build" );
566
    }
567
    else
568
    {
569
      addCommand( "-locatepkg=" + packageLoc );
570
      addCommand( "build" );
872 dpurdie 571
      addCommand( "--package" );
866 mhunt 572
 
573
      if ( family.compareTo( "windows" ) == 0 )
574
      {
575
        addCommand( "--cache" );
576
      }
577
    }
578
 
579
    runCommand( "Failure to set up sandbox" );
580
 
872 dpurdie 581
    //--------------------------------------------------------------------------
582
    //  Make Package phase
583
    //  Create the package (make)
584
 
866 mhunt 585
    initCommand();
872 dpurdie 586
    addCommand( "jats" );
587
 
588
    if ( gbebuildfilter != null )
589
    {
590
      addCommand( "-buildfilter" );
591
      addCommand( gbebuildfilter);
592
    }
593
 
866 mhunt 594
    if ( buildStandard == BuildStandards.ANT )
595
    {
872 dpurdie 596
      addCommand( "-locatefile=" + packageName + ".xml" );
597
      addCommand( "abt" );
598
      addCommand( "-java=" + javaVersion.getJavaVersion() );
599
      addCommand( "-buildfile=" + packageName + ".xml" );
866 mhunt 600
      addCommand( "make_package" );
601
    }
602
    else
603
    {
604
      addCommand( "-locatepkg=" + packageLoc );
605
      addCommand( "make" );
872 dpurdie 606
      addCommand( "NODEPEND=1" );
607
 
866 mhunt 608
      if ( compileTarget == CompileTargets.PROD )
609
      {
610
        addCommand( "prod" );
611
        addCommand( "package_prod" );
612
      }
872 dpurdie 613
      else if ( compileTarget == CompileTargets.DEBUG )
866 mhunt 614
      {
615
        addCommand( "debug" );
616
        addCommand( "package_debug" );
617
      }
618
      else
619
      {
620
        addCommand( "all" );
621
      }
622
    }
872 dpurdie 623
 
624
    runCommand( "Failure to generate derived files" );
866 mhunt 625
 
626
 
872 dpurdie 627
    //--------------------------------------------------------------------------
628
    //  Unit tests phase
629
    //  Run autonimous unit tests
630
 
866 mhunt 631
    if ( unittests != null )
632
    {
633
      initCommand();
872 dpurdie 634
      addCommand( "jats" );
635
 
636
      if ( gbebuildfilter != null )
637
      {
638
        addCommand( "-buildfilter" );
639
        addCommand( gbebuildfilter);
640
      }
641
 
866 mhunt 642
      if ( buildStandard == BuildStandards.ANT )
643
      {
872 dpurdie 644
        addCommand( "-locatefile=" + packageName + ".xml" );
645
        addCommand( "abt" );
646
        addCommand( "-java=" + javaVersion.getJavaVersion() );
647
        addCommand( "-buildfile=" + packageName + ".xml" );
866 mhunt 648
        addCommand( "run_tests" );
649
      }
650
      else
651
      {
652
        addCommand( "-locatepkg=" + packageLoc );
872 dpurdie 653
        addCommand( "make" );
866 mhunt 654
        if ( compileTarget == CompileTargets.PROD )
655
        {
656
          addCommand( "run_unit_tests_prod" );
657
        }
872 dpurdie 658
        else if ( compileTarget == CompileTargets.DEBUG )
866 mhunt 659
        {
660
          addCommand( "run_unit_tests_debug" );
661
        }
662
        else
663
        {
664
          addCommand( "run_unit_tests" );
665
        }
666
      }
872 dpurdie 667
 
866 mhunt 668
      runCommand( "Failure to run unit tests" );
669
    }
872 dpurdie 670
 
671
    //--------------------------------------------------------------------------
672
    //  create_dpkg phase
673
    //  Publish the package to dpkg_archive
674
    //
675
 
866 mhunt 676
    initCommand();
677
    addCommand( "jats" );
678
    if ( buildStandard == BuildStandards.ANT )
679
    {
872 dpurdie 680
      addCommand( "-locatefile=" + packageName + ".xml" );
866 mhunt 681
    }
682
    else
683
    {
684
      addCommand( "-locatepkg=" + packageLoc );
685
    }
686
    addCommand( "create_dpkg" );
687
    addCommand( "-o" );
688
    addCommand( "-m" );
689
    addCommand( "-pname" );
690
    addCommand( packageName );
691
    addCommand( "-pversion" );
692
    if ( packageExtension.length() > 0 )
693
    {
694
      addCommand( packageVersion + "." + packageExtension );
695
    }
696
    else
697
    {
698
      addCommand( packageVersion );
699
    }
700
 
701
    if ( generic != null )
702
    {
703
      addCommand( "-generic" );
704
    }
705
 
706
    runCommand( "Failure to publish to archive" );
707
  }
708
 
868 mhunt 709
  private void publish(String gatherMetricsOnly) throws Exception
866 mhunt 710
  {    
711
    // check dpkg_archive    
712
    for (Iterator<Platform> it=platformCollection.iterator(); it.hasNext(); )
713
    {
714
      Platform platform = it.next();
715
      fullyPublished = published( dpkg_archive, platform.getGbe_Machtype() );
716
 
717
      if ( fullyPublished.compareTo("no") == 0 )
718
      {
719
        break;
720
      }
721
    }
722
 
723
    if ( fullyPublished.compareTo("no") == 0 )
724
    {
725
      // check deploy_archive    
726
      for (Iterator<Platform> it=platformCollection.iterator(); it.hasNext(); )
727
      {
728
        Platform platform = it.next();
729
        fullyPublished = published( deploy_archive, platform.getGbe_Machtype() );
730
 
731
        if ( fullyPublished.compareTo("no") == 0 )
732
        {
733
          break;
734
        }
735
      }
736
    }
868 mhunt 737
 
738
    if ( gatherMetricsOnly != null )
739
    {
740
      return;
741
    }
866 mhunt 742
 
743
    if ( fullyPublished.compareTo("yes") == 0 && daemon != null )
744
    {
745
      if ( doesNotRequireSourceControlInteraction == null )
746
      {
872 dpurdie 747
        //
748
        //  Save modified build files
749
        //  Label the resultant files
750
        //  Create a command of the form:
751
        //        jats etool jats_save_build
752
        //              -locatepkg=zzzz     (Optional)
753
        //              -infile=aaaa        (Optional)
754
        //              -outfile=bbbb       (Optional)
755
        //              -pname=xxxx
756
        //              -pversion=yyyy
757
        //              -wiplabel=ccccc     (Optional)
758
        //              -infofile=path_name
759
        //
760
        Log("publish save build files", warn);
761
 
762
        File saveinfo = new File(basedir + fs + rtagId + "abtinfo.txt");
763
        if ( saveinfo.exists() )
866 mhunt 764
        {
872 dpurdie 765
          saveinfo.delete();
866 mhunt 766
        }
767
 
768
        initCommand();
769
        addCommand( "jats" );
872 dpurdie 770
        if ( buildStandard == BuildStandards.ANT )
866 mhunt 771
        {
872 dpurdie 772
          addCommand( "-locatefile=" + packageName + ".xml" );
773
        }
774
        else
775
        {
866 mhunt 776
          addCommand( "-locatepkg=" + packageLoc );
777
        }
872 dpurdie 778
 
866 mhunt 779
        addCommand( "etool" );
780
        addCommand( "jats_save_build" );
872 dpurdie 781
 
866 mhunt 782
        if ( buildStandard == BuildStandards.ANT )
783
        {
784
          addCommand( "-infile" );
785
          addCommand( "auto.xml" );
786
          addCommand( "-outfile" );
787
          addCommand( packageName + "depends.xml" );
788
        }
872 dpurdie 789
        else
790
        {
791
          addCommand( "-infile" );
792
          addCommand( "auto.pl" );
793
          addCommand( "-outfile" );
794
          addCommand( "build.pl" );
795
        }
866 mhunt 796
 
872 dpurdie 797
        addCommand( "-pname" );
798
        addCommand( packageName );
799
 
800
        addCommand( "-pversion" );
801
        if ( packageExtension.length() > 0 )
866 mhunt 802
        {
872 dpurdie 803
          addCommand( packageVersion + "." + packageExtension );
866 mhunt 804
        }
805
        else
806
        {
872 dpurdie 807
          addCommand( packageVersion );
866 mhunt 808
        }
872 dpurdie 809
 
810
        addCommand( "-infofile" );
811
        addCommand( saveinfo.getAbsolutePath() );
812
 
813
        if ( directChange != null )
814
        {
815
          // its a WIP. Pass in existing Label
816
          addCommand( "-wiplabel" );
817
          addCommand( packageLabel );
818
        }
819
 
866 mhunt 820
        if ( oldExtension != null && newExtension != null && packageExtension.compareTo( newExtension ) == 0 )
821
        {
822
          // only branch build.pl where its extension is being migrated
823
          addCommand( "-branch" );
824
          addCommand( "project_migration_branch" );
825
          addCommand( "-newbranch" );
826
        }
872 dpurdie 827
 
828
        runCommand( "Failure to save build file changes into source control" );
829
 
830
        //
898 mhunt 831
        //  The command creates an info file(saveinfo) to pass information back
872 dpurdie 832
        //  to the caller (me). This is a 'properties' file
833
        //  Need to extract the following information
834
        //    newLabel
835
        //
898 mhunt 836
        Log("publish read info file", info);
872 dpurdie 837
 
838
        Properties properties = new Properties();
839
        try
866 mhunt 840
        {
872 dpurdie 841
          properties.load(new FileInputStream(saveinfo));
866 mhunt 842
        }
872 dpurdie 843
        catch (IOException e)
866 mhunt 844
        {
872 dpurdie 845
          reportErrorException( "Failed to open save_build info file", 262 );
866 mhunt 846
        }
872 dpurdie 847
 
848
        newLabel = properties.getProperty("Label" );
849
        if ( newLabel == null )
850
        {
851
          reportErrorException( "Save_build info. Missing property:Label", 262 );
852
        }
853
        Log("publish read info file. Label:" + newLabel , info);
854
      }
866 mhunt 855
    }
856
  }
857
 
858
  public void execute()
859
  {
860
    boolean errorReported = false;
861
    boolean benign = false;
862
    try
863
    {
864
      re = new Redirector(this);
865
 
866
      // early ant built in
867
      project = getProject();
868
      // required by the Execute API on non win32 platforms, don't ask because I don't know
869
      project.setProperty("ant.home", System.getenv("ANT_HOME"));
870
 
871
      daemon = project.getProperty("abt_daemon");
872
 
873
      if ( daemon != null )
874
      {
875
        Log("execute daemon: yes", info);
876
      }
877
 
878
      // early target related
879
      target = getOwningTarget();
880
      packageAlias = target.getName();
881
      packageLabel = project.getProperty(packageAlias + "packagelabel");
882
      Log("execute packageLabel: ", packageLabel);
883
 
884
      if ( packageLabel == null )
885
      {
886
        // this abt task has no properties, by design
887
        // future use to estimate build completion time
898 mhunt 888
        Log("execute packageAlias: " + packageAlias, info);
866 mhunt 889
        return;
890
      }
891
 
898 mhunt 892
      Log("execute packageAlias: " + packageAlias, warn);
893
 
866 mhunt 894
      // ant built in
895
      basedir = project.getProperty("basedir");
896
      Log("execute basedir: ", basedir);
897
 
898
      // global
899
      master = false;
900
 
901
      String mode = project.getProperty("abt_MASTER");
902
 
903
      if ( mode != null && mode.compareTo("yes") == 0 )
904
      {
905
      	master = true;
906
      }
907
 
908
      gbebuildfilter = project.getProperty("abt_GBE_BUILDFILTER");
909
      if ( gbebuildfilter != null )
910
      {
872 dpurdie 911
        //
912
        // Ensure the Execute task passes gbebuildfilter as one parameter...
913
        // Replace spaces with commas
914
        //
915
        gbebuildfilter = gbebuildfilter.replace( " ", ",");
866 mhunt 916
        Log("execute gbebuildfilter: ", gbebuildfilter);
917
      }
918
 
919
      mailServer = project.getProperty("abt_mail_server");
920
 
921
      if ( mailServer == null )
922
      {
894 mhunt 923
        mailServer = new String( "auperadom10.aupera.erggroup.com" );
866 mhunt 924
      }
925
 
926
      Log("execute mailServer: ", mailServer);
927
 
928
      mailSender = project.getProperty( "abt_mail_sender" );
929
 
930
      if ( mailSender == null )
931
      {
932
        mailSender = new String( "buildadm@erggroup.com" );
933
      }
934
 
935
      Log("execute mailSender: ", mailSender);
936
 
937
      // project related
938
      rtagId = project.getProperty("abt_rtag_id");
939
      Log("execute rtagId: ", rtagId);
940
 
941
      release = project.getProperty("abt_release");
942
      Log("execute release: ", release);
943
      buildtoolVersion = project.getProperty("abt_buildtool_version");
944
      Log("execute buildtoolVersion: ", buildtoolVersion);
945
      family = project.getProperty("abt_family");
946
      Log("execute family: ", family);
947
      oldExtension = project.getProperty("abt_old_extension");
948
      Log("execute oldExtension: ", oldExtension);
949
      newExtension = project.getProperty("abt_new_extension");
950
      Log("execute newExtension: ", newExtension);
908 mhunt 951
      testBuildInstruction = project.getProperty("abt_test_build_instruction");
952
      Log("execute testBuildInstruction: ", testBuildInstruction);
953
 
954
      if ( testBuildInstruction == null )
955
      {
956
        // use a meaningful default
957
        testBuildInstruction = "0";
958
      }
866 mhunt 959
 
960
      // redirect all thread (therefore jats) output to the output file in the basedir
961
      if ( daemon != null )
962
      {
963
        // thread logging is done to <rtagId>thread.log and is continually re-used every build
964
        // full thread and non thread (ie abt logging) is done to the DefaultLogger set up by the build daemons, <rtagId>.log
965
        // this file is copied on a build failure to cwd (if it exists) and is continually re-used every build
966
        output = new File( rtagId + "thread.log" );
967
        // capture full logging
968
        re.setAlwaysLog(true);
969
      }
970
      else
971
      {
972
        output = new File( packageAlias + ".log" );
973
      }
974
 
975
      re.setOutput( output );
976
      thread = new Execute(re.createHandler());
977
      thread.setAntRun( project );
978
      thread.setVMLauncher(false);
979
 
980
      // must set up package name and owners before reportError
981
      packageName = project.getProperty(packageAlias + "packagename");
982
      Log("execute packageName: ", packageName);
983
 
984
      for (Iterator<Owner> it=ownerCollection.iterator(); it.hasNext(); )
985
      {
986
        Owner owner = it.next();
987
 
988
        if ( owners == null )
989
        {
990
          owners = new String();
991
        }
992
        else
993
        {
994
          owners += ",";
995
        }
996
        owners += owner.getEmail();
997
        Log("execute owner: ", owner.getEmail());
998
      }
999
 
1000
      Log("execute owners: ", owners);
1001
 
1002
      if ( packageAlias.compareTo("AbtSetUp") == 0 )
1003
      {
872 dpurdie 1004
        String packageSrcPath = project.getProperty(packageAlias + "packageSrcPath");
866 mhunt 1005
 
872 dpurdie 1006
        if ( packageSrcPath != null )
866 mhunt 1007
        {
872 dpurdie 1008
          Log("execute packageSrcPath: ", packageSrcPath);
878 mhunt 1009
          // create rtag_id directory from scratch
1010
          File rId = new File( rtagId );
1011
          deleteDirectory( rId );
1012
          rId.mkdirs();
866 mhunt 1013
 
1014
          // jats release -extract pkgLabel -path=src_path -root=rtag_id/timestamp -tag=timestamp -noprefix
1015
          initCommand();
1016
          addCommand( "jats" );
1017
          addCommand( "release" );
1018
          addCommand( "-extract" );
1019
          addCommand( packageLabel );
872 dpurdie 1020
          addCommand( "-path=" + packageSrcPath );
878 mhunt 1021
          addCommand( "-root=" + rtagId );
866 mhunt 1022
          addCommand( "-tag=" + daemon );
1023
          addCommand( "-noprefix" );
1024
          addCommand( "-verbose" );
1025
          addCommand( "-verbose" );
1026
 
1027
          runCommand( "Failure to extract source code from source control" );
1028
        }
1029
        return;      
1030
      }
1031
 
1032
      // target related    
1033
      packageVersion = project.getProperty(packageAlias + "packageversion");
1034
      Log("execute packageVersion: ", packageVersion);
1035
      packageExtension = project.getProperty(packageAlias + "packageextension");
1036
      Log("execute packageExtension: ", packageExtension);
1037
      packageLoc = packageName;
1038
 
1039
      if ( packageExtension.length() > 0 )
1040
      {
1041
        packageLoc += "." + packageExtension;
1042
      }
1043
 
1044
      generic = project.getProperty(packageAlias + "generic");
1045
 
1046
      if ( generic != null )
1047
      {
1048
        Log("execute generic: yes", info);  
1049
      }
1050
 
1051
      int platformIndex = 0;
1052
 
1053
      for ( Iterator<Platform> it = platformCollection.iterator(); it.hasNext(); )
1054
      {
1055
        Platform platform = it.next();
1056
        platformIndex++;
1057
 
1058
        if ( gbeMachtype.compareTo( platform.getGbe_Machtype() ) == 0 )
1059
        {
1060
          break;
1061
        }
1062
      }
1063
 
1064
      int index = 0;
1065
 
1066
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1067
      {
1068
        Jats j = it.next();
1069
        index++;
1070
 
1071
        if ( platformIndex == index )
1072
        {
1073
          String target = j.getTarget();
1074
          if ( target.compareTo( "none" ) == 0 )
1075
          {
1076
            compileTarget = CompileTargets.NONE;
1077
          }
1078
          else
1079
          if ( target.compareTo( "production" ) == 0 )
1080
          {
1081
            compileTarget = CompileTargets.PROD;
1082
          }
1083
          else
1084
          if ( target.compareTo( "debug") == 0 )
1085
          {
1086
            compileTarget = CompileTargets.DEBUG;
1087
          }
1088
          else
1089
          if ( target.compareTo( "all" ) == 0 )
1090
          {
1091
            compileTarget = CompileTargets.ALL;
1092
          }
1093
          else
1094
          {
1095
            reportErrorException( "Failure, unsupported build environment " + target + ", internal ABT problem", 256 );
1096
          }
1097
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1098
          Log( "execute compileTarget: ", compileTarget.getCompileTarget() );
1099
          break;
1100
        }
1101
      }
1102
 
1103
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1104
      {
1105
        Ant a = it.next();
1106
        index++;
1107
 
1108
        if ( platformIndex == index )
1109
        {
1110
          buildStandard = BuildStandards.ANT;
1111
          String version = a.getJava();
1112
          if ( version.compareTo( "none" ) == 0 )
1113
          {
1114
            javaVersion = JavaVersions.NONE;
1115
          }
1116
          else
1117
          if ( version.compareTo( "1.4" ) == 0 )
1118
          {
1119
            javaVersion = JavaVersions.FOUR;
1120
          }
1121
          else
1122
          if ( version.compareTo( "1.5" ) == 0 )
1123
          {
1124
            javaVersion = JavaVersions.FIVE;
1125
          }
1126
          else
1127
          if ( version.compareTo( "1.6" ) == 0 )
1128
          {
1129
            javaVersion = JavaVersions.SIX;
1130
          }
1131
          else
1132
          {
1133
            reportErrorException( "Failure, unsupported build environment " + version + ", internal ABT problem", 256 );
1134
          }
1135
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1136
          Log( "execute javaVersion: ", javaVersion.getJavaVersion() );
1137
          break;
1138
        }
1139
      }
1140
 
1141
      if ( packageAlias.compareTo("AbtTearDown") == 0 )
1142
      {
1143
        // tear the ClearCase view down, regardless of build error
1144
        wd = new File( basedir );
1145
 
1146
        // only now change the thread working directory back
1147
        thread.setWorkingDirectory( wd );
1148
 
868 mhunt 1149
        File buildDirectory = new File(wd + getProject().getProperty("abt_package_location"));
866 mhunt 1150
 
1151
        if ( buildDirectory.exists() )
1152
        {
1153
          // jats release -extract pkgLabel -root=rtag_id/timestamp -tag=timestamp -noprefix -delete
1154
          initCommand();
1155
          addCommand( "jats" );
1156
          addCommand( "release" );
1157
          addCommand( "-extract" );
1158
          addCommand( packageLabel );
878 mhunt 1159
          addCommand( "-root=" + rtagId );
866 mhunt 1160
          addCommand( "-tag=" + daemon );
1161
          addCommand( "-noprefix" );
1162
          addCommand( "-delete" );
1163
          addCommand( "-verbose" );
1164
          addCommand( "-verbose" );
1165
 
1166
          runCommand( "Failure to remove source code extraction" );
1167
        }
1168
 
878 mhunt 1169
        // delete the rtag directory
1170
        deleteDirectory( new File( rtagId ) );
866 mhunt 1171
 
1172
        return;      
1173
      }
1174
 
1175
      directChange = project.getProperty(packageAlias + "directchange");
1176
 
1177
      if ( directChange != null )
1178
      {
1179
        Log("execute directChange: yes", info);  
1180
      }
1181
 
1182
      doesNotRequireSourceControlInteraction = project.getProperty(packageAlias + "doesnotrequiresourcecontrolinteraction");
1183
 
1184
      if ( doesNotRequireSourceControlInteraction != null )
1185
      {
1186
        Log("execute doesNotRequireSourceControlInteraction: true", info);  
1187
      }
1188
 
1189
      for (Iterator<Platform> it=platformCollection.iterator(); it.hasNext(); )
1190
      {
1191
        Platform platform = it.next();
1192
        Log("execute platform: ", platform.getGbe_Machtype());
1193
      }
1194
 
1195
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1196
      {
1197
        Jats jats = it.next();
1198
        Log("execute jats: ", jats.getTarget());
1199
      }
1200
 
1201
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1202
      {
1203
        Ant ant = it.next();
1204
        Log("execute ant: ", ant.getJava());
1205
      }
1206
 
1207
      newLabel = packageName + "_" + packageVersion;
1208
 
1209
      if ( packageExtension.length() > 0 )
1210
      {
1211
        newLabel += "." + packageExtension;
1212
      }
1213
 
1214
      loc = project.getProperty(packageAlias + "loc");
1215
      Log("execute loc: ", loc);
1216
      cwd = basedir + loc;
1217
      Log("execute cwd: ", cwd);
1218
      wd = new File( cwd );
1219
 
1220
      if ( !wd.exists() )
1221
      {
1222
        reportErrorException( "Failure " + cwd + " does not exist", 265 );
1223
      }
1224
 
868 mhunt 1225
      String gatherMetricsOnly = System.getenv("GBE_GATHER_METRICS");
1226
 
866 mhunt 1227
      // only now change the thread working directory
1228
      thread.setWorkingDirectory( wd );
1229
 
1230
      if ( packageAlias.compareTo("AbtPublish") == 0 )
1231
      {
868 mhunt 1232
        publish(gatherMetricsOnly);
866 mhunt 1233
        if ( daemon != null )
1234
        {
1235
          // set properties to drive BuildThread attributes
1236
          // these are used to determine what ant did
1237
          getProject().setProperty("abt_fully_published", fullyPublished);
1238
          getProject().setProperty("abt_new_label", newLabel);
1239
        }
1240
 
1241
        return;
1242
      }
1243
 
1244
      packageVersionID = project.getProperty(packageAlias + "pv_id");
1245
      Log("execute packageVersionID: ", packageVersionID);
1246
      unittests = project.getProperty(packageAlias + "unittests");
1247
 
1248
      if ( unittests != null )
1249
      {
1250
        Log("execute unittests: yes", info);
1251
      }
1252
 
1253
      for (Iterator<Depend> it=dependCollection.iterator(); it.hasNext(); )
1254
      {
1255
        Depend depend = it.next();
1256
        Log("execute depend: ", depend.getPackage_Alias());
1257
      }
1258
 
1259
      // check platform
1260
      if ( gbeMachtype == null )
1261
      {
1262
        reportErrorException( "GBE_MACHTYPE environment variable not set", 256 );
1263
      }
1264
 
1265
      if ( daemon == null )
1266
      {
1267
        // escrow centric
1268
        // recognise an escrow will be run multiple times on a build stage
1269
        // do not force continuous rebuilding each time
1270
        // has this package version already been published on this platform
1271
        String published = published( dpkg_archive, gbeMachtype );
1272
 
1273
        if ( published.compareTo("no") == 0 )
1274
        {
1275
          published = published( deploy_archive, gbeMachtype );
1276
        }
1277
 
1278
        if ( published.compareTo("no") != 0 )
1279
        {
1280
          Log( "execute package has been published on this platform - skipping", info);
1281
          propertyValue = "257";
1282
          throw new Exception();
1283
        }
1284
      }
910 mhunt 1285
      else
866 mhunt 1286
      {
910 mhunt 1287
        // DEVI 56714 daemon centric check
1288
        String majorV = this.getClass().getPackage().getSpecificationVersion();
1289
 
1290
        if ( buildtoolVersion.compareTo( majorV ) != 0 )
1291
        {
1292
          reportErrorException( "Failure, incompatible build.xml not generated with version " + majorV, 256 );
1293
        }
866 mhunt 1294
      }
1295
 
1296
      if ( ( buildStandard == BuildStandards.ANT && javaVersion == JavaVersions.NONE ) ||
1297
           ( buildStandard == BuildStandards.JATS && compileTarget == CompileTargets.NONE ) )
1298
      {
1299
        // flag a benign build is good
1300
        benign = true;
1301
      }
1302
 
868 mhunt 1303
      genbuild( gatherMetricsOnly );
866 mhunt 1304
 
1305
      if ( !benign )
1306
      {
868 mhunt 1307
        if ( gatherMetricsOnly != null )
1308
        {
1309
          // special for metrics
1310
          String archive = dpkg_archive;
1311
 
1312
          if (archive != null)
1313
          {
1314
            String fs = System.getProperty( "file.separator" );
1315
            String destination = archive + fs + getProject().getProperty("abt_package_name") + fs + getProject().getProperty("abt_package_version");
1316
 
1317
            // do this for the win32 and generic based platforms
1318
            new File( destination ).mkdirs();
1319
            new File( destination, "built.win32" ).createNewFile();
1320
            new File( destination, "built.generic" ).createNewFile();
1321
          }
1322
 
1323
        }
1324
        else
1325
        {
1326
          jwrap();
1327
        }
866 mhunt 1328
      }
1329
 
1330
      if ( master )
1331
      {
1332
        File metrics = new File(basedir + fs + rtagId + "abtmetrics.txt");
1333
 
1334
        if ( metrics.exists() )
1335
        {
1336
          metrics.delete();
1337
        }
1338
 
1339
        // gather metrics
886 mhunt 1340
        // jats -locatefile=.jats.packageroot etool jats_metrics -mode=finish -out=abtmetrics.txt
866 mhunt 1341
        initCommand();
1342
        addCommand( "jats" );
886 mhunt 1343
        addCommand( "-locatefile=.jats.packageroot" );
866 mhunt 1344
        addCommand( "etool" );
1345
        addCommand( "jats_metrics" );
1346
        addCommand( "-mode=finish" );
1347
        addCommand( "-out=" + metrics.getAbsolutePath() );
1348
 
1349
        runCommand( "Failure to collect metrics" );
1350
      }
1351
    }
1352
    catch( SecurityException e)
1353
    {
1354
      errorReported = true;
1355
      reportError( "Failure caught SecurityException", 256 );
1356
    }
1357
    catch( IOException e)
1358
    {
1359
      errorReported = true;
1360
      reportError( "Failure caught IOException", 256 );
1361
    }
1362
    catch( Exception e)
1363
    {
1364
      // assume this condition has been reported on
1365
      errorReported = true;
1366
 
1367
      if ( e.getMessage() != null )
1368
      {
898 mhunt 1369
        Log( "execute caught Exception " + e.getMessage(), warn );
866 mhunt 1370
      }
1371
      else
1372
      {
1373
        Log( "execute caught Exception", warn );
1374
      }
1375
    }
1376
    finally
1377
    {
1378
      try
1379
      {
1380
        if ( daemon != null )
1381
        {
1382
          // do not write to publish.log
1383
          throw new IOException();
1384
        }
1385
 
1386
        FileWriter publish = new FileWriter( basedir + fs + "publish.log", true );
1387
        String friendlyVersion = packageVersion;
1388
        if ( packageExtension.length() > 0 )
1389
        {
1390
          friendlyVersion += "." + packageExtension;
1391
        }
1392
 
1393
        if ( propertyValue.compareTo( "0" ) == 0 )
1394
        {
1395
          if ( benign )
1396
          {
1397
            publish.write( "successfully published " + packageName + " at " + friendlyVersion + ", no action required on this platform" );
1398
          }
1399
          else
1400
          {
1401
            publish.write( "successfully published " + packageName + " at " + friendlyVersion );
1402
          }
1403
 
1404
          publish.write( ls );
1405
        }
1406
        else
1407
        if ( propertyValue.compareTo( "256" ) == 0 )
1408
        {
1409
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion +  ", internal abt issue" + ls );
1410
        }
1411
        else
1412
        if ( propertyValue.compareTo( "257" ) == 0 )
1413
        {
1414
          errorReported = false;
1415
          publish.write( "previously published " + packageName + " at " + friendlyVersion + ls );
1416
        }
1417
        else
872 dpurdie 1418
        if ( propertyValue.compareTo( "262" ) == 0 )
1419
        {
1420
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't process save_build info" + ls );
1421
        }
1422
        else
866 mhunt 1423
        if ( propertyValue.compareTo( "263" ) == 0 )
1424
        {
1425
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't write to auto.cfg" + ls );
1426
        }
1427
        else
1428
        if ( propertyValue.compareTo( "265" ) == 0 )
1429
        {
1430
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", " + cwd + " does not exist" + ls );
1431
        }
1432
        else
1433
        {
1434
          // nb jats or ant can presumably return a value 1 to 255
1435
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", jats or ant failed" + ls );
1436
        }
1437
 
1438
        publish.close();
1439
      }
1440
      catch( IOException e )
1441
      {
1442
        if ( daemon == null )
1443
        {
1444
          reportError( "Failure to write to publish.log", 266 );
1445
        }
1446
      }
1447
      catch( Exception e )
1448
      {
1449
        if ( daemon == null )
1450
        {
1451
          reportError( "Failure to write to publish.log", 266 );
1452
        }
1453
      }
1454
 
1455
      getProject().setProperty(packageAlias + ".res", propertyValue);
1456
 
1457
      if ( errorReported )
1458
      {
1459
        // designed to prevent subsequent build activity on this build file
1460
        // supply the build failure log file in message with / as file sep
1461
        // takes the form hostname/rtag_id/daemon/logfile
1462
        if ( daemon != null )
1463
        {
1464
          String message = hostname + "/" + rtagId + "/" + daemon + "/" + packageAlias + ".log";
1465
          throw new BuildException( message );
1466
        }
1467
        else
1468
        {
1469
          throw new BuildException();
1470
        }
1471
      }
1472
 
1473
    }
1474
  }
1475
 
1476
  private void deleteDirectory(File directory)
1477
  {
1478
    Log("deleteDirectory " + directory.getName(), debug);
1479
    try
1480
    {
1481
      if ( directory.exists() )
1482
      {
878 mhunt 1483
        File[] children = directory.listFiles();
866 mhunt 1484
 
1485
        if ( children != null )
1486
        {
1487
          for ( int child=0; child < children.length; child++ )
1488
          {
1489
            Log("deleteDirectory deleting " + children[ child ].getName(), warn);
1490
 
1491
            if ( children[ child ].isDirectory() )
1492
            {
1493
              deleteDirectory( children[ child ] );
1494
            }
1495
            else
1496
            {
1497
              children[ child ].delete();
1498
            }
1499
          }
1500
        }
1501
        directory.delete();
1502
      }
1503
    }
1504
    catch( SecurityException e )
1505
    {
1506
      // this can be thrown by exists and delete
1507
       Log("deleteDirectory caught SecurityException", warn);
1508
    }
1509
  }
1510
 
1511
  public Depend createDepend()
1512
  {
1513
    Depend depend = new Depend();
1514
    dependCollection.add(depend);
1515
    return depend;
1516
  }
1517
 
1518
  public Platform createPlatform()
1519
  {
1520
    Platform platform = new Platform();
1521
    platformCollection.add(platform);
1522
    return platform;
1523
  }
1524
 
1525
  public Jats createJats()
1526
  {
1527
    Jats jats = new Jats();
1528
    jatsCollection.add(jats);
1529
    return jats;
1530
  }
1531
 
1532
  public Ant createAnt()
1533
  {
1534
    Ant ant = new Ant();
1535
    antCollection.add(ant);
1536
    return ant;
1537
  }
1538
 
1539
  public Owner createOwner()
1540
  {
1541
    Owner owner = new Owner();
1542
    ownerCollection.add(owner);
1543
    return owner;
1544
  }
1545
}