Загрузка данных


src/build.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="AppWorkspace" default=".help">

    <import file="${basedir}/.sencha/workspace/find-cmd-impl.xml"/>
    <target name="init-cmd"
            depends="find-cmd-in-path,
                     find-cmd-in-environment,
                     find-cmd-in-shell">
        <echo>Using Sencha Cmd from ${cmd.dir} for ${ant.file}</echo>

        <!--
        load the sencha.jar ant task definitions.

        NOTE: the 'loaderref' attribute stores this task def's class loader
        on the project by that name, so it will be sharable across sub-projects.
        This fixes out-of-memory issues, as well as increases performance.

        To supoprt this, it is recommended that any customizations that use
        'ant' or 'antcall' tasks set 'inheritrefs=true' on those tasks, in order
        to propagate the senchaloader reference to those subprojects.

        The sencha 'x-ant-call' task, which extends 'antcall' and defaults
        'inheritrefs' to true, may be used in place of antcall in
        build process customizations.
        -->
        <taskdef resource="com/sencha/ant/antlib.xml"
                 classpath="${cmd.dir}/sencha.jar"
                 loaderref="senchaloader"/>

        <!--
        Some operations require sencha.jar in the current java classpath,
        so this will extend the java.lang.Thread#contextClassLoader with the
        specified java classpath entries
        -->
        <x-extend-classpath>
            <jar path="${cmd.dir}/sencha.jar"/>
        </x-extend-classpath>
    </target>

    <target name="generate-core-app" depends="init-cmd">
        <x-echo>Generate AppCore application.</x-echo>
        <input message="Enter application name:" addproperty="args.name"/>
        <condition property="do.abort">
            <equals arg1="" arg2="${args.name}"/>
        </condition>
        <fail if="do.abort">Requires application name!</fail>
        <input message="Enter application path:" addproperty="args.path" defaultValue="./${args.name}"/>
        <copy file="${basedir}/.sencha/workspace/templates/App/_$template.js" tofile="${basedir}/.sencha/workspace/templates/App/$template.js" force="true" overwrite="true" quiet="true"/>
        <x-shell dir="${basedir}">
            sencha config -p templates.dir=${basedir}/.sencha/workspace/templates  then generate app -ext -classic ${args.name} ${args.path}
        </x-shell>
        <x-shell dir="${args.path}">
            sencha app refresh
        </x-shell>
    </target>

    <target name="generate-core-module" depends="init-cmd">
        <x-echo>Generate AppCore module.</x-echo>
        <input message="Enter module name:" addproperty="args.name"/>
        <condition property="do.abort">
            <equals arg1="" arg2="${args.name}"/>
        </condition>
        <fail if="do.abort">Requires module name!</fail>
        <x-shell dir="${basedir}">
            sencha generate package -f=ext ${args.name}
        </x-shell>
        <property name="args.path" value="${basedir}/packages/local/${args.name}"/>
        <x-generate dir="${basedir}/.sencha/workspace/templates/package" todir="${args.path}"
                    store="${args.path}/.sencha/package/codegen.json"
                    basedir="${args.path}">
            <param name="name" value="${args.name}"/>
        </x-generate>
    </target>

    <target name=".props" depends="init-cmd">
        <echoproperties/>
    </target>

</project>

