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