Subversion Repositories DevTools

Rev

Rev 906 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.erggroup.buildtool.escrow;

import com.erggroup.buildtool.ripple.MutableString;
import com.erggroup.buildtool.ripple.ReleaseManager;
import com.erggroup.buildtool.ripple.RippleEngine;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.log4j.xml.DOMConfigurator;

public class ESCROWBuild
{
  /**
   * @aggregation shared
   */
  protected ReleaseManager mReleaseManager;

  /**
   * @aggregation shared
   */
  protected RippleEngine mRippleEngine;

  public static void main(String[] args)
  {
    String usage = 
      new String("Usage: java -jar escrowD.jar -c connectionString -u username -p password -b BOM id");
    String connectionString = new String();
    String username = new String();
    String password = new String();
    String bomID = new String();

    for (int optind = 0; optind < args.length; optind++)
    {
      if (args[optind].equals("-c") && optind < (args.length - 1))
      {
        connectionString = args[++optind];
      }
      else if (args[optind].equals("-u") && optind < (args.length - 1))
      {
        username = args[++optind];
      }
      else if (args[optind].equals("-p") && optind < (args.length - 1))
      {
        password = args[++optind];
      }
      else if (args[optind].equals("-b") && optind < (args.length - 1))
      {
        bomID = args[++optind];
      }
    }

    if (connectionString.compareTo("") == 0 || 
        username.compareTo("") == 0 || password.compareTo("") == 0 || 
        bomID.compareTo("") == 0)
    {
      System.out.println(usage);
      System.exit(1);
    }

    DOMConfigurator.configure("abtd.xml");

    ReleaseManager releaseManager = 
      new ReleaseManager(connectionString, username, password);
      
    RippleEngine rippleEngine = new RippleEngine(releaseManager, Integer.parseInt(bomID), false);
    try
    {
      rippleEngine.collectMetaData();
      rippleEngine.planRelease();
    }
    catch( Exception e )
    {
      System.out.println("ESCROWBuild::main caught Exception " + e.getMessage());
    }
    
    File cwd = new File( "." );
    String buildFileName = new String();
    int buildFileNumber = 1;
    MutableString buildFileContent = new MutableString();
    try
    {
      boolean moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
        
      do
      {
        if (moreBuildFiles)
        {
            buildFileName = "build";
            buildFileName += buildFileNumber;
            buildFileName += ".xml";
            File buildFile = new File(cwd, buildFileName);
            FileWriter buildFileWriter = new FileWriter(buildFile);
            buildFileWriter.write(buildFileContent.value);
            buildFileWriter.close();
            buildFileNumber++;
            moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
        }
      }
      while (moreBuildFiles);
      
      {
        File f = new File(cwd, "escrow_set_up");
        FileWriter fw = new FileWriter(f);
        fw.write(rippleEngine.getESCROWSetUp());
        fw.close();
      }
      
      {
        File f = new File(cwd, "raw_data.csv");
        FileWriter fw = new FileWriter(f);
        fw.write(rippleEngine.getRawData());
        fw.close();
      }
    }
    catch( IOException e )
    {
      System.out.println("ESCROWBuild::main caught IOException");
    }

  }
}