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/12 16:42:49 UTC

[GitHub] [shardingsphere] totalo opened a new pull request #15386: Implement ExampleGenerator using SPI

totalo opened a new pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386


   For #12366.
   
   Changes proposed in this pull request:
   - implement ExampleGenerator using SPI
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252390



##########
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:
       All right, thanks




-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805331560



##########
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:
       my fault,done.




-- 
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



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15386](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d6d36ef) into [master](https://codecov.io/gh/apache/shardingsphere/commit/688c7400788b69000a67a19436dac976b15a8608?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (688c740) will **not change** coverage.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15386/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff            @@
   ##             master   #15386   +/-   ##
   =========================================
     Coverage     60.39%   60.39%           
     Complexity     1949     1949           
   =========================================
     Files          3215     3215           
     Lines         48084    48084           
     Branches       8162     8162           
   =========================================
     Hits          29040    29040           
     Misses        16707    16707           
     Partials       2337     2337           
   ```
   
   
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [688c740...d6d36ef](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15386](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (814a02e) into [master](https://codecov.io/gh/apache/shardingsphere/commit/688c7400788b69000a67a19436dac976b15a8608?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (688c740) will **decrease** coverage by `0.00%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15386/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15386      +/-   ##
   ============================================
   - Coverage     60.39%   60.38%   -0.01%     
     Complexity     1949     1949              
   ============================================
     Files          3215     3215              
     Lines         48084    48084              
     Branches       8162     8162              
   ============================================
   - Hits          29040    29037       -3     
   - Misses        16707    16710       +3     
     Partials       2337     2337              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [688c740...814a02e](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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



[GitHub] [shardingsphere] codecov-commenter commented on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15386](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b9ee9ff) into [master](https://codecov.io/gh/apache/shardingsphere/commit/688c7400788b69000a67a19436dac976b15a8608?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (688c740) will **decrease** coverage by `0.00%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15386/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15386      +/-   ##
   ============================================
   - Coverage     60.39%   60.38%   -0.01%     
     Complexity     1949     1949              
   ============================================
     Files          3215     3215              
     Lines         48084    48084              
     Branches       8162     8162              
   ============================================
   - Hits          29040    29037       -3     
   - Misses        16707    16710       +3     
     Partials       2337     2337              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [688c740...b9ee9ff](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252345



##########
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:
       All right, thanks




-- 
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



[GitHub] [shardingsphere] terrymanu merged pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252811



##########
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:
       All right, thanks




-- 
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



[GitHub] [shardingsphere] codecov-commenter commented on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15386](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b9ee9ff) into [master](https://codecov.io/gh/apache/shardingsphere/commit/688c7400788b69000a67a19436dac976b15a8608?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (688c740) will **decrease** coverage by `0.00%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15386/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15386      +/-   ##
   ============================================
   - Coverage     60.39%   60.38%   -0.01%     
     Complexity     1949     1949              
   ============================================
     Files          3215     3215              
     Lines         48084    48084              
     Branches       8162     8162              
   ============================================
   - Hits          29040    29037       -3     
   - Misses        16707    16710       +3     
     Partials       2337     2337              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [688c740...b9ee9ff](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252819



##########
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:
       All right, thanks.

##########
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:
       All right, thanks.

##########
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:
       All right, thanks.

##########
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:
       All right, thanks.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805319927



##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception

Review comment:
       `Template Exception` should rewrite to `template exception`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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;
+import java.util.Map.Entry;
+
+/**
+ * Freemarker generate util.
+ */
+public final class GenerateUtil {

Review comment:
       Please add private constructor to avoid user new utility class.

##########
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:
       The `String[] combs` has not changed yet

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception
+     * @throws IOException IO Exception

Review comment:
       `IO Exception` should rewrite to `IO exception`




-- 
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



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919






-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252280



##########
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:
       All right, thanks

##########
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:
       All right, thanks

##########
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:
       All right, thanks

##########
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:
       All right, thanks

##########
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:
       All right, thanks

##########
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:
       All right, thanks.

##########
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:
       All right, thanks.

##########
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:
       All right, thanks.

##########
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:
       All right, thanks.

##########
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:
       done.

##########
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:
       done.

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception

Review comment:
       All right.done

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception
+     * @throws IOException IO Exception

Review comment:
       All right.thanks

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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;
+import java.util.Map.Entry;
+
+/**
+ * Freemarker generate util.
+ */
+public final class GenerateUtil {

Review comment:
       All right.thanks

##########
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:
       my fault,done.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252280



##########
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:
       All right, thanks




-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805331209



##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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;
+import java.util.Map.Entry;
+
+/**
+ * Freemarker generate util.
+ */
+public final class GenerateUtil {

Review comment:
       All right.thanks




-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252447



##########
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:
       All right, thanks




-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805252859



##########
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:
       done.

##########
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:
       done.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
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`

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception

Review comment:
       `Template Exception` should rewrite to `template exception`

##########
File path: examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/GenerateUtil.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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;
+import java.util.Map.Entry;
+
+/**
+ * Freemarker generate util.
+ */
+public final class GenerateUtil {

Review comment:
       Please add private constructor to avoid user new utility class.

##########
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:
       The `String[] combs` has not changed yet

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception
+     * @throws IOException IO Exception

Review comment:
       `IO Exception` should rewrite to `IO exception`




-- 
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



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15386: Implement ExampleGenerator using SPI

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#issuecomment-1037452919


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15386](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1b97975) into [master](https://codecov.io/gh/apache/shardingsphere/commit/688c7400788b69000a67a19436dac976b15a8608?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (688c740) will **not change** coverage.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15386/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff            @@
   ##             master   #15386   +/-   ##
   =========================================
     Coverage     60.39%   60.39%           
     Complexity     1949     1949           
   =========================================
     Files          3215     3215           
     Lines         48084    48084           
     Branches       8162     8162           
   =========================================
     Hits          29040    29040           
     Misses        16707    16707           
     Partials       2337     2337           
   ```
   
   
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [688c740...1b97975](https://codecov.io/gh/apache/shardingsphere/pull/15386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15386:
URL: https://github.com/apache/shardingsphere/pull/15386#discussion_r805331151



##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception

Review comment:
       All right.done

##########
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 directories and files by template.
+     * 
+     * @throws TemplateException Template Exception
+     * @throws IOException IO Exception

Review comment:
       All right.thanks




-- 
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