Skip to content

Commit ee67d87

Browse files
authored
Fix/small freemarker example and generator adjustments (#183)
1 parent 3056672 commit ee67d87

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ before_install:
3333
- openssl aes-256-cbc -K $encrypted_324cf7253e32_key -iv $encrypted_324cf7253e32_iv
3434
-in secret-key.gpg.enc -out secret-key.gpg -d
3535

36+
cache:
37+
directories:
38+
- $HOME/.m2
39+
- $HOME/.gradle
40+

org.contextmapper.dsl.ui/samples/freemarker/markdown-templates/glossary/GlossaryTemplate.md.ftl

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
Glossary for '${filename}'
2-
=========================
1+
---
2+
title: Glossary for '${fileName}'
3+
project: ${projectName}
4+
author: ${userName}
5+
date: ${timeStamp}, Context Mapper version ${contextMapperVersion}
6+
copyright: The authors, 2020. All rights reserved.
7+
---
38

4-
This glossary forms the [ubiquituous language](https://martinfowler.com/bliki/UbiquitousLanguage.html) for '${filename}'.
9+
Ubiquitous Language Glossary for '${fileName}'
10+
=============================================
511

6-
Analysis Model
12+
This glossary forms the [ubiquituous language](https://martinfowler.com/bliki/UbiquitousLanguage.html) for '${fileName}'.
13+
14+
Analysis Model
715
--------------
816

9-
### Domain Overview
17+
<#if domains?has_content>
18+
## Domain Overview
1019

1120
<#list domains as d>
1221
Domain `${d.name}` has the following domain vision statement:
@@ -24,7 +33,9 @@ ${d.name} contains the following subdomains:
2433
</#list>
2534

2635
### Entities
27-
<#list d.subdomains as sd><#list sd.entities as e><#if e?has_content>
36+
<#list d.subdomains as sd>
37+
<#list sd.entities as e>
38+
<#if e?has_content>
2839
#### ${e.name}
2940
Entity in subdomain ${sd.name} (in domain ${d.name}).
3041
<#if e.hint?has_content>
@@ -45,15 +56,17 @@ Hint: ${e.hint!"*no hint given*"}
4556
* ${uc.name}
4657
</#list>
4758
</#if>
59+
</#if>
4860

4961
Design Model
50-
============
62+
------------
5163

52-
## Overview
64+
<#if filterBoundedContexts(boundedContexts)?has_content>
65+
## Bounded Context Overview
5366

5467
The following [bounded context](https://martinfowler.com/bliki/BoundedContext.html)s are defined:
5568

56-
<#list boundedContexts as bc>
69+
<#list filterBoundedContexts(boundedContexts) as bc>
5770
* *${bc.name}*: ${bc.domainVisionStatement!"[domain vision of the context not defined]"}
5871
</#list>
5972

@@ -150,12 +163,14 @@ It contains the following Bounded Contexts:
150163
* ${bc.name}
151164
</#list>
152165
</#if>
166+
</#if>
153167

154-
168+
<#if filterTeams(boundedContexts)?has_content>
155169
## Teams
156170
<#list filterTeams(boundedContexts) as team>
157171
* ${team.name}
158172
</#list>
173+
</#if>
159174

160175
<#macro renderDomainObjectOperationsAndAttributes simpleDomainObject>
161176
<#if simpleDomainObject.operations?has_content>

org.contextmapper.dsl.ui/src/org/contextmapper/dsl/ui/handler/GenericTextFileGenerationHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.core.commands.ExecutionEvent;
2727
import org.eclipse.core.resources.IFile;
2828
import org.eclipse.core.runtime.CoreException;
29+
import org.eclipse.core.runtime.IPath;
2930
import org.eclipse.core.runtime.IStatus;
3031
import org.eclipse.core.runtime.Platform;
3132
import org.eclipse.core.runtime.QualifiedName;
@@ -82,7 +83,9 @@ public void run() {
8283
}
8384

8485
private void registerCustomGenerationVariables(ExecutionEvent event) {
85-
generator.registerCustomModelProperty("projectname", getSelectedFile(event).getProject().getName());
86+
String projectName = getSelectedFile(event).getProject().getName();
87+
generator.registerCustomModelProperty("projectname", projectName); // for backwards compatibility
88+
generator.registerCustomModelProperty("projectName", projectName);
8689
Bundle contextMapperBundle = Platform.getBundle("org.contextmapper.dsl.ui");
8790
if (contextMapperBundle != null)
8891
generator.registerCustomModelProperty("contextMapperVersion", contextMapperBundle.getVersion().toString());
@@ -94,7 +97,8 @@ private GenerateGenericTextFileContext getLastStoredContext(ExecutionEvent event
9497
Map<QualifiedName, String> properties = selectedCmlFile.getPersistentProperties();
9598
if (!properties.containsKey(getQualifiedName4File(selectedCmlFile, LAST_SELECTED_TEMPLATE_PROPERTY)))
9699
return context;
97-
IFile templateFile = findFileInContainer(selectedCmlFile.getProject(), properties.get(getQualifiedName4File(selectedCmlFile, LAST_SELECTED_TEMPLATE_PROPERTY)));
100+
IFile templateFile = findFileInContainer(selectedCmlFile.getWorkspace().getRoot(),
101+
properties.get(getQualifiedName4File(selectedCmlFile, LAST_SELECTED_TEMPLATE_PROPERTY)));
98102
context.setFreemarkerTemplateFile(templateFile);
99103
if (properties.containsKey(getQualifiedName4File(selectedCmlFile, LAST_TARGET_FILE_NAME_PROPERTY)))
100104
context.setTargetFileName(properties.get(getQualifiedName4File(selectedCmlFile, LAST_TARGET_FILE_NAME_PROPERTY)));
@@ -106,8 +110,9 @@ private GenerateGenericTextFileContext getLastStoredContext(ExecutionEvent event
106110

107111
private void persistContext(GenerateGenericTextFileContext context) {
108112
try {
113+
IFile templateFile = context.getFreemarkerTemplateFile();
109114
selectedCmlFile.setPersistentProperty(getQualifiedName4File(selectedCmlFile, LAST_SELECTED_TEMPLATE_PROPERTY),
110-
context.getFreemarkerTemplateFile().getProjectRelativePath().toString());
115+
templateFile.getProject().getName() + IPath.SEPARATOR + templateFile.getProjectRelativePath().toString());
111116
selectedCmlFile.setPersistentProperty(getQualifiedName4File(selectedCmlFile, LAST_TARGET_FILE_NAME_PROPERTY), context.getTargetFileName());
112117
} catch (CoreException e) {
113118
StatusManager.getManager().handle(new Status(IStatus.ERROR, DslActivator.PLUGIN_ID, "Could not persist template file location.", e));

org.contextmapper.dsl/src/org/contextmapper/dsl/generator/freemarker/FreemarkerTextGenerator.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ private Map<String, Object> prepareModelData(ContextMappingModel contextMappingM
8888
dataMap.put("domains", contextMappingModel.getDomains());
8989
dataMap.put("imports", contextMappingModel.getImports());
9090
dataMap.put("useCases", contextMappingModel.getUseCases());
91-
dataMap.put("timestamp", new SimpleDateFormat("dd.MM.YYYY HH:mm:ss z").format(new Date()));
92-
dataMap.put("filename", contextMappingModel.eResource().getURI().lastSegment().toString());
93-
dataMap.put("username", System.getProperty("user.name"));
91+
String timeStamp = new SimpleDateFormat("dd.MM.YYYY HH:mm:ss z").format(new Date());
92+
dataMap.put("timestamp", timeStamp); // for backwards compatibility
93+
dataMap.put("timeStamp", timeStamp);
94+
String fileName = contextMappingModel.eResource().getURI().lastSegment().toString();
95+
dataMap.put("filename", fileName); // for backwards compatibility
96+
dataMap.put("fileName", fileName);
97+
String userName = System.getProperty("user.name");
98+
dataMap.put("username", userName); // for backwards compatibility
99+
dataMap.put("userName", userName);
94100

95101
dataMap.putAll(createTemplatingHelperMethods());
96102
dataMap.putAll(createClassMap());

0 commit comments

Comments
 (0)