From 454a49ceee22760241c713b5c078c3c94bdab3bb Mon Sep 17 00:00:00 2001 From: Juanjo Garcia Date: Mon, 13 Jan 2025 09:43:33 +0100 Subject: [PATCH] Refs #13740: Solved backport conflicts Signed-off-by: Juanjo Garcia --- .../java/com/eprosima/fastdds/fastddsgen.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index a4d79fa7..46221bbb 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -40,8 +40,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.IOError; import java.io.InputStreamReader; import java.io.OutputStream; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -282,7 +285,11 @@ else if (arg.equals("-I")) { if (count < args.length) { - m_includePaths.add("-I".concat(args[count++])); + String pathStr = args[count++]; + if (!isIncludePathDuplicated(pathStr)) + { + m_includePaths.add("-I".concat(pathStr)); + } } else { @@ -510,6 +517,42 @@ private void showVersion() System.out.println(m_appName + " version " + version); } + private boolean isIncludePathDuplicated(String pathToCheck) + { + try + { + Path path = Paths.get(pathToCheck); + String absPath = path.toAbsolutePath().toString(); + boolean isDuplicateFound = false; + for (String includePath : m_includePaths) + { + // include paths are prefixed with "-I" + if (includePath.length() <= 2) + { + continue; + } + String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) + { + isDuplicateFound = true; + break; + } + } + + if (isDuplicateFound) + { + return true; + } + + } + catch (InvalidPathException | IOError | SecurityException ex) + { + // path operations failed, just returning false + } + + return false; + } + public static void printHelp() { System.out.println(m_appName + " usage:");