]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/JobGenerator.java
arguments can now be entered directly from ant
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / JobGenerator.java
1 package at.ac.tuwien.lsdc;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 public class JobGenerator {
10         private static final Logger log = LoggerFactory.getLogger(JobGenerator.class);
11         private static final String USAGE = "JobGenerator needs exactly 3 parameters: Szenario, count, targetFile";
12         
13         private enum ScenarioType { A, B, C };
14         
15         private static ScenarioType scenario;
16         private static int count;
17         private static File targetFile;
18         
19
20         public static void main(String[] args) throws Exception {
21                 System.out.println("args: " + args + " len: " + args.length);
22                 if (args.length != 3) {
23                         log.info(USAGE);
24                         System.exit(1);
25                 }
26                 log.info("Generate CSV with...");
27                 doArgumentHandling(args);               
28         }
29         
30         private static void doArgumentHandling(String[] args) {
31                 String scenarioStr = args[0];
32                 String countStr = args[1];
33                 String targetFileStr = args[2];
34                 scenario = ScenarioType.valueOf(scenarioStr);
35                 try {
36                         boolean fileWriteOK = false;
37                         count = Integer.parseInt(countStr);
38                         targetFile = new File(targetFileStr);
39                         if (targetFile.exists()) {
40                                 fileWriteOK = targetFile.canWrite();
41                         } else {
42                                 targetFile.createNewFile();
43                                 fileWriteOK = true;
44                         }
45                         if (!fileWriteOK)
46                                 throw new IOException("Can not write to File " + targetFileStr);
47                 } catch (Exception e) {
48                         e.printStackTrace();
49                         log.info(USAGE);
50                         System.exit(1);
51                 }
52         }
53 }