2121import java .nio .file .Paths ;
2222import java .text .SimpleDateFormat ;
2323import java .util .Date ;
24- import java .util .Properties ;
2524
2625import fr .cnes .sonar .plugin .tools .SonarPropertiesLoader ;
2726
@@ -140,30 +139,24 @@ public static ReportConfiguration create(final String[] pArgs) throws IOExceptio
140139 String token = new String ();
141140
142141 if (commandLineManager .hasOption ("i" )) {
143- // If we have a sonar.properties file, we read it and configure url and
144- // projectkey from it, possibly token.
142+ // If we have a sonar.properties file, we read it and set server, projectKey and token from it if possible.
145143 try {
146- SonarPropertiesLoader propLoader = new SonarPropertiesLoader ();
147- Properties sonarProps = propLoader
148- .loadSonarProperties (Paths .get (commandLineManager .getOptionValue ("i" )));
144+ SonarPropertiesLoader propLoader = new SonarPropertiesLoader (Paths .get (commandLineManager .getOptionValue ("i" )));
149145
150146 // If -s input does not exist, add it with the value of
151- // sonarprops.get("sonar.host.url"). If it does, no action (Command line is
152- // authoritative).
153- if (!commandLineManager .hasOption ("s" )) {
154- server = sonarProps .getProperty (StringManager .SONAR_SERVER );
155- server = server != null ? server : "" ;
156- }
157- if (!commandLineManager .hasOption ("p" )) {
158- projectKey = sonarProps .getProperty (StringManager .SONAR_KEY );
159- projectKey = projectKey != null ? projectKey : "" ;
160- }
161- if (!commandLineManager .hasOption ("t" )) {
162- token = sonarProps .getProperty (StringManager .SONAR_TOKEN );
163- token = token != null ? token : "" ;
164- }
147+ // sonarprops.get("sonar.host.url"). If it does, no action (Command line is authoritative).
165148 // Similar logic for other parameters, projectKey, token, etc.
149+
150+ if (!commandLineManager .hasOption ("s" ))
151+ server = propLoader .getSonarProperty (StringManager .SONAR_SERVER );
152+ if (!commandLineManager .hasOption ("p" ))
153+ projectKey = propLoader .getSonarProperty (StringManager .SONAR_KEY );
154+ if (!commandLineManager .hasOption ("t" ))
155+ token = propLoader .getSonarProperty (StringManager .SONAR_TOKEN );
156+
166157 } catch (IOException e ) {
158+ // If sonar.properties was not properly opened, we raise this to main to halt
159+ // execution.
167160 throw e ;
168161 }
169162 }
@@ -173,22 +166,16 @@ public static ReportConfiguration create(final String[] pArgs) throws IOExceptio
173166 StringManager .NO_BRANCH );
174167 return new ReportConfiguration (commandLineManager .hasOption ("h" ), commandLineManager .hasOption ("v" ),
175168 commandLineManager .getOptionValue ("i" , StringManager .getProperty (StringManager .SONAR_PROPERTIES )),
176- server .isEmpty ()
177- ? commandLineManager .getOptionValue ("s" , StringManager .getProperty (StringManager .SONAR_URL ))
178- : server ,
179- token .isEmpty ()
180- ? commandLineManager .getOptionValue ("t" , StringManager .getProperty (StringManager .SONAR_TOKEN ))
181- : token ,
169+ server .isEmpty () ? commandLineManager .getOptionValue ("s" , StringManager .getProperty (StringManager .SONAR_URL )): server ,
170+ token .isEmpty () ? commandLineManager .getOptionValue ("t" , StringManager .getProperty (StringManager .SONAR_TOKEN )): token ,
182171 projectKey .isEmpty () ? commandLineManager .getOptionValue ("p" , StringManager .EMPTY ) : projectKey ,
183172 commandLineManager .getOptionValue ("o" , StringManager .getProperty (StringManager .DEFAULT_OUTPUT )),
184173 commandLineManager .getOptionValue ("l" , StringManager .getProperty (StringManager .DEFAULT_LANGUAGE )),
185174 commandLineManager .getOptionValue ("a" , StringManager .getProperty (StringManager .DEFAULT_AUTHOR )),
186175 commandLineManager .getOptionValue ("d" ,
187176 new SimpleDateFormat (StringManager .DATE_PATTERN ).format (new Date ())),
188177 !commandLineManager .hasOption ("c" ), !commandLineManager .hasOption ("w" ),
189- !commandLineManager .hasOption ("e" ), !commandLineManager .hasOption ("f" ), // Why f ? Because every "logic"
190- // options like "c" are already
191- // used
178+ !commandLineManager .hasOption ("e" ), !commandLineManager .hasOption ("f" ), // Why f ? Because every "logic" options like "c" are already used
192179 !commandLineManager .hasOption ("m" ), commandLineManager .getOptionValue ("r" , StringManager .EMPTY ),
193180 commandLineManager .getOptionValue ("x" , StringManager .EMPTY ),
194181 commandLineManager .getOptionValue ("n" , StringManager .EMPTY ),
0 commit comments