@@ -18,76 +18,84 @@ private val CHUNK_SIZE = "chunkSize"
1818fun main (args : Array <String >) {
1919
2020 val cli = CLI .create(" crawler" )
21- .setSummary(" A REST Client to query all model element from server." )
22- .addArguments(listOf (
23- Argument ()
24- .setArgName(" username" )
25- .setIndex(0 )
26- .setDefaultValue(" admin" )
27- .setDescription(" TWC username." ),
28- Argument ()
29- .setArgName(" password" )
30- .setIndex(1 )
31- .setDefaultValue(" admin" )
32- .setDescription(" TWC password." )
33- ))
34- .addOptions(listOf (
35- Option ()
36- .setLongName(" help" )
37- .setShortName(" h" )
38- .setDescription(" Show help site." )
39- .setFlag(true ),
40- Option ()
41- .setLongName(" server" )
42- .setShortName(" S" )
43- .setDescription(" Set server path." ),
44- Option ()
45- .setLongName(" port" )
46- .setShortName(" P" )
47- .setDescription(" Set server port number." ),
48- Option ()
49- .setLongName(" instanceNum" )
50- .setShortName(" I" )
51- .setDescription(" Set number of RESTVerticle instances. Default:16" )
52- .setDefaultValue(" 16" ),
53- Option ()
54- .setLongName(" workspaceId" )
55- .setShortName(" W" )
56- .setDescription(" Select workspace to crawl" ),
57- Option ()
58- .setLongName(" resourceId" )
59- .setShortName(" R" )
60- .setDescription(" Select resource to crawl" ),
61- Option ()
62- .setLongName(" branchId" )
63- .setShortName(" B" )
64- .setDescription(" Select branch to crawl" ),
65- Option ()
66- .setLongName(" revision" )
67- .setShortName(" REV" )
68- .setDescription(" Select revision to crawl" ),
69- Option ()
70- .setLongName(" debug" )
71- .setShortName(" D" )
72- .setDescription(" Enable debug logging. Default: false" )
73- .setFlag(true ),
74- Option ()
75- .setLongName(" requestSingleElement" )
76- .setShortName(" RSE" )
77- .setDescription(" Request elements one-by-one. Default: false" )
78- .setFlag(true ),
79- Option ()
80- .setLongName(CHUNK_SIZE )
81- .setShortName(" C" )
82- .setDescription(" Set the size of chunks to use when crawling elements. Default: -1 to disable chunks" )
83- .setDefaultValue(" -1" )
84- ))
85-
86-
87-
88- val commandLine = cli.parse(args.asList(),false )
89-
90- if (commandLine.isFlagEnabled(" help" )) {
21+ .setSummary(" A REST Client to query all model element from server." )
22+ .addArguments(
23+ listOf (
24+ Argument ()
25+ .setArgName(" username" )
26+ .setIndex(0 )
27+ .setDefaultValue(" admin" )
28+ .setDescription(" TWC username." ),
29+ Argument ()
30+ .setArgName(" password" )
31+ .setIndex(1 )
32+ .setDefaultValue(" admin" )
33+ .setDescription(" TWC password." )
34+ )
35+ )
36+ .addOptions(
37+ listOf (
38+ Option ()
39+ .setLongName(" help" )
40+ .setShortName(" h" )
41+ .setDescription(" Show help site." )
42+ .setFlag(true ),
43+ Option ()
44+ .setLongName(" server" )
45+ .setShortName(" S" )
46+ .setDescription(" Set server path." ),
47+ Option ()
48+ .setLongName(" port" )
49+ .setShortName(" P" )
50+ .setDescription(" Set server port number." ),
51+ Option ()
52+ .setLongName(" ssl" )
53+ .setShortName(" ssl" )
54+ .setDescription(" SSL server connection. Default: false" )
55+ .setFlag(true ),
56+ Option ()
57+ .setLongName(" instanceNum" )
58+ .setShortName(" I" )
59+ .setDescription(" Set number of RESTVerticle instances. Default:16" )
60+ .setDefaultValue(" 16" ),
61+ Option ()
62+ .setLongName(" workspaceId" )
63+ .setShortName(" W" )
64+ .setDescription(" Select workspace to crawl" ),
65+ Option ()
66+ .setLongName(" resourceId" )
67+ .setShortName(" R" )
68+ .setDescription(" Select resource to crawl" ),
69+ Option ()
70+ .setLongName(" branchId" )
71+ .setShortName(" B" )
72+ .setDescription(" Select branch to crawl" ),
73+ Option ()
74+ .setLongName(" revision" )
75+ .setShortName(" REV" )
76+ .setDescription(" Select revision to crawl" ),
77+ Option ()
78+ .setLongName(" debug" )
79+ .setShortName(" D" )
80+ .setDescription(" Enable debug logging. Default: false" )
81+ .setFlag(true ),
82+ Option ()
83+ .setLongName(" requestSingleElement" )
84+ .setShortName(" RSE" )
85+ .setDescription(" Request elements one-by-one. Default: false" )
86+ .setFlag(true ),
87+ Option ()
88+ .setLongName(CHUNK_SIZE )
89+ .setShortName(" C" )
90+ .setDescription(" Set the size of chunks to use when crawling elements. Default: -1 to disable chunks" )
91+ .setDefaultValue(" -1" )
92+ )
93+ )
94+
95+
96+ val commandLine = cli.parse(args.asList(), false )
97+
98+ if (commandLine.isFlagEnabled(" help" )) {
9199 val builder = StringBuilder ()
92100 cli.usage(builder)
93101 println (builder.toString())
@@ -96,10 +104,11 @@ fun main(args: Array<String>) {
96104
97105 val vertx = Vertx .vertx()
98106 val sd = vertx.sharedData()
99- val twcMap = sd.getLocalMap<Any ,Any >(" twcMap" )
107+ val twcMap = sd.getLocalMap<Any , Any >(" twcMap" )
100108
101109 val serverOpt = commandLine.getOptionValue<String >(" server" )
102110 val portOpt = commandLine.getOptionValue<String >(" port" )
111+ val isSslEnabled = commandLine.isFlagEnabled(" ssl" )
103112 val instanceNum = commandLine.getOptionValue<String >(" instanceNum" ).toInt()
104113 val workspaceId = commandLine.getOptionValue<String >(" workspaceId" )
105114 val resourceId = commandLine.getOptionValue<String >(" resourceId" )
@@ -109,98 +118,106 @@ fun main(args: Array<String>) {
109118 val debug = commandLine.isFlagEnabled(" debug" )
110119 val requestSingleElement = commandLine.isFlagEnabled(" requestSingleElement" )
111120
112- twcMap.put( " debug" , debug)
113- if (debug) {
121+ twcMap[ " debug" ] = debug
122+ if (debug) {
114123 println (" Debug mode is enabled" )
115124 }
116125
117- twcMap.put( " requestSingleElement" , requestSingleElement)
118- if (requestSingleElement) {
126+ twcMap[ " requestSingleElement" ] = requestSingleElement
127+ if (requestSingleElement) {
119128 println (" Request single elements mode is enabled" )
120129 }
121130
122- twcMap.put( CHUNK_SIZE , chunkSize)
131+ twcMap[ CHUNK_SIZE ] = chunkSize
123132 println (" Chunk size is $chunkSize " )
124133
125- if (instanceNum!= null ){
134+ if (instanceNum != null ) {
126135 println (" Instance number set to $instanceNum " )
127- if (instanceNum< 1 ) {
136+ if (instanceNum < 1 ) {
128137 error(" Number of Instances should be at least 1." )
129138 }
130139 }
131- if (workspaceId != null ){
140+ if (workspaceId != null ) {
132141 println (" Workspace ID set to $workspaceId " )
133- twcMap.put( DataConstants .WORKSPACE_ID , workspaceId)
142+ twcMap[ DataConstants .WORKSPACE_ID ] = workspaceId
134143 }
135- if (resourceId != null ){
144+ if (resourceId != null ) {
136145 println (" Resource ID set to $resourceId " )
137- twcMap.put( DataConstants .RESOURCE_ID , resourceId)
146+ twcMap[ DataConstants .RESOURCE_ID ] = resourceId
138147 }
139- if (branchId != null ){
148+ if (branchId != null ) {
140149 println (" Branch ID set to $branchId " )
141- twcMap.put( DataConstants .BRANCH_ID , branchId)
150+ twcMap[ DataConstants .BRANCH_ID ] = branchId
142151 }
143- if (revision != null ){
152+ if (revision != null ) {
144153 println (" Revision set to $revision " )
145- twcMap.put( DataConstants .REVISION , revision.toInt() )
154+ twcMap[ DataConstants .REVISION ] = revision.toInt()
146155 }
147156
148157
149- if (serverOpt != null && portOpt!= null ){
150- if (! File (" server.config" ).exists()){
158+ if (serverOpt != null && portOpt != null ) {
159+ if (! File (" server.config" ).exists()) {
151160 File (" server.config" ).createNewFile()
152161 }
153162
154- File (" server.config" ).writeText(Json .encode(Server (serverOpt,portOpt.toInt())))
155- twcMap.put(" server_path" ,serverOpt)
156- twcMap.put(" server_port" ,portOpt.toInt())
163+ File (" server.config" ).writeText(Json .encode(Server (serverOpt, portOpt.toInt(), isSslEnabled)))
164+ twcMap[" server_path" ] = serverOpt
165+ twcMap[" server_port" ] = portOpt.toInt()
166+ twcMap[" server_ssl" ] = isSslEnabled
157167 println (" New Server config" )
158168
159169 } else {
160- if (File (" server.config" ).exists()) {
170+ if (File (" server.config" ).exists()) {
161171 val config = File (" server.config" ).readText()
162172
163173 if (config != " " ) {
164174 val serverConf = JsonObject (config)
165175 val serverPath = serverConf.getString(" path" )
166176 val serverPort = serverConf.getInteger(" port" )
167- twcMap.put(" server_path" , serverPath)
168- twcMap.put(" server_port" , serverPort)
177+ val sslEnabled = serverConf.getBoolean(" ssl" )
178+ twcMap[" server_path" ] = serverPath
179+ twcMap[" server_port" ] = serverPort
180+ twcMap[" server_ssl" ] = sslEnabled
169181 } else {
170- error(" Server config is empty.\n " +
171- " Please set Server Path and Port.\n " +
172- " (Check usage with -h (--help) cli option)" )
182+ error(
183+ " Server config is empty.\n " +
184+ " Please set Server Path and Port.\n " +
185+ " (Check usage with -h (--help) cli option)"
186+ )
173187 }
174188 } else {
175- error(" No server config found.\n " +
176- " Please set Server Path and Port.\n " +
177- " (Check usage with -h (--help) cli option)" )
189+ error(
190+ " No server config found.\n " +
191+ " Please set Server Path and Port.\n " +
192+ " (Check usage with -h (--help) cli option)"
193+ )
178194 }
179195 }
180- println (" Server config: ${twcMap.get( " server_path" ) } :${twcMap.get( " server_port" )} " )
196+ println (" Server config: ${twcMap[ " server_path" ] } :${twcMap[ " server_port" ]} (ssl: ${twcMap[ " server_ssl " ]} ) " )
181197
182198 val restVerticle = RESTVerticle ()
183199
184200 var options = DeploymentOptions ().setWorker(true ).setHa(true ).setInstances(instanceNum).setWorkerPoolSize(32 )
185201
186- twcMap.put( " flag" , 0 )
187- vertx.deployVerticle(restVerticle.javaClass.name,options, { deploy ->
202+ twcMap[ " flag" ] = 0
203+ vertx.deployVerticle(restVerticle.javaClass.name, options) { deploy ->
188204 if (deploy.failed()) {
189205 error(" Deploy failed: ${deploy.cause().message} " )
190206 } else {
191207
192208 val usr = commandLine.getArgumentValue<String >(" username" )
193209 val pswd = commandLine.getArgumentValue<String >(" password" )
194- twcMap.put(" credential" ," Basic ${java.util.Base64 .getEncoder().encodeToString(" ${usr} :${pswd} " .toByteArray())} " )
195- twcMap.put(" username" ,usr)
210+ twcMap[" credential" ] =
211+ " Basic ${java.util.Base64 .getEncoder().encodeToString(" ${usr} :${pswd} " .toByteArray())} "
212+ twcMap[" username" ] = usr
196213
197- vertx.deployVerticle(MainVerticle (usr,pswd),{ deploy->
198- if (deploy.failed()){
214+ vertx.deployVerticle(MainVerticle (usr, pswd)) { deploy ->
215+ if (deploy.failed()) {
199216 error(" Deploy failed: ${deploy.cause().message} \n ${deploy.cause().printStackTrace()} " )
200217 }
201- })
218+ }
202219 }
203- })
220+ }
204221
205222}
206223
0 commit comments