2121
2222package com .igormaznitsa .jcp ;
2323
24+ import static com .igormaznitsa .jcp .InfoHelper .makeTextForHelpInfo ;
25+ import static com .igormaznitsa .jcp .utils .PreprocessorUtils .readWholeTextFileIntoArray ;
26+ import static com .igormaznitsa .jcp .utils .PreprocessorUtils .throwPreprocessorException ;
27+ import static com .igormaznitsa .meta .common .utils .Assertions .assertNotNull ;
28+
29+
2430import com .igormaznitsa .jcp .cmdline .AllowWhitespaceDirectiveHandler ;
2531import com .igormaznitsa .jcp .cmdline .CareForLastEolHandler ;
2632import com .igormaznitsa .jcp .cmdline .ClearTargetHandler ;
5359import com .igormaznitsa .jcp .expression .ValueType ;
5460import com .igormaznitsa .jcp .utils .PreprocessorUtils ;
5561import com .igormaznitsa .meta .annotation .MustNotContainNull ;
56- import lombok .Data ;
57- import org .apache .commons .io .FileUtils ;
58- import org .apache .commons .io .FilenameUtils ;
59- import org .springframework .util .AntPathMatcher ;
60-
61- import javax .annotation .Nonnull ;
6262import java .io .File ;
6363import java .io .IOException ;
6464import java .nio .charset .StandardCharsets ;
6969import java .util .List ;
7070import java .util .Locale ;
7171import java .util .Set ;
72-
73- import static com . igormaznitsa . jcp . InfoHelper . makeTextForHelpInfo ;
74- import static com . igormaznitsa . jcp . utils . PreprocessorUtils . readWholeTextFileIntoArray ;
75- import static com . igormaznitsa . jcp . utils . PreprocessorUtils . throwPreprocessorException ;
76- import static com . igormaznitsa . meta . common . utils . Assertions . assertNotNull ;
72+ import javax . annotation . Nonnull ;
73+ import lombok . Data ;
74+ import org . apache . commons . io . FileUtils ;
75+ import org . apache . commons . io . FilenameUtils ;
76+ import org . springframework . util . AntPathMatcher ;
7777
7878/**
7979 * The main class implements the Java Comment Preprocessor, it has the main
@@ -211,17 +211,22 @@ public PreprocessorContext getContext() {
211211 @ Nonnull
212212 public Statistics execute () throws IOException {
213213 final long timeStart = System .currentTimeMillis ();
214- processConfigFiles ();
215214
216- this .context .logInfo (String .format ("File extensions: %s excluded %s" , this .context .getExtensions (), this .context .getExcludeExtensions ()));
215+ this .context .getActivatedConfigFiles ().addAll (processConfigFiles ());
216+
217+ this .context .logInfo (String
218+ .format ("File extensions: %s excluded %s" , this .context .getExtensions (),
219+ this .context .getExcludeExtensions ()));
217220 final List <PreprocessorContext .SourceFolder > srcFolders = this .context .getSources ();
218221 this .context .logDebug ("Source folders: " + srcFolders );
219222
220223 if (srcFolders .isEmpty ()) {
221224 this .context .logWarning ("Source folder list is empty!" );
222225 }
223226
224- final Collection <FileInfoContainer > filesToBePreprocessed = collectFilesToPreprocess (srcFolders , this .context .getExcludeFolders ());
227+ final Collection <FileInfoContainer > filesToBePreprocessed =
228+ collectFilesToPreprocess (srcFolders , this .context .getExcludeFolders ());
229+ this .context .getPreprocessedResources ().addAll (filesToBePreprocessed );
225230
226231 final List <PreprocessingState .ExcludeIfInfo > excludedIf = processGlobalDirectives (filesToBePreprocessed );
227232
@@ -323,7 +328,9 @@ private Statistics preprocessFiles(@Nonnull @MustNotContainNull final Collection
323328 if (this .context .isVerbose ()) {
324329 this .context .logForVerbose (String .format ("Copy file %s -> {dst} %s" , PreprocessorUtils .getFilePath (fileRef .getSourceFile ()), fileRef .makeTargetFilePathAsString ()));
325330 }
326- PreprocessorUtils .copyFile (fileRef .getSourceFile (), destinationFile , this .context .isKeepAttributes ());
331+ PreprocessorUtils .copyFile (fileRef .getSourceFile (), destinationFile ,
332+ this .context .isKeepAttributes ());
333+ fileRef .getGeneratedResources ().add (destinationFile );
327334 copiedCounter ++;
328335 }
329336 }
@@ -332,12 +339,19 @@ private Statistics preprocessFiles(@Nonnull @MustNotContainNull final Collection
332339 fileRef .preprocessFile (null , this .context );
333340 final long elapsedTime = System .currentTimeMillis () - startTime ;
334341 if (this .context .isVerbose ()) {
335- this .context .logForVerbose (String .format ("File preprocessing completed '%s', elapsed time %d ms" , PreprocessorUtils .getFilePath (fileRef .getSourceFile ()), elapsedTime ));
342+ this .context .logForVerbose (String
343+ .format ("File preprocessing completed '%s', elapsed time %d ms" ,
344+ PreprocessorUtils .getFilePath (fileRef .getSourceFile ()), elapsedTime ));
336345 }
337346 preprocessedCounter ++;
338347 }
339348 }
340- return new Statistics (preprocessedCounter , copiedCounter , excludedCounter );
349+
350+ return new Statistics (
351+ preprocessedCounter ,
352+ copiedCounter ,
353+ excludedCounter
354+ );
341355 }
342356
343357 private void createTargetFolder () throws IOException {
@@ -430,7 +444,8 @@ private Set<File> findAllFiles(
430444 if (excludedFolderPattern == null ) {
431445 result .addAll (findAllFiles (sourceCanonicalPath , file , antPathMatcher , excludedFolderPatterns ));
432446 } else {
433- this .context .logForVerbose (String .format ("Folder '%s' excluded by '%s'" , folderPath , excludedFolderPattern ));
447+ this .context .logForVerbose (
448+ String .format ("Folder '%s' excluded by '%s'" , folderPath , excludedFolderPattern ));
434449 }
435450 } else {
436451 result .add (file );
@@ -440,9 +455,13 @@ private Set<File> findAllFiles(
440455 return result ;
441456 }
442457
443- void processConfigFiles () throws IOException {
458+ List <File > processConfigFiles () throws IOException {
459+
460+ final List <File > processedConfigFileList = new ArrayList <>();
444461
445462 for (final File file : context .getConfigFiles ()) {
463+ processedConfigFileList .add (file );
464+
446465 final String [] lines = readWholeTextFileIntoArray (file , StandardCharsets .UTF_8 , null );
447466
448467 int readStringIndex = -1 ;
@@ -499,6 +518,7 @@ void processConfigFiles() throws IOException {
499518 }
500519 }
501520 }
521+ return processedConfigFileList ;
502522 }
503523
504524 @ Data
0 commit comments