Skip to content

Commit 4427ae4

Browse files
mergify[bot]Juanjo Garcia
and
Juanjo Garcia
authored
Avoid inclussion of duplicate included paths (#429) (#431)
Signed-off-by: Juanjo Garcia <[email protected]> Co-authored-by: Juanjo Garcia <[email protected]>
1 parent 2f781a0 commit 4427ae4

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/main/java/com/eprosima/fastdds/fastddsgen.java

+43-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
import java.io.FileOutputStream;
4141
import java.io.IOException;
4242
import java.io.InputStream;
43+
import java.io.IOError;
4344
import java.io.InputStreamReader;
4445
import java.io.OutputStream;
46+
import java.nio.file.InvalidPathException;
4547
import java.nio.file.Path;
4648
import java.nio.file.Paths;
4749
import java.util.ArrayList;
@@ -299,7 +301,11 @@ else if (arg.equals("-I"))
299301
{
300302
if (count < args.length)
301303
{
302-
m_includePaths.add("-I".concat(args[count++]));
304+
String pathStr = args[count++];
305+
if (!isIncludePathDuplicated(pathStr))
306+
{
307+
m_includePaths.add("-I".concat(pathStr));
308+
}
303309
}
304310
else
305311
{
@@ -542,6 +548,42 @@ private void showVersion()
542548
System.out.println(m_appName + " version " + version);
543549
}
544550

551+
private boolean isIncludePathDuplicated(String pathToCheck)
552+
{
553+
try
554+
{
555+
Path path = Paths.get(pathToCheck);
556+
String absPath = path.toAbsolutePath().toString();
557+
boolean isDuplicateFound = false;
558+
for (String includePath : m_includePaths)
559+
{
560+
// include paths are prefixed with "-I"
561+
if (includePath.length() <= 2)
562+
{
563+
continue;
564+
}
565+
String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString();
566+
if (absPath.toLowerCase().equals(absIncludePath.toLowerCase()))
567+
{
568+
isDuplicateFound = true;
569+
break;
570+
}
571+
}
572+
573+
if (isDuplicateFound)
574+
{
575+
return true;
576+
}
577+
578+
}
579+
catch (InvalidPathException | IOError | SecurityException ex)
580+
{
581+
// path operations failed, just returning false
582+
}
583+
584+
return false;
585+
}
586+
545587
public static void printHelp()
546588
{
547589
System.out.println(m_appName + " usage:");

0 commit comments

Comments
 (0)