2121
2222package com .igormaznitsa .jcp .containers ;
2323
24+ import static java .util .Objects .requireNonNull ;
25+
26+
2427import com .igormaznitsa .jcp .context .PreprocessingState ;
2528import com .igormaznitsa .jcp .context .PreprocessorContext ;
2629import com .igormaznitsa .jcp .directives .AbstractDirectiveHandler ;
3538import java .util .Collection ;
3639import java .util .HashSet ;
3740import java .util .List ;
38- import java .util .Objects ;
3941import java .util .Set ;
4042import java .util .regex .Matcher ;
4143import java .util .regex .Pattern ;
@@ -67,9 +69,13 @@ public class FileInfoContainer {
6769 */
6870 private final boolean copyOnly ;
6971 /**
70- * List of file generated from the file.
72+ * Collection of files generated with the file.
7173 */
7274 private final Collection <File > generatedResources = new HashSet <>();
75+ /**
76+ * Collection of files which took part during preprocessing of the file
77+ */
78+ private final Collection <File > includedSources = new HashSet <>();
7379 /**
7480 * The flag shows that the file has been excluded from preprocessing and it will not be preprocessed and copied
7581 */
@@ -85,8 +91,8 @@ public class FileInfoContainer {
8591
8692 public FileInfoContainer (final File srcFile , final String targetFileName ,
8793 final boolean copyOnly ) {
88- Objects . requireNonNull (srcFile , "Source file is null" );
89- Objects . requireNonNull (targetFileName , "Target file name is null" );
94+ requireNonNull (srcFile , "Source file is null" );
95+ requireNonNull (targetFileName , "Target file name is null" );
9096
9197 this .copyOnly = copyOnly ;
9298 excludedFromPreprocessing = false ;
@@ -123,12 +129,12 @@ private static String findTailRemover(final String str, final PreprocessorContex
123129 }
124130
125131 public void setTargetFolder (final String targetFolder ) {
126- this .targetFolder = Objects . requireNonNull (targetFolder , "Target folder must not be null" );
132+ this .targetFolder = requireNonNull (targetFolder , "Target folder must not be null" );
127133 }
128134
129135 public void setTargetName (final String targetName ) {
130136 this .targetFileName =
131- Objects . requireNonNull (targetFileName , "Target file name must not be null" );
137+ requireNonNull (targetFileName , "Target file name must not be null" );
132138 }
133139
134140
@@ -206,7 +212,7 @@ public List<PreprocessingState.ExcludeIfInfo> processGlobalDirectives(
206212 }
207213 }
208214 if (!preprocessingState .isIfStackEmpty ()) {
209- final TextFileDataContainer lastIf = Objects . requireNonNull (preprocessingState .peekIf ());
215+ final TextFileDataContainer lastIf = requireNonNull (preprocessingState .peekIf ());
210216 throw new PreprocessorException (
211217 "Unclosed " + AbstractDirectiveHandler .DIRECTIVE_PREFIX + "_if instruction detected" ,
212218 "" , new FilePositionInfo [] {
@@ -336,8 +342,12 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
336342 context .clearLocalVariables ();
337343 }
338344
339- final PreprocessingState preprocessingState =
340- state != null ? state : context .produceNewPreprocessingState (this , 1 );
345+ final PreprocessingState preprocessingState ;
346+ if (state == null ) {
347+ preprocessingState = context .produceNewPreprocessingState (this , 1 );
348+ } else {
349+ preprocessingState = state ;
350+ }
341351
342352 String leftTrimmedString = null ;
343353
@@ -402,7 +412,7 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
402412 AbstractDirectiveHandler .PREFIX_FOR_KEEPING_LINES_PROCESSED_DIRECTIVES +
403413 extractedDirective ;
404414 final ResetablePrinter thePrinter =
405- Objects . requireNonNull (preprocessingState .getPrinter ());
415+ requireNonNull (preprocessingState .getPrinter ());
406416 if (doPrintLn ) {
407417 thePrinter .println (text , context .getEol ());
408418 } else {
@@ -416,7 +426,7 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
416426 AbstractDirectiveHandler .PREFIX_FOR_KEEPING_LINES_PROCESSED_DIRECTIVES +
417427 extractedDirective ;
418428 final ResetablePrinter thePrinter =
419- Objects . requireNonNull (preprocessingState .getPrinter ());
429+ requireNonNull (preprocessingState .getPrinter ());
420430 if (doPrintLn ) {
421431 thePrinter .println (text , context .getEol ());
422432 } else {
@@ -429,7 +439,7 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
429439 }
430440 }
431441
432- final ResetablePrinter thePrinter = Objects . requireNonNull (preprocessingState .getPrinter ());
442+ final ResetablePrinter thePrinter = requireNonNull (preprocessingState .getPrinter ());
433443 if (preprocessingState .isDirectiveCanBeProcessed () &&
434444 !preprocessingState .getPreprocessingFlags ()
435445 .contains (PreprocessingFlag .TEXT_OUTPUT_DISABLED )) {
@@ -494,22 +504,22 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
494504
495505 if (!preprocessingState .isIfStackEmpty ()) {
496506 final TextFileDataContainer lastIf =
497- Objects . requireNonNull (preprocessingState .peekIf (), "'IF' stack is empty" );
507+ requireNonNull (preprocessingState .peekIf (), "'IF' stack is empty" );
498508 throw new PreprocessorException (
499509 "Unclosed " + AbstractDirectiveHandler .DIRECTIVE_PREFIX + "if instruction detected" ,
500510 "" , new FilePositionInfo [] {
501511 new FilePositionInfo (lastIf .getFile (), lastIf .getNextStringIndex ())}, null );
502512 }
503513 if (!preprocessingState .isWhileStackEmpty ()) {
504514 final TextFileDataContainer lastWhile =
505- Objects . requireNonNull (preprocessingState .peekWhile (), "'WHILE' stack is empty" );
515+ requireNonNull (preprocessingState .peekWhile (), "'WHILE' stack is empty" );
506516 throw new PreprocessorException (
507517 "Unclosed " + AbstractDirectiveHandler .DIRECTIVE_PREFIX + "while instruction detected" ,
508518 "" , new FilePositionInfo [] {
509519 new FilePositionInfo (lastWhile .getFile (), lastWhile .getNextStringIndex ())}, null );
510520 }
511521
512- if (!context .isDryRun () && Objects . requireNonNull (lastTextFileDataContainer ).isAutoFlush ()) {
522+ if (!context .isDryRun () && requireNonNull (lastTextFileDataContainer ).isAutoFlush ()) {
513523 final File outFile = context .createDestinationFileForPath (makeTargetFilePathAsString ());
514524
515525 final boolean wasSaved =
0 commit comments