Skip to content

Commit 5f95b79

Browse files
authored
Avoid inclussion of duplicate included paths (#429)
Signed-off-by: Juanjo Garcia <juanjosegarcia@eprosima.com>
1 parent 23125d2 commit 5f95b79

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

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

Lines changed: 31 additions & 3 deletions
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.Files;
4648
import java.nio.file.Path;
4749
import java.nio.file.Paths;
@@ -273,7 +275,10 @@ else if (arg.equals(include_path_arg))
273275
{
274276
if (count < args.length)
275277
{
276-
m_includePaths.add(include_path_arg.concat(args[count++]));
278+
String pathStr = args[count++];
279+
if (!isIncludePathDuplicated(pathStr)) {
280+
m_includePaths.add(include_path_arg.concat(pathStr));
281+
}
277282
}
278283
else
279284
{
@@ -560,8 +565,31 @@ private void showVersion()
560565
System.out.println(m_appName + " version " + version);
561566
}
562567

563-
564-
568+
private boolean isIncludePathDuplicated(String pathToCheck) {
569+
try {
570+
Path path = Paths.get(pathToCheck);
571+
String absPath = path.toAbsolutePath().toString();
572+
boolean isDuplicateFound = false;
573+
for (String includePath : m_includePaths) {
574+
// include paths are prefixed with "-I"
575+
if (includePath.length() <= 2) {
576+
continue;
577+
}
578+
String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString();
579+
if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) {
580+
isDuplicateFound = true;
581+
break;
582+
}
583+
}
584+
if (isDuplicateFound) {
585+
return true;
586+
}
587+
} catch (InvalidPathException | IOError | SecurityException ex) {
588+
// path operations failed, just returning false
589+
}
590+
return false;
591+
}
592+
565593
/*
566594
* ----------------------------------------------------------------------------------------
567595
* Arguments

0 commit comments

Comments
 (0)