Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate Guava #59

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.16.6" date="not released">
<release version="1.17.0" date="not released">
<action type="update" dev="sseifert" issue="57">
Special handling for detecting ".cfg.json" file extensions.
</action>
<action type="remove" dev="sseifert" issue="59">
Remove Guava dependency.
</action>
</release>

<release version="1.16.4" date="2023-10-18">
Expand Down
10 changes: 8 additions & 2 deletions generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.parent</artifactId>
<version>1.16.5-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand All @@ -44,7 +44,7 @@
<dependency>
<groupId>io.wcm.devops.conga</groupId>
<artifactId>io.wcm.devops.conga.model</artifactId>
<version>1.16.5-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand All @@ -54,6 +54,12 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
import static io.wcm.devops.conga.generator.ContextProperties.TENANTS_BY_ROLE;
import static io.wcm.devops.conga.generator.ContextProperties.TENANT_ROLES;
import static io.wcm.devops.conga.generator.ContextProperties.VERSION;
import static java.util.Map.entry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableMap;

import io.wcm.devops.conga.generator.util.ObjectCloner;
import io.wcm.devops.conga.generator.util.VariableObjectTreeResolver;
import io.wcm.devops.conga.generator.util.VariableStringResolver;
Expand All @@ -55,20 +54,20 @@
*/
public final class ContextPropertiesBuilder {

static final Map<String, Object> EMPTY_CONTEXT_VARIABLES = ImmutableMap.<String, Object>builder()
.put(VERSION, "")
.put(ENVIRONMENT, "")
.put(NODES, Collections.emptyList())
.put(NODES_BY_ROLE, Collections.emptyMap())
.put(NODES_BY_ROLE_VARIANT, Collections.emptyMap())
.put(TENANTS, Collections.emptyMap())
.put(TENANTS_BY_ROLE, Collections.emptyMap())
.put(ROLE, "")
.put(ROLE_VARIANT, "")
.put(NODE, "")
.put(TENANT, "")
.put(TENANT_ROLES, Collections.emptyList())
.build();
static final Map<String, Object> EMPTY_CONTEXT_VARIABLES = Map.ofEntries(
entry(VERSION, ""),
entry(ENVIRONMENT, ""),
entry(NODES, Collections.emptyList()),
entry(NODES_BY_ROLE, Collections.emptyMap()),
entry(NODES_BY_ROLE_VARIANT, Collections.emptyMap()),
entry(TENANTS, Collections.emptyMap()),
entry(TENANTS_BY_ROLE, Collections.emptyMap()),
entry(ROLE, ""),
entry(ROLE_VARIANT, ""),
entry(NODE, ""),
entry(TENANT, ""),
entry(TENANT_ROLES, Collections.emptyList())
);

private ContextPropertiesBuilder() {
// static methods only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.export.NodeModelExport;
Expand Down Expand Up @@ -132,10 +129,10 @@ final class EnvironmentGenerator {
ResourceLoader resourceLoader = new ResourceLoader(resourceClassLoader);

// prepare template and role directories
List<ResourceCollection> templateDirs = ImmutableList.of(
List<ResourceCollection> templateDirs = List.of(
resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getTemplateDir()),
resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_TEMPLATES_DIR));
List<ResourceCollection> roleDirs = ImmutableList.of(
List<ResourceCollection> roleDirs = List.of(
resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getRoleDir()),
resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_ROLES_DIR));

Expand All @@ -154,7 +151,7 @@ final class EnvironmentGenerator {
this.handlebarsManager = new HandlebarsManager(templateDirs, this.pluginContextOptions);

this.defaultMultiplyPlugin = options.getPluginManager().get(NoneMultiply.NAME, MultiplyPlugin.class);
this.environmentContextProperties = ImmutableMap.copyOf(
this.environmentContextProperties = Collections.unmodifiableMap(
ContextPropertiesBuilder.buildEnvironmentContextVariables(environmentName, this.environment, options.getVersion(),
variableObjectTreeResolver, variableStringResolver));

Expand All @@ -178,7 +175,7 @@ public void generate(String[] nodeNames) {
log.info("");
log.info("===== Environment '{}' =====", environmentName);

Set<String> nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : ImmutableSet.copyOf(nodeNames);
Set<String> nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : Set.of(nodeNames);
for (Node node : environment.getNodes()) {
if (isSelectedNode(node, nodeNamesIndex)) {
generateNode(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.slf4j.Logger;

import com.github.jknack.handlebars.Template;
import com.google.common.collect.ImmutableList;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.plugins.fileheader.NoneFileHeader;
Expand Down Expand Up @@ -423,7 +422,7 @@ private Collection<GeneratedFileContext> applyPostProcessor(FileContext fileItem
private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFiles, PostProcessorPlugin plugin) {

// process all files from given map
ImmutableList.copyOf(consolidatedFiles.values()).stream()
List.copyOf(consolidatedFiles.values()).stream()
// do not apply post processor twice
.filter(fileItem -> !fileItem.getPostProcessors().contains(plugin.getName()))
.filter(fileItem -> plugin.accepts(fileItem.getFileContext(), postProcessorContext))
Expand All @@ -441,7 +440,7 @@ private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFi
});

// remove items that do no longer exist
ImmutableList.copyOf(consolidatedFiles.values()).forEach(fileItem -> {
List.copyOf(consolidatedFiles.values()).forEach(fileItem -> {
if (!fileItem.getFileContext().getFile().exists()) {
consolidatedFiles.remove(fileItem.getFileContext().getCanonicalPath());
}
Expand Down Expand Up @@ -469,7 +468,7 @@ private void applyPostProcessor(Map<String, GeneratedFileContext> consolidatedFi
});

// remove items that do no longer exist
ImmutableList.copyOf(consolidatedFiles.values()).forEach(fileItem -> {
List.copyOf(consolidatedFiles.values()).forEach(fileItem -> {
if (!fileItem.getFileContext().getFile().exists()) {
consolidatedFiles.remove(fileItem.getFileContext().getCanonicalPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import org.apache.commons.io.FileUtils;

import com.google.common.collect.ImmutableList;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.util.FileUtil;
import io.wcm.devops.conga.model.environment.Environment;
Expand All @@ -54,7 +52,7 @@ public Generator(GeneratorOptions options) {

ClassLoader resourceClassLoader = ResourceLoaderUtil.buildClassLoader(options.getContainerClasspathUrls());
ResourceLoader resourceLoader = new ResourceLoader(resourceClassLoader);
List<ResourceCollection> environmentDirs = ImmutableList.of(
List<ResourceCollection> environmentDirs = List.of(
resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getEnvironmentDir()),
resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_ENVIRONMENTS_DIR));
this.environments = ResourceLoaderUtil.readModels(environmentDirs, new EnvironmentReader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FilenameUtils;

import com.google.common.collect.ImmutableMap;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.spi.context.PluginContextOptions;
import io.wcm.devops.conga.generator.spi.context.UrlFilePluginContext;
Expand Down Expand Up @@ -114,7 +113,7 @@ public static <T> Map<String, T> readModels(List<ResourceCollection> dirs, Model
}
}
}
return ImmutableMap.copyOf(models);
return Collections.unmodifiableMap(models);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;

import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.jknack.handlebars.EscapingStrategy;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
Expand All @@ -31,11 +33,7 @@
import com.github.jknack.handlebars.helper.ConditionalHelpers;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.io.TemplateLoader;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.spi.context.PluginContextOptions;
import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin;
import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
Expand All @@ -55,7 +53,7 @@ public class HandlebarsManager {
private final HelperContext helperContext;

private final LoadingCache<HandlebarsKey, Handlebars> handlebarsCache =
CacheBuilder.newBuilder().build(new CacheLoader<HandlebarsKey, Handlebars>() {
Caffeine.newBuilder().build(new CacheLoader<HandlebarsKey, Handlebars>() {
@SuppressWarnings("unchecked")
@Override
public Handlebars load(HandlebarsKey options) throws Exception {
Expand Down Expand Up @@ -108,12 +106,7 @@ public HandlebarsManager(List<ResourceCollection> templateDirs, PluginContextOpt
*/
public Handlebars get(String escapingStrategy, String charset) {
HandlebarsKey key = new HandlebarsKey(escapingStrategy, charset);
try {
return handlebarsCache.get(key);
}
catch (ExecutionException ex) {
throw new GeneratorException("Unable to get handlebars instance for " + key.toString(), ex);
}
return handlebarsCache.get(key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.yaml.snakeyaml.Yaml;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.spi.export.NodeModelExportPlugin;
import io.wcm.devops.conga.generator.spi.export.context.ExportNodeRoleData;
Expand Down Expand Up @@ -74,7 +73,7 @@ public void export(NodeModelExportContext context) {

Map<String, String> versionInfo = context.getContainerVersionInfo();
if (versionInfo != null) {
modelMap.put("versionInfo", ImmutableSortedMap.copyOf(versionInfo));
modelMap.put("versionInfo", Collections.unmodifiableSortedMap(new TreeMap<>(versionInfo)));
}

// save YAML file
Expand All @@ -101,7 +100,7 @@ private void addRole(List<Map<String, Object>> modelList, ExportNodeRoleData rol
Map<String, Object> itemMap = new LinkedHashMap<>();
itemMap.put("path", cleanupFileName(item.getFileContext().getCanonicalPath(), nodeDirPath));
if (!item.getPostProcessors().isEmpty()) {
itemMap.put("postProcessors", ImmutableList.copyOf(item.getPostProcessors()));
itemMap.put("postProcessors", List.copyOf(item.getPostProcessors()));
}
Map<String, Object> modelOptions = item.getFileContext().getModelOptions();
if (modelOptions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.ImmutableList;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.spi.FileHeaderPlugin;
Expand Down Expand Up @@ -120,7 +119,7 @@ protected final FileHeaderContext extractFileHeaderBetweenBlockStartEnd(FileCont
int posBlockEnd = content.indexOf(getCommentBlockEnd());
if (posBlockStart == insertPosition && posBlockEnd > 0) {
String fileHeader = content.substring(posBlockStart + getCommentBlockStart().length(), posBlockEnd);
List<String> lines = ImmutableList.copyOf(StringUtils.split(fileHeader, getLineBreak()));
List<String> lines = Arrays.asList(StringUtils.split(fileHeader, getLineBreak()));
return new FileHeaderContext().commentLines(lines);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;

import javax.xml.XMLConstants;
Expand All @@ -40,8 +41,6 @@
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import com.google.common.collect.ImmutableList;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.spi.FileHeaderPlugin;
Expand Down Expand Up @@ -121,7 +120,7 @@ public FileHeaderContext extract(FileContext file) {
Node firstNode = doc.getChildNodes().item(0);
if (firstNode instanceof Comment) {
String comment = StringUtils.trim(((Comment)firstNode).getTextContent());
List<String> lines = ImmutableList.copyOf(StringUtils.split(comment, "\n"));
List<String> lines = Arrays.asList(StringUtils.split(comment, "\n"));
return new FileHeaderContext().commentLines(lines);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand All @@ -34,7 +35,6 @@
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.helper.EachHelper;
import com.google.common.collect.ImmutableList;

import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext;
Expand Down Expand Up @@ -67,7 +67,7 @@ public final Object apply(Object context, Options options, HelperContext pluginC
}
}
else {
return apply(ImmutableList.of(context), options, pluginContext);
return apply(List.of(context), options, pluginContext);
}
}
return delegate.apply(context, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package io.wcm.devops.conga.generator.plugins.handlebars.helper;

import com.google.common.base.Objects;
import java.util.Objects;

/**
* Handlebars helper that extends the each helper by iterating only on list items that have a specified property set to
Expand All @@ -41,7 +41,7 @@ public EachIfEqualsHelper() {
if (expectedValue == null) {
return false;
}
return Objects.equal(value, expectedValue);
return Objects.equals(value, expectedValue);
});
}

Expand Down
Loading