src/application/build.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="WebGui" default=".help">
    <!--
    The build-impl.xml file imported here contains the guts of the build process. It is
    a great idea to read that file to understand how the process works, but it is best to
    limit your changes to this file.
    -->

    <import file="${basedir}/.sencha/app/build-impl.xml"/>

    <script language="javascript">
        <![CDATA[
            var dir = project.getProperty("basedir"),
                cmdDir = project.getProperty("cmd.dir"),
                cmdLoaded = project.getReference("senchaloader");

            if (!cmdLoaded) {
                function echo(message, file) {
                    var e = project.createTask("echo");
                    e.setMessage(message);
                    if (file) {
                        e.setFile(file);
                    }
                    e.execute();
                };

                if (!cmdDir) {

                    function exec(args) {
                        var process = java.lang.Runtime.getRuntime().exec(args),
                            input = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream())),
                            headerFound = false,
                            line;

                        while (line = input.readLine()) {
                            line = line + '';
                            java.lang.System.out.println(line);
                            if (line.indexOf("Sencha Cmd") > -1) {
                                headerFound = true;
                            }
                            else if (headerFound && !cmdDir) {
                                cmdDir = line;
                                project.setProperty("cmd.dir", cmdDir);
                            }
                        }
                        process.waitFor();
                        return !!cmdDir;
                    }

                    if (!exec(["sencha", "which"])) {
                        var tmpFile = "tmp.sh";
                        echo("source ~/.bash_profile; sencha " + whichArgs.join(" "), tmpFile);
                        exec(["/bin/sh", tmpFile]);
                        new java.io.File(tmpFile)['delete']();
                    }
                }
            }

            if (cmdDir && !project.getTargets().containsKey("init-cmd")) {
                var importDir = project.getProperty("build-impl.dir") ||
                                (cmdDir + "/ant/build/app/build-impl.xml");
                var importTask = project.createTask("import");

                importTask.setOwningTarget(self.getOwningTarget());
                importTask.setLocation(self.getLocation());
                importTask.setFile(importDir);
                importTask.execute();
            }
        ]]>
    </script>

    <!-- Добавление сборки бэкэнда при сборке приложения -->
    <target name="-after-build">
        <x-ant-call target="backend"/>
    </target>

    <!-- Основной таргет для сборки бэкэнда -->
    <target name="backend">
        <x-echo>[BACKEND] Begin build.</x-echo>
        <x-echo>[BACKEND] Clear.</x-echo>
        <x-ant-call target="clearBackend"/>                            <!-- Очистка -->
        <x-echo>[BACKEND] Create from app.</x-echo>
        <antcallback target="createBackendFormApp" return="success"/>  <!-- Создание основы -->
        <if><equals arg1="${success}" arg2="true"/>
            <then>
                <x-echo>[BACKEND] ...success</x-echo>
                <x-ant-call target="applyPackagesBackends"/>           <!-- Импорт из пакетов -->
            </then>
            <else>
                <x-echo level="warning">[BACKEND] ...failure. Backend not created.</x-echo>
            </else>
        </if>
    </target>

    <!-- Добавление бэкэнда из пакета -->
    <target name="applyBackendPackage">
        <dirset id="dirSetList" dir="${packageDir}" includes="*"/>
        <property name="PackagesList" refid="dirSetList"/>
        <for list="${PackagesList}" param="PackageName" delimiter=";">
            <sequential>
                <x-echo>[BACKEND] Check package @{PackageName}...</x-echo>
                <if><available type="dir" file="${packageDir}/@{PackageName}/backend"/>
                    <then>
                        <x-ant-call target="concatBackendFiles">
                            <param name="FileToConcat" value="containers.php"/>
                            <param name="Package" value="${packageDir}/@{PackageName}"/>
                        </x-ant-call>

                        <x-ant-call target="concatBackendFiles">
                            <param name="FileToConcat" value="routes.php"/>
                            <param name="Package" value="${packageDir}/@{PackageName}"/>
                        </x-ant-call>

                        <if>
                            <available type="dir" file="${packageDir}/@{PackageName}/backend/app/controllers" />
                            <then>
                                <x-echo>[BACKEND] ...copy ${packageDir}/@{PackageName}/backend/app/controllers</x-echo>
                                <copy todir="${build.out.page.dir}/backend/app/controllers">
                                    <fileset dir="${packageDir}/@{PackageName}/backend/app/controllers"/>
                                </copy>
                            </then>
                        </if>
                        <if>
                            <available type="dir" file="${packageDir}/@{PackageName}/backend/app/models" />
                            <then>
                                <x-echo>[BACKEND] ...copy ${packageDir}/@{PackageName}/backend/app/models</x-echo>
                                <copy todir="${build.out.page.dir}/backend/app/models">
                                    <fileset dir="${packageDir}/@{PackageName}/backend/app/models"/>
                                </copy>
                            </then>
                        </if>
                    </then>
                </if>
            </sequential>
        </for>
    </target>

    <!-- Объединение файлов бэкэнда -->
    <target name="concatBackendFiles"> <!-- FileToConcat-->
        <if>
            <and>
                <available type="file" file="${build.out.page.dir}/backend/app/${FileToConcat}"/>
                <available type="file" file="${Package}/backend/app/${FileToConcat}"/>
            </and>
            <then>
                <x-echo>[BACKEND] ...apply ${Package}/backend/app/${FileToConcat}</x-echo>
                <concat destfile="${build.out.page.dir}/backend/app/${FileToConcat}" append="yes">
                    <filelist dir="${Package}/backend/app/" files="${FileToConcat}"/>
                    <filterchain>
                        <tokenfilter>
                            <replaceregex pattern="&lt;\?php" replace="" flags="gi"/>
                        </tokenfilter>
                    </filterchain>
                </concat>
            </then>
            <else>
                <x-echo level="warning">[BACKEND] ...not found ${Package}/backend/app/${FileToConcat}</x-echo>
            </else>
        </if>
    </target>

    <!-- Добавление бэкэндов из пакетов локальных и внешних -->
    <target name="applyPackagesBackends">
        <for list="${workspace.packages.extract},${workspace.packages.dir}" param="dir">
            <sequential>
                <if><available type="dir" file="@{dir}" />
                    <then>
                        <x-ant-call target="applyBackendPackage">
                            <param name="packageDir" value="@{dir}"/>
                        </x-ant-call>
                    </then>
                </if>
            </sequential>
        </for>
    </target>

    <!-- Очистка директории бэкэнда приложения -->
    <target name="clearBackend">
        <if>
            <available type="dir" file="${build.out.page.dir}/backend"/>
            <then>
                <delete dir="${build.out.page.dir}/backend"/>
            </then>
        </if>
    </target>

    <!-- Перенос бекенда приложения в билд -->
    <target name="createBackendFormApp">
        <if>
            <available type="dir" file="${basedir}/backend" />
            <then>
                <mkdir dir="${build.out.page.dir}/backend"/>
                <copy todir="${build.out.page.dir}/backend">
                    <fileset dir="${basedir}/backend"/>
                </copy>
                <property name="success" value="true"/>
            </then>
            <else>
                <property name="success" value="false"/>
            </else>
        </if>
    </target>

    <!--
    The following targets can be provided to inject logic before and/or after key steps
    of the build process:

        The "init-local" target is used to initialize properties that may be personalized
        for the local machine.

            <target name="-before-init-local"/>
            <target name="-after-init-local"/>

        The "clean" target is used to clean build output from the build.dir.

            <target name="-before-clean"/>
            <target name="-after-clean"/>

        The general "init" target is used to initialize all other properties, including
        those provided by Sencha Cmd.

            <target name="-before-init"/>
            <target name="-after-init"/>

        The "page" target performs the call to Sencha Cmd to build the 'all-classes.js' file.

            <target name="-before-page"/>
            <target name="-after-page"/>

        The "build" target performs the call to Sencha Cmd to build the application.

            <target name="-before-build"/>
            <target name="-after-build"/>
    -->

