-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathModuleBatchRunner.java
More file actions
106 lines (89 loc) · 3.29 KB
/
ModuleBatchRunner.java
File metadata and controls
106 lines (89 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package base.workbench;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
/**
* Provides a CLI to run module trees.
* @author Marcel Boeing
*
*/
public class ModuleBatchRunner {
public static void main(String[] args) {
// Define command line options
Options options = new Options();
options.addOption("c", "config", true, "Module tree configuration file");
options.addOption("u", "update", true, "Update module tree configuration file and write it to the specified location");
options.addOption("h", "help", false, "Show help and exit");
// Instantiate parser for CLI options
CommandLineParser parser = new org.apache.commons.cli.DefaultParser();
CommandLine commandLine = null;
try {
commandLine = parser.parse( options, args);
} catch (ParseException e) {
Logger.getLogger("").log(Level.SEVERE, "Parsing of the command line options failed.", e);
System.exit(1);
}
// Show help if requested
if (commandLine.hasOption("h")) {
HelpFormatter lvFormater = new HelpFormatter();
lvFormater.printHelp("java [-server -d64 -Xms500m -Xmx7500m] -jar ModuleBatchRunner.jar <options>", options);
System.exit(0);
}
// Read config file path from CLI option
String configFilePath = null;
if(commandLine.hasOption("c")) {
configFilePath = commandLine.getOptionValue("c");
} else {
// No config file path option present; cannot continue.
Logger.getLogger("").log(Level.SEVERE, "Please use the option -c <file> to set a module tree config file to use.");
System.exit(1);
}
// Update?
String updatedFilePath = null;
if(commandLine.hasOption("u")) {
updatedFilePath = commandLine.getOptionValue("u");
}
/*
* All options are read, now to create a controller and reconstruct the module tree from the config file
*/
// Create new controller
ModuleWorkbenchController controller = null;
try {
controller = new ModuleWorkbenchController();
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, "Could not instantiate a new module workbench controller.", e);
System.exit(1);
}
if (updatedFilePath != null && !updatedFilePath.isEmpty()){
Logger.getLogger("").log(Level.INFO, "Updating exp file '"+configFilePath+"'.");
try {
controller.updateExpFile(new File(configFilePath), new File(updatedFilePath));
Logger.getLogger("").log(Level.INFO, "Update successful.");
} catch (Exception e){
Logger.getLogger("").log(Level.SEVERE, "An error has occurred.", e);
System.exit(1);
}
System.exit(0);
}
// Load module tree config file
try {
controller.loadModuleNetworkFromFile(new File(configFilePath));
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, "Could not load module tree from given config file.", e);
System.exit(1);
}
// Finally: Run the module tree
try {
controller.getModuleNetwork().runModules(true);
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, "Error running the module tree.", e);
System.exit(1);
}
Logger.getLogger("").log(Level.INFO, "Finished successfully.");
}
}