You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by sg...@apache.org on 2021/01/09 12:16:26 UTC
[freemarker-generator] 01/03: FREEMARKER-161 [freemarker-generator]
Cleanup code
This is an automated email from the ASF dual-hosted git repository.
sgoeschl pushed a commit to branch FREEMARKER-161
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
commit d308ede197f1c2972e3b328b9a37fa233cae101a
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Sat Jan 9 10:41:01 2021 +0100
FREEMARKER-161 [freemarker-generator] Cleanup code
---
.../freemarker/generator/base/util/UriUtils.java | 2 +-
freemarker-generator-cli/pom.xml | 6 ++--
.../cli/config/ConfigurationSupplier.java | 11 +++---
.../cli/config/OutputGeneratorsSupplier.java | 16 +++++++++
.../generator/cli/config/ToolsSupplier.java | 13 ++++---
.../generator/cli/model/DataSourcesModel.java | 40 ----------------------
.../cli/model/GeneratorObjectWrapper.java | 16 +++++++++
.../generator/cli/config/CompositeGroupDemo.java | 16 +++++++++
.../generator/maven/OperatingSystem.java | 16 +++++++++
.../generator/tools/commonscsv/CommonsCSVTool.java | 2 +-
10 files changed, 81 insertions(+), 57 deletions(-)
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java
index fab27e0..b8135bb 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/UriUtils.java
@@ -50,7 +50,7 @@ public class UriUtils {
public static String toStringWithoutFragment(URI uri) {
final String str = uri.toString();
final int index = str.indexOf('#');
- return (index > 0) ? str.substring(0, index) : str;
+ return index > 0 ? str.substring(0, index) : str;
}
public static boolean isUri(String str) {
diff --git a/freemarker-generator-cli/pom.xml b/freemarker-generator-cli/pom.xml
index da3494b..f69de25 100644
--- a/freemarker-generator-cli/pom.xml
+++ b/freemarker-generator-cli/pom.xml
@@ -161,10 +161,12 @@
<configuration>
<excludes>
<exclude>README.md</exclude>
- <exclude>src/site/markdown/**/*.md</exclude>
+ <exclude>CHANGELOG.md</exclude>
<exclude>.travis.yml</exclude>
+ <exclude>src/app/examples/data/*/**</exclude>
+ <exclude>src/app/scripts/run-examples.bat</exclude>
<exclude>src/main/resources/patterns/*</exclude>
- <exclude>examples/data/*/**</exclude>
+ <exclude>src/site/markdown/**/*.md</exclude>
<exclude>src/test/data/encoding/utf8.txt</exclude>
<exclude>src/test/data/json/*/**</exclude>
<exclude>src/test/data/yaml/environments.yaml</exclude>
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ConfigurationSupplier.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ConfigurationSupplier.java
index 3bce48d..60c7743 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ConfigurationSupplier.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ConfigurationSupplier.java
@@ -19,17 +19,16 @@ package org.apache.freemarker.generator.cli.config;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Version;
+import org.apache.freemarker.generator.base.util.PropertiesTransformer;
import org.apache.freemarker.generator.cli.model.GeneratorObjectWrapper;
import java.util.Properties;
import java.util.function.Supplier;
+import java.util.stream.Stream;
import static freemarker.template.Configuration.VERSION_2_3_29;
import static java.util.Objects.requireNonNull;
-import static java.util.stream.Stream.of;
import static org.apache.freemarker.generator.base.FreeMarkerConstants.Configuration.SETTING_PREFIX;
-import static org.apache.freemarker.generator.base.util.PropertiesTransformer.filterKeyPrefix;
-import static org.apache.freemarker.generator.base.util.PropertiesTransformer.removeKeyPrefix;
/**
* Supply a FreeMarker configuration.
@@ -81,9 +80,9 @@ public class ConfigurationSupplier implements Supplier<Configuration> {
* @return FreeMarker configuration settings
*/
private Properties freeMarkerConfigurationSettings() {
- return of(settings.getConfiguration())
- .map(p -> filterKeyPrefix(p, SETTING_PREFIX))
- .map(p -> removeKeyPrefix(p, SETTING_PREFIX))
+ return Stream.of(settings.getConfiguration())
+ .map(p -> PropertiesTransformer.filterKeyPrefix(p, SETTING_PREFIX))
+ .map(p -> PropertiesTransformer.removeKeyPrefix(p, SETTING_PREFIX))
.findFirst().get();
}
}
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/OutputGeneratorsSupplier.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/OutputGeneratorsSupplier.java
index f41c7ab..2a33bfd 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/OutputGeneratorsSupplier.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/OutputGeneratorsSupplier.java
@@ -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 org.apache.freemarker.generator.base.FreeMarkerConstants.Location;
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ToolsSupplier.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ToolsSupplier.java
index 34efb5f..cb0e4d5 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ToolsSupplier.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/config/ToolsSupplier.java
@@ -16,20 +16,19 @@
*/
package org.apache.freemarker.generator.cli.config;
+import org.apache.freemarker.generator.base.FreeMarkerConstants.Configuration;
import org.apache.freemarker.generator.base.FreeMarkerConstants.Model;
import org.apache.freemarker.generator.base.tools.ToolsFactory;
+import org.apache.freemarker.generator.base.util.PropertiesTransformer;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.function.Supplier;
+import java.util.stream.Stream;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toMap;
-import static java.util.stream.Stream.of;
-import static org.apache.freemarker.generator.base.FreeMarkerConstants.Configuration.TOOLS_PREFIX;
-import static org.apache.freemarker.generator.base.util.PropertiesTransformer.filterKeyPrefix;
-import static org.apache.freemarker.generator.base.util.PropertiesTransformer.removeKeyPrefix;
/**
* Supplies FreeMarker tools based on the provided settings.
@@ -76,9 +75,9 @@ public class ToolsSupplier implements Supplier<Map<String, Object>> {
* @return tool properties
*/
private Properties toolsProperties() {
- return of(configuration)
- .map(p -> filterKeyPrefix(p, TOOLS_PREFIX))
- .map(p -> removeKeyPrefix(p, TOOLS_PREFIX))
+ return Stream.of(configuration)
+ .map(p -> PropertiesTransformer.filterKeyPrefix(p, Configuration.TOOLS_PREFIX))
+ .map(p -> PropertiesTransformer.removeKeyPrefix(p, Configuration.TOOLS_PREFIX))
.findFirst().get();
}
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/DataSourcesModel.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/DataSourcesModel.java
deleted file mode 100644
index 45fa479..0000000
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/DataSourcesModel.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.apache.freemarker.generator.cli.model;
-
-import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
-import org.apache.freemarker.generator.base.datasource.DataSource;
-import org.apache.freemarker.generator.base.datasource.DataSources;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Wraps an instance of <code>DataSources</code> into a more user-friendly <code>BeanModel</code>
- * so the user can use FreeMarker directives and features instead of using the exposed methods.
- */
-public class DataSourcesModel extends BeanModel {
-
- public DataSourcesModel(DataSources dataSources, BeansWrapper objectWrapper) {
- super(new SimpleDataSourcesAdapter(dataSources), requireNonNull(objectWrapper));
- }
-
- private static final class SimpleDataSourcesAdapter {
-
- private final DataSources dataSources;
-
- public SimpleDataSourcesAdapter(DataSources dataSources) {
- this.dataSources = dataSources;
- }
-
- public DataSource get(int index) {
- return dataSources.get(index);
- }
-
- public DataSource get(String name) {
- return dataSources.get(name);
- }
-
- public int size() {
- return dataSources.size();
- }
- }
-}
diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/GeneratorObjectWrapper.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/GeneratorObjectWrapper.java
index 57b9867..289611f 100644
--- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/GeneratorObjectWrapper.java
+++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/model/GeneratorObjectWrapper.java
@@ -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.model;
import freemarker.template.DefaultMapAdapter;
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/CompositeGroupDemo.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/CompositeGroupDemo.java
index 8b7f80a..4f4dfe3 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/CompositeGroupDemo.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/config/CompositeGroupDemo.java
@@ -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 org.apache.commons.lang3.Validate;
diff --git a/freemarker-generator-maven-plugin/src/test/java/org/apache/freemarker/generator/maven/OperatingSystem.java b/freemarker-generator-maven-plugin/src/test/java/org/apache/freemarker/generator/maven/OperatingSystem.java
index 9c974c2..4575238 100644
--- a/freemarker-generator-maven-plugin/src/test/java/org/apache/freemarker/generator/maven/OperatingSystem.java
+++ b/freemarker-generator-maven-plugin/src/test/java/org/apache/freemarker/generator/maven/OperatingSystem.java
@@ -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.maven;
import java.util.Locale;
diff --git a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java
index 552ae16..3490ee8 100644
--- a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java
+++ b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/commonscsv/CommonsCSVTool.java
@@ -50,7 +50,7 @@ public class CommonsCSVTool {
public List<CSVParser> parse(Collection<DataSource> dataSources) {
return dataSources.stream()
.map(this::parse)
- .collect(Collectors.toList());
+ .collect(toList());
}
public CSVParser parse(DataSource dataSource, CSVFormat format) {