Skip to content

Commit ef87060

Browse files
committed
Merge branch 'develop'
2 parents a0301b3 + 817be42 commit ef87060

File tree

113 files changed

+879
-873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+879
-873
lines changed

changes.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
2424
<body>
2525

26+
<release version="1.17.0" date="2024-01-26">
27+
<action type="update" dev="sseifert" issue="57">
28+
Special handling for detecting ".cfg.json" file extensions.
29+
</action>
30+
<action type="remove" dev="sseifert" issue="59">
31+
Remove Guava dependency.
32+
</action>
33+
</release>
34+
2635
<release version="1.16.4" date="2023-10-18">
2736
<action type="fix" dev="sseifert" issue="47">
2837
Increase SnakeYAML codepoint limit to 64MB (from default 3MB).

generator/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm.devops.conga</groupId>
2727
<artifactId>io.wcm.devops.conga.parent</artifactId>
28-
<version>1.16.4</version>
28+
<version>1.17.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>io.wcm.devops.conga</groupId>
4646
<artifactId>io.wcm.devops.conga.model</artifactId>
47-
<version>1.16.4</version>
47+
<version>1.17.0</version>
4848
<scope>compile</scope>
4949
</dependency>
5050

@@ -54,6 +54,12 @@
5454
<scope>compile</scope>
5555
</dependency>
5656

57+
<dependency>
58+
<groupId>com.github.ben-manes.caffeine</groupId>
59+
<artifactId>caffeine</artifactId>
60+
<scope>compile</scope>
61+
</dependency>
62+
5763
<dependency>
5864
<groupId>com.github.jknack</groupId>
5965
<artifactId>handlebars</artifactId>

generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
import static io.wcm.devops.conga.generator.ContextProperties.TENANTS_BY_ROLE;
3333
import static io.wcm.devops.conga.generator.ContextProperties.TENANT_ROLES;
3434
import static io.wcm.devops.conga.generator.ContextProperties.VERSION;
35+
import static java.util.Map.entry;
3536

3637
import java.util.ArrayList;
3738
import java.util.Collections;
3839
import java.util.HashMap;
3940
import java.util.List;
4041
import java.util.Map;
4142

