<!--
 * 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="copy-script-extensions">
        <echo message="--- copying script extensions to My Account ---"/>
        <copy todir="target/identity-apps/apps/myaccount/scripts/" overwrite="true">
            <fileset dir="script-extensions/" includes="**" />
        </copy>
        <echo message="--- copying script extensions to Console ---"/>
        <copy todir="target/identity-apps/apps/console/scripts/" overwrite="true">
            <fileset dir="script-extensions/" includes="**" />
        </copy>
    </target>

    <target name="copy-presets">
        <echo message="--- copying license header template override preset ---"/>
        <copy todir="target/identity-apps/" file="license-header-override.js" overwrite="true"/>
    </target>

    <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/.github/workflows/scripts/" file=".github/workflows/scripts/lint-changed.sh" overwrite="true"/>
        <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/" file="app-extensions/console/babel.config.js" 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/home.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/console/src/features/core/components/pre-loader" overwrite="true">
            <fileset dir="app-extensions/console/src/extensions/components/component-extensions/core/pre-loader" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/console/src/public/" file="app-extensions/console/src/public/deployment.config.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/console/src/public/" file="app-extensions/console/src/public/robots.txt" overwrite="true"/>
        <copy todir="target/identity-apps/apps/console/src/public/WEB-INF/" file="app-extensions/console/src/public/WEB-INF/web.xml" 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/apps/myaccount/src" file="app-extensions/myaccount/src/index.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/myaccount/src" file="app-extensions/myaccount/src/home.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/" file="app-extensions/lerna.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/myaccount/src/components/shared/pre-loader" overwrite="true">
            <fileset dir="app-extensions/console/src/extensions/components/component-extensions/core/pre-loader" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/myaccount/src/public/" file="app-extensions/myaccount/src/public/deployment.config.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/myaccount/src/public/" file="app-extensions/myaccount/src/public/robots.txt" overwrite="true"/>
        <copy todir="target/identity-apps/apps/myaccount/src/public/WEB-INF/" file="app-extensions/myaccount/src/public/WEB-INF/web.xml" 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/emailOtp.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/smsOtp.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/smsOtpError.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/mobile.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"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/totpError.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/backup-code.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/backup-code-error.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/oauth2_consent.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/consent.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/oauth2_error.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/requested-claims.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/dynamic_prompt.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/user-not-found.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/block-sign-in.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/magic_link_notification.jsp" overwrite="true" />
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/mau_over_usage.jsp" overwrite="true" />
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/includes/" file="app-extensions/authentication-portal/src/includes/error-tracking-reference.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/includes/" file="app-extensions/authentication-portal/src/includes/init-url.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/includes/"
              file="app-extensions/authentication-portal/src/includes/template-mapper.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/oauth2_logout_consent.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/fido2-auth.jsp" overwrite="true" />
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/logout.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/generic-exception-response.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/retry.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/templates/"
              file="app-extensions/authentication-portal/src/templates/finishAccountLink.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/templates/"
              file="app-extensions/authentication-portal/src/templates/startAccountLink.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/util/" file="app-extensions/authentication-portal/src/util/app-insights-util.js" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/app-insights.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/samlsso_response.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/oauth_response.jsp" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/util/" file="app-extensions/authentication-portal/src/util/string-utils.js" overwrite="true"/>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/resources/" overwrite="true">
            <fileset dir="app-extensions/authentication-portal/src/main/resources/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/errors/" overwrite="true">
            <fileset dir="app-extensions/authentication-portal/src/errors/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/authentication-portal/src/main/webapp/" file="app-extensions/authentication-portal/src/robots.txt" overwrite="true"/>
    </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/includes/" overwrite="true">
            <fileset dir="app-extensions/recovery-portal/src/includes/" 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>
        <copy todir="target/identity-apps/apps/recovery-portal/src/main/resources/" overwrite="true">
            <fileset dir="app-extensions/recovery-portal/src/main/resources/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/apps/recovery-portal/src/main/webapp/errors/" overwrite="true">
            <fileset dir="app-extensions/recovery-portal/src/errors/" 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="copy-login-portal-layouts-extensions">
        <echo message="--- copying login portal layouts extensions ---"/>
        <copy todir="target/identity-apps/components/login-portal-layouts/" overwrite="true">
            <fileset dir="login-portal-layouts-extensions/" includes="**" />
        </copy>
    </target>

    <target
        name="init-extensions"
        depends="
            copy-presets,
            copy-script-extensions,
            copy-console-extensions,
            copy-myaccount-extensions,
            copy-theme-extensions,
            copy-auth-portal-extensions,
            copy-recovery-portal-extensions,
            copy-x509-cert-portal-extensions,
            copy-login-portal-layouts-extensions"
    />

</project>
