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
  // 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
        if ( directChange != null )
795
        {
926 dpurdie 796
          addCommand( "-isawip" );
872 dpurdie 797
        }
926 dpurdie 798
 
799
        addCommand( "-infofile" );
800
        addCommand( saveinfo.getAbsolutePath() );
872 dpurdie 801
 
926 dpurdie 802
        addCommand( "-baselabel" );
803
        addCommand( packageVcsTag );
924 dpurdie 804
 
805
 
866 mhunt 806
        if ( oldExtension != null && newExtension != null && packageExtension.compareTo( newExtension ) == 0 )
807
        {
808
          // only branch build.pl where its extension is being migrated
809
          addCommand( "-branch" );
810
          addCommand( "project_migration_branch" );
811
          addCommand( "-newbranch" );
812
        }
872 dpurdie 813
 
814
        runCommand( "Failure to save build file changes into source control" );
815
 
816
        //
898 mhunt 817
        //  The command creates an info file(saveinfo) to pass information back
872 dpurdie 818
        //  to the caller (me). This is a 'properties' file
819
        //  Need to extract the following information
924 dpurdie 820
        //    newVcsTag - which is held as VCS.tag
872 dpurdie 821
        //
898 mhunt 822
        Log("publish read info file", info);
872 dpurdie 823
 
824
        Properties properties = new Properties();
825
        try
866 mhunt 826
        {
872 dpurdie 827
          properties.load(new FileInputStream(saveinfo));
866 mhunt 828
        }
872 dpurdie 829
        catch (IOException e)
866 mhunt 830
        {
872 dpurdie 831
          reportErrorException( "Failed to open save_build info file", 262 );
866 mhunt 832
        }
872 dpurdie 833
 
924 dpurdie 834
        newVcsTag = properties.getProperty("VCS.tag" );
835
        if ( newVcsTag == null )
872 dpurdie 836
        {
924 dpurdie 837
          reportErrorException( "Save_build info. Missing property:VCS.tag", 262 );
872 dpurdie 838
        }
924 dpurdie 839
        Log("publish read info file. Label:" + newVcsTag , info);
872 dpurdie 840
      }
866 mhunt 841
    }
842
  }
843
 
844
  public void execute()
