Skip to content
Permalink
Browse files
FREEMARKER-136 freemarker-generator: Fix broken "site:stage" build (#8)
* FREEMARKER-136 freemarker-generator: Fix broken "site:stage" build

* FREEMARKER-136 freemarker-generator: Fix broken "site:stage" build

* FREEMARKER-136 freemarker-generator: Fix broken "site:stage" build

* FREEMARKER-136 freemarker-generator: Fix broken site:stage build

* FREEMARKER-136 freemarker-generator: Fix broken "site:stage" build
  • Loading branch information
sgoeschl committed Mar 13, 2020
1 parent 64ad16b commit 2e4517b0d6f04b4fc9de7788b74caf7f23ac5efb
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 39 deletions.
@@ -22,6 +22,7 @@ build.properties
archive/
ide-dependencies/
META-INF
velocity.log

out/
bin/
@@ -26,8 +26,8 @@
</parent>

<artifactId>freemarker-generator-base</artifactId>
<name>Apache FreeMarker Generator: Base</name>
<description>Common functionality</description>
<name>Base</name>
<description>Common functionality independent from Apache FreeMarker</description>

<dependencies>
<dependency>
@@ -48,15 +48,22 @@

<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<exclude>*.md</exclude>
<exclude>README.md</exclude>
<exclude>src/site/markdown/**/*.md</exclude>
<exclude>**/*.csv</exclude>
<exclude>src/test/data/txt/file_01.txt</exclude>
</excludes>
</excludes>
</configuration>
</plugin>
</plugins>
@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.freemarker.generator.base;

import java.nio.charset.Charset;
@@ -58,6 +58,7 @@ public class DatasourcesSupplier implements Supplier<List<Datasource>> {
*
* @param sources List of source files and/or directories
* @param include Optional include pattern for resolving source files or directory
* @param exclude Optional exclude pattern for resolving source files or directory
* @param charset The charset for loading text files
*/
public DatasourcesSupplier(Collection<String> sources, String include, String exclude, Charset charset) {
@@ -33,7 +33,7 @@
* <li>file:///users.csv</li>
* <li>users=file:///users.csv</li>
* <li>users:admin=file:///users.csv</li>
* <li>users=file:///users.csv#charset=UTF-16&mimetype=text/csv</li>
* <li>users=file:///users.csv#charset=UTF-16&amp;mimetype=text/csv</li>
* </ul>
*/
public class NamedUriParser {
@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.freemarker.generator.base.util;

import java.io.IOException;
@@ -0,0 +1 @@
TBD
@@ -26,7 +26,7 @@
</parent>

<artifactId>freemarker-generator-cli</artifactId>
<name>Apache FreeMarker Generator: CLI</name>
<name>CLI</name>
<description>Command-line client for Apache FreeMarker</description>

<build>
@@ -130,29 +130,25 @@
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<exclude>*.md</exclude>
<exclude>README.md</exclude>
<exclude>src/site/markdown/**/*.md</exclude>
<exclude>.travis.yml</exclude>
<exclude>src/main/resources/patterns/*</exclude>
<exclude>site/sample/*/**</exclude>
<exclude>src/test/data/encoding/utf8.txt</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>

@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.freemarker.generator.cli.config;

import freemarker.cache.TemplateLoader;
@@ -0,0 +1,124 @@
## The Mental Model

* A command line invocation requires 1..n `templates` and 0..n `datasources`
* A command line invocation is mapped to a series of `transformations`
* The mapping strategy is either
* `aggregating`: each `template` yields one output file based on 0..n `datasources`
* `generating`: each `datasources` yields one output per `template`
* The `transformation` consists of exactly one `template`, 0..n `datasources` and an `output`
* An `output` is either written to
* `stdout`
* an output file
* an output directory
* When the output is written to a directory
* the structure of the input directory is preserved
* the file names can be customized using an output mapping

## Aggregation Versus Generation

This distiniction is only relevant if you have more than one `datasource` for a given `template`

* aggregation will invoke the `template` once with all `datasources`
* generation will invoke the `template` multiple times with only one `datasources`

### Aggregation

A nice example for `aggregation` is the generation of test user documentation with the following directory layout

```text
.
|-- data
| |-- user-products.csv
| |-- user-transactions.csv
| `-- users.csv
`-- templates
|-- test-user-documentation.html.ftl
`-- test-user-documentation.md.ftl
```

We want to transform those three CSV input files into a `Markdown` and `HTML` document copied into an `out` directory

```text
# Using short options
> freemarker-cli -t templates -d data -output-dir out
# Using long options
> freemarker-cli -m aggregate -t templates -d data -output-dir out
> freemarker-cli --mode aggregate --template templates --datasource data -output-dir out
```

The invocation would generate the following files

```text
.
`-- out
|-- test-user-documentation.html
`-- test-user-documentation.md
```

### Generation

#### Source Code Generation

A good example for `generation` is the creation of souce code, e.g. as provided by the `maven-generator-plugin`

```text
.
|-- data
| |-- ProductDao.java.json
| |-- TransactionDao.java.json
| `-- UserDao.java.json
`-- templates
`-- generate-dao.ftl
```

We want to generate three Java files based on JSON files and a single template

```text
# Using short options
> freemarker-cli -m generate -t templates -d data -output-dir out
# Using long options
> freemarker-cli --mode generate --template templates --datasource data -output-dir out
```

The invocation would generate the following files

```text
.
`-- out
|-- ProductDao.java
|-- TransactionDao.java
`-- UserDao.java
```

#### Configuration File Generations

Another example for `generation` comes from cloud computing, i.e. the generation of configuration files using the following directory layout

```text
.
|-- config
| |-- application.yml
| `-- nginx.conf
`-- config.json
```

We want to generate a set of expanded configuration files

```text
# Using short options
> freemarker-cli -m generate -t config -d config.json -output-dir out
# Using long options
> freemarker-cli --mode generate --template templates --datasource data -output-dir out
```

which results in the following directory structure

```text
.
`-- out
| |-- application.yml
| `-- nginx.conf
```
@@ -0,0 +1 @@
TBD
@@ -0,0 +1,24 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="CLI">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html" />
<item name="Concepts" href="cli/concepts.html" />
</menu>
</body>
</project>
@@ -28,7 +28,7 @@
<artifactId>freemarker-generator-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>

<name>Apache FreeMarker Generator: Maven Plugin</name>
<name>Maven Plugin</name>
<description>Maven plugin for Apache FreeMarker</description>

<properties>
@@ -179,12 +179,19 @@

<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<exclude>*.md</exclude>
<exclude>README.md</exclude>
<exclude>src/site/markdown/**/*.md</exclude>
<excludde>**/*.json</excludde>
<excludde>src/test/data/generating-file-visitor/data/mydir/bad-extension-test.txt</excludde>
</excludes>
@@ -51,6 +51,11 @@ private GeneratingFileVisitor(Configuration config, MavenSession session, Map<St

/**
* Factory method that calls constructor, added to facilitate testing with jmockit.
*
* @param config FreeMarker configuration
* @param session Maven session
* @param extensionToBuilder builder extension
* @return GeneratingFileVisitor instance
*/
public static GeneratingFileVisitor create(Configuration config, MavenSession session, Map<String, OutputGeneratorPropertiesProvider> extensionToBuilder) {
return new GeneratingFileVisitor(config, session, extensionToBuilder);

0 comments on commit 2e4517b

Please sign in to comment.