Skip to content

Commit

Permalink
Improve path processing (#131)
Browse files Browse the repository at this point in the history
* Refs #20755: Normilize path

Signed-off-by: elianalf <[email protected]>

* Refs #20755: Substitute backslash with slash

Signed-off-by: elianalf <[email protected]>

---------

Signed-off-by: elianalf <[email protected]>
  • Loading branch information
elianalf authored Apr 26, 2024
1 parent 7acf712 commit 60ec03c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main/java/com/eprosima/idl/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.eprosima.idl.util.Util;
import java.io.File;
import java.io.StringReader;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -112,7 +113,7 @@ public Context(

// The scope file has to be initialized because could occur the preprocessor
// is not called (using -ppDisable).
m_scopeFile = m_file;
m_scopeFile = Paths.get(m_file).normalize().toString();

m_includePaths = new ArrayList<String>();
m_dependencies = new LinkedHashSet<String>();
Expand All @@ -139,12 +140,7 @@ public Context(
{
include = include.substring(m_directoryFile.length());
}
// Add last separator (can be empty by now...)
if (!include.isEmpty() && include.charAt(include.length() - 1) != java.io.File.separatorChar)
{
include += java.io.File.separator;
}
m_includePaths.add(include);
m_includePaths.add(Paths.get(include).normalize().toString() + java.io.File.separator);
}

// Reorder include paths;
Expand Down Expand Up @@ -886,7 +882,7 @@ public void processPreprocessorLine(

// Read filename
scanner.next();
String file = scanner.next();
String file = Paths.get(scanner.next()).normalize().toString();

// Read flags.
boolean systemFile = false, enteringFile = false, exitingFile = false;
Expand Down Expand Up @@ -986,6 +982,8 @@ else if (flag == 3)
includeFile.substring(0, includeFile.length() - 4).replace('.', '_');
// Change back to "." for relative paths.
dependency_to_add = dependency_to_add.replaceAll("__/", "../");
// Substitute "\\" with File separator.
dependency_to_add = dependency_to_add.replace('\\', '/');

m_directIncludeDependencies.add(dependency_to_add);
}
Expand Down

0 comments on commit 60ec03c

Please sign in to comment.