Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.abt;
2
 
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
 
9
import java.net.InetAddress;
10
import java.net.UnknownHostException;
11
 
12
import java.util.Iterator;
13
import java.util.Vector;
872 dpurdie 14
import java.util.Properties;
866 mhunt 15
 
16
import org.apache.log4j.Logger;
17
import org.apache.tools.ant.Project;
18
import org.apache.tools.ant.Target;
19
import org.apache.tools.ant.Task;
20
import org.apache.tools.ant.taskdefs.Execute;
21
import org.apache.tools.ant.taskdefs.Redirector;
22
import org.apache.tools.ant.BuildException;
868 mhunt 23
 
866 mhunt 24
import com.erggroup.buildtool.smtp.Smtpsend;
25
 
26
public class ABT extends Task
27
{
28
  // static fields
29
  // public
30
  // protected
31
  // private
32
 
33
  // fields
34
  // public
35
  // protected
36
  // private
37
  // System
38
  private String fs = System.getProperty( "file.separator" );
39
  private String ls = System.getProperty( "line.separator" );
40
  private String gbeMachtype = System.getenv("GBE_MACHTYPE");
41
  private String dpkg_archive = System.getenv("GBE_DPKG");
42
  // ant built in
43
  private Project project;
44
  private String basedir;
45
  // global
46
  private boolean master;
47
  private String gbebuildfilter;
48
  private String mailServer;
49
  private String mailSender;
50
  // project related
51
  private String rtagId;
52
  private String daemon;
53
  private String release;
54
  private String buildtoolVersion;
55
  private String family;
56
  private String oldExtension;
57
  private String newExtension;
58
  // target related
59
  private Target target;
60
  private String packageVersionID;
61
  private String packageAlias;
62
  private String packageName;
63
  private String packageVersion;
64
  private String packageExtension;
65
  private String packageLoc;
924 dpurdie 66
  private String packageVcsTag;
866 mhunt 67
  private String directChange;
68
  private String doesNotRequireSourceControlInteraction;
908 mhunt 69
  private String testBuildInstruction;
866 mhunt 70
  private String generic;
71
  private String loc;
72
  private String unittests;
73
  private Vector<Depend> dependCollection = new Vector<Depend>();
74
  private Vector<Platform> platformCollection = new Vector<Platform>();
75
  private Vector<Jats> jatsCollection = new Vector<Jats>();
76
  private Vector<Ant> antCollection = new Vector<Ant>();
77
  private Vector<Owner> ownerCollection = new Vector<Owner>();
78
  private String owners;
79
  // set up in execute
80
  private BuildStandards buildStandard = BuildStandards.JATS;
81
  private JavaVersions javaVersion = JavaVersions.NONE;
82
  private CompileTargets compileTarget = CompileTargets.NONE;
83
  // abt task result property
84
  private String propertyValue = "0";
85
  // output redirector
86
  private Redirector re;
87
  private File output;
88
  // exec thread
89
  private String[] command = new String[100];
90
  private int commandIndex = 0;
91
  private String cwd;
92
  private Execute thread;
93
  private File wd;
924 dpurdie 94
  private String newVcsTag;
866 mhunt 95
  private static final Logger mLogger = Logger.getLogger(ABT.class);
96
  private String fullyPublished = "no";
97
  private String hostname = new String("unknown");
98
 
99
  private void Log(String message1, String message2)
100
  {
101
    Log( message1 + message2, info );
102
  }
103
 
104
  private static final char debug = 0;
105
  private static final char info = 1;
106
  private static final char warn = 2;
107
  private static final char error = 3;
108
  private static final char fatal = 4;
109
 
110
  private void Log(String message, char facility)
111
  {
112
    if ( daemon != null )
113
    {
114
	    if ( facility == debug)
115
	    {
116
	      mLogger.debug(message);
117
	    }
118
	    else
119
	    if ( facility == info)
120
	    {
121
	      mLogger.info(message);
122
	    }
123
	    else
124
	    if ( facility == warn)
125
	    {
126
	      mLogger.warn(message);
127
	    }
128
	    else
129
	    if ( facility == error)
130
	    {
131
	      mLogger.error(message);
132
	    }
133
	    else
134
	    {
135
	      mLogger.fatal(message);
136
	    }
137
    }
138
 
139
    log( message );
140
  }
141
 
142
  private void initCommand()
143
  {
144
    for( int i = 0; i < 100; i++ )
145
    {
146
      command[ i ] = null;
147
    }
148
    commandIndex = 0;
149
  }
150
 
151
  private void addCommand( String c )
152
  {
153
    command[ commandIndex ] = c;
154
    commandIndex++;
155
  }
156
 
157
  private String printCommand( String addendum, boolean log )
158
  {
159
    String commandToPrint = "";
160
 
161
    for( int i = 0; i < 100; i++ )
162
    {
163
      if ( command[ i ] != null )
164
      {
165
        commandToPrint += command[ i ] + " ";
166
      }
167
      else
168
      {
169
        break;
170
      }
171
    }
172
 
173
    if ( addendum != null )
174
    {
175
      commandToPrint += addendum;
176
    }
177
 
178
    if ( log )
179
    {
180
      Log( commandToPrint, warn );
181
    }
182
 
183
    return commandToPrint;
184
  }
185
 
186
  private int runCommand( String message ) throws Exception
187
  {
188
    String cmd[] = new String[commandIndex];
189
    for ( int i = 0; i < commandIndex; i++ )
190
    {
191
      cmd[i] = command[i];
192
    }
193
    thread.setCommandline(cmd);
194
    printCommand( null, true );
195
    int retVal = thread.execute();
196
 
197
    if ( retVal == Execute.INVALID )
198
    {
199
      reportErrorException( "Failure to execute thread, internal ABT problem", 256 );
200
    }
201
    else
202
    {
203
      printCommand( " returned " + String.valueOf( retVal ), true );
204
 
205
      if ( message != null && retVal != 0 )
206
      {
207
        reportErrorException( message + " : " + printCommand( " returned " + String.valueOf( retVal ), true ), retVal );
208
      }
209
    }
210
 
211
    return retVal;
212
  }
213
 
214
  private String published(String archive, String machtype) throws Exception
215
  {
216
    String retVal = "no";
217
 
218
    if (archive == null)
219
    {
924 dpurdie 220
      reportErrorException( "GBE_DPKG environment variable not set", 256 );
866 mhunt 221
    }
222
 
223
    String destination = archive + fs + packageName + fs + packageVersion;
224
 
225
    if ( packageExtension.length() > 0 )
226
    {
227
      destination += "." + packageExtension;
228
    }
229
 
230
    String filename = "built.";
231
 
232
    if ( generic != null )
233
    {
234
      filename += "generic";
235
    }
236
    else
237
    {
238
      filename += machtype;
239
    }
240
 
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);
4212 dpurdie 990
 
866 mhunt 991
      buildtoolVersion = project.getProperty("abt_buildtool_version");
992
      Log("execute buildtoolVersion: ", buildtoolVersion);
4212 dpurdie 993
 
866 mhunt 994
      family = project.getProperty("abt_family");
995
      Log("execute family: ", family);
4212 dpurdie 996
 
866 mhunt 997
      oldExtension = project.getProperty("abt_old_extension");
998
      Log("execute oldExtension: ", oldExtension);
4212 dpurdie 999
 
866 mhunt 1000
      newExtension = project.getProperty("abt_new_extension");
1001
      Log("execute newExtension: ", newExtension);
4212 dpurdie 1002
 
908 mhunt 1003
      testBuildInstruction = project.getProperty("abt_test_build_instruction");
1004
      Log("execute testBuildInstruction: ", testBuildInstruction);
1005
 
1006
      if ( testBuildInstruction == null )
1007
      {
1008
        // use a meaningful default
1009
        testBuildInstruction = "0";
1010
      }
866 mhunt 1011
 
1012
      // redirect all thread (therefore jats) output to the output file in the basedir
1013
      if ( daemon != null )
1014
      {
1015
        // thread logging is done to <rtagId>thread.log and is continually re-used every build
1016
        // full thread and non thread (ie abt logging) is done to the DefaultLogger set up by the build daemons, <rtagId>.log
1017
        // this file is copied on a build failure to cwd (if it exists) and is continually re-used every build
1018
        output = new File( rtagId + "thread.log" );
1019
        // capture full logging
1020
        re.setAlwaysLog(true);
1021
      }
1022
      else
1023
      {
1024
        output = new File( packageAlias + ".log" );
1025
      }
1026
 
1027
      re.setOutput( output );
1028
      thread = new Execute(re.createHandler());
1029
      thread.setAntRun( project );
1030
      thread.setVMLauncher(false);
1031
 
1032
      // must set up package name and owners before reportError
1033
      packageName = project.getProperty(packageAlias + "packagename");
1034
      Log("execute packageName: ", packageName);
1035
 
1036
      for (Iterator<Owner> it=ownerCollection.iterator(); it.hasNext(); )
1037
      {
1038
        Owner owner = it.next();
1039
 
1040
        if ( owners == null )
1041
        {
1042
          owners = new String();
1043
        }
1044
        else
1045
        {
1046
          owners += ",";
1047
        }
1048
        owners += owner.getEmail();
1049
        Log("execute owner: ", owner.getEmail());
1050
      }
1051
 
1052
      Log("execute owners: ", owners);
1053
 
1054
      if ( packageAlias.compareTo("AbtSetUp") == 0 )
1055
      {
924 dpurdie 1056
        // create rtag_id directory from scratch
1057
        File rId = new File( rtagId );
1058
        deleteDirectory( rId );
1059
        rId.mkdirs();
866 mhunt 1060
 
924 dpurdie 1061
        // jats jats_vcsrelease -extract -label=pkgVcsTag -path=src_path -root=rtag_id/timestamp -tag=timestamp -noprefix
1062
        initCommand();
1063
        addCommand( "jats" );
1064
        addCommand( "jats_vcsrelease" );
1065
        addCommand( "-extract" );
1066
        addCommand( "-label=" + packageVcsTag );
1067
        addCommand( "-root=" + rtagId );
1068
        addCommand( "-tag=" + daemon );
1069
        addCommand( "-noprefix" );
1070
        addCommand( "-verbose=2" );
866 mhunt 1071
 
924 dpurdie 1072
        runCommand( "Failure to extract source code from source control" );
1073
        return;
866 mhunt 1074
      }
1075
 
1076
      // target related    
1077
      packageVersion = project.getProperty(packageAlias + "packageversion");
1078
      Log("execute packageVersion: ", packageVersion);
1079
      packageExtension = project.getProperty(packageAlias + "packageextension");
1080
      Log("execute packageExtension: ", packageExtension);
1081
      packageLoc = packageName;
1082
 
1083
      if ( packageExtension.length() > 0 )
1084
      {
1085
        packageLoc += "." + packageExtension;
1086
      }
1087
 
1088
      generic = project.getProperty(packageAlias + "generic");
1089
 
1090
      if ( generic != null )
1091
      {
1092
        Log("execute generic: yes", info);  
1093
      }
1094
 
1095
      int platformIndex = 0;
1096
 
1097
      for ( Iterator<Platform> it = platformCollection.iterator(); it.hasNext(); )
1098
      {
1099
        Platform platform = it.next();
1100
        platformIndex++;
1101
 
1102
        if ( gbeMachtype.compareTo( platform.getGbe_Machtype() ) == 0 )
1103
        {
1104
          break;
1105
        }
1106
      }
1107
 
1108
      int index = 0;
1109
 
1110
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1111
      {
1112
        Jats j = it.next();
1113
        index++;
1114
 
1115
        if ( platformIndex == index )
1116
        {
1117
          String target = j.getTarget();
1118
          if ( target.compareTo( "none" ) == 0 )
1119
          {
1120
            compileTarget = CompileTargets.NONE;
1121
          }
1122
          else
1123
          if ( target.compareTo( "production" ) == 0 )
1124
          {
1125
            compileTarget = CompileTargets.PROD;
1126
          }
1127
          else
1128
          if ( target.compareTo( "debug") == 0 )
1129
          {
1130
            compileTarget = CompileTargets.DEBUG;
1131
          }
1132
          else
1133
          if ( target.compareTo( "all" ) == 0 )
1134
          {
1135
            compileTarget = CompileTargets.ALL;
1136
          }
1137
          else
1138
          {
1139
            reportErrorException( "Failure, unsupported build environment " + target + ", internal ABT problem", 256 );
1140
          }
1141
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1142
          Log( "execute compileTarget: ", compileTarget.getCompileTarget() );
1143
          break;
1144
        }
1145
      }
1146
 
1147
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1148
      {
1149
        Ant a = it.next();
1150
        index++;
1151
 
1152
        if ( platformIndex == index )
1153
        {
1154
          buildStandard = BuildStandards.ANT;
1155
          String version = a.getJava();
1156
          if ( version.compareTo( "none" ) == 0 )
1157
          {
1158
            javaVersion = JavaVersions.NONE;
1159
          }
1160
          else
1161
          if ( version.compareTo( "1.4" ) == 0 )
1162
          {
1163
            javaVersion = JavaVersions.FOUR;
1164
          }
1165
          else
1166
          if ( version.compareTo( "1.5" ) == 0 )
1167
          {
1168
            javaVersion = JavaVersions.FIVE;
1169
          }
1170
          else
1171
          if ( version.compareTo( "1.6" ) == 0 )
1172
          {
1173
            javaVersion = JavaVersions.SIX;
1174
          }
1175
          else
4130 dpurdie 1176
          if ( version.compareTo( "1.7" ) == 0 )
866 mhunt 1177
          {
4130 dpurdie 1178
            javaVersion = JavaVersions.SEVEN;
1179
          }
1180
          else
1181
          {
866 mhunt 1182
            reportErrorException( "Failure, unsupported build environment " + version + ", internal ABT problem", 256 );
1183
          }
1184
          Log( "execute buildStandard: ", buildStandard.getBuildStandard() );
1185
          Log( "execute javaVersion: ", javaVersion.getJavaVersion() );
1186
          break;
1187
        }
1188
      }
1189
 
1190
      if ( packageAlias.compareTo("AbtTearDown") == 0 )
1191
      {
924 dpurdie 1192
        // tear the build view down, regardless of build error
866 mhunt 1193
        wd = new File( basedir );
1194
 
1195
        // only now change the thread working directory back
1196
        thread.setWorkingDirectory( wd );
1197
 
868 mhunt 1198
        File buildDirectory = new File(wd + getProject().getProperty("abt_package_location"));
866 mhunt 1199
 
1200
        if ( buildDirectory.exists() )
1201
        {
4212 dpurdie 1202
          // jats jats_vcsrelease -label pkgTag -root=rtag_id/timestamp -tag=timestamp -noprefix -delete=2
866 mhunt 1203
          initCommand();
1204
          addCommand( "jats" );
924 dpurdie 1205
          addCommand( "jats_vcsrelease" );
1206
          addCommand( "-label=" + packageVcsTag );
878 mhunt 1207
          addCommand( "-root=" + rtagId );
866 mhunt 1208
          addCommand( "-tag=" + daemon );
1209
          addCommand( "-noprefix" );
924 dpurdie 1210
          addCommand( "-delete=2" );
1211
          addCommand( "-verbose=2" );
1212
 
866 mhunt 1213
          runCommand( "Failure to remove source code extraction" );
1214
        }
1215
 
878 mhunt 1216
        // delete the rtag directory
1217
        deleteDirectory( new File( rtagId ) );
1351 dpurdie 1218
 
1219
        // Always save the log files
1220
        saveLogs();
1221
 
866 mhunt 1222
        return;      
1223
      }
1224
 
1225
      directChange = project.getProperty(packageAlias + "directchange");
1226
 
1227
      if ( directChange != null )
1228
      {
1229
        Log("execute directChange: yes", info);  
1230
      }
1231
 
1232
      doesNotRequireSourceControlInteraction = project.getProperty(packageAlias + "doesnotrequiresourcecontrolinteraction");
1233
 
1234
      if ( doesNotRequireSourceControlInteraction != null )
1235
      {
1236
        Log("execute doesNotRequireSourceControlInteraction: true", info);  
1237
      }
1238
 
1239
      for (Iterator<Platform> it=platformCollection.iterator(); it.hasNext(); )
1240
      {
1241
        Platform platform = it.next();
1242
        Log("execute platform: ", platform.getGbe_Machtype());
1243
      }
1244
 
1245
      for (Iterator<Jats> it=jatsCollection.iterator(); it.hasNext(); )
1246
      {
1247
        Jats jats = it.next();
1248
        Log("execute jats: ", jats.getTarget());
1249
      }
1250
 
1251
      for (Iterator<Ant> it=antCollection.iterator(); it.hasNext(); )
1252
      {
1253
        Ant ant = it.next();
1254
        Log("execute ant: ", ant.getJava());
1255
      }
924 dpurdie 1256
 
1257
      // Set newVsTag to the existing VcsTag
1258
      // Will be used when rebuilding a package that already exists
1259
      newVcsTag = packageVcsTag;
1260
 
866 mhunt 1261
      loc = project.getProperty(packageAlias + "loc");
1262
      Log("execute loc: ", loc);
1263
      cwd = basedir + loc;
1264
      Log("execute cwd: ", cwd);
1265
      wd = new File( cwd );
1266
 
1267
      if ( !wd.exists() )
1268
      {
1269
        reportErrorException( "Failure " + cwd + " does not exist", 265 );
1270
      }
1271
 
868 mhunt 1272
      String gatherMetricsOnly = System.getenv("GBE_GATHER_METRICS");
1273
 
866 mhunt 1274
      // only now change the thread working directory
1275
      thread.setWorkingDirectory( wd );
1276
 
1277
      if ( packageAlias.compareTo("AbtPublish") == 0 )
1278
      {
868 mhunt 1279
        publish(gatherMetricsOnly);
866 mhunt 1280
        if ( daemon != null )
1281
        {
1282
          // set properties to drive BuildThread attributes
1283
          // these are used to determine what ant did
1284
          getProject().setProperty("abt_fully_published", fullyPublished);
924 dpurdie 1285
          getProject().setProperty("abt_new_vcstag", newVcsTag);
866 mhunt 1286
        }
1287
 
1288
        return;
1289
      }
1290
 
1291
      packageVersionID = project.getProperty(packageAlias + "pv_id");
1292
      Log("execute packageVersionID: ", packageVersionID);
1293
      unittests = project.getProperty(packageAlias + "unittests");
1294
 
1295
      if ( unittests != null )
1296
      {
1297
        Log("execute unittests: yes", info);
1298
      }
1299
 
1300
      for (Iterator<Depend> it=dependCollection.iterator(); it.hasNext(); )
1301
      {
1302
        Depend depend = it.next();
1303
        Log("execute depend: ", depend.getPackage_Alias());
1304
      }
1305
 
1306
      // check platform
1307
      if ( gbeMachtype == null )
1308
      {
1309
        reportErrorException( "GBE_MACHTYPE environment variable not set", 256 );
1310
      }
1311
 
1312
      if ( daemon == null )
1313
      {
1314
        // escrow centric
1315
        // recognise an escrow will be run multiple times on a build stage
1316
        // do not force continuous rebuilding each time
1317
        // has this package version already been published on this platform
1318
        String published = published( dpkg_archive, gbeMachtype );
1319
 
1320
        if ( published.compareTo("no") != 0 )
1321
        {
1322
          Log( "execute package has been published on this platform - skipping", info);
1323
          propertyValue = "257";
1324
          throw new Exception();
1325
        }
1326
      }
910 mhunt 1327
      else
866 mhunt 1328
      {
910 mhunt 1329
        // DEVI 56714 daemon centric check
1330
        String majorV = this.getClass().getPackage().getSpecificationVersion();
1331
 
1332
        if ( buildtoolVersion.compareTo( majorV ) != 0 )
1333
        {
1334
          reportErrorException( "Failure, incompatible build.xml not generated with version " + majorV, 256 );
1335
        }
866 mhunt 1336
      }
1337
 
1338
      if ( ( buildStandard == BuildStandards.ANT && javaVersion == JavaVersions.NONE ) ||
1339
           ( buildStandard == BuildStandards.JATS && compileTarget == CompileTargets.NONE ) )
1340
      {
1341
        // flag a benign build is good
1342
        benign = true;
1343
      }
1344
 
868 mhunt 1345
      genbuild( gatherMetricsOnly );
866 mhunt 1346
 
1347
      if ( !benign )
1348
      {
868 mhunt 1349
        if ( gatherMetricsOnly != null )
1350
        {
1351
          // special for metrics
1352
          String archive = dpkg_archive;
1353
 
1354
          if (archive != null)
1355
          {
1356
            String fs = System.getProperty( "file.separator" );
1357
            String destination = archive + fs + getProject().getProperty("abt_package_name") + fs + getProject().getProperty("abt_package_version");
1358
 
1359
            // do this for the win32 and generic based platforms
1360
            new File( destination ).mkdirs();
1361
            new File( destination, "built.win32" ).createNewFile();
1362
            new File( destination, "built.generic" ).createNewFile();
1363
          }
1364
 
1365
        }
1366
        else
1367
        {
1368
          jwrap();
1369
        }
866 mhunt 1370
      }
1371
 
1372
      if ( master )
1373
      {
1374
        File metrics = new File(basedir + fs + rtagId + "abtmetrics.txt");
1375
 
1376
        if ( metrics.exists() )
1377
        {
1378
          metrics.delete();
1379
        }
1380
 
1381
        // gather metrics
886 mhunt 1382
        // jats -locatefile=.jats.packageroot etool jats_metrics -mode=finish -out=abtmetrics.txt
866 mhunt 1383
        initCommand();
1384
        addCommand( "jats" );
886 mhunt 1385
        addCommand( "-locatefile=.jats.packageroot" );
866 mhunt 1386
        addCommand( "etool" );
1387
        addCommand( "jats_metrics" );
1388
        addCommand( "-mode=finish" );
1389
        addCommand( "-out=" + metrics.getAbsolutePath() );
1390
 
1391
        runCommand( "Failure to collect metrics" );
1392
      }
1393
    }
