diff --git a/wso2-maven-json-merge-plugin/pom.xml b/wso2-maven-json-merge-plugin/pom.xml index 14cb14aa..cb2f3b91 100644 --- a/wso2-maven-json-merge-plugin/pom.xml +++ b/wso2-maven-json-merge-plugin/pom.xml @@ -55,6 +55,10 @@ com.google.code.gson gson + + commons-io + commons-io + org.testng testng diff --git a/wso2-maven-json-merge-plugin/src/main/java/org/wso2/maven/Merge.java b/wso2-maven-json-merge-plugin/src/main/java/org/wso2/maven/Merge.java index e8a9bcc0..bb750d29 100644 --- a/wso2-maven-json-merge-plugin/src/main/java/org/wso2/maven/Merge.java +++ b/wso2-maven-json-merge-plugin/src/main/java/org/wso2/maven/Merge.java @@ -15,6 +15,7 @@ */ package org.wso2.maven; +import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -22,11 +23,14 @@ import org.apache.maven.plugins.annotations.Parameter; import java.io.BufferedWriter; +import java.io.File; +import java.io.FileFilter; import java.io.FileWriter; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Mojo for Json Merge @@ -51,8 +55,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { Map inputMap; String targetPath = taskModel.getTarget(); for (String aFile : taskModel.getInclude()) { - inputMap = Utils.getReadMap(aFile); - baseJsonMap = Utils.mergeMaps(baseJsonMap, inputMap, taskModel.isMergeChildren()); + for (String bFile : this.getMatchingFiles(aFile)) { + inputMap = Utils.getReadMap(bFile); + baseJsonMap = Utils.mergeMaps(baseJsonMap, inputMap, taskModel.isMergeChildren()); + } } try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(targetPath))) { @@ -64,4 +70,19 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } + + private String[] getMatchingFiles(String aFile) { + File file = new File(aFile).getParentFile(); + if (file != null && file.exists()) { + FileFilter fileFilter = new WildcardFileFilter(new File(aFile).getName()); + File[] files = Objects.requireNonNull(file.listFiles(fileFilter)); + String[] result = new String[files.length]; + for (int i = 0; i < files.length; i++) { + result[i] = files[i].getPath(); + } + return result; + } else { + return new String[]{ aFile }; + } + } }