Skip to content

Commit

Permalink
Add afunction that checks for repeated -I paths (#429) (#430)
Browse files Browse the repository at this point in the history
* Refs #13740: Solved mergify conflict #430

Signed-off-by: Juanjo Garcia <[email protected]>

* Refs #13740: corrected typo

Signed-off-by: Juanjo Garcia <[email protected]>

---------

Signed-off-by: Juanjo Garcia <[email protected]>
Co-authored-by: Juanjo Garcia <[email protected]>
  • Loading branch information
mergify[bot] and juanjo4936 authored Jan 16, 2025
1 parent e53360c commit bb44c0f
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/main/java/com/eprosima/fastdds/fastddsgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
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.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -310,7 +312,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
{
Expand Down Expand Up @@ -551,6 +557,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:");
Expand Down

0 comments on commit bb44c0f

Please sign in to comment.