@@ -313,7 +313,7 @@ else if (arg.equals("-I"))
313313 if (count < args .length )
314314 {
315315 String pathStr = args [count ++];
316- if (!isIncludePathDuplicated (pathStr ))
316+ if (!isIncludePathDuplicated (pathStr ))
317317 {
318318 m_includePaths .add ("-I" .concat (pathStr ));
319319 }
@@ -557,39 +557,39 @@ private void showVersion()
557557 System .out .println (m_appName + " version " + version );
558558 }
559559
560- private boolean isIncludePathDuplicated (String pathToCheck )
560+ private boolean isIncludePathDuplicated (String pathToCheck )
561561 {
562- try
562+ try
563563 {
564564 Path path = Paths .get (pathToCheck );
565565 String absPath = path .toAbsolutePath ().toString ();
566566 boolean isDuplicateFound = false ;
567- for (String includePath : m_includePaths )
567+ for (String includePath : m_includePaths )
568568 {
569569 // include paths are prefixed with "-I"
570- if (includePath .length () <= 2 )
570+ if (includePath .length () <= 2 )
571571 {
572572 continue ;
573573 }
574574 String absIncludePath = Paths .get (includePath .substring (2 )).toAbsolutePath ().toString ();
575- if (absPath .toLowerCase ().equals (absIncludePath .toLowerCase ()))
575+ if (absPath .toLowerCase ().equals (absIncludePath .toLowerCase ()))
576576 {
577577 isDuplicateFound = true ;
578578 break ;
579579 }
580580 }
581-
582- if (isDuplicateFound )
581+
582+ if (isDuplicateFound )
583583 {
584584 return true ;
585585 }
586-
587- }
588- catch (InvalidPathException | IOError | SecurityException ex )
586+
587+ }
588+ catch (InvalidPathException | IOError | SecurityException ex )
589589 {
590590 // path operations failed, just returning false
591591 }
592-
592+
593593 return false ;
594594 }
595595
@@ -823,14 +823,19 @@ private Project parseIDL(
823823 for (Map .Entry <String , String > entry : m_customStgOutput .entrySet ())
824824 {
825825 System .out .println ("Loading custom template " + entry .getKey () + "..." );
826- Path path = Paths .get (entry .getKey ());
827- String templateName = path .getFileName ().toString ().substring (0 , path .getFileName ().toString ().lastIndexOf ('.' ));
828- try {
829- String content = new String (Files .readAllBytes (path ));
830- tmanager .addGroupFromString (templateName , content );
831- } catch (IOException e ){
832- System .out .println (ColorMessage .error (
833- "IOException" ) + "Cannot read content from " + path .toString ());
826+ loadAndAddTemplate (entry .getKey (), tmanager );
827+ }
828+ }
829+ else
830+ {
831+ // Check if there is a '@' in the output_file_name
832+ for (Map .Entry <String , String > entry : m_customStgOutput .entrySet ())
833+ {
834+ if (entry .getValue ().contains ("@" ))
835+ {
836+ System .out .println ("Loading custom template " +
837+ entry .getKey () + " for included IDL file " + idlFilename + "..." );
838+ loadAndAddTemplate (entry .getKey (), tmanager );
834839 }
835840 }
836841 }
@@ -874,25 +879,27 @@ private Project parseIDL(
874879 {
875880 for (Map .Entry <String , String > entry : m_customStgOutput .entrySet ())
876881 {
877- Path path = Paths .get (entry .getKey ());
878- String templateName = path .getFileName ().toString ().substring (0 , path .getFileName ().toString ().lastIndexOf ('.' ));
879- System .out .println ("Generating from custom " + templateName + " to " + entry .getValue ());
880-
881- if (returnedValue = Utils .writeFile (output_dir + entry .getValue (), maintemplates .getTemplate (templateName ), m_replace ))
882+ if (! (returnedValue = createOutputCustomTemplate (
883+ entry , idlFilename , output_dir , relative_dir , ctx .getFilename (),
884+ maintemplates , m_replace , project )))
882885 {
883- // Try to determine if the file is a header file.
884- if (entry .getValue ().contains (".hpp" ) || entry .getValue ().contains (".h" ))
885- {
886- project .addCommonIncludeFile (relative_dir + entry .getValue ());
887- }
888- else
889- {
890- project .addCommonSrcFile (relative_dir + ctx .getFilename () + entry .getValue ());
891- }
886+ break ;
892887 }
893- else
888+ }
889+ }
890+ else
891+ {
892+ // Check if there is a '$' in the output_file_name
893+ for (Map .Entry <String , String > entry : m_customStgOutput .entrySet ())
894+ {
895+ if (entry .getValue ().contains ("@" ))
894896 {
895- break ;
897+ if (! (returnedValue = createOutputCustomTemplate (
898+ entry , idlFilename , output_dir , relative_dir , ctx .getFilename (),
899+ maintemplates , m_replace , project )))
900+ {
901+ break ;
902+ }
896903 }
897904 }
898905 }
@@ -1129,6 +1136,55 @@ private Project parseIDL(
11291136 return returnedValue ? project : null ;
11301137 }
11311138
1139+ private void loadAndAddTemplate (
1140+ String templatePath ,
1141+ TemplateManager tmanager )
1142+ {
1143+ try
1144+ {
1145+ Path path = Paths .get (templatePath );
1146+ String templateName = path .getFileName ().toString ();
1147+ templateName = templateName .substring (0 , templateName .lastIndexOf ('.' ));
1148+ String content = new String (Files .readAllBytes (path ));
1149+ tmanager .addGroupFromString (templateName , content );
1150+ }
1151+ catch (IOException e )
1152+ {
1153+ System .out .println (ColorMessage .error ("IOException" ) + "Cannot read content from " + templatePath );
1154+ }
1155+ }
1156+
1157+ private boolean createOutputCustomTemplate (
1158+ Map .Entry <String , String > entry ,
1159+ String idlFilename ,
1160+ String outputDir ,
1161+ String relativeDir ,
1162+ String contextFilename ,
1163+ TemplateGroup maintemplates ,
1164+ boolean replace ,
1165+ Project project )
1166+ {
1167+ Path path = Paths .get (entry .getKey ());
1168+ String templateName = path .getFileName ().toString ();
1169+ templateName = templateName .substring (0 , templateName .lastIndexOf ('.' ));
1170+ String outputName = entry .getValue ().replace ("@" , idlFilename .substring (0 , idlFilename .lastIndexOf ('.' )));
1171+ System .out .println ("Generating from custom " + templateName + " to " + outputName );
1172+
1173+ boolean ret_val = Utils .writeFile (outputDir + outputName , maintemplates .getTemplate (templateName ), replace );
1174+ if (ret_val )
1175+ {
1176+ if (outputName .contains (".hpp" ) || outputName .contains (".h" ))
1177+ {
1178+ project .addCommonIncludeFile (relativeDir + outputName );
1179+ }
1180+ else
1181+ {
1182+ project .addCommonSrcFile (relativeDir + contextFilename + outputName );
1183+ }
1184+ }
1185+ return ret_val ;
1186+ }
1187+
11321188 private boolean genSolution (
11331189 Solution solution )
11341190 {
0 commit comments