1394
    catch( SecurityException e)
1395
    {
1396
      errorReported = true;
1397
      reportError( "Failure caught SecurityException", 256 );
1398
    }
1399
    catch( IOException e)
1400
    {
1401
      errorReported = true;
1402
      reportError( "Failure caught IOException", 256 );
1403
    }
1404
    catch( Exception e)
1405
    {
1406
      // assume this condition has been reported on
1407
      errorReported = true;
1408
 
1409
      if ( e.getMessage() != null )
1410
      {
898 mhunt 1411
        Log( "execute caught Exception " + e.getMessage(), warn );
866 mhunt 1412
      }
1413
      else
1414
      {
1415
        Log( "execute caught Exception", warn );
1416
      }
1417
    }
1418
    finally
1419
    {
1420
      try
1421
      {
1422
        if ( daemon != null )
1423
        {
1424
          // do not write to publish.log
1425
          throw new IOException();
1426
        }
1427
 
1428
        FileWriter publish = new FileWriter( basedir + fs + "publish.log", true );
1429
        String friendlyVersion = packageVersion;
1430
        if ( packageExtension.length() > 0 )
1431
        {
1432
          friendlyVersion += "." + packageExtension;
1433
        }
1434
 
1435
        if ( propertyValue.compareTo( "0" ) == 0 )
1436
        {
1437
          if ( benign )
1438
          {
1439
            publish.write( "successfully published " + packageName + " at " + friendlyVersion + ", no action required on this platform" );
1440
          }
1441
          else
1442
          {
1443
            publish.write( "successfully published " + packageName + " at " + friendlyVersion );
1444
          }
1445
 
1446
          publish.write( ls );
1447
        }
1448
        else
1449
        if ( propertyValue.compareTo( "256" ) == 0 )
1450
        {
1451
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion +  ", internal abt issue" + ls );
1452
        }
1453
        else
1454
        if ( propertyValue.compareTo( "257" ) == 0 )
1455
        {
1456
          errorReported = false;
1457
          publish.write( "previously published " + packageName + " at " + friendlyVersion + ls );
1458
        }
1459
        else
872 dpurdie 1460
        if ( propertyValue.compareTo( "262" ) == 0 )
1461
        {
1462
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't process save_build info" + ls );
1463
        }
1464
        else
866 mhunt 1465
        if ( propertyValue.compareTo( "263" ) == 0 )
1466
        {
1467
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", couldn't write to auto.cfg" + ls );
1468
        }
