Skip to content
Permalink
Browse files
Bumping dependencies and minor code cleanup
  • Loading branch information
sgoeschl committed Aug 17, 2021
1 parent 82bd725 commit 77d79914f90e5f1d60785a7a47be6604418e31f3
Showing 18 changed files with 74 additions and 39 deletions.
@@ -3,7 +3,7 @@ Apache FreeMarker Generator

For documentation or to report bugs visit: [https://freemarker.apache.org](https://freemarker.apache.org)

Regarding pull requests on Github
Regarding pull requests on GitHub
-----------------------------------------------------------------------------

By sending a pull request you grant the Apache Software Foundation
@@ -63,6 +63,7 @@
<exclude>src/site/markdown/**/*.md</exclude>
<exclude>**/*.csv</exclude>
<exclude>src/test/data/txt/file_01.txt</exclude>
<exclude>src/test/data/txt/utf8.txt</exclude>
</excludes>
</configuration>
</plugin>
@@ -253,7 +253,7 @@ public InputStream getUnsafeInputStream() {
try {
return dataSource.getInputStream();
} catch (IOException e) {
throw new RuntimeException("Failed to get input stream: " + toString(), e);
throw new RuntimeException("Failed to get input stream: " + this, e);
}
}

@@ -268,7 +268,7 @@ public String getText(String charsetName) {
IOUtils.copy(is, writer, Charset.forName(charsetName));
return writer.toString();
} catch (IOException e) {
throw new RuntimeException("Failed to get text: " + toString(), e);
throw new RuntimeException("Failed to get text: " + this, e);
}
}

@@ -294,7 +294,7 @@ public List<String> getLines(String charsetName) {
try (InputStream inputStream = getUnsafeInputStream()) {
return IOUtils.readLines(inputStream, charsetName);
} catch (IOException e) {
throw new RuntimeException("Failed to get lines: " + toString(), e);
throw new RuntimeException("Failed to get lines: " + this, e);
}
}

@@ -319,18 +319,14 @@ public LineIterator getLineIterator() {
*/
public LineIterator getLineIterator(String charsetName) {
Validate.notEmpty(charsetName, "No charset name provided");
try {
return closeables.add(IOUtils.lineIterator(getUnsafeInputStream(), Charset.forName(charsetName)));
} catch (IOException e) {
throw new RuntimeException("Failed to create line iterator: " + toString(), e);
}
return closeables.add(IOUtils.lineIterator(getUnsafeInputStream(), Charset.forName(charsetName)));
}

public byte[] getBytes() {
try (InputStream inputStream = getUnsafeInputStream()) {
return IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new RuntimeException("Failed to get bytes: " + toString(), e);
throw new RuntimeException("Failed to get bytes: " + this, e);
}
}

@@ -360,7 +356,7 @@ public String getMetadata(String key) {
case METADATA_MIME_TYPE:
return getMimeType();
default:
throw new IllegalArgumentException("Unknown metatdata key: " + key);
throw new IllegalArgumentException("Unknown metadata key: " + key);
}
}

@@ -22,7 +22,6 @@
import org.apache.freemarker.generator.base.datasource.DataSourceLoader;
import org.apache.freemarker.generator.base.uri.NamedUri;
import org.apache.freemarker.generator.base.uri.NamedUriStringParser;
import org.apache.freemarker.generator.base.util.UriUtils;

import java.io.File;
import java.nio.charset.Charset;
@@ -27,7 +27,6 @@

