Skip to content

Commit

Permalink
fix(plc4j/profinet): Sonar fix regex matching zeo chars
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed May 11, 2023
1 parent a3ea768 commit 30995f2
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PacketHandler getPcapPacketHandler() {
@Required
@ConfigurationParameter("gsddirectory")
@ParameterConverter(ProfinetGsdFileConvertor.class)
static protected GsdFileMap gsdFiles;
protected static GsdFileMap gsdFiles;

@ConfigurationParameter("sendclockfactor")
@IntDefaultValue(32)
Expand All @@ -90,7 +90,7 @@ public PacketHandler getPcapPacketHandler() {

public static class ProfinetDeviceConvertor implements ConfigurationParameterConverter<ProfinetDevices> {

public static final String DEVICE_STRING = "((?<devicename>[\\w- ]*){1}[, ]+(?<deviceaccess>[\\w ]*){1}[, ]+\\((?<submodules>[\\w, ]*)\\)[, ]*(?<ipaddress>[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)?)";
public static final String DEVICE_STRING = "((?<devicename>[\\w- ]+)[, ]+(?<deviceaccess>[\\w ]+)[, ]+\\((?<submodules>[\\w, ]*)\\)[, ]*(?<ipaddress>\\d+\\.\\d+\\.\\d+\\.\\d+)?)";
public static final String DEVICE_ARRAY_STRING = "^\\[(?:(\\[" + DEVICE_STRING + "{1}\\])[, ]?)+\\]";
public static final Pattern DEVICE_NAME_ARRAY_PATTERN = Pattern.compile(DEVICE_ARRAY_STRING);
public static final Pattern DEVICE_PARAMETERS = Pattern.compile(DEVICE_STRING);
Expand Down Expand Up @@ -145,8 +145,9 @@ public Class<GsdFileMap> getType() {
@Override
public GsdFileMap convert(String value) {
HashMap<String, ProfinetISO15745Profile> gsdFiles = new HashMap<>();
DirectoryStream<Path> stream = null;
try {
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(value));
stream = Files.newDirectoryStream(Paths.get(value));
XmlMapper xmlMapper = new XmlMapper();
for (Path file : stream) {
try {
Expand All @@ -160,6 +161,14 @@ public GsdFileMap convert(String value) {
}
} catch (IOException e) {
throw new RuntimeException("GSDML File directory is un-readable");
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new GsdFileMap(gsdFiles);
}
Expand Down

0 comments on commit 30995f2

Please sign in to comment.