TyrantLucifer commented on code in PR #4016:
URL: 
https://github.com/apache/incubator-seatunnel/pull/4016#discussion_r1092809573


##########
seatunnel-core/seatunnel-core-starter/src/main/java/org/apache/seatunnel/core/starter/utils/ConfigBuilder.java:
##########
@@ -40,19 +44,37 @@ private ConfigBuilder() {
         // utility class and cannot be instantiated
     }
 
+    private static Config ofInner(@NonNull Path filePath){
+        return ConfigFactory
+            .parseFile(filePath.toFile())
+            .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+            .resolveWith(ConfigFactory.systemProperties(),
+                ConfigResolveOptions.defaults().setAllowUnresolved(true));
+    }
+
     public static Config of(@NonNull String filePath) {
         Path path = Paths.get(filePath);
         return of(path);
     }
 
     public static Config of(@NonNull Path filePath) {
         log.info("Loading config file from path: {}", filePath);
-        Config config = ConfigFactory
-                .parseFile(filePath.toFile())
-                
.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
-                .resolveWith(ConfigFactory.systemProperties(),
-                        
ConfigResolveOptions.defaults().setAllowUnresolved(true));
+        Optional<ConfigAdapter> adapterSupplier = 
ConfigAdapterUtils.selectAdapter(filePath);
+        Config config = adapterSupplier
+            .map(adapter -> of(adapter, filePath))
+            .orElseGet(()-> ofInner(filePath));
         log.info("Parsed config file: {}", 
config.root().render(CONFIG_RENDER_OPTIONS));
         return config;
     }
+
+    public static Config of(@NonNull ConfigAdapter configAdapter, @NonNull 
Path filePath) {
+        log.info("With spi {}", configAdapter.getClass().getName());
+        try{
+            Map<String, Object> flattenedMap = 
configAdapter.loadConfig(filePath);
+            return ConfigFactory.parseMap(flattenedMap);
+        }catch (Exception warn){
+            log.warn("Loading config failed with spi {}, fallback to HOCON 
loader.", configAdapter.getClass().getName());
+            return ofInner(filePath);

Review Comment:
   Format code.



##########
seatunnel-core/seatunnel-core-starter/src/main/java/org/apache/seatunnel/core/starter/utils/ConfigBuilder.java:
##########
@@ -40,19 +44,37 @@ private ConfigBuilder() {
         // utility class and cannot be instantiated
     }
 
+    private static Config ofInner(@NonNull Path filePath){
+        return ConfigFactory
+            .parseFile(filePath.toFile())
+            .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+            .resolveWith(ConfigFactory.systemProperties(),
+                ConfigResolveOptions.defaults().setAllowUnresolved(true));
+    }
+
     public static Config of(@NonNull String filePath) {
         Path path = Paths.get(filePath);
         return of(path);
     }
 
     public static Config of(@NonNull Path filePath) {
         log.info("Loading config file from path: {}", filePath);
-        Config config = ConfigFactory
-                .parseFile(filePath.toFile())
-                
.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
-                .resolveWith(ConfigFactory.systemProperties(),
-                        
ConfigResolveOptions.defaults().setAllowUnresolved(true));
+        Optional<ConfigAdapter> adapterSupplier = 
ConfigAdapterUtils.selectAdapter(filePath);
+        Config config = adapterSupplier
+            .map(adapter -> of(adapter, filePath))
+            .orElseGet(()-> ofInner(filePath));
         log.info("Parsed config file: {}", 
config.root().render(CONFIG_RENDER_OPTIONS));
         return config;
     }
+
+    public static Config of(@NonNull ConfigAdapter configAdapter, @NonNull 
Path filePath) {
+        log.info("With spi {}", configAdapter.getClass().getName());
+        try{
+            Map<String, Object> flattenedMap = 
configAdapter.loadConfig(filePath);
+            return ConfigFactory.parseMap(flattenedMap);
+        }catch (Exception warn){
+            log.warn("Loading config failed with spi {}, fallback to HOCON 
loader.", configAdapter.getClass().getName());
+            return ofInner(filePath);

Review Comment:
   {} should has a blank between other characters



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to