</project>


ivy/build_linux.xml:
<!--
Arguments for resolving dependencies
${conf} - configuration: build_windows, standard:(header, bin:(release,debug), docs), buildsrv:(header, bin-release), linux:(source), full
${local_libs_store}
${makelinks}: make links - true, do copy - false. 'true' is default value.
${build_number}
${branch}
${brand}
${resolver}: local or storage-main
${build.dir}: path to main or component root dir, <module.name> is subdir of this
${java.home}
ant get -Dconf=buildsrv
-->

<project xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:e="http://ant.apache.org/ivy/extra" name="webgui" default="pub">
    <!--taskdef resource="net/sf/antcontrib/antcontrib.properties" /-->
    <property name="artifacts.base" value="ivy/_artifacts" />
    <property name="artifacts.dir" value="${build.dir}/${artifacts.base}" />
    <property name="local_libs_store_base" value="_local_libs_store" />
    <property name="local_libs_store" value="${build.dir}/${local_libs_store_base}" />
    <property name="result" value="_result" />
    <property name="src_dir" value="${result}/src" />
    <property name="build_out" value="dist" />
    <property name="prefix" value="${build.dir}/${result}" />

	<!-- Каталог воркспейса -->
	<property name="workspace.dir" value="${build.dir}/src" />
	<!-- Каталог с пакетами -->
	<property name="packages.dir" value="${workspace.dir}/packages/local" />
	<!-- Инициализация Sencha Cmd -->
	<property name="sencha.jar" value="${build.dir}/_result/util/Sencha/sencha.jar" />
	<!-- Путь к локальному репозиторию sencha в песочнице -->
	<property name="local.repo.dir" value="${build.dir}/_result/repo" />
	<!-- Каталог conf -->
	<property name="conf.dir" value="${build.dir}\conf" />

	<property environment="env"/>

	<condition property="local_libs_store" value="${env.LOCAL_LIBS_STORE}">
		<isset property="env.LOCAL_LIBS_STORE" />
	</condition>
	<condition property="ivy.home" value="${local_libs_store}\.ivy2">
		<isset property="local_libs_store" />
	</condition>
	<condition property="ivy.local.repo" value="${local_libs_store}\.ivyloc">
		<isset property="local_libs_store" />
	</condition>
	<fail message="local_libs_store is not defined">
		<condition>
			<not>
				<isset property="local_libs_store"/>
			</not>
		</condition>
	</fail>

