diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index eb1e8a63..c4f5118d 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -589,7 +589,7 @@ private boolean isIncludePathDuplicated(String pathToCheck) { } return false; } - + /* * ---------------------------------------------------------------------------------------- * Arguments @@ -869,14 +869,19 @@ private Project parseIDL( for (Map.Entry 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('.')); - try { - String content = new String(Files.readAllBytes(path)); - tmanager.addGroupFromString(templateName, content); - } catch(IOException e){ - System.out.println(ColorMessage.error( - "IOException") + "Cannot read content from " + path.toString()); + loadAndAddTemplate(entry.getKey(), tmanager); + } + } + else + { + // Check if there is a '@' in the output_file_name + for (Map.Entry 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); } } } @@ -919,25 +924,27 @@ private Project parseIDL( { for (Map.Entry 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(output_dir + entry.getValue(), maintemplates.getTemplate(templateName), m_replace)) + if (! (returnedValue = createOutputCustomTemplate( + entry, idlFilename, output_dir, relative_dir, 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(relative_dir + entry.getValue()); - } - else - { - project.addCommonSrcFile(relative_dir + ctx.getFilename() + entry.getValue()); - } + break; } - else + } + } + else + { + // Check if there is a '$' in the output_file_name + for (Map.Entry entry : m_customStgOutput.entrySet()) + { + if (entry.getValue().contains("@")) { - break; + if (! (returnedValue = createOutputCustomTemplate( + entry, idlFilename, output_dir, relative_dir, ctx.getFilename(), + maintemplates, m_replace, project))) + { + break; + } } } } @@ -1177,6 +1184,55 @@ private Project parseIDL( return returnedValue ? project : null; } + private void loadAndAddTemplate( + String templatePath, + TemplateManager tmanager) + { + try + { + Path path = Paths.get(templatePath); + String templateName = path.getFileName().toString(); + templateName = templateName.substring(0, templateName.lastIndexOf('.')); + String content = new String(Files.readAllBytes(path)); + tmanager.addGroupFromString(templateName, content); + } + catch (IOException e) + { + System.out.println(ColorMessage.error("IOException") + "Cannot read content from " + templatePath); + } + } + + private boolean createOutputCustomTemplate( + Map.Entry entry, + String idlFilename, + String outputDir, + String relativeDir, + 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(relativeDir + outputName); + } + else + { + project.addCommonSrcFile(relativeDir + contextFilename + outputName); + } + } + return ret_val; + } + private boolean genSolution( Solution solution) {