Skip to content

Commit

Permalink
Merge branch 'dev_core'
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed May 20, 2020
2 parents bbd3c6d + 5fa444b commit ab8e9c3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ public Map<String, Template> loadTemplates(Trigger trigger)
if (templates.containsKey(ext.getRef())) {
Template template = templates.get(ext.getRef());
if (ext.getDestinationPath() != null) {
template.setUnresolvedTemplatePath(ext.getDestinationPath());
template.setUnresolvedTargetPath(ext.getDestinationPath());
}
if (ext.getMergeStrategy() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ public GenerationReportTo generate(Object input, List<? extends GenerableArtifac
Collection<TemplateTo> templatesToBeGenerated = flatten(generableArtifacts);

// generate
Map<File, File> tmpToOrigFileTrace = Maps.newHashMap();
Map<File, File> origToTmpFileTrace = Maps.newHashMap();
try {
for (TemplateTo template : templatesToBeGenerated) {
try {
Trigger trigger =
configurationHolder.readContextConfiguration().getTrigger(template.getTriggerId());
TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType());
InputValidator.validateTriggerInterpreter(triggerInterpreter, trigger);
tmpToOrigFileTrace.putAll(generate(template, triggerInterpreter));
generate(template, triggerInterpreter, origToTmpFileTrace);
progressCallback.accept("generates... ",
Math.round(1 / (float) templatesToBeGenerated.size() * 800));
} catch (CobiGenCancellationException e) {
Expand All @@ -198,11 +198,11 @@ public GenerationReportTo generate(Object input, List<? extends GenerableArtifac
// do nothing if cancelled
} else if (generationReport.isSuccessful()) {
try {
for (Entry<File, File> tmpToOrigFile : tmpToOrigFileTrace.entrySet()) {
Files.createDirectories(tmpToOrigFile.getValue().toPath().getParent());
Files.copy(tmpToOrigFile.getKey().toPath(), tmpToOrigFile.getValue().toPath(),
for (Entry<File, File> origToTmpFile : origToTmpFileTrace.entrySet()) {
Files.createDirectories(origToTmpFile.getKey().toPath().getParent());
Files.copy(origToTmpFile.getValue().toPath(), origToTmpFile.getKey().toPath(),
StandardCopyOption.REPLACE_EXISTING);
generationReport.addGeneratedFile(tmpToOrigFile.getValue().toPath());
generationReport.addGeneratedFile(origToTmpFile.getKey().toPath());
}
deleteTemporaryFiles();
} catch (IOException e) {
Expand Down Expand Up @@ -298,12 +298,14 @@ private void checkAndAddToTemplateMap(Map<String, TemplateTo> templateIdToTempla
* to be processed for generation
* @param triggerInterpreter
* {@link TriggerInterpreter} to be used for reading the input and creating the model
* @param origToTmpFileTrace
* the mapping of temporary generated files to their original target destination to eventually
* finalizing the generation process
* @throws InvalidConfigurationException
* if the inputs do not fit to the configuration or there are some configuration failures
* @return the mapping of temporary generated files to their original target destination to eventually
* finalizing the generation process
*/
private Map<File, File> generate(TemplateTo template, TriggerInterpreter triggerInterpreter) {
private void generate(TemplateTo template, TriggerInterpreter triggerInterpreter,
Map<File, File> origToTmpFileTrace) {

Trigger trigger = configurationHolder.readContextConfiguration().getTrigger(template.getTriggerId());

Expand All @@ -326,7 +328,6 @@ private Map<File, File> generate(TemplateTo template, TriggerInterpreter trigger
throw new UnknownTemplateException(template.getId());
}

Map<File, File> tmpToOrigFileTrace = Maps.newHashMap();
for (Object generatorInput : inputObjects) {

Map<String, Object> model = buildModel(triggerInterpreter, trigger, generatorInput, templateEty);
Expand All @@ -343,9 +344,15 @@ private Map<File, File> generate(TemplateTo template, TriggerInterpreter trigger
pathExpressionResolver.evaluateExpressions(templateEty.getUnresolvedTemplatePath());

File originalFile = targetRootPath.resolve(resolvedTargetDestinationPath).toFile();
File tmpOriginalFile = tmpTargetRootPath.resolve(resolvedTmpDestinationPath).toFile();
// remember mapping to later on copy the generated resources to its target destinations
tmpToOrigFileTrace.put(tmpOriginalFile, originalFile);
File tmpOriginalFile;
if (origToTmpFileTrace.containsKey(originalFile)) {
// use the available temporary file
tmpOriginalFile = origToTmpFileTrace.get(originalFile);
} else {
tmpOriginalFile = tmpTargetRootPath.resolve(resolvedTmpDestinationPath).toFile();
// remember mapping to later on copy the generated resources to its target destinations
origToTmpFileTrace.put(originalFile, tmpOriginalFile);
}

if (originalFile.exists() || tmpOriginalFile.exists()) {
if (!tmpOriginalFile.exists()) {
Expand Down Expand Up @@ -415,7 +422,6 @@ private Map<File, File> generate(TemplateTo template, TriggerInterpreter trigger
generateTemplateAndWriteFile(tmpOriginalFile, templateEty, templateEngine, model, targetCharset);
}
}
return tmpToOrigFileTrace;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import javax.inject.Inject;

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

import com.devonfw.cobigen.api.InputInterpreter;
import com.devonfw.cobigen.api.annotation.Cached;
import com.devonfw.cobigen.api.exception.CobiGenRuntimeException;
Expand All @@ -25,6 +28,9 @@
*/
public class InputInterpreterImpl implements InputInterpreter {

/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(InputInterpreterImpl.class);

/** Configuration interpreter instance */
@Inject
private TriggerMatchingEvaluator configurationInterpreter;
Expand Down Expand Up @@ -65,23 +71,16 @@ public Object read(Path path, Charset inputCharset, Object... additionalArgument
for (String s : keySet) {
try {
if (isMostLikelyReadable(s, path)) {
LOG.debug("Try reading input {} with inputreader '{}'...", path, s);
return getInputReader(s).read(path, inputCharset, additionalArguments);
}
} catch (InputReaderException e) {
// nothing to do.
}
}

// No input reader is most likely readable, then we try with every of them until we find the correct
// one
for (String s : keySet) {
try {
return getInputReader(s).read(path, inputCharset, additionalArguments);
} catch (InputReaderException e) {
// nothing to do.
LOG.debug(
"Was not able to read input {} with inputreader '{}' although it was reported to be most likely readable. Trying next input reader...",
path, s, e);
}
}
return null;
throw new InputReaderException("Could not read input at path " + path + " with any installed plugin.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,18 @@ public static URL getContextConfiguration(ClassLoader classLoader) throws Invali
* Initializes the ClassLoader with given URLs array
* @param urls
* URL[] Array of URLs to load into ClassLoader
* @param classLoader
* to add urls to
* @return ClassLoader to load resources from
*/
private static ClassLoader getUrlClassLoader(URL[] urls) {
private static ClassLoader getUrlClassLoader(URL[] urls, ClassLoader classLoader) {
ClassLoader inputClassLoader = null;
inputClassLoader = URLClassLoader.newInstance(urls, TemplatesClassloaderUtil.class.getClassLoader());
if (classLoader != null) {
inputClassLoader = URLClassLoader.newInstance(urls, classLoader);
} else {
inputClassLoader = URLClassLoader.newInstance(urls, TemplatesClassloaderUtil.class.getClassLoader());
}

return inputClassLoader;
}

Expand Down Expand Up @@ -123,7 +130,7 @@ public static List<Class<?>> resolveUtilClasses(Path configurationFolder, ClassL
if (configurationFolder != null) {
templateRoot = configurationFolder;
classLoaderUrls = addFoldersToClassLoaderUrls(configurationFolder);
inputClassLoader = getUrlClassLoader(classLoaderUrls.toArray(new URL[] {}));
inputClassLoader = getUrlClassLoader(classLoaderUrls.toArray(new URL[] {}), classLoader);
contextConfigurationLocation = configurationFolder.toUri().toURL();
} else {
inputClassLoader = classLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ public void testRelocate_overlappingTemplateExtensionAndScan() {
assertThat(template.getRelativeTemplatePath()).isEqualTo("templates/" + pathWithName);
assertThat(template.getAbsoluteTemplatePath().toString().replace('\\', '/'))
.isEqualTo(templatesConfigurationRoot + "templates/" + pathWithName);
assertThat(template.getUnresolvedTemplatePath()).isEqualTo(templateName);
assertThat(template.getUnresolvedTemplatePath())
.isEqualTo(templateScanDestinationPath + scanRelTemplatePath + templateName);
assertThat(template.getUnresolvedTargetPath()).isEqualTo(templateName);
}

Expand Down
2 changes: 1 addition & 1 deletion cobigen/cobigen-core-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<properties>
<cobigencore.version>6.1.0</cobigencore.version>
<cobigencore.version>6.1.1</cobigencore.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This document contains the documentation of the CobiGen core module as well as a

---

* CobiGen v6.1.0
* CobiGen v6.1.1
* CobiGen - Java Plug-in v2.2.0
* CobiGen - XML Plug-in v4.2.0
* CobiGen - TypeScript Plug-in v2.4.3
Expand Down

0 comments on commit ab8e9c3

Please sign in to comment.