/**
* Captures the information of a user-supplied "named URI".
* <p>
* <ul>
* <li><code>name</code> is optional</li>
* <li><code>group</code> is optional</li>
@@ -1,3 +1,4 @@
# Apache FreeMarker Generator Base

This package contains infrastructure code not depending on `Apache FreeMarker` directly since `DataSources` and their creation might be useful for un-related command-line tools.
This package contains infrastructure code not depending on `Apache FreeMarker` directly since `DataSources` and their
creation might be useful for un-related command-line tools.
@@ -96,7 +96,7 @@ public void shouldCreateDataSourceFromInputStream() {
}

@Test
@Ignore
@Ignore("Requires internet access")
public void shouldCreateDataSourceFromURL() throws IOException {
final URL url = new URL("https://jsonplaceholder.typicode.com/posts/2");
final DataSource dataSource = DataSourceFactory.fromUrl("jsonplaceholder.typicode.com", "default", url);
@@ -1,7 +1,7 @@
Apache FreeMarker Generator CLI
=============================================================================

This module provides provides the CLI for `Apache FreeMarker`.
This module provides the CLI for `Apache FreeMarker`.

* Requires JDK 1.8+ on Linux, Mac OSX and Windows
* Add the bin/freemarker-generator or bin/freemarker-generator.bat to your PATH variable
@@ -73,7 +73,6 @@ public List<String> getDataModels() {
} else {
return emptyList();
}

}

public TemplateSourceDefinition getTemplateSourceDefinition() {
@@ -83,7 +83,7 @@ URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-ge
URI : file:/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/examples/data/json/swagger-spec.json```
```

Access to `stdin` is implemented as `DataSource` - please not that `stdin` is read lazily to cater for arbitrary large input data
Access to `stdin` is implemented as `DataSource` - please note that `stdin` is read lazily to cater for arbitrary large input data

```
cat examples/data/csv/contract.csv | bin/freemarker-generator -t freemarker-generator/info.ftl --stdin
@@ -157,7 +157,7 @@ selection of data sources (using Apache Commons IO wild-card matching)

### Using a DataSource

In most cases the data source will passed to a tool but the are some useful operations available as shown below
In most cases the data source will be passed to a tool, but there are some useful operations available as shown below

```text
Invoke Arbitrary Methods On DataSource
@@ -1,6 +1,6 @@
## Named URIs

Named URIs allow to identify `DataSources` and pass additional information
Named URIs allow identifying `DataSources` and pass additional information

A Named URI consists of

@@ -1,6 +1,6 @@
## Passing Configuration Data

`Apache FreeMarker Generator CLI` provides multiple ways to pass configuration data used in in templates
`Apache FreeMarker Generator CLI` provides multiple ways to pass configuration data used in templates

* System properties
* Parameters
@@ -27,7 +27,6 @@
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class DataModelSupplierTest {

@@ -60,7 +59,7 @@ public void shouldCopyAllEnvironmentVariablesToDataModelVariable() {
}

@Test
public void shouldCopySingleEnvironmentVariablesToTopLevelDataModel() {
public void shouldCopySingleEnvironmentVariableToTopLevelDataModel() {
final DataModelSupplier supplier = supplier("env:///" + ANY_ENV_VARIABLE);

final Map<String, Object> model = supplier.get();
@@ -87,7 +86,7 @@ public void shouldThrowIllegalArgumentExceptionForNonExistingEnvironmentVariable
// === Properties ===

@Test
public void shouldCopeyPropertiesFileToTopLevelDataModel() {
public void shouldCopyPropertiesFileToTopLevelDataModel() {
final DataModelSupplier supplier = supplier("./src/test/data/properties/test.properties");

final Map<String, Object> model = supplier.get();
@@ -133,6 +132,7 @@ public void shouldCopyJsonObjectFileToTopLevelDataModel() {
}

@Test
@SuppressWarnings("rawtypes")
public void shouldCopyJsonArrayFileToDataModelVariable() {
final DataModelSupplier supplier = supplier("list=./src/test/data/json/list.json");

@@ -164,17 +164,17 @@ public void shouldResolveYamlFileToTopLevelDataModel() {
// == URL ===

@Test
@Ignore
@Ignore("Requires internet access")
public void shouldResolveUrlToTopLevelDataModel() {
final DataModelSupplier supplier = supplier("https://jsonplaceholder.typicode.com/posts/2");

final Map<String, Object> model = supplier.get();

assertTrue(model.size() == 4);
assertEquals(4, model.size());
}

@Test
@Ignore
@Ignore("Requires internet access")
public void shouldResolveUrlToDataModelVariable() {
final DataModelSupplier supplier = supplier("post=https://jsonplaceholder.typicode.com/posts/2");

@@ -185,7 +185,7 @@ public void shouldResolveUrlToDataModelVariable() {
}

@Test
@Ignore
@Ignore("Requires internet access")
public void shouldResolveUrlToDataModelVariables() {
supplier("https://jsonplaceholder.typicode.com/posts/does-not-exist").get();
}
@@ -1,7 +1,7 @@
Apache FreeMarker Generator Maven Plugin Sample
=============================================================================

This project allows to play around with `freemarker-generator-maven-plugin` quickly.
This project allows playing around with `freemarker-generator-maven-plugin` quickly.

Let's create a Java class and text file using the `freemarker-generator-maven-plugin`, compile and package it (so you know that the generated code is compiling)

@@ -58,7 +58,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.8</version>
<version>1.9.0</version>
</dependency>
<!-- DataFrame -->
<dependency>
@@ -97,7 +97,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.8.7</version>
</dependency>
<!-- Java Faker -->
<dependency>
@@ -115,13 +115,13 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
</dependency>
<!-- JsoupTool -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
<version>1.14.2</version>
</dependency>
<!-- SnakeYamlTool -->
<dependency>
@@ -57,13 +57,10 @@ private static DataFrameBuilder addColumn(DataFrameBuilder builder, String colum
return builder.addLongColumn(columnName);
case "java.lang.Short":
return builder.addShortColumn(columnName);
case "java.lang.String":
return builder.addStringColumn(columnName);
case "java.util.Date":
case "java.time.LocalDate":
return builder.addStringColumn(columnName);
case "java.time.LocalTime":
return builder.addStringColumn(columnName);
case "java.util.Date":
case "java.lang.String":
return builder.addStringColumn(columnName);
default:
throw new RuntimeException("Unable to add column for the following type: " + columnType.getName());
@@ -19,6 +19,8 @@
import com.github.javafaker.Faker;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

@@ -54,6 +56,47 @@ public void shouldGetTimeUnits() {
assertEquals(6, javaFakerTool().getTimeUnits().size());
}

@Test
public void shouldShowGeneralUsage() {
final String language = "de";
final String country = "DE";
final Locale locale = new Locale(language, country);
final Faker faker = javaFakerTool().getFaker(locale);
final String iban = faker.finance().iban(country);
final String firstName = faker.name().firstName();
final String lastName = faker.name().lastName();
final String email = String.format("%s.%s@gmail.com", firstName, lastName).toLowerCase();
final Date birthday = faker.date().birthday(21, 65);
final String streetAddress = faker.address().streetAddress();
final String state = faker.address().stateAbbr();
final String zipCode = faker.address().zipCode();
final int numberBetween = faker.number().numberBetween(10, 99);
final List<String> words = faker.lorem().words(10);

assertTrue(iban.startsWith("DE"));
assertFalse(firstName.isEmpty());
assertFalse(lastName.isEmpty());
assertFalse(email.isEmpty());
assertNotNull(birthday);
assertFalse(streetAddress.isEmpty());
assertFalse(state.isEmpty());
assertFalse(zipCode.isEmpty());
assertTrue(numberBetween >= 10 && numberBetween <= 99);
assertFalse(words.isEmpty());

/*
System.out.println("iban: " + iban);
System.out.println("name: " + firstName + " " + lastName);
System.out.println("email: " + email);
System.out.println("birthday: " + birthday);
System.out.println("streetName: " + streetAddress);
System.out.println("state: " + state);
System.out.println("zipCode: " + zipCode);
System.out.println("numberBetween: " + numberBetween);
System.out.println("words: " + words);
*/
}

private static JavaFakerTool javaFakerTool() {
return new JavaFakerTool();
}
@@ -119,7 +119,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>

0 comments on commit 77d7991

Please sign in to comment.