4242import org .slf4j .Logger ;
4343
4444import com .github .jknack .handlebars .Template ;
45- import com .google .common .collect .ImmutableList ;
4645
4746import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
4847import io .wcm .devops .conga .generator .plugins .fileheader .NoneFileHeader ;
@@ -98,14 +97,13 @@ class FileGenerator {
9897 static final String POSTPROCESSOR_KEY_FILE_HEADER = "postProcessor.fileHeader" ;
9998 static final String POSTPROCESSOR_KEY_VALIDATORS = "postProcessor.validators" ;
10099
101- //CHECKSTYLE:OFF
100+ @ SuppressWarnings ({ "java:S107" , "checkstyle:ParameterNumberCheck" }) // allow many parameters
102101 FileGenerator (GeneratorOptions options , String environmentName ,
103102 String roleName , List <String > roleVariantNames , String templateName ,
104103 File nodeDir , File file , String url , String symlinkTarget ,
105104 RoleFile roleFile , Map <String , Object > config , Template template ,
106105 VariableMapResolver variableMapResolver , UrlFileManager urlFileManager , PluginContextOptions pluginContextOptions ,
107106 Collection <String > dependencyVersions ) {
108- //CHECKSTYLE:ON
109107 this .environmentName = environmentName ;
110108 this .roleName = roleName ;
111109 this .roleVariantNames = roleVariantNames ;
@@ -207,6 +205,10 @@ private List<String> formatFileHeaderCommentLines(List<String> lines) {
207205 * @return List of files that where generated directly or indirectly (by post processors).
208206 */
209207 @ SuppressFBWarnings ({ "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" , "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" })
208+ @ SuppressWarnings ({
209+ "java:S3776" , // ignore complexity
210+ "java:S2696" // static variable set by intention
211+ })
210212 public Collection <GeneratedFileContext > generate () throws IOException {
211213 File dir = file .getParentFile ();
212214 if (!dir .exists ()) {
@@ -215,7 +217,9 @@ public Collection<GeneratedFileContext> generate() throws IOException {
215217
216218 Collection <GeneratedFileContext > postProcessedFiles ;
217219 if (template != null ) {
218- log .info ("Generate file {}" , getFilenameForLog (fileContext ));
220+ if (log .isInfoEnabled ()) {
221+ log .info ("Generate file {}" , getFilenameForLog (fileContext ));
222+ }
219223
220224 // generate with template
221225 generateWithTemplate ();
@@ -231,7 +235,9 @@ else if (StringUtils.isNotBlank(url)) {
231235 // if copying from a local file try to create a symlink instead of coyping it
232236 boolean symlinkCreated = false ;
233237 if (allowSymlinks && !symlinkCreationFailed && urlFileManager .isLocalFile (url ) && !roleFile .isDeleteSource ()) {
234- log .info ("Symlink file {} from {}" , getFilenameForLog (fileContext ), url );
238+ if (log .isInfoEnabled ()) {
239+ log .info ("Symlink file {} from {}" , getFilenameForLog (fileContext ), url );
240+ }
235241 if (createSymlinkToLocalFile ()) {
236242 symlinkCreated = true ;
237243 }
@@ -242,7 +248,9 @@ else if (StringUtils.isNotBlank(url)) {
242248
243249 // generate by downloading/copying from URL
244250 if (!symlinkCreated ) {
245- log .info ("Copy file {} from {}" , getFilenameForLog (fileContext ), url );
251+ if (log .isInfoEnabled ()) {
252+ log .info ("Copy file {} from {}" , getFilenameForLog (fileContext ), url );
253+ }
246254 copyFromUrlFile ();
247255 }
248256
@@ -310,7 +318,7 @@ private boolean createSymlinkToLocalFile() throws IOException {
310318 }
311319 catch (IOException ex ) {
312320 // creates symbolic link failed - log warning and fallback to copying content
313- log .warn ("Unable to create symbolic link: " + ex .getMessage ());
321+ log .warn ("Unable to create symbolic link: {}" , ex .getMessage ());
314322 return false ;
315323 }
316324 }
@@ -333,7 +341,7 @@ private void createSymlinkToSymlinkTarget() throws IOException {
333341 }
334342 catch (IOException ex ) {
335343 // creates symbolic link failed - create text file with link instead (similar to git)
336- log .warn ("Created link textfile instead of symbolic link: " + ex .getMessage ());
344+ log .warn ("Created link textfile instead of symbolic link: {}" , ex .getMessage ());
337345 FileUtils .write (linkPath .toFile (), relativizedPath .toString (), StandardCharsets .UTF_8 );
338346 }
339347 }
@@ -387,7 +395,9 @@ private void applyFileHeader(FileContext fileItem, String pluginName) {
387395 }
388396
389397 private void applyFileHeader (FileContext fileItem , FileHeaderPlugin plugin ) {
390- log .debug (" Add {} file header to file {}" , plugin .getName (), getFilenameForLog (fileItem ));
398+ if (log .isDebugEnabled ()) {
399+ log .debug (" Add {} file header to file {}" , plugin .getName (), getFilenameForLog (fileItem ));
400+ }
391401 plugin .apply (fileItem , fileHeaderContext );
392402 }
393403
@@ -398,7 +408,9 @@ private void applyValidation(FileContext fileItem, List<String> pluginNames) {
398408 }
399409
400410 private void applyValidation (FileContext fileItem , ValidatorPlugin plugin ) {
401- log .info (" Validate {} for file {}" , plugin .getName (), getFilenameForLog (fileItem ));
411+ if (log .isInfoEnabled ()) {
412+ log .info (" Validate {} for file {}" , plugin .getName (), getFilenameForLog (fileItem ));
413+ }
402414 plugin .apply (fileItem , validatorContext );
403415 }
404416
@@ -423,7 +435,7 @@ private Collection<GeneratedFileContext> applyPostProcessor(FileContext fileItem
423435 private void applyPostProcessor (Map <String , GeneratedFileContext > consolidatedFiles , PostProcessorPlugin plugin ) {
424436
425437 // process all files from given map
426- ImmutableList .copyOf (consolidatedFiles .values ()).stream ()
438+ List .copyOf (consolidatedFiles .values ()).stream ()
427439 // do not apply post processor twice
428440 .filter (fileItem -> !fileItem .getPostProcessors ().contains (plugin .getName ()))
429441 .filter (fileItem -> plugin .accepts (fileItem .getFileContext (), postProcessorContext ))
@@ -441,14 +453,14 @@ private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFi
441453 });
442454
443455 // remove items that do no longer exist
444- ImmutableList .copyOf (consolidatedFiles .values ()).forEach (fileItem -> {
456+ List .copyOf (consolidatedFiles .values ()).forEach (fileItem -> {
445457 if (!fileItem .getFileContext ().getFile ().exists ()) {
446458 consolidatedFiles .remove (fileItem .getFileContext ().getCanonicalPath ());
447459 }
448460 });
449461
450462 // apply post processor configured as implicit ALWAYS
451- consolidatedFiles .values ().forEach (fileItem -> {
463+ consolidatedFiles .values ().forEach (fileItem ->
452464 pluginManager .getAll (PostProcessorPlugin .class ).stream ()
453465 .filter (implicitPlugin -> implicitPlugin .accepts (fileItem .getFileContext (), postProcessorContext ))
454466 .filter (implicitPlugin -> implicitPlugin .implicitApply (fileItem .getFileContext (), postProcessorContext ) == ImplicitApplyOptions .ALWAYS )
@@ -465,11 +477,11 @@ private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFi
465477 }
466478 generatedFileContext .postProcessor (implicitPlugin .getName ());
467479 });
468- });
469- } );
480+ })
481+ );
470482
471483 // remove items that do no longer exist
472- ImmutableList .copyOf (consolidatedFiles .values ()).forEach (fileItem -> {
484+ List .copyOf (consolidatedFiles .values ()).forEach (fileItem -> {
473485 if (!fileItem .getFileContext ().getFile ().exists ()) {
474486 consolidatedFiles .remove (fileItem .getFileContext ().getCanonicalPath ());
475487 }
@@ -478,7 +490,9 @@ private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFi
478490 }
479491
480492 private List <FileContext > applyPostProcessor (FileContext fileItem , PostProcessorPlugin plugin ) {
481- log .info (" Post-process {} for file {}" , plugin .getName (), getFilenameForLog (fileItem ));
493+ if (log .isInfoEnabled ()) {
494+ log .info (" Post-process {} for file {}" , plugin .getName (), getFilenameForLog (fileItem ));
495+ }
482496
483497 List <FileContext > processedFiles = plugin .apply (fileItem , postProcessorContext );
484498
@@ -510,7 +524,7 @@ private List<String> getPostProcessorValidators() {
510524 return (List <String >)validators ;
511525 }
512526 else {
513- return ImmutableList .of ();
527+ return List .of ();
514528 }
515529 }
516530
0 commit comments