Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.escrow;
2
 
3
import com.erggroup.buildtool.ripple.BuildFile;
4
import com.erggroup.buildtool.ripple.BuildFile.BuildFileState;
5
import com.erggroup.buildtool.ripple.ReleaseManager;
6
import com.erggroup.buildtool.ripple.RippleEngine;
7
 
8
import java.io.File;
9
import java.io.FileWriter;
10
import java.io.IOException;
11
 
12
import org.apache.log4j.xml.DOMConfigurator;
13
 
14
public class ESCROWBuild
15
{
16
  /**
17
   * @aggregation shared
18
   */
19
  protected ReleaseManager mReleaseManager;
20
 
21
  /**
22
   * @aggregation shared
23
   */
24
  protected RippleEngine mRippleEngine;
25
 
26
  public static void main(String[] args)
27
  {
28
    String usage = 
29
      new String("Usage: java -jar escrowD.jar -c connectionString -u username -p password -b BOM id");
30
    String connectionString = new String();
31
    String username = new String();
32
    String password = new String();
33
    String bomID = new String();
34
 
35
    for (int optind = 0; optind < args.length; optind++)
36
    {
37
      if (args[optind].equals("-c") && optind < (args.length - 1))
38
      {
39
        connectionString = args[++optind];
40
      }
41
      else if (args[optind].equals("-u") && optind < (args.length - 1))
42
      {
43
        username = args[++optind];
44
      }
45
      else if (args[optind].equals("-p") && optind < (args.length - 1))
46
      {
47
        password = args[++optind];
48
      }
49
      else if (args[optind].equals("-b") && optind < (args.length - 1))
50
      {
51
        bomID = args[++optind];
52
      }
53
    }
54
 
55
    if (connectionString.compareTo("") == 0 || 
56
        username.compareTo("") == 0 || password.compareTo("") == 0 || 
57
        bomID.compareTo("") == 0)
58
    {
59
      System.out.println(usage);
60
      System.exit(1);
61
    }
62
 
63
    DOMConfigurator.configure("abtd.xml");
64
 
65
    ReleaseManager releaseManager = new ReleaseManager(connectionString, username, password);
66
    RippleEngine rippleEngine = new RippleEngine(releaseManager, Integer.parseInt(bomID), false);
67
 
68
    generateEscrowFiles(rippleEngine, ".");
69
  }
70
 
71
    /** Generate the Escrow Files
72
     * 		Factored out to improve testability
73
     */
74
    public static void generateEscrowFiles(RippleEngine rippleEngine, String basePath)
75
    {
76
	    try
77
	    {
78
	      rippleEngine.collectMetaData();
79
	      rippleEngine.planRelease(false);
80
	    }
81
	    catch( Exception e )
82
	    {
83
	      System.out.println("ESCROWBuild::main caught Exception " + e.getMessage());
84
	    }
85
 
86
	    File cwd = new File( basePath );
87
	    String buildFileName = new String();
88
	    int buildFileNumber = 1;
89
	    BuildFile buildFile;
90
 
91
	    try
92
	    {
93
	    	//	Write out all the Escrow build<n>.xml files
94
	    	buildFile = rippleEngine.getFirstBuildFileContent();
95
	    	while (buildFile.state != BuildFileState.Empty)
96
	    	{
97
	    		buildFileName = "build";
98
	    		buildFileName += buildFileNumber;
99
	    		buildFileName += ".xml";
100
	    		FileWriter buildFileWriter = new FileWriter(new File(cwd, buildFileName));
101
	    		buildFileWriter.write(buildFile.content);
102
	    		buildFileWriter.close();
103
	    		buildFileNumber++;
104
	    		buildFile = rippleEngine.getNextBuildFileContent();
105
	    	}
106
 
107
	    	//	Write out the Escrow Set Up file
108
	    	{
109
	    		File f = new File(cwd, "escrow_set_up");
110
	    		FileWriter fw = new FileWriter(f);
111
	    		fw.write(rippleEngine.getEscrowSetUp());
112
	    		fw.close();
113
	    	}
114
 
115
	    	//	Write out the Escrow Raw data as a CSV file
116
	    	{
117
	    		File f = new File(cwd, "raw_data.csv");
118
	    		FileWriter fw = new FileWriter(f);
119
	    		fw.write(rippleEngine.getRawData());
120
	    		fw.close();
121
	    	}
122
	    }
123
	    catch( IOException e )
124
	    {
125
	      System.out.println("ESCROWBuild::main caught IOException");
126
	    }
127
 
128
	  }
129
  }