Skip to content

Commit

Permalink
Fix sonar problems
Browse files Browse the repository at this point in the history
  • Loading branch information
AB-xdev committed May 27, 2024
1 parent 6753604 commit 33cb417
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions standalone/src/main/java/software/xdev/mockserver/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,7 @@ else if(isNotBlank(System.getenv(parsedArgument.shortEnvironmentVariableName()))
}
MockServerLoggerConfiguration.configureLogger();
final Integer[] localPorts = INTEGER_STRING_LIST_PARSER.toArray(parsedArgs.get(serverPort.name()));
if(parsedArgs.containsKey(proxyRemotePort.name()))
{
String remoteHost = parsedArgs.get(proxyRemoteHost.name());
if(isBlank(remoteHost))
{
remoteHost = "localhost";
}
new MockServer(Integer.parseInt(parsedArgs.get(proxyRemotePort.name())), remoteHost, localPorts);
}
else
{
new MockServer(localPorts);
}
launchMockServer(parsedArgs, localPorts);
setPort(localPorts);
}
else
Expand All @@ -250,6 +238,24 @@ else if(isNotBlank(System.getenv(parsedArgument.shortEnvironmentVariableName()))
}
}

@SuppressWarnings("resource") // Launch
private static void launchMockServer(final Map<String, String> parsedArgs, final Integer[] localPorts)
{
if(parsedArgs.containsKey(proxyRemotePort.name()))
{
String remoteHost = parsedArgs.get(proxyRemoteHost.name());
if(isBlank(remoteHost))
{
remoteHost = "localhost";
}
new MockServer(Integer.parseInt(parsedArgs.get(proxyRemotePort.name())), remoteHost, localPorts);
}
else
{
new MockServer(localPorts);
}
}

static String formatArgsForLog(final Map<String, String> args)
{
return "[\n\t"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ExpandedParameterDecoder
{
private static final Logger LOG = LoggerFactory.getLogger(ExpandedParameterDecoder.class);

private static final Pattern QUOTED_PARAMETER_VALUE = Pattern.compile("\\s*^[\"']+(.*)[\"']+\\s*$");
private static final Pattern QUOTED_PARAMETER_VALUE = Pattern.compile("^\\s*[\"']+(.*)[\"']+\\s*$");
private static final Pattern JSON_VALUE = Pattern.compile("(?s)^\\s*[{\\[].*[}\\]]\\s*$");

private final ServerConfiguration configuration;
Expand Down Expand Up @@ -157,7 +157,7 @@ public List<NottableString> splitOnDelimiter(
}
else if(!JSON_VALUE.matcher(value.getValue()).matches())
{
for(final String splitValue : value.getValue().split(style.getRegex().replaceAll("<name>", name)))
for(final String splitValue : value.getValue().split(style.getRegex().replace("<name>", name)))
{
if(value.isOptional())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ private static Properties readPropertyFile()
{
LOG.debug("Property file not found on classpath using path [{}]", propertyFile());
}
try
try(final FileInputStream fis = new FileInputStream(propertyFile()))
{
properties.load(new FileInputStream(propertyFile()));
properties.load(fis);
}
catch(final FileNotFoundException e)
{
Expand Down

0 comments on commit 33cb417

Please sign in to comment.