<!--    &lt;!&ndash; Local artifacts cache&ndash;&gt;
    <condition property="ivy.home" value="${env.IVY_LOCAL_CACHE}" else="${local_libs_store}/.ivycache">
        <isset property="env.IVY_LOCAL_CACHE" />
    </condition>
    &lt;!&ndash; Local repository to publish artifacts &ndash;&gt;
    <condition property="ivy.local.repo" value="${env.IVY_LOCAL_REPO}" else="${local_libs_store}/.ivyloc">
        <isset property="env.IVY_LOCAL_REPO" />
    </condition>-->

	<import file="makelink.xml"/>

	<!-- Initializing version and module.name variables -->
	<exec executable="python" dir="${build.dir}" failonerror="true">
		<arg line="${build.dir}/ivy/generate_ivy_version_files.py --main_dir=${build.dir} --build_number=${build_number}"/>
	</exec>

	<property file="${build.dir}/${result}/AllPlatforms/generated/version.properties" />


	<!-- Сборка компонента -->
	<target name="build" depends="get" description="-->Build component">
		<echo message="Сборка приложения..."/>
		<!-- Сборка приложения -->
		<sencha working.dir="${workspace.dir}/application/"
				cmd.args="config -prop _FOOTER_VERSION_=${version} -prop _SHOW_WEBGUI_VERSION_=${show_webgui_version} then app build" />

		<!-- Подготовка архива для публикации на artifactory -->
		<echo message="Подготовка архива для публикации на artifactory..."/>
		<echo message="${version}" file="${build.dir}\_result\build\production\WebGui\resources\VERSION.WEBGUI"/>
		<zip destfile="${artifacts.dir}/${module.name}-src.zip">
			<zipfileset dir="${conf.dir}" prefix="webgui_http_server_conf"/>
			<zipfileset dir="${build.dir}/_result/build/production/WebGui/" prefix="${module.name}" />
		</zip>
		<exec executable="ls" dir="${artifacts.dir}/">
			<arg line="-all"/>
		</exec>
	</target>

	<!-- Сборка компонента -->
	<target name="build_conf" depends="get" description="-->Build components configuration">
		<echo message="Сборка конфигурационных файлов..."/>
		<!-- Подготовка архива для публикации на artifactory -->
		<echo message="Подготовка архива для публикации на artifactory..."/>
		<zip destfile="${artifacts.dir}/${module.name}-src.zip">
			<zipfileset dir="${conf.dir}" prefix="webgui_http_server_conf"/>
		</zip>
	</target>

	<target name="pub" description="-->Publish lib to the repository" depends="build">
		<echo message="publication..."/>
		<ivy:publish resolver="${resolver}" overwrite="true" organisation="main" module="${module.name}" revision="${version}" update="true" pubbranch="${branch}">
			<artifacts pattern="${artifacts.dir}/[artifact].[ext]" />
		</ivy:publish>
		<delete dir="${artifacts.dir}"/>
	</target>

	<target name="initrepo" description="-->Initialize local sencha repository in sandbox" depends="get">
		<echo message="Initialize local sencha repository in sandbox ..."/>
		<copy todir="${local.repo.dir}/" overwrite="true">
			<fileset dir="${build.dir}/sign/" />
		</copy>
	</target>

	<target name="get" description="-->Downloads all artifacts and prepare it">
		<!-- Deleting garbage from previous builds -->
		<delete file="${artifacts.dir}/ivy.xml"/>

		<ivy:resolve file="ivy-linux.xml" conf="${conf}" resolveMode="default" />
		<ivy:deliver conf="*" deliverpattern="${artifacts.dir}/resolved_ivy.xml" />

		<!--<exec executable="python" dir="${build_dir}" failonerror="true">
			<arg line="${build_dir}/ivy/generate_ivy_version_files.py &#45;&#45;main_dir=${build_dir} &#45;&#45;build_number=${build_number}"/>
		</exec>-->

		<exec executable="python" failonerror="true">
			<arg value="${build.dir}/_result/src/build_info/ver_tools/generate_version_files.py"/>
			<arg value="--main_dir=${build.dir}"/>
			<arg value="--build_number=${build_number}"/>
		</exec>

		<!-- Установка пакетов -->
		<echo message="Установка пакетов..."/>
		<dirset id="remotePackages" dir="${build.dir}/_result/src/" includes="*"/>
		<property name="remotePackagesList" refid="remotePackages"/>
		<for list="${remotePackagesList}" param="PackageDir" delimiter=";">
			<sequential>
				<for param="file">
					<path>
						<fileset dir="${build.dir}/_result/src/@{PackageDir}" includes="*.pkg"/>
					</path>
					<sequential>
						<echo>Установка пакета @{file}...</echo>
						<sencha working.dir="${workspace.dir}" cmd.args="package add @{file}" />
					</sequential>
				</for>
			</sequential>
		</for>

	</target>

	<!-- Макрос для запуска Sencha Cmd -->
	<macrodef name="sencha">
		<!-- Рабочий каталог -->
		<attribute name="working.dir" />
		<!-- Аргументы Sencha Cmd -->
		<attribute name="cmd.args" />
		<sequential>
			<echo message="Запуск java... dir @{working.dir} -jar ${sencha.jar}"/>
			<exec executable="${java.home}/bin/java" dir="@{working.dir}" failonerror="true">
				<arg line="-XX:-UseGCOverheadLimit -jar ${sencha.jar} config -prop app.file_version=${version} -prop brand=${brand} -prop repo.local.dir=${local.repo.dir} then @{cmd.args}" />
			</exec>
		</sequential>
	</macrodef>

	<!-- Сборка pkg -->
	<macrodef name="buildpkg">
		<!-- Имя пакета -->
		<attribute name="package.name" />
		<!-- Версия пакета -->
		<attribute name="package.version" />
		<sequential>
			<echo message="Building package ${packages.dir}/@{package.name} @ @{package.version} ..."/>

			<!-- Задаем версию пакета -->
			<replace file="${packages.dir}/@{package.name}/package.json">
				<replacetoken><![CDATA["version": "1.0.0.0"]]></replacetoken>
				<replacevalue><![CDATA["version": "@{package.version}"]]></replacevalue>
			</replace>
			<replace file="${packages.dir}/@{package.name}/package.json">
				<replacetoken><![CDATA["compatVersion": "1.0.0.0"]]></replacetoken>
				<replacevalue><![CDATA["compatVersion": "@{package.version}"]]></replacevalue>
			</replace>

			<!-- Сборка неподписанного pkg -->
			<sencha working.dir="${packages.dir}/@{package.name}/" cmd.args="package build" />
			<!-- Подпись -->
			<sencha working.dir="${workspace.dir}/" cmd.args="package add ${workspace.dir}/build/@{package.name}/@{package.name}.pkg" />

			<!-- Перемещение подписанного pkg в каталог артифактов сборки -->
			<move file="${local.repo.dir}/pkgs/@{package.name}/@{package.version}/@{package.name}.pkg" tofile="${artifacts.dir}/@{package.name}.pkg" />
		</sequential>
	</macrodef>

    <!--&lt;!&ndash;<import file="makelink.xml"/&ndash;&gt;

    &lt;!&ndash;<taskdef resource="net/sf/antcontrib/antcontrib.properties"/&ndash;&gt;

    &lt;!&ndash;<taskdef name="artifactproperty" classname="org.apache.ivy.ant.IvyArtifactProperty"/&ndash;&gt;
    &lt;!&ndash;<if>
        <equals arg1="${makelinks}" arg2="false"/>
        <then>
            <var name="makelinksVal" value="false"/>
        </then>
        <else>
            <var name="makelinksVal" value="true"/>
        </else>
    </if&ndash;&gt;
	
	<dirname property="build.dir" file="${ant.file}\.." />

     &lt;!&ndash; Скрипт подписи используется из citools &ndash;&gt;
    <property name="signutil" value="${build.dir}\_result\util\citools\code_sign" />
    <property name="citools" value="${build.dir}\_result\util\citools" />
    <property name="python" value="python.exe" />
	<property name="java" value="java" />

    <ivy:settings id="ivy.set" file="ivysettings.xml"/>
    <property name="artifacts.dir" value="${build.dir}\ivy\artifacts"/>
	
	&lt;!&ndash; Инициализация Sencha Cmd &ndash;&gt;
	<property name="sencha.jar" value="${build.dir}\_result\util\Sencha\sencha.jar" />
	
	&lt;!&ndash; Путь к локальному репозиторию sencha в песочнице &ndash;&gt;
	<property name="local.repo.dir" value="${build.dir}\_result\repo" />
	&lt;!&ndash; Каталог воркспейса &ndash;&gt;
	<property name="workspace.dir" value="${build.dir}\package" />
	&lt;!&ndash; Каталог с пакетами &ndash;&gt;
	<property name="packages.dir" value="${workspace.dir}\packages\local" />
	
	&lt;!&ndash; Макрос для запуска Sencha Cmd &ndash;&gt;
	<macrodef name="sencha">
		&lt;!&ndash; Рабочий каталог &ndash;&gt;
		<attribute name="working.dir" />
		&lt;!&ndash; Аргументы Sencha Cmd &ndash;&gt;
		<attribute name="cmd.args" />
		<sequential>
			<exec executable="${java}" dir="@{working.dir}" failonerror="true">
				<arg line="-XX:-UseGCOverheadLimit -jar ${sencha.jar} config -prop repo.local.dir=${local.repo.dir} then @{cmd.args}" />
			</exec>
		</sequential>
	</macrodef>
	
	&lt;!&ndash; Сборка pkg &ndash;&gt;
	<macrodef name="buildpkg">
		&lt;!&ndash; Имя пакета &ndash;&gt;
		<attribute name="package.name" />
		&lt;!&ndash; Версия пакета &ndash;&gt;
		<attribute name="package.version" />
		<sequential>
			<echo message="Building package @{package.name} @ @{package.version} ..."/>
		
			&lt;!&ndash; Задаем версию пакета &ndash;&gt;
			<replace file="${packages.dir}\@{package.name}\package.json">
				<replacetoken><![CDATA["version": "1.0.0.0"]]></replacetoken>
				<replacevalue><![CDATA["version": "@{package.version}"]]></replacevalue>
			</replace>
			<replace file="${packages.dir}\@{package.name}\package.json">
				<replacetoken><![CDATA["compatVersion": "1.0.0.0"]]></replacetoken>
				<replacevalue><![CDATA["compatVersion": "@{package.version}"]]></replacevalue>
			</replace>
			
			&lt;!&ndash; Сборка неподписанного pkg &ndash;&gt;
			<sencha working.dir="${packages.dir}\@{package.name}\" cmd.args="package build" />
			&lt;!&ndash; Подпись &ndash;&gt;
			<sencha working.dir="${workspace.dir}\" cmd.args="package add ${workspace.dir}\build\@{package.name}\@{package.name}.pkg" />
			
			&lt;!&ndash; Перемещение подписанного pkg в каталог артифактов сборки &ndash;&gt;
			<move file="${local.repo.dir}\pkgs\@{package.name}\@{package.version}\@{package.name}.pkg" tofile="${artifacts.dir}\@{package.name}.pkg" />
		</sequential>
	</macrodef>


    <property file="${build.dir}/_result/AllPlatforms/generated/version.properties" />
	
	&lt;!&ndash; Инициализация локального репозитория в песочнице &ndash;&gt;-->

