Skip to content

Commit

Permalink
devonfw#1696: applied code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini committed Aug 10, 2023
1 parent 07599a9 commit f33d900
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.devonfw.cobigen.impl.config.reader;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
import com.devonfw.cobigen.api.util.TemplatesJarUtil;
import com.devonfw.cobigen.impl.config.ContextConfiguration;
import com.devonfw.cobigen.impl.config.TemplatesConfiguration;
import com.devonfw.cobigen.impl.config.entity.TemplateSet;
import com.devonfw.cobigen.impl.util.FileSystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Stream;

public class TemplateSetsConfigReader extends ConfigurationReader {

Expand All @@ -26,12 +31,13 @@ public class TemplateSetsConfigReader extends ConfigurationReader {
private final Map<String, TemplateSet> templateSets = new HashMap<>();

/**
* Need to cache template set reader as they read context and templates configuration in one go, while both is queried separately by the engine.
* It is fully initialized after context configuration read time.
* Need to cache template set reader as they read context and templates configuration in one go, while both is queried
* separately by the engine. It is fully initialized after context configuration read time.
*/
private final Map<String, TemplateSetReader> templateSetReaderCache = Collections.synchronizedMap(new HashMap<>());

public TemplateSetsConfigReader(Path configRoot) {

super(configRoot);
readTemplateSets(configRoot);
}
Expand Down Expand Up @@ -75,11 +81,14 @@ public ContextConfiguration readContextConfiguration() {

@Override
public TemplatesConfiguration readTemplatesConfiguration(String triggerOrTemplateSet) {

TemplateSetReader templateSetReader = templateSetReaderCache.get(triggerOrTemplateSet);
if (templateSetReader == null)
throw new InvalidConfigurationException("A template set with name '" + triggerOrTemplateSet + "' was referenced, but could not be found.");
throw new InvalidConfigurationException(
"A template set with name '" + triggerOrTemplateSet + "' was referenced, but could not be found.");

return templateSetReader.readTemplatesConfiguration(templateSetReader.readContextConfiguration().getTrigger(triggerOrTemplateSet));
return templateSetReader
.readTemplatesConfiguration(templateSetReader.readContextConfiguration().getTrigger(triggerOrTemplateSet));
}

/**
Expand All @@ -93,7 +102,7 @@ protected void loadTemplateSetFilesAdapted(Path configRoot) {

for (Path templateDirectory : templateSetDirectories) {
Path templateSetFilePath = templateDirectory.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER)
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME);
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME);

// makes sure that only valid template set folders get added
if (Files.exists(templateSetFilePath)) {
Expand All @@ -104,7 +113,8 @@ protected void loadTemplateSetFilesAdapted(Path configRoot) {
templateSets.put(templateDirectory.getFileName().toString(), new TemplateSet(templateDirectory));
}
} else {
LOG.info("Ignoring folder {} as template set as it does not contain {} on top-level.", templateDirectory, templateSetFilePath.getFileName());
LOG.info("Ignoring folder {} as template set as it does not contain {} on top-level.", templateDirectory,
templateSetFilePath.getFileName());
}
}
}
Expand Down Expand Up @@ -146,9 +156,11 @@ protected void loadTemplateSetFilesDownloaded(Path configRoot) {
// makes sure that only valid template set jars get added
if (Files.exists(templateSetFilePath)) {
// TODO clarify on invariant, that downloaded jars are stored without version suffix
this.templateSets.put(jarPath.getFileName().toString(), new TemplateSet(jarPath.getFileName().toString(), jarPath));
this.templateSets.put(jarPath.getFileName().toString(),
new TemplateSet(jarPath.getFileName().toString(), jarPath));
} else {
LOG.info("Ignoring jar {} as template set as it does not contain {} on top-level.", jarPath, templateSetFilePath.getFileName());
LOG.info("Ignoring jar {} as template set as it does not contain {} on top-level.", jarPath,
templateSetFilePath.getFileName());
}
}
}
Expand Down

0 comments on commit f33d900

Please sign in to comment.