1

I have a directory with unknown depth and folder names.

>A
-> AB
--> configuration.xml
--> ABC
---> configuration.xml
-> AD
--> configuration.xml
-> allconfigurations.xml

I need a maven plugin to concat all the configuration.xml files and create allconfigurations.xml file in the root. Unfortunately folder names and depth is unknown. It would be great to accomplish it within the pom.xml file without needing any other files.

hevi
  • 2,432
  • 1
  • 32
  • 51

2 Answers2

2

just a quick google for you: the maven-shade-plugin with the XmlAppendingTransformer could help.

sample config is here

Community
  • 1
  • 1
krstf
  • 627
  • 7
  • 25
2

While struggling I realized that the real problem is to put a header and footer for the compiled allconfigurations.xml file, since each configuration.xml file is a fragment and when I concat all of them together resulting xml is not a valid xml.

here is the case; an xml file is something like:

<Configuration xmlns="abc">
     ...
    <connectionTimeoutInMs>240000</connectionTimeoutInMs>
    <socketTimeoutInMs>240000</socketTimeoutInMs>
    <persist>false</persist>
    <internal>false</internal>
    ...
</Configuration>

and putting many of them is not valid thus result xml must be something like;

<AllConfigurations xmlns="abc">
    ...
    <Configuration xmlns="abc">
       ...
    </Configuration >    
    ...
<AllConfigurations xmlns="abc">

so the first and last lines must be added to the result.

here is the solution I came up with;

            <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <!--<phase>process-resources</phase>-->
                    <!--<phase>compile</phase>-->
                    <configuration>
                        <target>
                            <concat destfile="${project.basedir}/.../allConfigurations.xml"
                                    force="yes">
                                <fileset dir="${project.basedir}/...">
                                    <include name="xmlHeaderForConfiguration"></include>
                                </fileset>
                                <fileset dir="${project.basedir}/...">
                                    <include name="**/configuration.xml"></include>
                                </fileset>
                                <fileset dir="${project.basedir}/...">
                                    <include name="xmlFooterForConfiguration"></include>
                                </fileset>
                            </concat>

                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

where xmlHeaderForConfiguration is a file with content; <AllConfigurations xmlns="abc"> and xmlHeaderForConfiguration has </AllConfigurations>

hevi
  • 2,432
  • 1
  • 32
  • 51