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