<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  ~  Copyright (c) 2005-2010, 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-distribution-parent</artifactId>
        <version>2.1.0-update5</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2am</artifactId>
    <packaging>pom</packaging>
    <name>WSO2 API Manager - Distribution </name>
    <url>http://www.wso2.org/projects/am/java</url>
    <description>WSO2 API Manager Distribution</description>

    <dependencies>
        <dependency>
            <groupId>org.wso2.andes.wso2</groupId>
            <artifactId>andes-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs.wso2</groupId>
            <artifactId>geronimo-jms_1.1_spec</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-digester.wso2</groupId>
            <artifactId>commons-digester</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database.wso2</groupId>
            <artifactId>h2-database-engine</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.osgi</groupId>
                    <artifactId>org.eclipse.osgi</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>unpack-wso2carbon</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon</groupId>
                                    <artifactId>wso2carbon-core</artifactId>
                                    <version>${carbon.kernel.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-rest-publisher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon.apimgt</groupId>
                                    <artifactId>org.wso2.carbon.apimgt.rest.api.publisher.feature</artifactId>
                                    <version>${carbon.apimgt.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-rest-store</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon.apimgt</groupId>
                                    <artifactId>org.wso2.carbon.apimgt.rest.api.store.feature</artifactId>
                                    <version>${carbon.apimgt.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-rest-admin</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon.apimgt</groupId>
                                    <artifactId>org.wso2.carbon.apimgt.rest.api.admin.feature</artifactId>
                                    <version>${carbon.apimgt.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>extract-docs-from-components</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <property name="tempdir" value="target/docs-temp" />
                                <property name="hideMenu" value="&lt;/Security&gt;${line.separator} ${line.separator} &lt;!--Hide unnecessary menu Items--&gt; ${line.separator} &lt;HideMenuItemIds&gt; ${line.separator} &lt;HideMenuItemId&gt;claim_mgt_menu&lt;/HideMenuItemId&gt; ${line.separator} &lt;HideMenuItemId&gt;identity_mgt_emailtemplate_menu&lt;/HideMenuItemId&gt; ${line.separator} &lt;HideMenuItemId&gt;identity_security_questions_menu&lt;/HideMenuItemId&gt; ${line.separator} &lt;/HideMenuItemIds&gt;" />

                                <mkdir dir="${tempdir}" />
                                <unzip dest="${tempdir}">
                                    <fileset dir="target">
                                        <include name="wso2am-${project.version}.zip" />
                                    </fileset>
                                </unzip>
                                <replace file="target/wso2carbon-core-${carbon.kernel.version}/repository/conf/carbon.xml" token="&lt;/Security&gt;" value="${hideMenu}" />
                                <copy todir="target/wso2carbon-core-${carbon.kernel.version}/repository/components/" overwrite="false">
                                    <fileset dir="${tempdir}/wso2am-${project.version}/repository/components/">
                                    </fileset>
                                </copy>
                                <delete file="target/wso2am-${project.version}.zip" />
                                <delete dir="${tempdir}" />
                                <mkdir dir="${tempdir}" />
                                <unzip dest="${tempdir}">
                                    <fileset dir="target/wso2carbon-core-${carbon.kernel.version}/repository/components/plugins/">
                                        <include name="*.ui*.jar" />
                                    </fileset>
                                </unzip>
                                <move todir="${tempdir}/web/" includeemptydirs="false">
                                    <fileset dir="${tempdir}/web/">
                                        <exclude name="**/yui/**" />
                                        <exclude name="**/ajax/**" />
                                        <exclude name="**/editarea/**" />
                                        <exclude name="**/codepress/**" />
                                        <exclude name="**/WEB-INF/**" />
                                        <exclude name="**/diffview/**" />
                                        <include name="**/*.html" />
                                    </fileset>
                                    <mapper type="glob" from="*.html" to="*.xml" />
                                </move>
                                <delete dir="src/site/xdoc" />
                                <mkdir dir="src/site/xdoc" />
                                <copy todir="src/site/xdoc" overwrite="false" includeemptydirs="false">
                                    <fileset dir="${tempdir}/web">
                                        <exclude name="**/yui/**" />
                                        <exclude name="**/ajax/**" />
                                        <exclude name="**/WEB-INF/**" />
                                        <exclude name="**/diffview/**" />
                                        <exclude name="**/*.html" />
                                        <exclude name="**/*.js" />
                                        <exclude name="**/*.jsp" />
                                        <exclude name="**/*.xsl" />
                                        <exclude name="*.*" />
                                    </fileset>
                                </copy>
                                <copy todir="src/site" overwrite="false" includeemptydirs="false">
                                    <fileset dir="../../../docs">
                                    </fileset>
                                </copy>
                                <copy todir="target/site/" overwrite="false" includeemptydirs="false">
                                    <fileset dir="src/site/xdoc/">
                                        <include name="**/images/*.*" />
                                    </fileset>
                                </copy>
                                <zip destfile="target/site/publisher-api-docs.zip" basedir="target/features/" includes="org.wso2.carbon.apimgt.rest.api.publisher*/api-docs/" />
                                <zip destfile="target/site/store-api-docs.zip" basedir="target/features/" includes="org.wso2.carbon.apimgt.rest.api.store*/api-docs/" />
                                <zip destfile="target/site/admin-api-docs.zip" basedir="target/features/" includes="org.wso2.carbon.apimgt.rest.api.admin*/api-docs/" />
                                <delete dir="features" />
                                <delete dir="plugins" />
                                <delete dir="${tempdir}" />
                            </tasks>
                        </configuration>
                    </execution>
                    <execution>
                        <id>modify_entitlement_properties</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <tasks>
                                <replace token="PIP.AttributeDesignators.Designator.2=org.wso2.carbon.identity.application.authz.xacml.pip.AuthenticationContextAttributePIP" value="#PIP.AttributeDesignators.Designator.2=org.wso2.carbon.identity.application.authz.xacml.pip.AuthenticationContextAttributePIP" dir="${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/">
                                    <include name="entitlement.properties" />
                                </replace>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>modify_application_authenticaton</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <tasks>
                                <replace token="&lt;AuthorizationHandler&gt;" value="&lt;!--AuthorizationHandler&gt;" dir="${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/">
                                    <include name="application-authentication.xml" />
                                </replace>
                                <replace token="&lt;/AuthorizationHandler&gt;" value="&lt;/AuthorizationHandler--&gt;" dir="${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/">
                                    <include name="application-authentication.xml" />
                                </replace>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>clean_target</id>
                        <phase>install</phase>
                        <configuration>
                            <tasks>
                                <delete dir="target/archive-tmp" />
                                <delete dir="target/dependency-maven-plugin-markers" />
                                <delete dir="target/maven-archiver" />
                                <delete dir="target/wso2carbon-core-${carbon.kernel.version}" />
                                <delete dir="target/sources" />
                                <delete dir="target/site" />
                                <delete dir="src/site" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>site</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pre_dist</id>
                        <phase>test</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <filters>
                                <filter>${basedir}/src/main/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>src/main/assembly/dist.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>dist</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <filters>
                                <filter>${basedir}/src/main/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>src/main/assembly/bin.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>docs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>${basedir}/src/main/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>src/main/assembly/docs.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>
		<executions>
            	    <!-- Replace Datasource, Scope mpl classes and OAuth callback class in identity.xml -->
                    <execution>
                        <id>replace-for-identity</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                        <configuration>
                            <file>${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/identity.xml</file>
                            <replacements>
                                <replacement>
                                    <xpath>/Server/JDBCPersistenceManager/DataSource/Name</xpath>
                                    <token>(jdbc/WSO2CarbonDB)</token>
                                    <value>jdbc/WSO2AM_DB</value>
			        </replacement>
			        <replacement>
				    <xpath>/Server/OAuth/SupportedGrantTypes/SupportedGrantType</xpath>
                                    <token>(org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationCodeGrantHandler)</token>
                                    <value>org.wso2.carbon.apimgt.keymgt.handlers.ExtendedAuthorizationCodeGrantHandler</value>
			        </replacement>
			        <replacement>
				    <xpath>/Server/OAuth/SupportedGrantTypes/SupportedGrantType</xpath>
                                    <token>(org.wso2.carbon.identity.oauth2.token.handlers.grant.PasswordGrantHandler)</token>
                                    <value>org.wso2.carbon.apimgt.keymgt.handlers.ExtendedPasswordGrantHandler</value>
			        </replacement>
			        <replacement>
				    <xpath>/Server/OAuth/SupportedGrantTypes/SupportedGrantType</xpath>
                                    <token>(org.wso2.carbon.identity.oauth2.token.handlers.grant.ClientCredentialsGrantHandler)</token>
                                    <value>org.wso2.carbon.apimgt.keymgt.handlers.ExtendedClientCredentialsGrantHandler</value>
			        </replacement>
			        <replacement>
				    <xpath>/Server/OAuth/SupportedGrantTypes/SupportedGrantType</xpath>
				    <token>(org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandler)</token>
				    <value>org.wso2.carbon.apimgt.keymgt.handlers.ExtendedSAML2BearerGrantHandler</value>
			        </replacement>
                                <replacement>
                                    <xpath>/Server/OAuth/SupportedGrantTypes/SupportedGrantType</xpath>
                                    <token>(org.wso2.carbon.identity.oauth2.token.handlers.grant.iwa.ntlm.NTLMAuthenticationGrantHandler)</token>
                                    <value>org.wso2.carbon.identity.oauth2.token.handlers.grant.iwa.ntlm.NTLMAuthenticationGrantHandlerWithHandshake</value>
                                </replacement>
			        <replacement>
				    <xpath>/Server/OAuth/OAuthCallbackHandlers</xpath>
				    <token>(org.wso2.carbon.identity.oauth.callback.DefaultCallbackHandler)</token>
			    	    <value>org.wso2.carbon.apimgt.keymgt.util.APIManagerOAuthCallbackHandler</value>
			        </replacement>

                            </replacements>
                        </configuration>
		    </execution>
            <!-- Replace Datasource, Scope mpl classes and OAuth callback class in identity.xml -->
            <!-- Disable MQTT as it's not needed -->
            <execution>
                <id>replace-for-broker</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>replace</goal>
                </goals>
                <configuration>
                    <file>${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/broker.xml</file>
                    <replacements>
                        <replacement>
                            <xpath>/broker/transports/mqtt/@enabled</xpath>
                            <token>(true)</token>
                            <value>false</value>
                        </replacement>
                        <replacement>
                            <xpath>/broker/performanceTuning/slots/windowSize</xpath>
                            <token>(1000)</token>
                            <value>50</value>
                        </replacement>
                        <replacement>
                            <xpath>/broker/performanceTuning/slots/messageAccumulationTimeout</xpath>
                            <token>(2000)</token>
                            <value>50</value>
                        </replacement>
                        <replacement>
                            <xpath>/broker/performanceTuning/slots/timerPeriod</xpath>
                            <token>(1000)</token>
                            <value>40</value>
                        </replacement>
                        <replacement>
                            <xpath>/broker/deployment/mode</xpath>
                            <token>(default)</token>
                            <value>standalone</value>
                        </replacement>
                    </replacements>
                </configuration>
            </execution>
            <!-- End disabling MQTT -->

		    <!-- Replace the Datasource in the thrift-authentication.xml file -->
                    <execution>
                        <id>replace-for-thrift</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                        <configuration>
                            <file>${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/thrift-authentication.xml</file>
                            <replacements>
                                <replacement>
                                    <xpath>/Server/JDBCPersistenceManager/DataSource/Name</xpath>
                                    <token>(jdbc/WSO2CarbonDB)</token>
                                    <value>jdbc/WSO2AM_DB</value>
                                </replacement>
                            </replacements>
                        </configuration>
                    </execution>

		   <!-- Update Owasp.CsrfGuard.properties file location to fix IBM JDK issue -->
		   <execution>
                        <id>replace-for-owasp</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
			<configuration>
		 	   <file>${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/carbon/WEB-INF/web.xml</file>
                            <replacements>
                                <replacement>
                                    <xpath>/web-app/context-param/param-value</xpath>
                                    <token>(/repository/conf/security/Owasp.CsrfGuard.Carbon.properties)</token>
                                    <value>repository/conf/security/Owasp.CsrfGuard.Carbon.properties</value>
                                </replacement>
                            </replacements>
			</configuration>
                    </execution>
                </executions>
	    </plugin>

            <!-- Add the scope validator to the identity.xml file -->
            <plugin>
                <groupId>com.google.code.maven-config-processor-plugin</groupId>
                <artifactId>config-processor-maven-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>add-scope-validator</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <failOnMissingXpath>false</failOnMissingXpath>
                            <transformations>
                                <transformation>
                                    <input>
                                        ${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/identity.xml
                                    </input>
                                    <output>
                                        ../../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/identity.xml
                                    </output>
                                    <config>identity_config_change.xml</config>
                                </transformation>
                            </transformations>
                            <namespaceContexts>
                                <s>http://wso2.org/projects/carbon/carbon.xml</s>
                            </namespaceContexts>
                        </configuration>
                    </execution>
                    <execution>
                        <id>init-claim-manager</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <failOnMissingXpath>false</failOnMissingXpath>
                            <transformations>
                                <transformation>
                                    <input>
                                        ${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/user-mgt.xml
                                    </input>
                                    <output>
                                        ../../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/user-mgt.xml
                                    </output>
                                    <config>user_mgt_config_change.xml</config>
                                </transformation>
                            </transformations>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-mime-types</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <failOnMissingXpath>false</failOnMissingXpath>
                            <transformations>
                                <transformation>
                                    <input>
                                        ${basedir}/../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/web.xml
                                    </input>
                                    <output>
                                        ../../../p2-profile/product/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/web.xml
                                    </output>
                                    <config>tomcat_web_xml_change.xml</config>
                                </transformation>
                            </transformations>
                            <namespaceContexts>
                                <tom>http://java.sun.com/xml/ns/javaee</tom>
                            </namespaceContexts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

	    <!-- Skip deploying the product zip to nexus -->
	    <plugin>
  		<groupId>org.apache.maven.plugins</groupId>
  		<artifactId>maven-deploy-plugin</artifactId>
  		<configuration>
    		   <skip>true</skip>
  		</configuration>
	    </plugin>

        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.4</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>index</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>

</project>