1469
        else
1470
        if ( propertyValue.compareTo( "265" ) == 0 )
1471
        {
1472
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", " + cwd + " does not exist" + ls );
1473
        }
1474
        else
1475
        {
1476
          // nb jats or ant can presumably return a value 1 to 255
1477
          publish.write( "failed to publish " + packageName + " at " + friendlyVersion + ", jats or ant failed" + ls );
1478
        }
1479
 
1480
        publish.close();
1481
      }
1482
      catch( IOException e )
1483
      {
1484
        if ( daemon == null )
1485
        {
1486
          reportError( "Failure to write to publish.log", 266 );
1487
        }
1488
      }
1489
      catch( Exception e )
1490
      {
1491
        if ( daemon == null )
1492
        {
1493
          reportError( "Failure to write to publish.log", 266 );
1494
        }
1495
      }
1496
 
1497
      getProject().setProperty(packageAlias + ".res", propertyValue);
1498
 
1499
      if ( errorReported )
1500
      {
1501
        // designed to prevent subsequent build activity on this build file
1502
        // supply the build failure log file in message with / as file sep
1503
        // takes the form hostname/rtag_id/daemon/logfile
1504
        if ( daemon != null )
1505
        {
1506
          String message = hostname + "/" + rtagId + "/" + daemon + "/" + packageAlias + ".log";
1507
          throw new BuildException( message );
1508
        }
1509
        else
1510
        {
1511
          throw new BuildException();
1512
        }
1513
      }
