Skip to content

Commit 6847a13

Browse files
cferreiragonzmergify[bot]
authored andcommitted
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 <[email protected]> (cherry picked from commit fbb0672) # Conflicts: # src/main/java/com/eprosima/fastdds/fastddsgen.java
1 parent 83c8b4b commit 6847a13

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

src/main/java/com/eprosima/fastdds/fastddsgen.java

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,50 @@ private boolean isIncludePathDuplicated(String pathToCheck)
580580
{
581581
// path operations failed, just returning false
582582
}
583+
<<<<<<< HEAD
583584

584585
return false;
585586
}
587+
=======
588+
return false;
589+
}
590+
591+
/*
592+
* ----------------------------------------------------------------------------------------
593+
* Arguments
594+
*/
595+
private static final String case_sensitive_arg = "-cs";
596+
private static final String output_path_arg = "-d";
597+
private static final String default_container_prealloc_size = "-default-container-prealloc-size";
598+
private static final String default_extensibility_arg = "-default_extensibility";
599+
private static final String default_extensibility_short_arg = "-de";
600+
private static final String specific_platform_arg = "-example";
601+
private static final String extra_template_arg = "-extrastg";
602+
private static final String flat_output_directory_arg = "-flat-output-dir";
603+
private static final String fusion_arg = "-fusion";
604+
private static final String help_arg = "-help";
605+
private static final String include_path_arg = "-I";
606+
private static final String language_arg = "-language";
607+
private static final String no_typesupport_arg = "-no-typesupport";
608+
private static final String no_typeobjectsupport_arg = "-no-typeobjectsupport";
609+
private static final String no_dependencies_arg = "-no-dependencies";
610+
private static final String package_arg = "-package";
611+
private static final String disable_preprocessor_arg = "-ppDisable";
612+
private static final String preprocessor_path_arg = "-ppPath";
613+
private static final String python_bindings_arg = "-python";
614+
private static final String replace_arg = "-replace";
615+
private static final String temp_dir_arg = "-t";
616+
private static final String ros2_names_arg = "-typeros2";
617+
private static final String cnames_arg = "-typesc";
618+
private static final String version_arg = "-version";
619+
620+
/*
621+
* ----------------------------------------------------------------------------------------
622+
* Developer Arguments
623+
*/
624+
private static final String generate_api_arg = "-genapi";
625+
private static final String execute_test_arg = "-test";
626+
>>>>>>> fbb0672 (Apply user template to included IDL files (#472) (#474))
586627

587628
public static void printHelp()
588629
{
@@ -783,9 +824,26 @@ private Project parseIDL(
783824
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
784825
{
785826
System.out.println("Loading custom template " + entry.getKey() + "...");
827+
<<<<<<< HEAD
786828
Path path = Paths.get(entry.getKey());
787829
String templateName = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf('.'));
788830
tmanager.addGroup(templateName);
831+
=======
832+
loadAndAddTemplate(entry.getKey(), tmanager);
833+
}
834+
}
835+
else
836+
{
837+
// Check if there is a '@' in the output_file_name
838+
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
839+
{
840+
if (entry.getValue().contains("@"))
841+
{
842+
System.out.println("Loading custom template " +
843+
entry.getKey() + " for included IDL file " + idlFilename + "...");
844+
loadAndAddTemplate(entry.getKey(), tmanager);
845+
}
846+
>>>>>>> fbb0672 (Apply user template to included IDL files (#472) (#474))
789847
}
790848
}
791849

@@ -828,6 +886,7 @@ private Project parseIDL(
828886
{
829887
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
830888
{
889+
<<<<<<< HEAD
831890
Path path = Paths.get(entry.getKey());
832891
String templateName = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf('.'));
833892
System.out.println("Generating from custom " + templateName + " to " + entry.getValue());
@@ -845,11 +904,32 @@ private Project parseIDL(
845904
}
846905
}
847906
else
907+
=======
908+
if (! (returnedValue = createOutputCustomTemplate(
909+
entry, idlFilename, output_dir, relative_dir, ctx.getFilename(),
910+
maintemplates, m_replace, project)))
911+
>>>>>>> fbb0672 (Apply user template to included IDL files (#472) (#474))
848912
{
849913
break;
850914
}
851915
}
852916
}
917+
else
918+
{
919+
// Check if there is a '$' in the output_file_name
920+
for (Map.Entry<String, String> entry : m_customStgOutput.entrySet())
921+
{
922+
if (entry.getValue().contains("@"))
923+
{
924+
if (! (returnedValue = createOutputCustomTemplate(
925+
entry, idlFilename, output_dir, relative_dir, ctx.getFilename(),
926+
maintemplates, m_replace, project)))
927+
{
928+
break;
929+
}
930+
}
931+
}
932+
}
853933

854934
System.out.println("Generating Type definition files...");
855935
if ((returnedValue) && (returnedValue =
@@ -1048,6 +1128,55 @@ private Project parseIDL(
10481128
return returnedValue ? project : null;
10491129
}
10501130

1131+
private void loadAndAddTemplate(
1132+
String templatePath,
1133+
TemplateManager tmanager)
1134+
{
1135+
try
1136+
{
1137+
Path path = Paths.get(templatePath);
1138+
String templateName = path.getFileName().toString();
1139+
templateName = templateName.substring(0, templateName.lastIndexOf('.'));
1140+
String content = new String(Files.readAllBytes(path));
1141+
tmanager.addGroupFromString(templateName, content);
1142+
}
1143+
catch (IOException e)
1144+
{
1145+
System.out.println(ColorMessage.error("IOException") + "Cannot read content from " + templatePath);
1146+
}
1147+
}
1148+
1149+
private boolean createOutputCustomTemplate(
1150+
Map.Entry<String, String> entry,
1151+
String idlFilename,
1152+
String outputDir,
1153+
String relativeDir,
1154+
String contextFilename,
1155+
TemplateGroup maintemplates,
1156+
boolean replace,
1157+
Project project)
1158+
{
1159+
Path path = Paths.get(entry.getKey());
1160+
String templateName = path.getFileName().toString();
1161+
templateName = templateName.substring(0, templateName.lastIndexOf('.'));
1162+
String outputName = entry.getValue().replace("@", idlFilename.substring(0, idlFilename.lastIndexOf('.')));
1163+
System.out.println("Generating from custom " + templateName + " to " + outputName);
1164+
1165+
boolean ret_val = Utils.writeFile(outputDir + outputName, maintemplates.getTemplate(templateName), replace);
1166+
if (ret_val)
1167+
{
1168+
if (outputName.contains(".hpp") || outputName.contains(".h"))
1169+
{
1170+
project.addCommonIncludeFile(relativeDir + outputName);
1171+
}
1172+
else
1173+
{
1174+
project.addCommonSrcFile(relativeDir + contextFilename + outputName);
1175+
}
1176+
}
1177+
return ret_val;
1178+
}
1179+
10511180
private boolean genSolution(
10521181
Solution solution)
10531182
{

0 commit comments

Comments
 (0)