From 3d9cb6d075777cd9ccc49045754d4e4ac1bddc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Tue, 20 May 2025 11:56:31 +0200 Subject: [PATCH 1/2] Apply user template to included IDL files (#472) (#474) * Refs #23150: Apply user template to included IDL files * Refs #23150: Apply Review --------- Signed-off-by: cferreiragonz (cherry picked from commit fbb06722c8f1a93f01aa64ffd598494af84710b8) # Conflicts: # src/main/java/com/eprosima/fastdds/fastddsgen.java --- .../java/com/eprosima/fastdds/fastddsgen.java | 145 +++++++++++++++--- 1 file changed, 121 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index ad0d5654..7f096714 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -589,9 +589,50 @@ private boolean isIncludePathDuplicated(String pathToCheck) { // path operations failed, just returning false } +<<<<<<< HEAD return false; } +======= + return false; + } + + /* + * ---------------------------------------------------------------------------------------- + * Arguments + */ + private static final String case_sensitive_arg = "-cs"; + private static final String output_path_arg = "-d"; + private static final String default_container_prealloc_size = "-default-container-prealloc-size"; + private static final String default_extensibility_arg = "-default_extensibility"; + private static final String default_extensibility_short_arg = "-de"; + private static final String specific_platform_arg = "-example"; + private static final String extra_template_arg = "-extrastg"; + private static final String flat_output_directory_arg = "-flat-output-dir"; + private static final String fusion_arg = "-fusion"; + private static final String help_arg = "-help"; + private static final String include_path_arg = "-I"; + private static final String language_arg = "-language"; + private static final String no_typesupport_arg = "-no-typesupport"; + private static final String no_typeobjectsupport_arg = "-no-typeobjectsupport"; + private static final String no_dependencies_arg = "-no-dependencies"; + private static final String package_arg = "-package"; + private static final String disable_preprocessor_arg = "-ppDisable"; + private static final String preprocessor_path_arg = "-ppPath"; + private static final String python_bindings_arg = "-python"; + private static final String replace_arg = "-replace"; + private static final String temp_dir_arg = "-t"; + private static final String ros2_names_arg = "-typeros2"; + private static final String cnames_arg = "-typesc"; + private static final String version_arg = "-version"; + + /* + * ---------------------------------------------------------------------------------------- + * Developer Arguments + */ + private static final String generate_api_arg = "-genapi"; + private static final String execute_test_arg = "-test"; +>>>>>>> fbb0672 (Apply user template to included IDL files (#472) (#474)) public static void printHelp() { @@ -823,14 +864,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); } } } @@ -874,25 +920,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; + } } } } @@ -1129,6 +1177,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) { From d5ac10170dbbf3d1d3bbe8ad6c365733cfd3b253 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Tue, 20 May 2025 12:03:58 +0200 Subject: [PATCH 2/2] Fix Conflicts Signed-off-by: cferreiragonz --- .../java/com/eprosima/fastdds/fastddsgen.java | 65 ++++--------------- 1 file changed, 12 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index 7f096714..1a749638 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -313,7 +313,7 @@ else if (arg.equals("-I")) if (count < args.length) { String pathStr = args[count++]; - if (!isIncludePathDuplicated(pathStr)) + if (!isIncludePathDuplicated(pathStr)) { m_includePaths.add("-I".concat(pathStr)); } @@ -557,82 +557,41 @@ private void showVersion() System.out.println(m_appName + " version " + version); } - private boolean isIncludePathDuplicated(String pathToCheck) + private boolean isIncludePathDuplicated(String pathToCheck) { - try + try { Path path = Paths.get(pathToCheck); String absPath = path.toAbsolutePath().toString(); boolean isDuplicateFound = false; - for (String includePath : m_includePaths) + for (String includePath : m_includePaths) { // include paths are prefixed with "-I" - if (includePath.length() <= 2) + if (includePath.length() <= 2) { continue; } String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); - if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) { isDuplicateFound = true; break; } } - - if (isDuplicateFound) + + if (isDuplicateFound) { return true; } - - } - catch (InvalidPathException | IOError | SecurityException ex) + + } + catch (InvalidPathException | IOError | SecurityException ex) { // path operations failed, just returning false } -<<<<<<< HEAD - + return false; } -======= - return false; - } - - /* - * ---------------------------------------------------------------------------------------- - * Arguments - */ - private static final String case_sensitive_arg = "-cs"; - private static final String output_path_arg = "-d"; - private static final String default_container_prealloc_size = "-default-container-prealloc-size"; - private static final String default_extensibility_arg = "-default_extensibility"; - private static final String default_extensibility_short_arg = "-de"; - private static final String specific_platform_arg = "-example"; - private static final String extra_template_arg = "-extrastg"; - private static final String flat_output_directory_arg = "-flat-output-dir"; - private static final String fusion_arg = "-fusion"; - private static final String help_arg = "-help"; - private static final String include_path_arg = "-I"; - private static final String language_arg = "-language"; - private static final String no_typesupport_arg = "-no-typesupport"; - private static final String no_typeobjectsupport_arg = "-no-typeobjectsupport"; - private static final String no_dependencies_arg = "-no-dependencies"; - private static final String package_arg = "-package"; - private static final String disable_preprocessor_arg = "-ppDisable"; - private static final String preprocessor_path_arg = "-ppPath"; - private static final String python_bindings_arg = "-python"; - private static final String replace_arg = "-replace"; - private static final String temp_dir_arg = "-t"; - private static final String ros2_names_arg = "-typeros2"; - private static final String cnames_arg = "-typesc"; - private static final String version_arg = "-version"; - - /* - * ---------------------------------------------------------------------------------------- - * Developer Arguments - */ - private static final String generate_api_arg = "-genapi"; - private static final String execute_test_arg = "-test"; ->>>>>>> fbb0672 (Apply user template to included IDL files (#472) (#474)) public static void printHelp() {