Skip to content
Permalink
Browse files
FREEMARKER-151 Ensure that build and and examples are running on Wind…
…ows (#19)
  • Loading branch information
sgoeschl committed Jul 7, 2020
1 parent b27c6ba commit 8ef281b853f3cd4fbc7403f604d64ea504cbd61f
Showing 24 changed files with 478 additions and 71 deletions.
@@ -25,6 +25,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;

@@ -68,10 +69,11 @@ public List<File> get() {
return emptyList();
}

// sort the result to have a reproducible order across different OS
return sources.stream()
.map(this::resolve)
.flatMap(Collection::stream)
.sorted()
.sorted(Comparator.comparing(File::getAbsolutePath))
.collect(toList());
}

@@ -46,7 +46,7 @@ public static synchronized MimetypesFileTypeMap create() {
mimeTypes.addMimeTypes(MIME_APPLICATION_XML + " xml XML");
mimeTypes.addMimeTypes(MIME_APPLICATION_XHTML + " xhtml XHTML");
mimeTypes.addMimeTypes(MIME_TEXT_CSV + " csv CSV");
mimeTypes.addMimeTypes(MIME_TEXT_PLAIN + " adoc ADOC env ENV ini INI log LOG properties txt TXT");
mimeTypes.addMimeTypes(MIME_TEXT_PLAIN + " adoc ADOC bat BAT env ENV ftl FTL ini INI log LOG properties txt TXT");
mimeTypes.addMimeTypes(MIME_TEXT_HTML + " htm HTM html HTML");
mimeTypes.addMimeTypes(MIME_TEXT_MARKDOWM + " md MD");
mimeTypes.addMimeTypes(MIME_TEXT_RTF + " rtf RTF");
@@ -16,6 +16,8 @@
*/
package org.apache.freemarker.generator.base.util;

import org.apache.commons.io.FilenameUtils;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -26,7 +28,7 @@ public class UriUtils {

public static URI toURI(String str) {
try {
return new URI(str);
return new URI(separatorsToUnix(str));
} catch (URISyntaxException e) {
throw new RuntimeException("Failed to create URI: " + str, e);
}
@@ -64,4 +66,8 @@ public static boolean isEnvUri(URI uri) {
}
return "env".equalsIgnoreCase(uri.getScheme());
}

private static String separatorsToUnix(String str) {
return FilenameUtils.separatorsToUnix(str);
}
}
@@ -16,6 +16,7 @@
*/
package org.apache.freemarker.generator.datasource;

import org.apache.commons.io.FilenameUtils;
import org.apache.freemarker.generator.base.datasource.DataSource;
import org.apache.freemarker.generator.base.datasource.DataSourceFactory;
import org.apache.freemarker.generator.base.uri.NamedUri;
@@ -29,7 +30,6 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Paths;

import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -40,12 +40,13 @@

public class DataSourceFactoryTest {

private static final String PWD = Paths.get(".").toAbsolutePath().normalize().toString();
private static final String PWD = FilenameUtils.separatorsToUnix(new File("").getAbsolutePath());
private static final String ANY_TEXT = "Hello World";
private static final String ANY_FILE_NAME = "pom.xml";
private static final String ANY_FILE_URI = format("file:///%s/pom.xml", PWD);
private static final Charset ANY_CHAR_SET = UTF_8;
private static final File ANY_FILE = new File(ANY_FILE_NAME);
private static final String ANY_ENV_VARIABLE = "JAVA_HOME";
private static final String ANY_NAMED_URL_STRING = "content:www=https://www.google.com?foo=bar#contenttype=application/json";

@Test
@@ -156,14 +157,15 @@ public void shouldCreateDataSourceFromNamedEnviroment() {
}

@Test
public void shouldCreateDataSourceFromEnviromentVariable() {
final NamedUri namedUri = NamedUriStringParser.parse("pwd=env:///PWD");
public void shouldCreateDataSourceFromEnvironmentVariable() {
final String uri = "env:///" + ANY_ENV_VARIABLE;
final NamedUri namedUri = NamedUriStringParser.parse("myenv=" + uri);
final DataSource dataSource = DataSourceFactory.fromNamedUri(namedUri);

assertEquals("pwd", dataSource.getName());
assertEquals("myenv", dataSource.getName());
assertEquals("default", dataSource.getGroup());
assertEquals(UTF_8, dataSource.getCharset());
assertEquals("env:///PWD", dataSource.getUri().toString());
assertEquals(uri, dataSource.getUri().toString());
assertEquals("text/plain", dataSource.getContentType());
}
}
@@ -67,7 +67,7 @@ public void shouldSupportFileDataSource() throws IOException {
assertEquals("pom", dataSource.getBaseName());
assertEquals("xml", dataSource.getExtension());
assertEquals(ANY_FILE.toURI().toString(), dataSource.getUri().toString());
assertEquals(Charset.defaultCharset(), dataSource.getCharset());
assertEquals(ANY_CHAR_SET.name(), dataSource.getCharset().name());
assertEquals("application/xml", dataSource.getContentType());
assertTrue(dataSource.getLength() > 0);
assertFalse(dataSource.getText().isEmpty());
@@ -16,12 +16,13 @@
*/
package org.apache.freemarker.generator.datasource;

import org.apache.commons.io.FilenameUtils;
import org.apache.freemarker.generator.base.datasource.DataSource;
import org.apache.freemarker.generator.base.datasource.DataSourcesSupplier;
import org.junit.Test;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

@@ -34,7 +35,7 @@ public class DataSourcesSupplierTest {

private static final String NO_EXCLUDE = null;
private static final String DATA_DIRECTORY = "./src/test/data";
private static final String PWD = Paths.get(".").toAbsolutePath().normalize().toString();
private static final String PWD = FilenameUtils.separatorsToUnix(new File("").getAbsolutePath());

@Test
public void shouldResolveSingleFile() {
@@ -19,7 +19,6 @@
import org.apache.freemarker.generator.base.template.TemplateSource;
import org.apache.freemarker.generator.base.template.TemplateSource.Origin;
import org.apache.freemarker.generator.base.template.TemplateSourceFactory;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
@@ -32,7 +31,8 @@ public class TemplateSourceFactoryTest {
private static final String ANY_TEMPLATE_PATH = "any/template/path.ftl";
private static final String ANY_FILE_NAME = "pom.xml";
private static final String ANY_URL = "https://raw.githubusercontent.com/apache/freemarker-generator/master/freemarker-generator-cli/templates/info.ftl";
private static final String ANY_ENVIRONMENT_VARIABLE = "env:///PWD";
private static final String ANY_ENV_VARIABLE = "JAVA_HOME";
private static final String ANY_ENV_URI = "env:///" + ANY_ENV_VARIABLE;

@Test
public void shouldCreateFromTemplatePath() {
@@ -56,9 +56,9 @@ public void shouldCreateFromFile() {

@Test
public void shouldCreateFromEnvironmentVariable() {
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_ENVIRONMENT_VARIABLE);
final TemplateSource templateSource = TemplateSourceFactory.create(ANY_ENV_URI);

assertEquals("PWD", templateSource.getName());
assertEquals(ANY_ENV_VARIABLE, templateSource.getName());
assertEquals(Origin.CODE, templateSource.getOrigin());
assertNull(templateSource.getPath());
assertFalse(templateSource.getCode().isEmpty());
@@ -63,7 +63,7 @@ public void shouldParseRelativeFileName() {
}

@Test
public void shouldParseAbsoluteFileName() {
public void shouldParseAbsoluteUnixFileName() {
final NamedUri namedURI = parse("/data/users.csv");

assertNull(namedURI.getName());
@@ -73,6 +73,17 @@ public void shouldParseAbsoluteFileName() {
assertEquals(0, namedURI.getParameters().size());
}

@Test
public void shouldParseAbsoluteWindosFileName() {
final NamedUri namedURI = parse("\\data\\users.csv");

assertNull(namedURI.getName());
assertNull(namedURI.getGroup());
assertEquals("/data/users.csv", namedURI.getUri().toString());
assertEquals("users.csv", namedURI.getFile().getName());
assertEquals(0, namedURI.getParameters().size());
}

@Test
public void shouldParseDirectoryName() {
final NamedUri namedURI = parse("users/");
@@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file. We try to a
* [FREEMARKER-129] Use version "0.X.Y" to cater for API changes according to [Semantic Versioning](https://semver.org)

### Fixed
* [FREEMARKER-151] Ensure that build and and examples are running on Windows
* [FREEMARKER-147] Complete Maven site documentation
* [FREEMARKER-127] Site build fails with missing "org/apache/maven/doxia/siterenderer/DocumentContent"

@@ -41,4 +42,5 @@ All notable changes to this project will be documented in this file. We try to a
[FREEMARKER-144]: https://issues.apache.org/jira/browse/FREEMARKER-144
[FREEMARKER-146]: https://issues.apache.org/jira/browse/FREEMARKER-146
[FREEMARKER-147]: https://issues.apache.org/jira/browse/FREEMARKER-147
[FREEMARKER-149]: https://issues.apache.org/jira/browse/FREEMARKER-149
[FREEMARKER-149]: https://issues.apache.org/jira/browse/FREEMARKER-149
[FREEMARKER-151]: https://issues.apache.org/jira/browse/FREEMARKER-151
@@ -136,8 +136,3 @@ Small Number : ${smallNumber}
Large Number : ${largeNumber}
Date : ${.now?date}
Time : ${.now?time}

17) Execute a program
---------------------------------------------------------------------------
> date
${ExecTool.execute("date")}
@@ -75,6 +75,7 @@
<copy file="README.md" todir="./target/appassembler" />
<copy file="LICENSE" todir="./target/appassembler" />
<copy file="NOTICE" todir="./target/appassembler" />
<copy file="./src/main/scripts/run-examples.bat" todir="./target/appassembler" />
<copy file="./src/main/scripts/run-examples.sh" todir="./target/appassembler" />
<copy todir="./target/appassembler/templates">
<fileset dir="templates" />

0 comments on commit 8ef281b

Please sign in to comment.