Skip to content

[23150] Apply user template to included IDL files (backport #472) #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 74 additions & 21 deletions src/main/java/com/eprosima/fastdds/fastddsgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ private boolean isIncludePathDuplicated(String pathToCheck)
{
// path operations failed, just returning false
}

return false;
}
}

public static void printHelp()
{
Expand Down Expand Up @@ -783,9 +783,20 @@ private Project parseIDL(
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
{
System.out.println("Loading custom template " + entry.getKey() + "...");
Path path = Paths.get(entry.getKey());
String templateName = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf('.'));
tmanager.addGroup(templateName);
loadAndAddTemplate(entry.getKey(), tmanager);
}
}
else
{
// Check if there is a '@' in the output_file_name
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
{
if (entry.getValue().contains("@"))
{
System.out.println("Loading custom template " +
entry.getKey() + " for included IDL file " + idlFilename + "...");
loadAndAddTemplate(entry.getKey(), tmanager);
}
}
}

Expand Down Expand Up @@ -828,25 +839,27 @@ private Project parseIDL(
{
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
{
Path path = Paths.get(entry.getKey());
String templateName = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf('.'));
System.out.println("Generating from custom " + templateName + " to " + entry.getValue());

if (returnedValue = Utils.writeFile(m_outputDir + entry.getValue(), maintemplates.getTemplate(templateName), m_replace))
if (! (returnedValue = createOutputCustomTemplate(
entry, idlFilename, m_outputDir, ctx.getFilename(),
maintemplates, m_replace, project)))
{
// Try to determine if the file is a header file.
if (entry.getValue().contains(".hpp") || entry.getValue().contains(".h"))
{
project.addCommonIncludeFile(entry.getValue());
}
else
{
project.addCommonSrcFile(ctx.getFilename() + entry.getValue());
}
break;
}
else
}
}
else
{
// Check if there is a '$' in the output_file_name
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
{
if (entry.getValue().contains("@"))
{
break;
if (! (returnedValue = createOutputCustomTemplate(
entry, idlFilename, m_outputDir, ctx.getFilename(),
maintemplates, m_replace, project)))
{
break;
}
}
}
}
Expand Down Expand Up @@ -1048,6 +1061,46 @@ private Project parseIDL(
return returnedValue ? project : null;
}

private void loadAndAddTemplate(
String templatePath,
TemplateManager tmanager)
{
Path path = Paths.get(templatePath);
String templateName = path.getFileName().toString();
templateName = templateName.substring(0, templateName.lastIndexOf('.'));
tmanager.addGroup(templateName);
}

private boolean createOutputCustomTemplate(
Map.Entry<String, String> entry,
String idlFilename,
String outputDir,
String contextFilename,
TemplateGroup maintemplates,
boolean replace,
Project project)
{
Path path = Paths.get(entry.getKey());
String templateName = path.getFileName().toString();
templateName = templateName.substring(0, templateName.lastIndexOf('.'));
String outputName = entry.getValue().replace("@", idlFilename.substring(0, idlFilename.lastIndexOf('.')));
System.out.println("Generating from custom " + templateName + " to " + outputName);

boolean ret_val = Utils.writeFile(outputDir + outputName, maintemplates.getTemplate(templateName), replace);
if (ret_val)
{
if (outputName.contains(".hpp") || outputName.contains(".h"))
{
project.addCommonIncludeFile(outputName);
}
else
{
project.addCommonSrcFile(contextFilename + outputName);
}
}
return ret_val;
}

private boolean genSolution(
Solution solution)
{
Expand Down