This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e0233a7fb17 Fix example generator (#27254)
e0233a7fb17 is described below
commit e0233a7fb17c5c96fec57d7f681c2c73e93b306a
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jul 17 20:49:53 2023 +0800
Fix example generator (#27254)
---
.../example/generator/core/ExampleGenerator.java | 48 +++++++++++++++++-----
.../generator/scenario/ExampleScenarioFactory.java | 7 ++--
2 files changed, 41 insertions(+), 14 deletions(-)
diff --git
a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
index 22abfe4e64d..3a78f494a2c 100644
---
a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
+++
b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
@@ -40,6 +40,12 @@ public interface ExampleGenerator extends TypedSPI {
String RESOURCES_PATH = "src/main/resources";
+ /**
+ * Build output path.
+ *
+ * @param exampleConfig example configuration
+ * @return built output path
+ */
default String buildOutputPath(YamlExampleConfiguration exampleConfig) {
if (Strings.isNullOrEmpty(exampleConfig.getOutput())) {
return DEFAULT_OUTPUT + PROJECT_PATH;
@@ -47,6 +53,14 @@ public interface ExampleGenerator extends TypedSPI {
return exampleConfig.getOutput() + PROJECT_PATH;
}
+ /**
+ * Generate example.
+ *
+ * @param templateConfig template configuration
+ * @param exampleConfig example configuration
+ * @throws IOException IO exception
+ * @throws TemplateException template exception
+ */
default void generate(final Configuration templateConfig, final
YamlExampleConfiguration exampleConfig) throws IOException, TemplateException {
for (String eachMode : exampleConfig.getModes()) {
for (String eachTransaction : exampleConfig.getTransactions()) {
@@ -58,11 +72,32 @@ public interface ExampleGenerator extends TypedSPI {
}
}
}
-
+
+ /**
+ * Generate example.
+ *
+ * @param templateConfig template configuration
+ * @param dataModel data model
+ * @param outputPath output path
+ * @throws IOException IO exception
+ * @throws TemplateException template exception
+ */
+ void generate(Configuration templateConfig, Map<String, String> dataModel,
String outputPath) throws IOException, TemplateException;
+
+ /**
+ * Build data model.
+ *
+ * @param props properties
+ * @param mode mode
+ * @param transaction transaction
+ * @param framework framework
+ * @param feature feature
+ * @return built data model
+ */
default Map<String, String> buildDataModel(final Properties props, final
String mode, final String transaction, final String framework, final String
feature) {
Map<String, String> result = new LinkedHashMap<>();
props.forEach((key, value) -> result.put(key.toString(),
value.toString()));
- result.put("product", getType());
+ result.put("product", getType().toString());
result.put("mode", mode);
result.put("transaction", transaction);
result.put("feature", feature);
@@ -70,13 +105,4 @@ public interface ExampleGenerator extends TypedSPI {
result.put("shardingsphereVersion", ShardingSphereVersion.VERSION);
return result;
}
-
- /**
- * Generate.
- * @param templateConfig template configuration
- * @param dataModel data model
- * @throws IOException IO exception
- * @throws TemplateException template exception
- */
- void generate(final Configuration templateConfig, final Map<String,
String> dataModel, final String outputPath) throws IOException,
TemplateException;
}
diff --git
a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
index ac1d054043a..2affddd55a9 100644
---
a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
+++
b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
@@ -48,8 +48,9 @@ public final class ExampleScenarioFactory {
}
private Collection<FeatureExampleScenario> getFeatureScenarios(final
String feature) {
- return null == feature ? Collections.emptyList() :
- Arrays.stream(feature.split(",")).map(each ->
TypedSPILoader.getService(FeatureExampleScenario.class,
each.trim())).collect(Collectors.toList());
+ return null == feature
+ ? Collections.emptyList()
+ : Arrays.stream(feature.split(",")).map(each ->
TypedSPILoader.getService(FeatureExampleScenario.class,
each.trim())).collect(Collectors.toList());
}
private FrameworkExampleScenario getFrameworkScenario(final String
framework) {
@@ -74,7 +75,7 @@ public final class ExampleScenarioFactory {
for (FeatureExampleScenario each : featureScenarios) {
result.putAll(each.getJavaClassTemplateMap());
}
- if (frameworkScenario.getType().contains("spring-boot-starter") &&
transactionScenario.getType().contains("xa")) {
+ if
(frameworkScenario.getType().toString().contains("spring-boot-starter") &&
transactionScenario.getType().toString().contains("xa")) {
result.put("java/TransactionConfiguration.ftl",
"TransactionConfiguration.java");
}
result.putAll(frameworkScenario.getJavaClassTemplateMap());