<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  ~  Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
  ~
  ~  WSO2 Inc. licenses this file to you under the Apache License,
  ~  Version 2.0 (the "License"); you may not use this file except
  ~  in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<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">

    <parent>
        <groupId>org.wso2.am</groupId>
        <artifactId>am-parent</artifactId>
        <version>3.0.0-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.wso2.is-km</groupId>
    <artifactId>org.wso2.is-km</artifactId>
    <version>5.7.0</version>
    <packaging>pom</packaging>
    <name>IS as Key Manager</name>
    <url>http://wso2.org</url>

    <build>
        <plugins>
            <plugin>
                <groupId>org.wso2.maven</groupId>
                <artifactId>carbon-p2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>feature-install</id>
                        <phase>package</phase>
                        <goals>
                            <goal>p2-profile-gen</goal>
                        </goals>
                        <configuration>
                            <profile>default</profile>
                            <metadataRepository>file:${p2_repo_folder}</metadataRepository>
                            <artifactRepository>file:${p2_repo_folder}</artifactRepository>
                            <destination>${is_folder_name}/repository/components</destination>
                            <deleteOldProfileFiles>false</deleteOldProfileFiles>
                            <!--Install key manager feature and REST API DCR feature in IS pack-->
                            <features>
                                <feature>
                                    <id>org.wso2.carbon.apimgt.keymanager.feature.group</id>
                                    <version>${keymanager.feature.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.apimgt.rest.api.dcr.feature.group</id>
                                    <version>${keymanager.feature.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.governance.lifecycle.management.feature.group</id>
                                    <version>${carbon-governance.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.apimgt.tracing.feature.group</id>
                                    <version>${keymanager.feature.version}</version>
                                </feature>
                            </features>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <replace token="false" value="true"
                                         dir="${is_folder_name}/repository/components/default/configuration/org.eclipse.equinox.simpleconfigurator">
                                    <include name="**/bundles.info"/>
                                </replace>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-installed</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon.apimgt</groupId>
                                    <artifactId>org.wso2.carbon.apimgt.rest.api.util</artifactId>
                                    <version>${carbon.apimgt.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${is_folder_name}/lib/runtimes/cxf3</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resource-one</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/${is_folder_name}/repository/conf</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <directory>${basedir}</directory>
                                    <includes>
                                        <include>deployment.toml</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resource-two</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>

                        <configuration>
                            <outputDirectory>${basedir}/${is_folder_name}/repository/resources/lifecycles</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <directory>../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/lifecycles/</directory>
                                    <includes>
                                        <include>APILifeCycle.xml</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.wso2.maven</groupId>
                <artifactId>wso2-maven-json-merge-plugin</artifactId>
                <version>5.2.10</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <task>
                                    <base>${basedir}/../distribution/product/src/main/resources/conf/default.json</base>
                                    <include>
                                        <param>
                                            ${basedir}/${is_folder_name}/repository/resources/conf/default.json
                                        </param>
                                        <param>
                                            ${basedir}/../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/conf/org.wso2.carbon.apimgt.core.default.json
                                        </param>
                                    </include>
                                    <target>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/default-merged.json
                                    </target>
                                </task>
                                <task>
                                    <base>${basedir}/../distribution/product/src/main/resources/conf/infer.json</base>
                                    <include>
                                        <param>
                                            ${basedir}/${is_folder_name}/repository/resources/conf/infer.json
                                        </param>
                                    </include>
                                    <target>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/infer-merged.json
                                    </target>
                                </task>
                                <task>
                                    <base>${basedir}/../distribution/product/src/main/resources/conf/key-mappings.json
                                    </base>
                                    <include>
                                        <param>
                                            ${basedir}/${is_folder_name}/repository/resources/conf/key-mappings.json
                                        </param>
                                    </include>
                                    <target>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/key-mappings-merged.json
                                    </target>
                                </task>
                                <task>
                                    <base>${basedir}/../distribution/product/src/main/resources/conf/unit-resolve.json
                                    </base>
                                    <include>
                                        <param>
                                            ${basedir}/../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/conf/org.wso2.carbon.apimgt.core.unit-resolve.json
                                        </param>
                                        <param>
                                            ${basedir}/${is_folder_name}/repository/resources/conf/unit-resolve.json
                                        </param>
                                    </include>
                                    <target>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/unit-resolve-merged.json
                                    </target>
                                    <mergeChildren>true</mergeChildren>
                                </task>
                                <task>
                                    <base>${basedir}/../distribution/product/src/main/resources/conf/validator.json</base>
                                    <include>
                                        <param>
                                            ${basedir}/${is_folder_name}/repository/resources/conf/validator.json
                                        </param>
                                    </include>
                                    <target>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/validator-merged.json
                                    </target>
                                </task>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.coderplus.maven.plugins</groupId>
                <artifactId>copy-rename-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <id>copy-file</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <sourceFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/default-merged.json
                                    </sourceFile>
                                    <destinationFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/default.json
                                    </destinationFile>
                                </fileSet>
                                <fileSet>
                                    <sourceFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/infer-merged.json
                                    </sourceFile>
                                    <destinationFile>${basedir}/${is_folder_name}/repository/resources/conf/infer.json
                                    </destinationFile>
                                </fileSet>
                                <fileSet>
                                    <sourceFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/key-mappings-merged.json
                                    </sourceFile>
                                    <destinationFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/key-mappings.json
                                    </destinationFile>
                                </fileSet>
                                <fileSet>
                                    <sourceFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/unit-resolve-merged.json
                                    </sourceFile>
                                    <destinationFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/unit-resolve.json
                                    </destinationFile>
                                </fileSet>
                                <fileSet>
                                    <sourceFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/validator-merged.json
                                    </sourceFile>
                                    <destinationFile>
                                        ${basedir}/${is_folder_name}/repository/resources/conf/validator.json
                                    </destinationFile>
                                </fileSet>
                            </fileSets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <configuration>
                            <tasks>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/org.wso2.carbon.apimgt.core.default.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/org.wso2.carbon.apimgt.core.unit-resolve.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/default-merged.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/infer-merged.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/key-mappings-merged.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/unit-resolve-merged.json"/>
                                <delete file="${basedir}/${is_folder_name}/repository/resources/conf/validator-merged.json"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>wso2-nexus</id>
            <name>WSO2 internal Repository</name>
            <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>wso2-maven-releases-repository</id>
            <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
        </pluginRepository>
        <pluginRepository>
            <id>wso2-maven-snapshots-repository</id>
            <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
        </pluginRepository>
    </pluginRepositories>

    <properties>
        <is_folder_name>wso2is-5.9.0</is_folder_name>
        <p2_repo_folder>../p2-profile/product/target/p2-repo</p2_repo_folder>
        <keymanager.feature.version>${carbon.apimgt.version}</keymanager.feature.version>
        <carbon-governance.version>${carbon.governance.version}</carbon-governance.version>
    </properties>
</project>
