<?xml version="1.0" encoding="UTF-8"?>
<!--
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

  Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.

  Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  Other names may be trademarks of their respective owners.

  The contents of this file are subject to the terms of either the GNU General Public
  License Version 2 only ("GPL") or the Common Development and Distribution
  License("CDDL") (collectively, the "License"). You may not use this file except in
  compliance with the License. You can obtain a copy of the License at
  http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
  License for the specific language governing permissions and limitations under the
  License.  When distributing the software, include this License Header Notice in
  each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP.  Oracle
  designates this particular file as subject to the "Classpath" exception as provided
  by Oracle in the GPL Version 2 section of the License file that accompanied this code.
  If applicable, add the following below the License Header, with the fields enclosed
  by brackets [] replaced by your own identifying information:
  "Portions Copyrighted [year] [name of copyright owner]"
  
  Contributor(s):
  
  The Original Software is NetBeans. The Initial Developer of the Original Software
  is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
  Rights Reserved.
  
  If you wish your version of this file to be governed by only the CDDL or only the
  GPL Version 2, indicate your decision by adding "[Contributor] elects to include
  this software in this distribution under the [CDDL or GPL Version 2] license." If
  you do not indicate a single choice of license, a recipient has the option to
  distribute your version of this file under either the CDDL, the GPL Version 2 or
  to extend the choice of license to its licensees as provided above. However, if you
  add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the
  option applies only if the new code is made subject to such option by the copyright
  holder.
-->

<!--
  This is the base build script for nbi engine. 
  
  It is not intended to be used directly, but to be imported into derivative
  implementaion scripts, which will provide properties' values that are 
  specific the concrete engine implementation. The derivative scripts may also
  provide some additional functionality that is required by their respective
  engine implementations.
  
  This script exposes five primary targets: 'init', 'clean', 'checkout', 
  'build' and 'release'; as well as two aggregate targets: 'build-all', 
  which tranlates into 'init', 'clean', 'checkout', 'build', and 
  'release-all' - 'init', 'clean', 'checkout', 'build', 'release'. For the 
  detailed description of the functionality of these targets, consult the 
  corresponsing documentation.
