@@ -46,6 +46,8 @@ public CxAuth(CxScanConfig scanConfig, Logger log) throws IOException, URISyntax
46
46
this .secret = scanConfig .getClientSecret ();
47
47
this .apikey = scanConfig .getApiKey ();
48
48
49
+ validateConfigValues ();
50
+
49
51
if (scanConfig .getPathToExecutable () != null && !scanConfig .getPathToExecutable ().isEmpty ()) {
50
52
File file = new File (scanConfig .getPathToExecutable ());
51
53
this .executable = file .toURI ();
@@ -58,6 +60,16 @@ public CxAuth(CxScanConfig scanConfig, Logger log) throws IOException, URISyntax
58
60
}
59
61
}
60
62
63
+ private void validateConfigValues (){
64
+ if (StringUtils .isEmpty (this .baseuri )) {
65
+ throw new CxException ("Checkmarx server URL was not set" );
66
+ }
67
+
68
+ if (StringUtils .isEmpty (this .apikey ) && (StringUtils .isEmpty (this .key ) && StringUtils .isEmpty (this .secret ))) {
69
+ throw new CxException ("Credentials were not set" );
70
+ }
71
+ }
72
+
61
73
private URI packageExecutable () throws IOException , URISyntaxException {
62
74
String osName = System .getProperty ("os.name" );
63
75
@@ -94,7 +106,7 @@ private URI getFile(URI jarLocation, final String fileName) throws IOException {
94
106
location = new File (jarLocation );
95
107
96
108
if (location .isDirectory ()) {
97
- fileURI = URI .create (jarLocation . toString () + fileName );
109
+ fileURI = URI .create (jarLocation + fileName );
98
110
} else {
99
111
final ZipFile zipFile ;
100
112
@@ -218,7 +230,7 @@ private String runResultExecutionCommands(List<String> commands) throws IOExcept
218
230
Process process = exec .executeCommand (commands );
219
231
BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
220
232
StringBuilder builder = new StringBuilder ();
221
- String line = null ;
233
+ String line ;
222
234
while ((line = reader .readLine ()) != null ) {
223
235
builder .append (line );
224
236
builder .append (System .getProperty ("line.separator" ));
@@ -235,7 +247,7 @@ private CxCommandOutput runExecutionCommands(List<String> commands) throws IOExc
235
247
ExecutionService exec = new ExecutionService ();
236
248
Process process = exec .executeCommand (commands );
237
249
String line ;
238
- CxScan scanObject = null ;
250
+ CxScan scanObject ;
239
251
InputStream is = process .getInputStream ();
240
252
InputStreamReader isr = new InputStreamReader (is );
241
253
BufferedReader br = new BufferedReader (isr );
@@ -347,6 +359,10 @@ public CxCommandOutput cxScanCreate(Map<CxParamType, String> params) throws IOEx
347
359
commands .add ("scan" );
348
360
commands .add ("create" );
349
361
362
+ if (!params .containsKey (CxParamType .PROJECT_NAME )) {
363
+ throw new CxException ("Checkmarx project name was not set" );
364
+ }
365
+
350
366
for (Map .Entry <CxParamType , String > param : params .entrySet ()) {
351
367
if (param .getKey () == CxParamType .ADDITIONAL_PARAMETERS && param .getValue () != null ) {
352
368
addIndividualParams (commands , param .getValue ());
@@ -392,9 +408,9 @@ private void addAuthCredentials(List<String> commands) {
392
408
}
393
409
}
394
410
395
- private List <CxScan > transformToCxScanList (String line ) throws IOException {
411
+ private List <CxScan > transformToCxScanList (String line ) {
396
412
ObjectMapper objectMapper = new ObjectMapper ();
397
- List <CxScan > scanList = null ;
413
+ List <CxScan > scanList ;
398
414
try {
399
415
scanList = objectMapper .readValue (line , new TypeReference <List <CxScan >>() {
400
416
});
@@ -409,12 +425,12 @@ public boolean isValidJSON(final String json) {
409
425
boolean valid = false ;
410
426
try {
411
427
final JsonParser parser = new ObjectMapper ().createParser (json );
428
+ //noinspection StatementWithEmptyBody
412
429
while (parser .nextToken () != null ) {
413
430
}
414
431
valid = true ;
415
432
} catch (IOException ignored ) {
416
433
}
417
- ;
418
434
return valid ;
419
435
}
420
436
0 commit comments