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