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 |
|
package info.magnolia.module.groovy.remote; |
35 |
|
|
36 |
|
import groovyjarjarcommonscli.BasicParser; |
37 |
|
import groovyjarjarcommonscli.CommandLine; |
38 |
|
import groovyjarjarcommonscli.CommandLineParser; |
39 |
|
import groovyjarjarcommonscli.HelpFormatter; |
40 |
|
import groovyjarjarcommonscli.Options; |
41 |
|
import groovyjarjarcommonscli.ParseException; |
42 |
|
|
43 |
|
import java.io.File; |
44 |
|
import java.util.ArrayList; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
|
|
| 0% |
Uncovered Elements: 78 (78) |
Complexity: 14 |
Complexity Density: 0.25 |
|
53 |
|
public class RemoteClientConsoleMain { |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@throws |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 12 |
Complexity Density: 0.27 |
|
60 |
0 |
public static void main(String[] args) throws ParseException {... |
61 |
|
|
62 |
0 |
String user = null; |
63 |
0 |
String pass = null; |
64 |
0 |
String uri = null; |
65 |
0 |
ArrayList<Object> inputArgs = new ArrayList<Object>(); |
66 |
|
|
67 |
|
|
68 |
0 |
CommandLineParser parser = new BasicParser(); |
69 |
|
|
70 |
0 |
Options options = initCommandLineOptions(); |
71 |
|
|
72 |
0 |
CommandLine commandLine = parser.parse(options, args); |
73 |
|
|
74 |
|
|
75 |
0 |
if (commandLine.hasOption("help")) { |
76 |
0 |
printHelp(options); |
77 |
0 |
System.exit(0); |
78 |
|
} |
79 |
0 |
if (commandLine.hasOption("user")) { |
80 |
0 |
user = commandLine.getOptionValue("user"); |
81 |
|
} else { |
82 |
0 |
printHelp(options); |
83 |
0 |
System.exit(0); |
84 |
|
} |
85 |
0 |
if (commandLine.hasOption("pass")) { |
86 |
0 |
pass = commandLine.getOptionValue("pass"); |
87 |
|
} else { |
88 |
0 |
printHelp(options); |
89 |
0 |
System.exit(0); |
90 |
|
} |
91 |
0 |
if (commandLine.hasOption("uri")) { |
92 |
0 |
uri = commandLine.getOptionValue("uri"); |
93 |
|
} |
94 |
|
else { |
95 |
0 |
printHelp(options); |
96 |
0 |
System.exit(0); |
97 |
|
} |
98 |
0 |
if (!commandLine.hasOption("file") && !commandLine.hasOption("cmd")) { |
99 |
0 |
printHelp(options); |
100 |
0 |
System.exit(0); |
101 |
|
} |
102 |
0 |
if (commandLine.hasOption("file")) { |
103 |
0 |
String[] stringFiles = commandLine.getOptionValues("file"); |
104 |
0 |
for (String s : stringFiles) { |
105 |
0 |
File f = new File(s); |
106 |
0 |
if (!f.exists()) { |
107 |
0 |
System.out.println("File don't exist " + f.getAbsolutePath()); |
108 |
0 |
continue; |
109 |
|
} |
110 |
0 |
inputArgs.add(f); |
111 |
|
} |
112 |
|
} |
113 |
0 |
if (commandLine.hasOption("cmd")) { |
114 |
0 |
String[] stringCmds = commandLine.getOptionValues("cmd"); |
115 |
0 |
for (String s : stringCmds) { |
116 |
0 |
inputArgs.add(s); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
0 |
RemoteClientConsole groovyClient = new RemoteClientConsole(uri, user, pass); |
121 |
0 |
if (groovyClient.isConnected()) { |
122 |
0 |
for (Object o : inputArgs) { |
123 |
0 |
System.out.println("-----------------------------------------------------------"); |
124 |
0 |
System.out.println("will run the following groovy script: " + ((o instanceof File) ? ((File) o).getAbsolutePath() : o)); |
125 |
0 |
System.out.println("" + groovyClient.execute(o)); |
126 |
|
} |
127 |
|
|
128 |
0 |
groovyClient.disconnect(); |
129 |
|
} else { |
130 |
0 |
System.out.println("Unable to connect"); |
131 |
|
} |
132 |
|
|
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
138 |
0 |
private static void printHelp(Options options) {... |
139 |
0 |
HelpFormatter formatter = new HelpFormatter(); |
140 |
0 |
formatter.printHelp("RemoteClientConsoleMain", options, true); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
146 |
0 |
private static Options initCommandLineOptions() {... |
147 |
|
|
148 |
0 |
Options options = new Options(); |
149 |
0 |
options.addOption("help", "help", false, "Print this usage information"); |
150 |
0 |
options.addOption("user", "user", true, "Enter user"); |
151 |
0 |
options.addOption("pass", "password", true, "Enter password"); |
152 |
0 |
options.addOption("uri", "uri", true, "Enter Magnolia Uri like http://localhost:8080/contextpath"); |
153 |
0 |
options.addOption("file", "file", true, "Groovy File to execute. Can have one to n file arguments"); |
154 |
0 |
options.addOption("cmd", "cmd", true, "Groovy command line to be executed. Can have one to n cmd arguments"); |
155 |
0 |
return options; |
156 |
|
} |
157 |
|
} |