845
  {
846
    boolean errorReported = false;
847
    boolean benign = false;
848
    try
849
    {
850
      re = new Redirector(this);
851
 
852
      // early ant built in
853
      project = getProject();
854
      // required by the Execute API on non win32 platforms, don't ask because I don't know
855
      project.setProperty("ant.home", System.getenv("ANT_HOME"));
856
 
857
      daemon = project.getProperty("abt_daemon");
858
 
859
      if ( daemon != null )
860
      {
861
        Log("execute daemon: yes", info);
862
      }
863
 
864
      // early target related
865
      target = getOwningTarget();
866
      packageAlias = target.getName();
924 dpurdie 867
      packageVcsTag = project.getProperty(packageAlias + "packagevcstag");
868
      Log("execute packageVcsTag: ", packageVcsTag);
866 mhunt 869
 
924 dpurdie 870
      if ( packageVcsTag == null )
866 mhunt 871
      {
872
        // this abt task has no properties, by design
873
        // future use to estimate build completion time
898 mhunt 874
        Log("execute packageAlias: " + packageAlias, info);
866 mhunt 875
        return;
876
      }
877
 
898 mhunt 878
      Log("execute packageAlias: " + packageAlias, warn);
879
 
866 mhunt 880
      // ant built in
881
      basedir = project.getProperty("basedir");
882
      Log("execute basedir: ", basedir);
883
 
884
      // global
885
      master = false;
886
 
887
      String mode = project.getProperty("abt_MASTER");
888
 
889
      if ( mode != null && mode.compareTo("yes") == 0 )
890
      {
891
      	master = true;
892
      }
893
 
894
      gbebuildfilter = project.getProperty("abt_GBE_BUILDFILTER");
895
      if ( gbebuildfilter != null )
896
      {
872 dpurdie 897
        //
898
        // Ensure the Execute task passes gbebuildfilter as one parameter...
899
        // Replace spaces with commas
900
        //
901
        gbebuildfilter = gbebuildfilter.replace( " ", ",");
866 mhunt 902
        Log("execute gbebuildfilter: ", gbebuildfilter);
903
      }
904
 
905
      mailServer = project.getProperty("abt_mail_server");
906
 
907
      if ( mailServer == null )
908
      {
894 mhunt 909
        mailServer = new String( "auperadom10.aupera.erggroup.com" );
866 mhunt 910
      }
911
 
912
      Log("execute mailServer: ", mailServer);
913
 
914
      mailSender = project.getProperty( "abt_mail_sender" );
915
 
916
      if ( mailSender == null )
917
      {
918
        mailSender = new String( "buildadm@erggroup.com" );
919
      }
920
 
921
      Log("execute mailSender: ", mailSender);
922
 
923
      // project related
924
      rtagId = project.getProperty("abt_rtag_id");
925
      Log("execute rtagId: ", rtagId);
926
 
927
      release = project.getProperty("abt_release");
928
      Log("execute release: ", release);
929
      buildtoolVersion = project.getProperty("abt_buildtool_version");
930
      Log("execute buildtoolVersion: ", buildtoolVersion);
931
      family = project.getProperty("abt_family");
932
      Log("execute family: ", family);
933
      oldExtension = project.getProperty("abt_old_extension");
934
      Log("execute oldExtension: ", oldExtension);
935
      newExtension = project.getProperty("abt_new_extension");
936
      Log("execute newExtension: ", newExtension);
908 mhunt 937
      testBuildInstruction = project.getProperty("abt_test_build_instruction");
938
      Log("execute testBuildInstruction: ", testBuildInstruction);
939
 
940
      if ( testBuildInstruction == null )
941
      {
942
        // use a meaningful default
943
        testBuildInstruction = "0";
944
      }
866 mhunt 945
 
946
      // redirect all thread (therefore jats) output to the output file in the basedir
947
      if ( daemon != null )
948
      {
949
        // thread logging is done to <rtagId>thread.log and is continually re-used every build
950
        // full thread and non thread (ie abt logging) is done to the DefaultLogger set up by the build daemons, <rtagId>.log
951
        // this file is copied on a build failure to cwd (if it exists) and is continually re-used every build
952
        output = new File( rtagId + "thread.log" );
953
        // capture full logging
954
        re.setAlwaysLog(true);
955
      }
956
      else
957
      {
958
        output = new File( packageAlias + ".log" );
959
      }
960
 
961
      re.setOutput( output );
962
      thread = new Execute(re.createHandler());
963
      thread.setAntRun( project );
964
      thread.setVMLauncher(false);
965
 
966
      // must set up package name and owners before reportError
967
      packageName = project.getProperty(packageAlias + "packagename");
968
      Log("execute packageName: ", packageName);
969
 
970
      for (Iterator<Owner> it=ownerCollection.iterator(); it.hasNext(); )
971
      {
972
        Owner owner = it.next();
973
 
974
        if ( owners == null )
975
        {
976
          owners = new String();
977
        }
978
        else
979
        {
980
          owners += ",";
981
        }
982
        owners += owner.getEmail();
983
        Log("execute owner: ", owner.getEmail());
984
      }
985
 
986
      Log("execute owners: ", owners);
987
 
988
      if ( packageAlias.compareTo("AbtSetUp") == 0 )
989
      {
924 dpurdie 990
        // create rtag_id directory from scratch
991
        File rId = new File( rtagId );
992
        deleteDirectory( rId );
993
        rId.mkdirs();
866 mhunt 994
 
924 dpurdie 995
        // jats jats_vcsrelease -extract -label=pkgVcsTag -path=src_path -root=rtag_id/timestamp -tag=timestamp -noprefix
996
        initCommand();
997
        addCommand( "jats" );
998
        addCommand( "jats_vcsrelease" );
999
        addCommand( "-extract" );
1000
        addCommand( "-label=" + packageVcsTag );
1001
        addCommand( "-root=" + rtagId );
1002
        addCommand( "-tag=" + daemon );
1003
        addCommand( "-noprefix" );
1004
        addCommand( "-verbose=2" );
866 mhunt 1005
 
924 dpurdie 1006
        runCommand( "Failure to extract source code from source control" );
1007
        return;
866 mhunt 1008
      }
1009
 
1010
      // target related    
1011
      packageVersion = project.getProperty(packageAlias + "packageversion");
1012
      Log("execute packageVersion: ", packageVersion);
1013
      packageExtension = project.getProperty(packageAlias + "packageextension");
1014
      Log("execute packageExtension: ", packageExtension);
1015
      packageLoc = packageName;
1016
 
1017
      if ( packageExtension.length() > 0 )
1018
      {
1019
        packageLoc += "." + packageExtension;
1020
      }
1021
 
1022
      generic = project.getProperty(packageAlias + "generic");
1023
 
1024
      if ( generic != null )
1025
      {
1026
        Log("execute generic: yes", info);  
1027
      }
1028
 
1029
      int platformIndex = 0;
1030
 
1031
      for ( Iterator<Platform> it = platformCollection.iterator(); it.hasNext(); )
1032
      {
1033
        Platform platform = it.next();
1034
        platformIndex++;
1035
 
1036
        if ( gbeMachtype.compareTo( platform.getGbe_Machtype() ) == 0 )
1037
        {
1038
          break;
1039
        }
1040
      }
1041
 
1042
      int index = 0;
1043
 
1044
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1045
      {
1046
        Jats j = it.next();
1047
        index++;
1048
 
1049
        if ( platformIndex == index )
1050
        {
1051
          String target = j.getTarget();
1052
          if ( target.compareTo( "none" ) == 0 )
1053
          {
1054
            compileTarget = CompileTargets.NONE;
1055
          }
1056
          else
1057
          if ( target.compareTo( "production" ) == 0 )
1058
          {
1059
            compileTarget = CompileTargets.PROD;
1060
          }
1061
          else
1062
          if ( target.compareTo( "debug") == 0 )
1063
          {
1064
            compileTarget = CompileTargets.DEBUG;
1065
          }
1066
          else
1067
          if ( target.compareTo( "all" ) == 0 )
1068
          {
1069
            compileTarget = CompileTargets.ALL;
1070
          }
1071
          else
1072
          {
1073
            reportErrorException( "Failure, unsupported build environment " + target + ", internal ABT problem", 256 );
1074
          }
1075
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1076
          Log( "execute compileTarget: ", compileTarget.getCompileTarget() );
1077
          break;
1078
        }
1079
      }
1080
 
1081
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1082
      {
1083
        Ant a = it.next();
1084
        index++;
1085
 
1086
        if ( platformIndex == index )
1087
        {
1088
          buildStandard = BuildStandards.ANT;
1089
          String version = a.getJava();
1090
          if ( version.compareTo( "none" ) == 0 )
1091
          {
1092
            javaVersion = JavaVersions.NONE;
1093
          }
1094
          else
1095
          if ( version.compareTo( "1.4" ) == 0 )
1096
          {
1097
            javaVersion = JavaVersions.FOUR;
1098
          }
1099
          else
1100
          if ( version.compareTo( "1.5" ) == 0 )
1101
          {
1102
            javaVersion = JavaVersions.FIVE;
1103
          }
1104
          else
1105
          if ( version.compareTo( "1.6" ) == 0 )
1106
          {
1107
            javaVersion = JavaVersions.SIX;
1108
          }
1109
          else
1110
          {
1111
            reportErrorException( "Failure, unsupported build environment " + version + ", internal ABT problem", 256 );
1112
          }
1113
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1114
          Log( "execute javaVersion: ", javaVersion.getJavaVersion() );
1115
          break;
1116
        }
1117
      }
1118
 
1119
      if ( packageAlias.compareTo("AbtTearDown") == 0 )
1120
      {
924 dpurdie 1121
        // tear the build view down, regardless of build error
866 mhunt 1122
        wd = new File( basedir );
1123
 
1124
        // only now change the thread working directory back
1125
        thread.setWorkingDirectory( wd );
1126
 
868 mhunt 1127
        File buildDirectory = new File(wd + getProject().getProperty("abt_package_location"));
866 mhunt 1128
 
1129
        if ( buildDirectory.exists() )
1130
        {
924 dpurdie 1131
          // jats jats_vcsrelease -label pkgTag -root=rtag_id/timestamp -tag=timestamp -noprefix -delete
866 mhunt 1132
          initCommand();
1133
          addCommand( "jats" );
924 dpurdie 1134
          addCommand( "jats_vcsrelease" );
1135
          addCommand( "-label=" + packageVcsTag );
878 mhunt 1136
          addCommand( "-root=" + rtagId );
866 mhunt 1137
          addCommand( "-tag=" + daemon );
1138
          addCommand( "-noprefix" );
924 dpurdie 1139
          addCommand( "-delete=2" );
1140
          addCommand( "-verbose=2" );
1141
 
866 mhunt 1142
          runCommand( "Failure to remove source code extraction" );
1143
        }
1144
 
878 mhunt 1145
        // delete the rtag directory
1146
        deleteDirectory( new File( rtagId ) );
866 mhunt 1147
 
1148
        return;      
1149
      }
1150
 
1151
      directChange = project.getProperty(packageAlias + "directchange");
1152
 
1153
      if ( directChange != null )
1154
      {
1155
        Log("execute directChange: yes", info);  
1156
      }
1157
 
1158
      doesNotRequireSourceControlInteraction = project.getProperty(packageAlias + "doesnotrequiresourcecontrolinteraction");
1159
 
1160
      if ( doesNotRequireSourceControlInteraction != null )
1161
      {
1162
        Log("execute doesNotRequireSourceControlInteraction: true", info);  
1163
      }
1164
 
1165
      for (Iterator<Platform> it=platformCollection.iterator(); it.hasNext(); )
1166
      {
1167
        Platform platform = it.next();
1168
        Log("execute platform: ", platform.getGbe_Machtype());
1169
      }
1170
 
1171
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1172
      {
1173
        Jats jats = it.next();
1174
        Log("execute jats: ", jats.getTarget());
1175
      }
1176
 
1177
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1178
      {
1179
        Ant ant = it.next();
1180
        Log("execute ant: ", ant.getJava());
1181
      }
924 dpurdie 1182
 
1183
      // Set newVsTag to the existing VcsTag
1184
      // Will be used when rebuilding a package that already exists
1185
      newVcsTag = packageVcsTag;
1186
 
866 mhunt 1187
      loc = project.getProperty(packageAlias + "loc");
1188
      Log("execute loc: ", loc);
1189
      cwd = basedir + loc;
1190
      Log("execute cwd: ", cwd);
1191
      wd = new File( cwd );
1192
 
1193
      if ( !wd.exists() )
1194
      {
1195
        reportErrorException( "Failure " + cwd + " does not exist", 265 );
1196
      }
1197
 
868 mhunt 1198
      String gatherMetricsOnly = System.getenv("GBE_GATHER_METRICS");
1199
 
866 mhunt 1200
      // only now change the thread working directory
1201
      thread.setWorkingDirectory( wd );
1202
 
1203
      if ( packageAlias.compareTo("AbtPublish") == 0 )
1204
      {
868 mhunt 1205
        publish(gatherMetricsOnly);
866 mhunt 1206
        if ( daemon != null )
1207
        {
1208
          // set properties to drive BuildThread attributes
1209
          // these are used to determine what ant did
1210
          getProject().setProperty("abt_fully_published", fullyPublished);
924 dpurdie 1211
          getProject().setProperty("abt_new_vcstag", newVcsTag);
866 mhunt 1212
        }
1213
 
1214
        return;
1215
      }
1216
 
1217
      packageVersionID = project.getProperty(packageAlias + "pv_id");
1218
      Log("execute packageVersionID: ", packageVersionID);
1219
      unittests = project.getProperty(packageAlias + "unittests");
1220
 
1221
      if ( unittests != null )
1222
      {
1223
        Log("execute unittests: yes", info);
1224
      }
1225
 
1226
      for (Iterator<Depend> it=dependCollection.iterator(); it.hasNext(); )
1227
      {
1228
        Depend depend = it.next();
1229
        Log("execute depend: ", depend.getPackage_Alias());
1230
      }
1231
 
1232
      // check platform
1233
      if ( gbeMachtype == null )
1234
      {
1235
        reportErrorException( "GBE_MACHTYPE environment variable not set", 256 );
1236
      }
1237
 
1238
      if ( daemon == null )
1239
      {
1240
        // escrow centric
1241
        // recognise an escrow will be run multiple times on a build stage
1242
        // do not force continuous rebuilding each time
1243
        // has this package version already been published on this platform
1244
        String published = published( dpkg_archive, gbeMachtype );
1245
 
1246
        if ( published.compareTo("no") != 0 )
1247
        {
1248
          Log( "execute package has been published on this platform - skipping", info);
1249
          propertyValue = "257";
1250
          throw new Exception();
1251
        }
1252
      }
910 mhunt 1253
      else
866 mhunt 1254
      {
910 mhunt 1255
        // DEVI 56714 daemon centric check
1256
        String majorV = this.getClass().getPackage().getSpecificationVersion();
1257
 
1258
        if ( buildtoolVersion.compareTo( majorV ) != 0 )
1259
        {
1260
          reportErrorException( "Failure, incompatible build.xml not generated with version " + majorV, 256 );
1261
        }
866 mhunt 1262
      }
1263
 
1264
      if ( ( buildStandard == BuildStandards.ANT && javaVersion == JavaVersions.NONE ) ||
1265
           ( buildStandard == BuildStandards.JATS && compileTarget == CompileTargets.NONE ) )
1266
      {
1267
        // flag a benign build is good
1268
        benign = true;
1269
      }
1270
 
868 mhunt 1271
      genbuild( gatherMetricsOnly );
866 mhunt 1272
 
1273
      if ( !benign )
1274
      {
868 mhunt 1275
        if ( gatherMetricsOnly != null )
1276
        {
1277
          // special for metrics
1278
          String archive = dpkg_archive;
1279
 
1280
          if (archive != null)
1281
          {
1282
            String fs = System.getProperty( "file.separator" );
1283
            String destination = archive + fs + getProject().getProperty("abt_package_name") + fs + getProject().getProperty("abt_package_version");
1284
 
1285
            // do this for the win32 and generic based platforms
1286
            new File( destination ).mkdirs();
1287
            new File( destination, "built.win32" ).createNewFile();
1288
            new File( destination, "built.generic" ).createNewFile();
1289
          }
1290
 
1291
        }
1292
        else
1293
        {
1294
          jwrap();
1295
        }
866 mhunt 1296
      }
1297
 
1298
      if ( master )
1299
      {
1300
        File metrics = new File(basedir + fs + rtagId + "abtmetrics.txt");
1301
 
1302
        if ( metrics.exists() )
1303
        {
1304
          metrics.delete();
1305
        }
1306
 
1307
        // gather metrics
886 mhunt 1308
        // jats -locatefile=.jats.packageroot etool jats_metrics -mode=finish -out=abtmetrics.txt
866 mhunt 1309
        initCommand();
1310
        addCommand( "jats" );
886 mhunt 1311
        addCommand( "-locatefile=.jats.packageroot" );
866 mhunt 1312
        addCommand( "etool" );
1313
        addCommand( "jats_metrics" );
1314
        addCommand( "-mode=finish" );
1315
        addCommand( "-out=" + metrics.getAbsolutePath() );
1316
 
1317
        runCommand( "Failure to collect metrics" );
1318
      }
1319
    }
1320
    catch( SecurityException e)
1321
    {
1322
      errorReported = true;
1323
      reportError( "Failure caught SecurityException", 256 );
1324
    }
1325
    catch( IOException e)
1326
    {
1327
      errorReported = true;
1328
      reportError( "Failure caught IOException", 256 );
1329
    }
1330
    catch( Exception e)
1331
    {
1332
      // assume this condition has been reported on
1333
      errorReported = true;
1334
 
1335
      if ( e.getMessage() != null )
1336
      {
898 mhunt 1337
        Log( "execute caught Exception " + e.getMessage(), warn );
866 mhunt 1338
      }
1339
      else
1340
      {
1341
        Log( "execute caught Exception", warn );
1342
      }
1343
    }
1344
    finally
1345
    {
1346
      try
1347
      {
1348
        if ( daemon != null )
1349
        {
1350
          // do not write to publish.log
1351
          throw new IOException();
1352
        }
1353
 
1354
        FileWriter publish = new FileWriter( basedir + fs + "publish.log", true );
1355
        String friendlyVersion = packageVersion;
1356
        if ( packageExtension.length() > 0 )
1357
        {
1358
          friendlyVersion += "." + packageExtension;
1359
        }
1360
 
1361
        if ( propertyValue.compareTo( "0" ) == 0 )
1362
        {
1363
          if ( benign )
1364
          {
1365
            publish.write( "successfully published " + packageName + " at " + friendlyVersion + ", no action required on this platform" );
1366
          }
1367
          else
1368
          {
1369
            publish.write( "successfully published " + packageName + " at " + friendlyVersion );
1370
          }
1371
 
1372
          publish.write( ls );
1373
        }
1374
        else
1375
        if ( propertyValue.compareTo( "256" ) == 0 )
1376
        {
1377
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion +  ", internal abt issue" + ls );
1378
        }
1379
        else
1380
        if ( propertyValue.compareTo( "257" ) == 0 )
1381
        {
1382
          errorReported = false;
1383
          publish.write( "previously published " + packageName + " at " + friendlyVersion + ls );
1384
        }
1385
        else
872 dpurdie 1386
        if ( propertyValue.compareTo( "262" ) == 0 )
1387
        {
1388
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't process save_build info" + ls );
1389
        }
1390
        else
866 mhunt 1391
        if ( propertyValue.compareTo( "263" ) == 0 )
1392
        {
1393
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't write to auto.cfg" + ls );
1394
        }
1395
        else
1396
        if ( propertyValue.compareTo( "265" ) == 0 )
1397
        {
1398
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", " + cwd + " does not exist" + ls );
1399
        }
1400
        else
1401
        {
1402
          // nb jats or ant can presumably return a value 1 to 255
1403
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", jats or ant failed" + ls );
1404
        }
