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