42-
import com.google.common.collect.ImmutableMap;
43-
4443
import io.wcm.devops.conga.generator.util.ObjectCloner;
4544
import io.wcm.devops.conga.generator.util.VariableObjectTreeResolver;
4645
import io.wcm.devops.conga.generator.util.VariableStringResolver;
@@ -55,20 +54,20 @@
5554
*/
5655
public final class ContextPropertiesBuilder {
5756

58-
static final Map<String, Object> EMPTY_CONTEXT_VARIABLES = ImmutableMap.<String, Object>builder()
59-
.put(VERSION, "")
60-
.put(ENVIRONMENT, "")
61-
.put(NODES, Collections.emptyList())
62-
.put(NODES_BY_ROLE, Collections.emptyMap())
63-
.put(NODES_BY_ROLE_VARIANT, Collections.emptyMap())
64-
.put(TENANTS, Collections.emptyMap())
65-
.put(TENANTS_BY_ROLE, Collections.emptyMap())
66-
.put(ROLE, "")
67-
.put(ROLE_VARIANT, "")
68-
.put(NODE, "")
69-
.put(TENANT, "")
70-
.put(TENANT_ROLES, Collections.emptyList())
71-
.build();
57+
static final Map<String, Object> EMPTY_CONTEXT_VARIABLES = Map.ofEntries(
58+
entry(VERSION, ""),
59+
entry(ENVIRONMENT, ""),
60+
entry(NODES, Collections.emptyList()),
61+
entry(NODES_BY_ROLE, Collections.emptyMap()),
62+
entry(NODES_BY_ROLE_VARIANT, Collections.emptyMap()),
63+
entry(TENANTS, Collections.emptyMap()),
64+
entry(TENANTS_BY_ROLE, Collections.emptyMap()),
65+
entry(ROLE, ""),
66+
entry(ROLE_VARIANT, ""),
67+
entry(NODE, ""),
68+
entry(TENANT, ""),
69+
entry(TENANT_ROLES, Collections.emptyList())
70+
);
7271

7372
private ContextPropertiesBuilder() {
7473
// static methods only
@@ -83,6 +82,7 @@ private ContextPropertiesBuilder() {
8382
* @param variableStringResolver Variable string resolver
8483
* @return Context variables map
8584
*/
85+
@SuppressWarnings("java:S3776") // ignore complexity
8686
public static Map<String, Object> buildEnvironmentContextVariables(String environmentName,
8787
Environment environment, String version,
8888
VariableObjectTreeResolver variableObjectTreeResolver, VariableStringResolver variableStringResolver) {

generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.File;
2323
import java.io.IOException;
2424
import java.net.URL;
25+
import java.nio.file.Files;
2526
import java.util.ArrayList;
2627
import java.util.Collection;
2728
import java.util.Collections;
@@ -40,9 +41,6 @@
4041

4142
import com.github.jknack.handlebars.Handlebars;
4243
import com.github.jknack.handlebars.Template;
43-
import com.google.common.collect.ImmutableList;
44-
import com.google.common.collect.ImmutableMap;
45-
import com.google.common.collect.ImmutableSet;
4644

4745
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4846
import io.wcm.devops.conga.generator.export.NodeModelExport;
@@ -82,7 +80,7 @@
8280
/**
8381
* Generates file for one environment.
8482
*/
85-
class EnvironmentGenerator {
83+
final class EnvironmentGenerator {
8684

8785
private final GeneratorOptions options;
8886
private final String environmentName;
@@ -132,10 +130,10 @@ class EnvironmentGenerator {
132130
ResourceLoader resourceLoader = new ResourceLoader(resourceClassLoader);
133131

134132
// prepare template and role directories
135-
List<ResourceCollection> templateDirs = ImmutableList.of(
133+
List<ResourceCollection> templateDirs = List.of(
136134
resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getTemplateDir()),
137135
resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_TEMPLATES_DIR));
138-
List<ResourceCollection> roleDirs = ImmutableList.of(
136+
List<ResourceCollection> roleDirs = List.of(
139137
resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getRoleDir()),
140138
resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_ROLES_DIR));
141139

@@ -154,11 +152,11 @@ class EnvironmentGenerator {
154152
this.handlebarsManager = new HandlebarsManager(templateDirs, this.pluginContextOptions);
155153

156154
this.defaultMultiplyPlugin = options.getPluginManager().get(NoneMultiply.NAME, MultiplyPlugin.class);
157-
this.environmentContextProperties = ImmutableMap.copyOf(
155+
this.environmentContextProperties = Collections.unmodifiableMap(
158156
ContextPropertiesBuilder.buildEnvironmentContextVariables(environmentName, this.environment, options.getVersion(),
159157
variableObjectTreeResolver, variableStringResolver));
160158

161-
this.dependencyVersions = options.getDependencyVersionBuilder() != null ? options.getDependencyVersionBuilder().apply(environment) : ImmutableList.of();
159+
this.dependencyVersions = options.getDependencyVersionBuilder() != null ? options.getDependencyVersionBuilder().apply(environment) : List.of();
162160

163161
// prepare YAML representer
164162
yamlRepresenter = new YamlRepresenter();
@@ -178,7 +176,7 @@ public void generate(String[] nodeNames) {
178176
log.info("");
179177
log.info("===== Environment '{}' =====", environmentName);
180178

181-
Set<String> nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : ImmutableSet.copyOf(nodeNames);
179+
Set<String> nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : Set.of(nodeNames);
182180
for (Node node : environment.getNodes()) {
183181
if (isSelectedNode(node, nodeNamesIndex)) {
184182
generateNode(node);
@@ -241,8 +239,7 @@ private void generateNode(Node node) {
241239
mergedConfig.putAll(ContextPropertiesBuilder.buildCurrentContextVariables(node, nodeRole));
242240

243241
// collect role and tenant information for export model
244-
ExportNodeRoleData exportNodeRoleData = exportModelGenerator.addRole(roleName, variants, mergedConfig,
245-
role.getSensitiveConfigParameters());
242+
ExportNodeRoleData exportNodeRoleData = exportModelGenerator.addRole(roleName, variants, mergedConfig);
246243

247244
// generate files
248245
List<GeneratedFileContext> allFiles = new ArrayList<>();
@@ -321,6 +318,7 @@ private String getEscapingStrategy(RoleFile roleFile) {
321318
.getName();
322319
}
323320

321+
@SuppressWarnings("java:S107") // allow many parameters
324322
private void multiplyFiles(Role role, RoleFile roleFile, Map<String, Object> config, File nodeDir, Template template,
325323
String roleName, List<String> roleVariantNames, String templateName, List<GeneratedFileContext> generatedFiles) {
326324
MultiplyPlugin multiplyPlugin = defaultMultiplyPlugin;
@@ -367,7 +365,10 @@ private void multiplyFiles(Role role, RoleFile roleFile, Map<String, Object> con
367365
}
368366
}
369367

370-
@SuppressWarnings("PMD.PreserveStackTrace")
368+
@SuppressWarnings({
369+
"PMD.PreserveStackTrace",
370+
"java:S107" // allow many parameters
371+
})
371372
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
372373
private Collection<GeneratedFileContext> generateFile(RoleFile roleFile, String dir,
373374
String fileName, String url, String symlinkTarget,
@@ -386,7 +387,12 @@ private Collection<GeneratedFileContext> generateFile(RoleFile roleFile, String
386387

387388
File file = new File(nodeDir, dir != null ? FilenameUtils.concat(dir, generatedFileName) : generatedFileName);
388389
if (file.exists()) {
389-
file.delete();
390+
try {
391+
Files.delete(file.toPath());
392+
}
393+
catch (IOException ex) {
394+
throw new GeneratorException("Unable to delete: " + FileUtil.getCanonicalPath(file), ex);
395+
}
390396
}
391397

392398
FileGenerator fileGenerator = new FileGenerator(options, environmentName,

generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.slf4j.Logger;
4343

4444
import com.github.jknack.handlebars.Template;
45-
import com.google.common.collect.ImmutableList;
4645

4746
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4847
import 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

Comments
 (0)