|
40 | 40 | import java.io.FileOutputStream; |
41 | 41 | import java.io.IOException; |
42 | 42 | import java.io.InputStream; |
| 43 | +import java.io.IOError; |
43 | 44 | import java.io.InputStreamReader; |
44 | 45 | import java.io.OutputStream; |
| 46 | +import java.nio.file.InvalidPathException; |
| 47 | +import java.nio.file.Path; |
45 | 48 | import java.nio.file.Paths; |
46 | 49 | import java.util.ArrayList; |
47 | 50 | import java.util.List; |
@@ -282,7 +285,11 @@ else if (arg.equals("-I")) |
282 | 285 | { |
283 | 286 | if (count < args.length) |
284 | 287 | { |
285 | | - m_includePaths.add("-I".concat(args[count++])); |
| 288 | + String pathStr = args[count++]; |
| 289 | + if (!isIncludePathDuplicated(pathStr)) |
| 290 | + { |
| 291 | + m_includePaths.add("-I".concat(pathStr)); |
| 292 | + } |
286 | 293 | } |
287 | 294 | else |
288 | 295 | { |
@@ -510,6 +517,42 @@ private void showVersion() |
510 | 517 | System.out.println(m_appName + " version " + version); |
511 | 518 | } |
512 | 519 |
|
| 520 | + private boolean isIncludePathDuplicated(String pathToCheck) |
| 521 | + { |
| 522 | + try |
| 523 | + { |
| 524 | + Path path = Paths.get(pathToCheck); |
| 525 | + String absPath = path.toAbsolutePath().toString(); |
| 526 | + boolean isDuplicateFound = false; |
| 527 | + for (String includePath : m_includePaths) |
| 528 | + { |
| 529 | + // include paths are prefixed with "-I" |
| 530 | + if (includePath.length() <= 2) |
| 531 | + { |
| 532 | + continue; |
| 533 | + } |
| 534 | + String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); |
| 535 | + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) |
| 536 | + { |
| 537 | + isDuplicateFound = true; |
| 538 | + break; |
| 539 | + } |
| 540 | + } |
| 541 | + |
| 542 | + if (isDuplicateFound) |
| 543 | + { |
| 544 | + return true; |
| 545 | + } |
| 546 | + |
| 547 | + } |
| 548 | + catch (InvalidPathException | IOError | SecurityException ex) |
| 549 | + { |
| 550 | + // path operations failed, just returning false |
| 551 | + } |
| 552 | + |
| 553 | + return false; |
| 554 | + } |
| 555 | + |
513 | 556 | public static void printHelp() |
514 | 557 | { |
515 | 558 | System.out.println(m_appName + " usage:"); |
|
0 commit comments