<?xml version="1.0" ?>
<!--

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF 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 name="compiler-jx" default="main" basedir=".">

    <pathconvert property="basedir_clean" dirsep="/">
		<path location="${basedir}" />
    </pathconvert>
	
    <!-- The 'env' property contains all the environment variables -->
    <property environment="env"/>
    
    <!-- Properties can be overridden locally by loading a local.properties file -->
    <!-- Java 8 users probably need javadoc.params=-Xdoclint:none -->
    <property file="${basedir}/local.properties"/>
    <property file="${basedir}/../build.properties"/>
    
	<!-- Options for <javac> tasks -->
	<property name="javac.debug" value="true"/>
	<property name="javac.deprecation" value="false"/>
	<property name="javac.src" value="11"/>

    <!-- JAR manifest entries -->
    <property name="manifest.sealed" value="false"/>
    <property name="manifest.Implementation-Title" value="Apache Royale Compiler"/>
    <property name="manifest.Implementation-Version" value="${release.version}"/>
    <property name="manifest.Implementation-Vendor" value="Apache Software Foundation"/>

    <property name="src" value="${basedir_clean}/src/main/java" />
	<property name="lib" value="${basedir_clean}/lib" />
	
	<property name="royale.basedir" value="${basedir_clean}/../compiler" />
    <property name="royale.lib.dir" value="${royale.basedir}/lib" />
	
	<property name="classes.dir" value="${basedir_clean}/target/classes" />
	
	<property name="mxmlc.jar" value="${lib}/mxmlc.jar" />
    <property name="externc.jar" value="${lib}/externc.jar" />
	<property name="compc.jar" value="${lib}/compc.jar" />
	<property name="jsc.jar" value="${lib}/jsc.jar" />
    <property name="asdoc.jar" value="${lib}/asdoc.jar" />

    <!-- env.BUILD_NUMBER is set by Jenkins CI -->
    <condition property="build.number" value="nightly-${env.BUILD_NUMBER}">
        <isset property="env.BUILD_NUMBER"/>
    </condition>
    <property name="build.number" value="0"/>

    <path id="classpath">
        <filelist dir="${royale.lib.dir}/">
            <file name="compiler.jar" />
            <file name="compiler-common.jar" />
        </filelist>
        <filelist dir="${royale.lib.dir}/external">
            <file name="antlr.jar" />
            <file name="commons-lang-2.6.jar" />
        </filelist>
		<filelist dir="${lib}">
			<file name="commons-io.jar" />
            <file name="guava.jar" />
            <file name="failureaccess.jar" />
			<file name="flex-tool-api.jar" />
            <file name="externc.jar" />
            <file name="compiler-playerglobalc.jar" />
        </filelist>
		<filelist dir="${lib}/google/closure-compiler">
            <file name="compiler.jar" />
        </filelist>
	</path>

	<target name="compile">
		<javac debug="true" deprecation="${javac.deprecation}"
            includes="**/*.java"
            excludes=""
            destdir="${classes.dir}"
            classpathref="classpath"
            source="${javac.src}" target="${javac.src}">
			<src path="${src}" />
		</javac>
	</target>

    <target name="prebuild">
		<mkdir dir="${classes.dir}" />
        <mkdir dir="${classes.dir}/META-INF" />
        <mkdir dir="${lib}/google/closure-compiler" />
        <ant antfile="${basedir}/src/main/resources/downloads.xml" dir="${basedir}/src/main/resources" inheritAll="false"/>
    </target>
	
	<target name="main" depends="prebuild,compile">
        
        <property name="jar.classpath" value="commons-io.jar guava.jar failureaccess.jar ../../lib/external/antlr.jar ../../compiler/lib/external/antlr.jar ../../lib/external/commons-lang-2.6.jar ../../compiler/lib/external/commons-lang-2.6.jar google/closure-compiler/compiler.jar ../../compiler/lib/compiler.jar ../../lib/compiler.jar  ../../compiler/lib/compiler-common.jar ../../lib/compiler-common.jar" />

        <copy file="${basedir}/../LICENSE.base" tofile="${classes.dir}/META-INF/LICENSE"/>
        <copy file="${basedir}/../NOTICE.base" tofile="${classes.dir}/META-INF/NOTICE"/>
        
		<echo message="Building ${jsc.jar}" />
		<jar file="${jsc.jar}" basedir="${classes.dir}"
            includes="**/*.properties,org/apache/**/*,com/google/**/*,META-INF/**/*"
			excludes="**/JSDriver*,**/IASNodeAdapter*,org/apache/royale/compiler/internal/parsing/abc/*" >
            <include name="META-INF/LICENSE"/>
            <include name="META-INF/NOTICE"/>
            <manifest>
                <attribute name="Sealed" value="${manifest.sealed}"/>
                <attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
                <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
                <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
                <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
        </jar>

		<echo message="Building ${mxmlc.jar}" />
		<jar file="${mxmlc.jar}" basedir="${classes.dir}">
            <include name="META-INF/LICENSE"/>
            <include name="META-INF/NOTICE"/>
			<manifest>
                <attribute name="Sealed" value="${manifest.sealed}"/>
                <attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
                <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
                <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
				<attribute name="Main-Class" value="org.apache.royale.compiler.clients.MXMLJSC" />
                <attribute name="Class-Path" value="args4j.jar org.json.jar jsc.jar" />
			</manifest>
		</jar>

		<echo message="Building ${compc.jar}" />
		<jar file="${compc.jar}" basedir="${classes.dir}">
            <include name="META-INF/LICENSE"/>
            <include name="META-INF/NOTICE"/>
			<manifest>
                <attribute name="Sealed" value="${manifest.sealed}"/>
                <attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
                <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
                <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
				<attribute name="Main-Class" value="org.apache.royale.compiler.clients.COMPJSC" />
                <attribute name="Class-Path" value="jsc.jar" />
			</manifest>
		</jar>

        <echo message="Building ${asdoc.jar}" />
        <jar file="${asdoc.jar}" basedir="${classes.dir}">
            <include name="META-INF/LICENSE"/>
            <include name="META-INF/NOTICE"/>
            <manifest>
                <attribute name="Sealed" value="${manifest.sealed}"/>
                <attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
                <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
                <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
                <attribute name="Main-Class" value="org.apache.royale.compiler.clients.ASDOCJSC" />
                <attribute name="Class-Path" value="jsc.jar" />
            </manifest>
        </jar>

        <chmod dir="${basedir}/src/assembly" excludes="**/*.bat" perm="+x" />
	</target>

    <target name="test" description="Runs JUnit tests">
        <ant dir="src/test" />
    </target>

    <!--
		Cleanup
	-->
	
    <target name="super-clean" depends="thirdparty-clean,clean" />

    <target name="thirdparty-clean">
        <ant antfile="${basedir}/src/main/resources/downloads.xml" dir="${basedir}/src/main/resources" inheritAll="false" target="clean" />
        <delete dir="${basedir}/target" />
        <delete failonerror="false" includeemptydirs="true">
            <fileset dir="${lib}" />
        </delete>
    </target>

    <target name="clean" >
        <delete dir="${basedir}/target/classes" />
        <delete failonerror="false" includeemptydirs="true">
            <fileset dir="${lib}" >
                <include name="compc.jar" />
                <include name="externc.jar" />
                <include name="mxmlc.jar" />
                <include name="jsc.jar" />
                <include name="asdoc.jar" />
            </fileset>
		</delete>
    </target>

</project>