</project>

ivy/build.xml:
<!--
Arguments for resolving dependencies
${conf} - configuration: build_windows, standard:(header, bin:(release,debug), docs), buildsrv:(header, bin-release), linux:(source), full
${local_libs_store}
${makelinks}: make links - true, do copy - false. 'true' is default value.
${build_number}
${branch}
${brand}
${resolver}: local or storage-main
${build.dir}: path to main or component root dir, <module.name> is subdir of this
ant get -Dconf=buildsrv
-->

<project xmlns:ivy="antlib:org.apache.ivy.ant"
         xmlns:antcontrib="antlib:net.sf.antcontrib"
         xmlns:e="http://ant.apache.org/ivy/extra"
         default="pub">

    <property environment="env"/>
    <condition property="local_libs_store" value="${env.LOCAL_LIBS_STORE}">
        <isset property="env.LOCAL_LIBS_STORE" />
    </condition>
    <condition property="ivy.home" value="${local_libs_store}\.ivy2">
        <isset property="local_libs_store" />
    </condition>
    <condition property="ivy.local.repo" value="${local_libs_store}\.ivyloc">
        <isset property="local_libs_store" />
    </condition>
    <fail message="local_libs_store is not defined">
        <condition>
            <not>
                <isset property="local_libs_store"/>
            </not>
        </condition>
    </fail>

    <import file="makelink.xml"/>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

    <taskdef name="artifactproperty" classname="org.apache.ivy.ant.IvyArtifactProperty"/>
    <if>
        <equals arg1="${makelinks}" arg2="false"/>
        <then>
            <var name="makelinksVal" value="false"/>
        </then>
        <else>
            <var name="makelinksVal" value="true"/>
        </else>
    </if>
	
	<dirname property="build.dir" file="${ant.file}\.." />

     <!-- Скрипт подписи используется из citools -->
    <property name="signutil" value="${build.dir}\_result\util\citools\code_sign" />
    <property name="citools" value="${build.dir}\_result\util\citools" />
    <property name="python" value="python.exe" />
    <property name="java" value="java" />
	<property name="sencha.exec" value="sencha" />

    <ivy:settings id="ivy.set" file="ivysettings.xml"/>
    <property name="artifacts.dir" value="${build.dir}\ivy\artifacts"/>
	
	<!-- Инициализация Sencha Cmd -->
	<property name="sencha.jar" value="${build.dir}\_result\util\Sencha\sencha.jar" />
	
	<!-- Путь к локальному репозиторию sencha в песочнице -->
	<property name="local.repo.dir" value="${build.dir}\_result\repo" />
	<!-- Каталог воркспейса -->
	<property name="workspace.dir" value="${build.dir}\src" />

    <!-- Каталог conf -->
    <property name="conf.dir" value="${build.dir}\conf" />
	
	<!-- Макрос для запуска Sencha Cmd -->
	<macrodef name="sencha">
		<!-- Рабочий каталог -->
		<attribute name="working.dir" />
		<!-- Аргументы Sencha Cmd -->
		<attribute name="cmd.args" />
		<sequential>
			<var name="executable.opts" value="" />
			<var name="executable.name" value="${sencha.exec}" />

			<!-- 
				Локальный репозиторий в папке _result создается и используется только в конфигурации build_windows, т.е. на сборочном сервере,
				где нет возможности использовать установленную Sencha Cmd. В конфигурации standard (на машине разработчика) используется локальный репозиторий,
				сконфигурированный в установленной на машине Sencha Cmd.
		    -->
			<if>
				<equals arg1="${conf}" arg2="build_windows" />
				<then>
					<var name="executable.opts" value="-XX:-UseGCOverheadLimit -jar ${sencha.jar} config -prop repo.local.dir=${local.repo.dir} -prop brand=${brand} then" />
					<var name="executable.name" value="${java}" />
				</then>
			</if>
		
			<exec executable="${executable.name}" dir="@{working.dir}" failonerror="true">
				<arg line="${executable.opts} @{cmd.args}" />
			</exec>
		</sequential>
	</macrodef>

    <!-- Initializing version and module.name variables -->
    <exec executable="${python}" failonerror="true">
      <arg value="${build.dir}/ivy/generate_ivy_version_files.py"/>
      <arg value="--main_dir=${build.dir}"/>
      <arg value="--build_number=${build_number}"/>
    </exec>
    <property file="${build.dir}/_result/AllPlatforms/generated/version.properties" />

    <target name="get" description="-->Downloads all artifacts and prepare it">
        <!-- Deleting garbage from previous builds -->
        <delete file="${artifacts.dir}/ivy.xml"/>               
         
        <ivy:resolve file="ivy.xml" conf="${conf}" resolveMode="default" />
        <ivy:deliver conf="*" deliverpattern="${artifacts.dir}/resolved_ivy.xml" />

        <exec executable="${python}" failonerror="true">
            <arg value="${build.dir}/_result/src/build_info/ver_tools/generate_version_files.py"/>
            <arg value="--main_dir=${build.dir}"/>
            <arg value="--build_number=${build_number}"/>
        </exec>
		
		<!-- 
			Локальный репозиторий в папке _result создается и используется только в конфигурации build_windows, т.е. на сборочном сервере,
			где нет возможности использовать установленную Sencha Cmd. В конфигурации standard (на машине разработчика) используется локальный репозиторий,
			сконфигурированный в установленной на машине Sencha Cmd.
		-->
		<if>
			<equals arg1="${conf}" arg2="build_windows" />
			<then>
				<sencha working.dir="${workspace.dir}" cmd.args="package repo init -name BuildSandbox" />
			</then>
		</if>
		
		<!-- Установка пакетов -->
        <echo message="Установка пакетов..."/>
        <dirset id="remotePackages" dir="${build.dir}\_result\src\" includes="*"/>
        <property name="remotePackagesList" refid="remotePackages"/>
        <for list="${remotePackagesList}" param="PackageDir" delimiter=";">
            <sequential>
                <for param="file">
                    <path>
                        <fileset dir="${build.dir}\_result\src\@{PackageDir}" includes="*.pkg"/>
                    </path>
                    <sequential>
                        <echo>Установка пакета @{file}...</echo>
                        <sencha working.dir="${workspace.dir}" cmd.args="package add @{file}" />
                    </sequential>
                </for>
            </sequential>
        </for>
        <!--
		<sencha working.dir="${workspace.dir}" cmd.args="package add ${build.dir}\_result\src\webgui_frontend_package_core\Core.pkg" />
		<sencha working.dir="${workspace.dir}" cmd.args="package add ${build.dir}\_result\src\extjs_webapp_core\CoreTheme.pkg" />
        <sencha working.dir="${workspace.dir}" cmd.args="package add ${build.dir}\_result\src\extjs_webapp_core\FontProvance.pkg" />
        -->

    </target>

    <target name="pub" description="-->Publish lib to the repository" depends="build">
        <echo message="publication..."/>
        <ivy:publish resolver="${resolver}" overwrite="true" organisation="main" module="${module.name}" revision="${version}" update="true">
            <artifacts pattern="${artifacts.dir}/[artifact].[ext]" />
        </ivy:publish>
        <delete dir="${artifacts.dir}"/>
    </target>

	<!-- Сборка компонента -->
    <target name="build" depends="get" description="-->Build component">
        <echo message="Сборка приложения..."/>
		<!-- Сборка приложения -->
        <sencha working.dir="${workspace.dir}\application\"
                cmd.args="config -prop brand=${brand} -prop app.file_version=${version} -prop _FOOTER_VERSION_=${version} -prop _SHOW_WEBGUI_VERSION_=${show_webgui_version} then app build" />
		
		<!-- Подготовка архива для публикации на artifactory -->
        <echo message="Подготовка архива для публикации на artifactory..."/>

        <echo message="${version}" file="${build.dir}\_result\build\production\WebGui\resources\VERSION.WEBGUI"/>

        <zip destfile="${artifacts.dir}/${module.name}-src.zip">
            <zipfileset dir="${conf.dir}" prefix="webgui_http_server_conf"/>
    	    <zipfileset dir="${build.dir}\_result\build\production\WebGui\" prefix="${module.name}" />
	</zip>
    </target>
 
</project>