<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.mule.runtime</groupId>
        <artifactId>mule</artifactId>
        <version>4.1.5</version>
    </parent>
    <artifactId>mule-ce-sources</artifactId>
    <!-- Packaging 'pom' ensures that maven does not try to bind a plugin to the
         'package' phase. We bind the final zip through this pom, that's enough. -->
    <packaging>pom</packaging>
    <name>Community Sources Zip</name>
    <description>Bundles all Mule Community sources for download.</description>

    <properties>
        <outputFilename>mule-sources-${project.version}</outputFilename>

        <formatterConfigPath>../formatter.xml</formatterConfigPath>
    </properties>

    <build>
        <!--
            Keep the plugins ordered by build lifecycle 
            (http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)!
        -->
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                def muleRoot = "$project.build.directory/../../"

                                log.info("Mule project root: ${new File(muleRoot).canonicalPath}")

                                def tempDir = "$project.build.directory/sources-temp"
                                ant.mkdir(dir: tempDir)

                                ant.unjar(dest: tempDir) {
                                    fileset(dir: muleRoot) {
                                        include(name: '**/*-sources.jar')
                                        exclude(name: 'osgi-libs/**/*-sources.jar')
                                    }
                                }

                                ant.zip(destfile: "$project.build.directory/mule-${project.version}-src.zip") {
                                    fileset( dir: tempDir ) {
                                        // These JMH tests are autogenerated so they don't have licences headers and it's easier to directly exclude them.
                                        exclude(name: "**/*jmhTest.java")
                                        exclude(name: "**/*jmhType.java")
                                        exclude(name: "**/*jmhType_*.java")
                                    }
                                }
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <!--
            Attach the source zip that's generated by the groovy script to the build
            lifecycle so other modules can depend on it.
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/mule-${project.version}-src.zip</file>
                                    <type>zip</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
                 We generate a full source bundle using the groovy plugin above. Do not
                 publish maven's autogenerated and empty sources jar of this module.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <attach>false</attach>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
