-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from alberlau/feature/support-multiple-templat…
…e-engines Feature/support multiple template engines
- Loading branch information
Showing
19 changed files
with
225 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.db2code</groupId> | ||
<artifactId>DB2Code</artifactId> | ||
<version>1.3.8</version> | ||
</parent> | ||
|
||
<artifactId>freemarker-templating-provider</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>openapi-generator-maven-plugin</artifactId> | ||
<version>5.3.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.db2code</groupId> | ||
<artifactId>java-pojo-generator</artifactId> | ||
<version>1.3.8</version> | ||
</dependency> | ||
<!-- Add the FreeMarker templating engine --> | ||
<dependency> | ||
<groupId>org.freemarker</groupId> | ||
<artifactId>freemarker</artifactId> | ||
<version>2.3.32</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
...provider/src/main/java/org/db2code/generator/freemarker/FreemarkerTemplatingProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.db2code.generator.freemarker; | ||
|
||
import freemarker.template.Configuration; | ||
import freemarker.template.Template; | ||
import freemarker.template.TemplateException; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.db2code.generator.java.pojo.TemplatingProvider; | ||
|
||
public class FreemarkerTemplatingProvider implements TemplatingProvider { | ||
@Override | ||
public String merge(Object context, String templateLocation) { | ||
// Instantiating the Freemarker Configuration class | ||
Configuration config = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); | ||
// Setting the directory for the template | ||
// Loading the template | ||
StringWriter out; | ||
try { | ||
String fullPath = | ||
FilenameUtils.getFullPathNoEndSeparator( | ||
new File(new URI(templateLocation).getPath()).getAbsolutePath()); | ||
config.setDirectoryForTemplateLoading(new File(fullPath)); | ||
String name = FilenameUtils.getName(templateLocation); | ||
Template template = config.getTemplate(name); | ||
// Merging the template with the data model | ||
out = new StringWriter(); | ||
template.process(context, out); | ||
} catch (IOException | TemplateException e) { | ||
throw new RuntimeException(e); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return out.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ${package}; | ||
|
||
@SuppressWarnings({"PMD.DataClass"}) | ||
public class ${className} { | ||
|
||
<#list properties as property> | ||
private ${property.propertyType} ${property.propertyName}; | ||
</#list> | ||
|
||
<#list properties as property> | ||
public ${property.propertyType} get${property.methodName}() { | ||
return this.${property.propertyName}; | ||
} | ||
|
||
public void set${property.methodName}(${property.propertyType} ${property.propertyName}) { | ||
this.${property.propertyName} = ${property.propertyName}; | ||
} | ||
</#list> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.