Roberto Sánchez
2014-02-24 3ef2ddd5cb1ee57317ffb757aceb86355a612a17
src/main/java/net/curisit/securis/License.java
....@@ -2,7 +2,6 @@
22
33 import java.io.File;
44 import java.net.URISyntaxException;
5
-import java.util.Date;
65
76 import net.curisit.securis.utils.Params;
87
....@@ -16,21 +15,45 @@
1615 import org.apache.logging.log4j.LogManager;
1716 import org.apache.logging.log4j.Logger;
1817
18
+/**
19
+ * Main class when SeCuris client is used from command line.
20
+ *
21
+ * <pre>
22
+ * usage: securis-client [-c] [-g] [-h] [-l <lic_file>] [-r <lic_file>] [-s
23
+ * <url_license_server>] [-t]
24
+ * -c,--create Request a license file from server.
25
+ * --rfile and --server parameters are
26
+ * mandatory.
27
+ * -g,--gen_request Generate request file. If --rfile
28
+ * parameter is missing then It is
29
+ * generated in current directory.
30
+ * -h,--help Show help.
31
+ * -l,--validate <lic_file> Validate lic file.
32
+ * -r,--renew <lic_file> Synchronize/renew the current license
33
+ * file. --server parameter is mandatory.
34
+ * -s,--server <url_license_server> License server url.
35
+ * -t,--test_lc Test if License Server (LC) is
36
+ * available. --server parameter is
37
+ * mandatory.
38
+ * </pre>
39
+ *
40
+ * @author roberto <roberto.sanchez@curisit.net>
41
+ *
42
+ */
1943 public class License {
2044
21
- static {
22
- // BasicConfigurator.configure(new ConsoleAppender());
23
- // PropertyConfigurator.configure("/log4j.xml");
24
- // LogManager.getRootLogger().
25
- }
26
-
27
- // private static final Logger log = LoggerFactory.getLogger(License.class);
2845 private static final Logger log = LogManager.getLogger(License.class);
2946
47
+ /**
48
+ * Aplication entry point when it used as CLI
49
+ *
50
+ * @param args
51
+ * @throws URISyntaxException
52
+ */
3053 public static void main(String[] args) throws URISyntaxException {
3154 // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI());
3255
33
- log.info("Tool init {}", new Date());
56
+ log.debug("SeCuris client tool init ");
3457
3558 checkConfigFile();
3659 CommandLine cmd = getCommandLine(args);
....@@ -61,8 +84,43 @@
6184 System.exit(0);
6285 }
6386
87
+ if (cmd.hasOption('c')) {
88
+ String reqFilename = cmd.getOptionValue("rfile");
89
+ checkMandatoryParameter(reqFilename, "rfile");
90
+ String server = cmd.getOptionValue("server");
91
+ checkMandatoryParameter(server, "server");
92
+
93
+ log.warn("This command is not yet implemented");
94
+ System.exit(0);
95
+ }
96
+
97
+ if (cmd.hasOption('t')) {
98
+ String server = cmd.getOptionValue("server");
99
+ checkMandatoryParameter(server, "server");
100
+
101
+ log.warn("This command is not yet implemented");
102
+ System.exit(0);
103
+ }
104
+
105
+ if (cmd.hasOption('r')) {
106
+ String licFilename = cmd.getOptionValue("sync");
107
+ checkMandatoryParameter(licFilename, "sync");
108
+ String server = cmd.getOptionValue("server");
109
+ checkMandatoryParameter(server, "server");
110
+
111
+ log.warn("This command is not yet implemented");
112
+ System.exit(0);
113
+ }
114
+
64115 } catch (SeCurisException e) {
65116 log.error("The command generated an error: {}", e.toString());
117
+ }
118
+ }
119
+
120
+ private static void checkMandatoryParameter(String value, String param) {
121
+ if (value == null) {
122
+ log.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
123
+ System.exit(-5);
66124 }
67125 }
68126
....@@ -120,7 +178,7 @@
120178 options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
121179 options.addOption("c", "create", false, "Request a license file from server. --rfile and --server parameters are mandatory.");
122180 options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. --server parameter is mandatory.");
123
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("sync").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('y'));
181
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('r'));
124182
125183 return options;
126184 }