You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/02/13 03:10:22 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15386: Implement ExampleGenerator using SPI

terrymanu commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805231863



##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {

Review comment:
       Please do not use `Map.Entry`, just use `Entry` instead of it.

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util

Review comment:
       Please add `.` in end of first line in Java Doc.

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleGeneratorFactory.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.TemplateException;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Objects;
+import java.util.ServiceLoader;
+
+/**
+ * Example generator factory.
+ */
+public final class ExampleGeneratorFactory {
+    
+    private static final String DATA_MODEL_PATH = "/data-model/data-model.yaml";
+    
+    private final Configuration templateConfig;
+    
+    public ExampleGeneratorFactory() throws IOException {
+        templateConfig = createTemplateConfiguration();
+    }
+    
+    private Configuration createTemplateConfiguration() throws IOException {
+        Configuration result = new Configuration(Configuration.VERSION_2_3_31);
+        result.setDirectoryForTemplateLoading(new File(Objects.requireNonNull(ExampleGeneratorFactory.class.getClassLoader().getResource("template")).getFile()));
+        result.setDefaultEncoding("UTF-8");
+        return result;
+    }
+    
+    /**
+     * Generate dirs and files by template.

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `directories` to instead of `dirs`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `configuration` to instead of `config`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `directories` to instead of `dirs`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `configuration` to instead of `config`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {
+            processFile(templateConfig, dataModel, entry.getKey(), outputPath + "/" + entry.getValue());
+        }
+    }
+    
+    /**
+     * Generate path.
+     *
+     * @param templateConfig template config
+     * @param model model
+     * @param relativePath relative path
+     * @return Path generated from the model
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static String generatePath(final Configuration templateConfig, final Object model, final String relativePath) throws IOException, TemplateException {
+        try (StringWriter result = new StringWriter()) {
+            new Template("path", relativePath, templateConfig).process(model, result);
+            return result.toString();
+        }
+    }
+    
+    /**
+     * Generate file.
+     *
+     * @param templateConfig template config
+     * @param model data model
+     * @param templateFile template file
+     * @param outputFile output file
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void processFile(final Configuration templateConfig, final Object model, final String templateFile, final String outputFile) throws IOException, TemplateException {
+        try (Writer writer = new FileWriter(outputFile)) {
+            templateConfig.getTemplate(templateFile).process(model, writer);
+        }
+    }
+    
+    /**
+     * Combination generator.
+     * 
+     * @param combs combs
+     * @return All combination
+     */
+    public static Collection<String> generateCombination(String[] combs) {
+        int len = combs.length;
+        Collection<String> result = new HashSet<>();
+        for (int i = 0, size = 1 << len; i < size; i++) {
+            StringBuilder tmp = new StringBuilder();

Review comment:
       `tmp` is not a good name, could consider rename it?

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {
+            processFile(templateConfig, dataModel, entry.getKey(), outputPath + "/" + entry.getValue());
+        }
+    }
+    
+    /**
+     * Generate path.
+     *
+     * @param templateConfig template config
+     * @param model model
+     * @param relativePath relative path
+     * @return Path generated from the model
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static String generatePath(final Configuration templateConfig, final Object model, final String relativePath) throws IOException, TemplateException {
+        try (StringWriter result = new StringWriter()) {
+            new Template("path", relativePath, templateConfig).process(model, result);
+            return result.toString();
+        }
+    }
+    
+    /**
+     * Generate file.
+     *
+     * @param templateConfig template config
+     * @param model data model
+     * @param templateFile template file
+     * @param outputFile output file
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void processFile(final Configuration templateConfig, final Object model, final String templateFile, final String outputFile) throws IOException, TemplateException {
+        try (Writer writer = new FileWriter(outputFile)) {
+            templateConfig.getTemplate(templateFile).process(model, writer);
+        }
+    }
+    
+    /**
+     * Combination generator.
+     * 
+     * @param combs combs

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `combinations` to instead of `combs`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {
+            processFile(templateConfig, dataModel, entry.getKey(), outputPath + "/" + entry.getValue());
+        }
+    }
+    
+    /**
+     * Generate path.
+     *
+     * @param templateConfig template config

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `configuration` to instead of `config`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {
+            processFile(templateConfig, dataModel, entry.getKey(), outputPath + "/" + entry.getValue());
+        }
+    }
+    
+    /**
+     * Generate path.
+     *
+     * @param templateConfig template config
+     * @param model model
+     * @param relativePath relative path
+     * @return Path generated from the model
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static String generatePath(final Configuration templateConfig, final Object model, final String relativePath) throws IOException, TemplateException {
+        try (StringWriter result = new StringWriter()) {
+            new Template("path", relativePath, templateConfig).process(model, result);
+            return result.toString();
+        }
+    }
+    
+    /**
+     * Generate file.
+     *
+     * @param templateConfig template config
+     * @param model data model
+     * @param templateFile template file
+     * @param outputFile output file
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void processFile(final Configuration templateConfig, final Object model, final String templateFile, final String outputFile) throws IOException, TemplateException {
+        try (Writer writer = new FileWriter(outputFile)) {
+            templateConfig.getTemplate(templateFile).process(model, writer);
+        }
+    }
+    
+    /**
+     * Combination generator.
+     * 
+     * @param combs combs
+     * @return All combination
+     */
+    public static Collection<String> generateCombination(String[] combs) {

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `combinations` to instead of `combs`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.shardingsphere.example.generator;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Freemarker generate util
+ */
+public final class GenerateUtil {
+    
+    /**
+     * Generate dirs.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param paths paths
+     * @param outputPath output path
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static void generateDirs(final Configuration templateConfig, final Map<String, String> dataModel, final Collection<String> paths, final String outputPath) throws IOException, TemplateException {
+        if (null == paths || 0 == paths.size()) {
+            new File(generatePath(templateConfig, dataModel, outputPath)).mkdirs();
+            return;
+        }
+        for (String each : paths) {
+            new File(generatePath(templateConfig, dataModel, outputPath + "/" + each)).mkdirs();
+        }
+    }
+    
+    /**
+     * Generate file.
+     * 
+     * @param templateConfig template config
+     * @param dataModel data model
+     * @param path paths
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static void generateFile(final Configuration templateConfig, final Map<String, String> dataModel, final Map<String, String> templateMap, final String path) throws IOException, TemplateException {
+        String outputPath = generatePath(templateConfig, dataModel, path);
+        for (Map.Entry<String, String> entry : templateMap.entrySet()) {
+            processFile(templateConfig, dataModel, entry.getKey(), outputPath + "/" + entry.getValue());
+        }
+    }
+    
+    /**
+     * Generate path.
+     *
+     * @param templateConfig template config
+     * @param model model
+     * @param relativePath relative path
+     * @return Path generated from the model
+     * @throws IOException IO exception
+     * @throws TemplateException template exception
+     */
+    public static String generatePath(final Configuration templateConfig, final Object model, final String relativePath) throws IOException, TemplateException {
+        try (StringWriter result = new StringWriter()) {
+            new Template("path", relativePath, templateConfig).process(model, result);
+            return result.toString();
+        }
+    }
+    
+    /**
+     * Generate file.
+     *
+     * @param templateConfig template config

Review comment:
       Please do not use abbreviation in Java Doc, it is better to use `configuration` to instead of `config`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org