1514
 
1515
    }
1516
  }
1517
 
1518
  private void deleteDirectory(File directory)
1519
  {
1520
    Log("deleteDirectory " + directory.getName(), debug);
1521
    try
1522
    {
1523
      if ( directory.exists() )
1524
      {
878 mhunt 1525
        File[] children = directory.listFiles();
866 mhunt 1526
 
1527
        if ( children != null )
1528
        {
1529
          for ( int child=0; child < children.length; child++ )
1530
          {
1531
            Log("deleteDirectory deleting " + children[ child ].getName(), warn);
1532
 
1533
            if ( children[ child ].isDirectory() )
1534
            {
1535
              deleteDirectory( children[ child ] );
1536
            }
1537
            else
1538
            {
1539
              children[ child ].delete();
1540
            }
1541
          }
1542
        }
1543
        directory.delete();
1544
      }
1545
    }
1546
    catch( SecurityException e )
1547
    {
1548
      // this can be thrown by exists and delete
1549
       Log("deleteDirectory caught SecurityException", warn);
1550
    }
1551
  }
1552
 
1553
  public Depend createDepend()
1554
  {
1555
    Depend depend = new Depend();
1556
    dependCollection.add(depend);
1557
    return depend;
1558
  }
1559
 
1560
  public Platform createPlatform()
1561
  {
1562
    Platform platform = new Platform();
1563
    platformCollection.add(platform);
1564
    return platform;
1565
  }
1566
 
1567
  public Jats createJats()
1568
  {
1569
    Jats jats = new Jats();
1570
    jatsCollection.add(jats);
1571
    return jats;
1572
  }
1573
 
1574
  public Ant createAnt()
1575
  {
1576
    Ant ant = new Ant();
1577
    antCollection.add(ant);
1578
    return ant;
1579
  }
1580
 
1581
  public Owner createOwner()
1582
  {
1583
    Owner owner = new Owner();
1584
    ownerCollection.add(owner);
1585
    return owner;
1586
  }
1587
}