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