-->
<project name="engine" default="usage" basedir=".">
    <!-- a default value for the ${common.dir} property, which allows the user 
         to see the usage information is he calls this script directly and not
         via a derivative (which is the proper way to do this) -->
    <property name="common.dir" value="${basedir}"/>
    
    <!-- import the common properties -->
    <property file="${common.dir}/common.properties"/>
    
    <!-- import properties specific to the engine's build script -->
    <property file="${common.dir}/engine.properties"/>
    
    <!-- import the common target library -->
    <import file="common.xml" optional="false"/>
    
    <!-- ============================================================================
      Initialization
    ============================================================================= -->
    
    <!--
      Initializes the engine's build script.
      
      This target overrides the '-init' target in common.xml, providing the 
      custom functionality that is required for the engine's build script
      initialization.
      
      In addition to the standard initialization routine, this target defines
      several custom ant tasks, which are specific to the engine's build 
      script.
      
      This target is not intended to be called directly.
    -->
    <target name="-init" depends=".init">
        <!-- define custom ant tasks -->
        <if property="release.to.server" value="true">
            <taskdef
                name="release-engine-server"
                classname="org.netbeans.installer.infra.build.ant.ReleaseEngine"
                classpath="${custom.tasks.cls}"/>
        </if>
        
        <if property="release.to.server" value="false">
            <taskdef 
                name="release-engine-filesystem"
                classname="org.netbeans.installer.infra.build.ant.registries.UpdateEngine"
                classpath="${custom.tasks.cls}"/>
        </if>
    </target>
    
    <!-- ============================================================================
      Clean-up
    ============================================================================= -->
    
    <!--
      Cleans the current working directory and the distributives directory.
      
      This target overrides the '-clean' target in common.xml, providing the 
      custom functionality that is required for correctly cleaning the engine.
      
      In addition to the standard behavior the engine distributive file is 
      removed from the distributives directory.
      
      This target is not intended to be called directly.
    -->
    <target name="-clean" depends=".clean">
        <!-- remove the engine's distributive file from the distributives 
             directory -->
        <delete file="${dist.dir}/${engine.dist.file.name}"/>
    </target>
    
    <!--
      Cleans the native components of the engine.
      
      This target overrides the '.clean-native' target defined in common.xml,
      as the engine's native components slightly differ from the defaults. 
      Besides cleaning the jni libraries, the engine also needs to clean the 
      native launcher stubs.
      
      This target is antcall'ed in a loop over the list of platforms from the 
      '.clean' target in common.xml.
      
      This target is only executed if the the ${build.native} property was set 
      to 'true'.
      
      This target is not intended to be called directly.
    -->
    <target name=".clean-native" if="do.build.native">
        <antcall target=".clean-jni"/>
        <antcall target=".clean-launcher"/>
    </target>
    
    <!--
      Cleans the native launcher stub for the given platform.
      
      This target is antcall'ed as part of the call to the '.clean-native' 
      target, and expects the ${platform} property to contain the code name of
      the platform for which the launcher should be built.
      
      It simply removes the current launcher stub.
      
      This target is only executed if the the ${build.native} property was set 
      to 'true'.
      
      This target is not intended to be called directly.
    -->
    <target name=".clean-launcher" if="do.build.native">
        <!-- does nothing at the moment -->
    </target>
    
    <!-- ============================================================================
      Check-out
    ============================================================================= -->
    
    <!--
      The functionality of the checkout procedure for the engine is indentical 
      to the standard one, thus there is not need to override the '-checkout'
      target, whosew default implementation is present in common.xml.
    -->
    
    <!-- ============================================================================
      Build
    ============================================================================= -->
    
    <!--
      Builds the engine and (optionally) its native components.
      
      This target overrides the '-build' target in common.xml, providing the 
      custom functionality that is required for correctly building the engine.
      
      The build process consists of three steps: first, the native components 
      of the engine (jni libraries and native launcher stubs) are built (if it
      is required), then the engine's netbeans project is compiled and 
      packaged, last the engine jar file is digitally signed and copied to the
      distributives directory.
      
      This target is not intended to be called directly.
    -->
    <target name="-build" depends=".build">
        <!-- copy the built binary to the distributives directory -->
        <copy file="${nbproject.dist.file}" todir="${dist.dir}"/>
        
        <!-- digitally sign the built binary -->
	<if property="jarsigner.enabled" value="true">
                <signjar jar="${dist.dir}/${engine.dist.file.name}" 
                         keystore="${jarsigner.keystore}"
                         storepass="${jarsigner.storepass}"
                         alias="${jarsigner.alias}"
                         maxmemory="${jarsigner.xmx}"/>
	</if>
    </target>
    
    <!--
      Builds the native components of the engine.
      
      This target overrides the '.build-native' target defined in common.xml,
      as the engine's native components slightly differ from the defaults. 
      Besides building the jni libraries, the engine also needs to build the 
      native launcher stubs, which will later be used to create redistributable 
      bundles.
      
      This target is antcall'ed in a loop over the list of platforms from the 
      '.build' target in common.xml.
      
      This target is only executed if the the ${build.native} property was set 
      to 'true'.
      
      This target is not intended to be called directly.
    -->
    <target name=".build-native" if="do.build.native">
        <antcall target=".build-jni"/>
        <antcall target=".build-launcher"/>
        <antcall target=".build-cleaner"/>
    </target>
    
    <!--
      Builds the native launcher stub for the given platform.
      
      This target is antcall'ed as part of the call to the '.build-native' 
      target, and expects the ${platform} property to contain the code name of
      the platform for which the launcher should be built.
      
      It connects to the registered satellite machine for the current platform
      using the 'ssh' utility, checks out the launcher's sources and builds it.
      The built binary is then copied back to the host machine using 'scp'.
      
      This target is only executed if the the ${build.native} property was set 
      to 'true'.
      
      This target is not intended to be called directly.
    -->
    <target name=".build-launcher" if="do.build.native">
        <!-- does nothing at the moment -->
    </target>
    
    <!--
      Builds the native cleaner for locked files for the given platform.
      
      This target is antcall'ed as part of the call to the '.build-native' 
      target, and expects the ${platform} property to contain the code name of
      the platform for which the launcher should be built.
      
      It connects to the registered satellite machine for the current platform
      using the 'ssh' utility, checks out the launcher's sources and builds it.
      The built binary is then copied back to the host machine using 'scp'.
      
      This target is only executed if the the ${build.native} property was set 
      to 'true'.
      
      This target is not intended to be called directly.
    -->
    <target name=".build-cleaner" if="do.build.native">
        <!-- does nothing at the moment -->
    </target>
    
    
    <!-- ============================================================================
      Release
    ============================================================================= -->
    
    <!--
      Releases the engine to the registries server.
      
      This target overrides the '-release' target in common.xml, providing the 
      custom functionality that is required for correctly releasing the engine.
      
      It is assumed that the engine has already been built, but a dependency 
      on the 'build' target is not defined, as it may be desirable to build 
      once and then release several times to different registries servers.
      
      This target is not intended to be called directly.
    -->
    <target name="-release">
        <if property="release.to.server" value="true">
            <echo message="Release URL is ${release.url}"/>
            <echo message="Archive is ${dist.dir}/${engine.dist.file.name}"/>
            
            <release-engine-server 
                url="${release.url}"
                archive="${dist.dir}/${engine.dist.file.name}"/>
        </if>
        <if property="release.to.server" value="false">
            <echo message="Registry root is ${release.registry.dir}"/>
            <echo message="Archive is ${dist.dir}/${engine.dist.file.name}"/>
            
            <release-engine-filesystem
                root="${release.registry.dir}"
                archive="${dist.dir}/${engine.dist.file.name}"/>
        </if>
    </target>
    
    <!-- ============================================================================
      Default
    ============================================================================= -->
    
    <!--
      The default target. 
      
      Does nothing except printing the usage information.
    -->
    <target name="usage">
        <echo>
            This is the base build script for nbi engine and is not intended to
            be called directly. In order to create a derivative implementation 
            script, see 
            ${basedir}/.templates/engine-template.xml
        </echo>
    </target>
</project>
