<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.atlassian.platform.dependencies</groupId>
        <artifactId>platform-deps</artifactId>
        <version>7.0.30</version>
    </parent>

    <artifactId>platform-spring-bundle</artifactId>

    <name>Atlassian - Spring</name>
    <description>Atlassian Bundle that exports Spring Framework for Plugin System (OSGi).</description>

    <properties>
        <bundle-symbolic.name>${project.groupId}.${project.artifactId}</bundle-symbolic.name>
        <bundle-name>${project.name} ${spring.version}</bundle-name>
        <!-- Bundle Plugin removes all breaking lines, so I break in the middle of a word to get expected result -->
        <bundle-description>
            ${project.description} Provided modules: spring-aop, spring-beans, spring-context, spring-context
            -support, spring-core, spring-expression, spring-jdbc, spring-tx, spring-web, spring-webmvc in version ${spring.version}.
        </bundle-description>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.platform.dependencies</groupId>
                <artifactId>platform-public-api</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.platform.dependencies</groupId>
                <artifactId>platform-deprecated-public-api</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.platform.dependencies</groupId>
                <artifactId>platform-internal-api</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <exclusions>
                <!-- It is a repackage of JCL API; already provided by the System Bundle -->
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jcl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!--
                Spring needs to be inlined in the jar (we cannot use META-INF/lib/* pattern),
                because Gemini expects files like services, handlers and schemas in the root directory of the bundle.
                Shade plugin gives us possibility to merge those files into single one.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
                                    <addHeader>false</addHeader>
                                </transformer>
                                <!-- Some Spring jars register the same services - they should be merged -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <!-- Similarly to services we should merge those files registering schemas and handlers -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.tooling</resource>
                                </transformer>
                            </transformers>
                            <!-- `MANIFEST.MF` is generated by the `bundle` plugin -->
                            <filters>
                                <filter>
                                    <artifact>org.springframework:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/MANIFEST.MF</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>${maven-bundle-plugin.version}</version>
                <executions>
                    <execution>
                        <id>generate-manifest</id>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <instructions>
                        <Bundle-Name>${bundle-name}</Bundle-Name>
                        <Bundle-Description>${bundle-description}</Bundle-Description>
                        <Export-Package>
                            org.aopalliance*;version="1.0";atlassian-access=public,
                            <!-- coming from `spring-jdbc -->
                            org.springframework.jdbc*;version="${spring.version}";atlassian-access=inherited,
                            <!-- coming from `spring-tx`-->
                            org.springframework.dao*;version="${spring.version}";atlassian-access=inherited,
                            org.springframework.jca*;version="${spring.version}";atlassian-access=inherited,
                            org.springframework.transaction*;version="${spring.version}";atlassian-access=inherited,
                            org.springframework*;version="${spring.version}";atlassian-access=public
                        </Export-Package>
                        <Import-Package>*;resolution:=optional</Import-Package>
                        <!--
                            It creates manifest with dependencies being included in the Import/Export calculation.
                            Since we are only executing `manifest` goal it is safe,
                            otherwise it would copy the dependencies to the jar - which is done by the `shade` plugin
                         -->
                        <Embed-Dependency>*;scope=compile;inline=true</Embed-Dependency>
                    </instructions>
                </configuration>
            </plugin>
            <!-- We need to explicitly copy MANIFEST generated by the `bundle` plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
