@@ -46,6 +46,8 @@ public CxAuth(CxScanConfig scanConfig, Logger log) throws IOException, URISyntax
4646 this .secret = scanConfig .getClientSecret ();
4747 this .apikey = scanConfig .getApiKey ();
4848
49+ validateConfigValues ();
50+
4951 if (scanConfig .getPathToExecutable () != null && !scanConfig .getPathToExecutable ().isEmpty ()) {
5052 File file = new File (scanConfig .getPathToExecutable ());
5153 this .executable = file .toURI ();
@@ -58,6 +60,16 @@ public CxAuth(CxScanConfig scanConfig, Logger log) throws IOException, URISyntax
5860 }
5961 }
6062
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+
6173 private URI packageExecutable () throws IOException , URISyntaxException {
6274 String osName = System .getProperty ("os.name" );
6375
@@ -94,7 +106,7 @@ private URI getFile(URI jarLocation, final String fileName) throws IOException {
94106 location = new File (jarLocation );
95107
96108 if (location .isDirectory ()) {
97- fileURI = URI .create (jarLocation . toString () + fileName );
109+ fileURI = URI .create (jarLocation + fileName );
98110 } else {
99111 final ZipFile zipFile ;
100112
@@ -218,7 +230,7 @@ private String runResultExecutionCommands(List<String> commands) throws IOExcept
218230 Process process = exec .executeCommand (commands );
219231 BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
220232 StringBuilder builder = new StringBuilder ();
221- String line = null ;
233+ String line ;
222234 while ((line = reader .readLine ()) != null ) {
223235 builder .append (line );
224236 builder .append (System .getProperty ("line.separator" ));
@@ -235,7 +247,7 @@ private CxCommandOutput runExecutionCommands(List<String> commands) throws IOExc
235247 ExecutionService exec = new ExecutionService ();
236248 Process process = exec .executeCommand (commands );
237249 String line ;
238- CxScan scanObject = null ;
250+ CxScan scanObject ;
239251 InputStream is = process .getInputStream ();
240252 InputStreamReader isr = new InputStreamReader (is );
241253 BufferedReader br = new BufferedReader (isr );
@@ -347,6 +359,10 @@ public CxCommandOutput cxScanCreate(Map<CxParamType, String> params) throws IOEx
347359 commands .add ("scan" );
348360 commands .add ("create" );
349361
362+ if (!params .containsKey (CxParamType .PROJECT_NAME )) {
363+ throw new CxException ("Checkmarx project name was not set" );
364+ }
365+
350366 for (Map .Entry <CxParamType , String > param : params .entrySet ()) {
351367 if (param .getKey () == CxParamType .ADDITIONAL_PARAMETERS && param .getValue () != null ) {
352368 addIndividualParams (commands , param .getValue ());
@@ -392,9 +408,9 @@ private void addAuthCredentials(List<String> commands) {
392408 }
393409 }
394410
395- private List <CxScan > transformToCxScanList (String line ) throws IOException {
411+ private List <CxScan > transformToCxScanList (String line ) {
396412 ObjectMapper objectMapper = new ObjectMapper ();
397- List <CxScan > scanList = null ;
413+ List <CxScan > scanList ;
398414 try {
399415 scanList = objectMapper .readValue (line , new TypeReference <List <CxScan >>() {
400416 });
@@ -409,12 +425,12 @@ public boolean isValidJSON(final String json) {
409425 boolean valid = false ;
410426 try {
411427 final JsonParser parser = new ObjectMapper ().createParser (json );
428+ //noinspection StatementWithEmptyBody
412429 while (parser .nextToken () != null ) {
413430 }
414431 valid = true ;
415432 } catch (IOException ignored ) {
416433 }
417- ;
418434 return valid ;
419435 }
420436
0 commit comments