1818
1919import java .io .File ;
2020import java .io .IOException ;
21+ import java .net .MalformedURLException ;
22+ import java .net .URL ;
2123import java .nio .file .Path ;
2224import java .nio .file .Paths ;
2325import java .util .ArrayList ;
@@ -117,7 +119,12 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
117119 state .analysisName = config .get ("analysisName" );
118120 state .includePaths = config .get ("includePaths" );
119121 state .excludePaths = config .get ("excludePaths" );
120- state .projectId = Integer .parseInt (config .get ("selectedProjectId" ));
122+ try {
123+ state .projectId = Integer .parseInt (config .get ("selectedProjectId" ));
124+ } catch (NumberFormatException e ) {
125+ logError (state , "No project selected. Please select a Code Dx project on the task configuration page." );
126+ return false ;
127+ }
121128 state .toolOutputFiles = config .get ("toolOutputFiles" );
122129 state .reportArchiveName = config .get ("reportArchiveName" );
123130 state .waitForResults = config .getAsBoolean ("waitForResults" );
@@ -133,16 +140,44 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
133140 state .apiUrl = ServerConfigManager .getUrl ();
134141 state .apiKey = ServerConfigManager .getApiKey ();
135142 state .fingerprint = ServerConfigManager .getFingerprint ();
143+
144+ if (state .apiUrl == null || state .apiKey == null || state .apiUrl .isEmpty () || state .apiKey .isEmpty ()) {
145+ logError (state , "Code Dx url and api key are not properly configured. Please configure them on the plug-in settings page." );
146+ return false ;
147+ }
136148 } else {
137149 state .apiUrl = config .get ("url" );
138150 state .apiKey = config .get ("apiKey" );
139151 state .fingerprint = config .get ("fingerprint" );
152+
153+ if (state .apiUrl == null || state .apiUrl .isEmpty ()) {
154+ logError (state , "Missing Code Dx url. Please configure it on the task configuration page." );
155+ return false ;
156+ } else {
157+ try {
158+ new URL (state .apiUrl );
159+ } catch (MalformedURLException e ) {
160+ logError (state , "Malformed Code Dx url. Please correct it on the task configuration page." );
161+ return false ;
162+ }
163+ }
164+
165+ if (state .apiKey == null || state .apiKey .isEmpty ()) {
166+ logError (state , "Missing Code Dx api key. Please configure it on the task configuration page." );
167+ return false ;
168+ }
140169 }
141170
142- if (state .apiUrl == null || state .apiKey == null || state . apiUrl . isEmpty () || state . apiKey .isEmpty ()) {
143- logError (state , "Code Dx url and api key are not properly configured . Please configure them on the plug-in settings page." );
171+ if (state .analysisName == null || state .analysisName .isEmpty ()) {
172+ logError (state , "Missing Code Dx Analysis Name . Please configure it on the task configuration page." );
144173 return false ;
145174 }
175+
176+ if (state .includePaths == null || state .includePaths .isEmpty ()) {
177+ logError (state , "Missing source and binary files. Please configure the field on the task configuration page." );
178+ return false ;
179+ }
180+
146181 log (state , "Code Dx url set to %s" , state .apiUrl );
147182
148183 return true ;
0 commit comments