1405
 
1406
        publish.close();
1407
      }
1408
      catch( IOException e )
1409
      {
1410
        if ( daemon == null )
1411
        {
1412
          reportError( "Failure to write to publish.log", 266 );
1413
        }
1414
      }
1415
      catch( Exception e )
1416
      {
1417
        if ( daemon == null )
1418
        {
1419
          reportError( "Failure to write to publish.log", 266 );
1420
        }
1421
      }
1422
 
1423
      getProject().setProperty(packageAlias + ".res", propertyValue);
1424
 
1425
      if ( errorReported )
1426
      {
1427
        // designed to prevent subsequent build activity on this build file
1428
        // supply the build failure log file in message with / as file sep
1429
        // takes the form hostname/rtag_id/daemon/logfile
1430
        if ( daemon != null )
1431
        {
1432
          String message = hostname + "/" + rtagId + "/" + daemon + "/" + packageAlias + ".log";
1433
          throw new BuildException( message );
1434
        }
1435
        else
1436
        {
1437
          throw new BuildException();
1438
        }
1439
      }
1440
 
1441
    }
1442
  }
1443
 
1444
  private void deleteDirectory(File directory)
1445
  {
1446
    Log("deleteDirectory " + directory.getName(), debug);
1447
    try
1448
    {
1449
      if ( directory.exists() )
1450
      {
878 mhunt 1451
        File[] children = directory.listFiles();
866 mhunt 1452
 
1453
        if ( children != null )
1454
        {
1455
          for ( int child=0; child < children.length; child++ )
1456
          {
1457
            Log("deleteDirectory deleting " + children[ child ].getName(), warn);
1458
 
1459
            if ( children[ child ].isDirectory() )
1460
            {
1461
              deleteDirectory( children[ child ] );
1462
            }
1463
            else
1464
            {
1465
              children[ child ].delete();
1466
            }
1467
          }
1468
        }
1469
        directory.delete();
1470
      }
1471
    }
1472
    catch( SecurityException e )
1473
    {
1474
      // this can be thrown by exists and delete
1475
       Log("deleteDirectory caught SecurityException", warn);
1476
    }
1477
  }
1478
 
1479
  public Depend createDepend()
1480
  {
1481
    Depend depend = new Depend();
1482
    dependCollection.add(depend);
1483
    return depend;
1484
  }
1485
 
1486
  public Platform createPlatform()
1487
  {
1488
    Platform platform = new Platform();
1489
    platformCollection.add(platform);
1490
    return platform;
1491
  }
1492
 
1493
  public Jats createJats()
1494
  {
1495
    Jats jats = new Jats();
1496
    jatsCollection.add(jats);
1497
    return jats;
1498
  }
1499
 
1500
  public Ant createAnt()
1501
  {
1502
    Ant ant = new Ant();
1503
    antCollection.add(ant);
1504
    return ant;
1505
  }
1506
 
1507
  public Owner createOwner()
1508
  {
1509
    Owner owner = new Owner();
1510
    ownerCollection.add(owner);
1511
    return owner;
1512
  }
1513
}