<!--
 * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 * 
 * This software is the property of WSO2 Inc. and its suppliers, if any.
 * Dissemination of any information or reproduction of any material contained
 * herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 * You may not alter or remove any copyright or other notice from copies of this content."
-->

<project name="identity-apps" basedir=".">

    <target name="check-theme-dir">
        <available property="distribution.theme.dir.exists" file="target/identity-apps/modules/theme/src/themes/${identity.apps.theme}" type="dir"
        />
    </target>

    <target name="create-auth-distribution-dir" depends="check-theme-dir" unless="distribution.theme.dir.exists">
        <mkdir dir="target/identity-apps/modules/theme/src/themes/${identity.apps.theme}"/>  
    </target>

    <target name="duplicate-default-theme" depends="check-theme-dir">
        <echo message="--- creating custom theme extensions ---"/>
        <copy todir="target/identity-apps/modules/theme/src/themes/${identity.apps.theme}/" overwrite="true">
            <fileset dir="target/identity-apps/modules/theme/src/themes/default/" includes="**" />
        </copy>
    </target>

    <target name="copy-theme-extensions" depends="duplicate-default-theme">
        <echo message="--- copying theme extensions ---"/>
        <copy todir="target/identity-apps/modules/theme/src/themes/${identity.apps.theme}" overwrite="true">
            <fileset dir="theme-extensions/${identity.apps.theme}" includes="**" />
        </copy>
    </target>

    <target name="copy-console-extensions">
        <echo message="--- copying console extensions ---"/>
        <copy todir="target/identity-apps/apps/console/src/extensions/" overwrite="true">
            <fileset dir="app-extensions/console/src/extensions/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/" file="app-extensions/lerna.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/console/src" file="app-extensions/console/src/index.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/console/src" file="app-extensions/console/src/index.html" overwrite="true"/>
    </target>

    <target name="copy-myaccount-extensions">
        <echo message="--- copying myaccount extensions ---"/>
        <copy todir="target/identity-apps/apps/myaccount/src/extensions/" overwrite="true">
            <fileset dir="app-extensions/myaccount/src/extensions/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/" file="app-extensions/lerna.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/myaccount/src/public/" file="app-extensions/myaccount/src/public/deployment.config.json" overwrite="true"/>
    </target>

    <target name="copy-auth-portal-extensions">
        <echo message="--- copying authentication portal extensions ---"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/extensions/" overwrite="true">
            <fileset dir="app-extensions/authentication-portal/src/extensions/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/basicauth.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/identifierauth.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/login.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/enableTOTP.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/totp.jsp" overwrite="true"/>
    </target>

    <target name="copy-email-otp-auth-portal-extensions">
        <echo message="--- copying email otp authentication portal extensions ---"/>
        <copy todir="target/identity-apps/apps/email-otp-authentication-portal/src/main/webapp/extensions/" overwrite="true">
            <fileset dir="app-extensions/email-otp-authentication-portal/src/extensions/" includes="**" />
        </copy>
    </target>

    <target name="copy-recovery-portal-extensions">
        <echo message="--- copying recovery portal extensions ---"/>
        <copy todir="target/identity-apps/apps/recovery-portal/src/main/webapp/extensions/" overwrite="true">
            <fileset dir="app-extensions/recovery-portal/src/extensions/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/recovery-portal/src/main/webapp/" overwrite="true">
            <fileset dir="app-extensions/recovery-portal/src/main/webapp/" includes="**" />
        </copy>
    </target>

    <target name="copy-sms-otp-portal-extensions">
        <echo message="--- copying sms otp authentication portal extensions ---"/>
        <copy todir="target/identity-apps/apps/sms-otp-authentication-portal/src/main/webapp/extensions/" overwrite="true">
            <fileset dir="app-extensions/sms-otp-authentication-portal/src/extensions/" includes="**" />
        </copy>
    </target>

    <target name="copy-x509-cert-portal-extensions">
        <echo message="--- copying x509 certificate authentication portal extensions ---"/>
        <copy todir="target/identity-apps/apps/x509-certificate-authentication-portal/src/main/webapp/extensions/" overwrite="true">
            <fileset dir="app-extensions/x509-certificate-authentication-portal/src/extensions/" includes="**" />
        </copy>
    </target>

    <target 
        name="init-extensions" 
        depends="
            copy-console-extensions,
            copy-myaccount-extensions,
            copy-theme-extensions,
            copy-auth-portal-extensions,
            copy-email-otp-auth-portal-extensions,
            copy-recovery-portal-extensions,
            copy-sms-otp-portal-extensions,
            copy-x509-cert-portal-extensions"
    />

</project>
