Subversion Repositories DevTools

Rev

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