text:
/**********************************************************************
* $Id$      lpc_ssp.h           2011-06-02
*//**
* @file     lpc_ssp.h
* @brief    Contains all macro definitions and function prototypes
*           support for SSP firmware library on LPC
* @version  1.0
* @date     02. June. 2011
* @author   NXP MCU SW Application Team
*
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors'
* relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers.  This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
**********************************************************************/

/* Peripheral group ----------------------------------------------------------- */
/** @defgroup SSP   SSP (Synchronous Serial Port)
 * @ingroup LPC_CMSIS_FwLib_Drivers
 * @{
 */

#ifndef __LPC_SSP_H_
#define __LPC_SSP_H_

/* Includes ------------------------------------------------------------------- */
#include "LPC407x_8x_177x_8x.h"
#include "lpc_types.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* Public Macros -------------------------------------------------------------- */
/** @defgroup SSP_Public_Macros SSP Public Macros
 * @{
 */

/*********************************************************************//**
 * SSP configuration parameter defines
 **********************************************************************/
/** Clock phase control bit */
#define SSP_CPHA_FIRST          ((uint32_t)(0))
#define SSP_CPHA_SECOND         SSP_CR0_CPHA_SECOND

/** Clock polarity control bit */
/* There's no bug here!!!
 * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames.
 * That means the active clock is in HI state.
 * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock
 * high between frames. That means the active clock is in LO state.
 */
#define SSP_CPOL_HI             ((uint32_t)(0))
#define SSP_CPOL_LO             SSP_CR0_CPOL_HI

/** SSP master mode enable */
#define SSP_SLAVE_MODE          SSP_CR1_SLAVE_EN
#define SSP_MASTER_MODE         ((uint32_t)(0))

/** SSP data bit number defines */
#define SSP_DATABIT_4       SSP_CR0_DSS(4)          /*!< Databit number = 4 */
#define SSP_DATABIT_5       SSP_CR0_DSS(5)          /*!< Databit number = 5 */
#define SSP_DATABIT_6       SSP_CR0_DSS(6)          /*!< Databit number = 6 */
#define SSP_DATABIT_7       SSP_CR0_DSS(7)          /*!< Databit number = 7 */
#define SSP_DATABIT_8       SSP_CR0_DSS(8)          /*!< Databit number = 8 */
#define SSP_DATABIT_9       SSP_CR0_DSS(9)          /*!< Databit number = 9 */
#define SSP_DATABIT_10      SSP_CR0_DSS(10)         /*!< Databit number = 10 */
#define SSP_DATABIT_11      SSP_CR0_DSS(11)         /*!< Databit number = 11 */
#define SSP_DATABIT_12      SSP_CR0_DSS(12)         /*!< Databit number = 12 */
#define SSP_DATABIT_13      SSP_CR0_DSS(13)         /*!< Databit number = 13 */
#define SSP_DATABIT_14      SSP_CR0_DSS(14)         /*!< Databit number = 14 */
#define SSP_DATABIT_15      SSP_CR0_DSS(15)         /*!< Databit number = 15 */
#define SSP_DATABIT_16      SSP_CR0_DSS(16)         /*!< Databit number = 16 */

/** SSP Frame Format definition */
/** Motorola SPI mode */
#define SSP_FRAME_SPI       SSP_CR0_FRF_SPI
/** TI synchronous serial mode */
#define SSP_FRAME_TI        SSP_CR0_FRF_TI
/** National Micro-wire mode */
#define SSP_FRAME_MICROWIRE SSP_CR0_FRF_MICROWIRE

/*********************************************************************//**
 * SSP Status defines
 **********************************************************************/
/** SSP status TX FIFO Empty bit */
#define SSP_STAT_TXFIFO_EMPTY       SSP_SR_TFE
/** SSP status TX FIFO not full bit */
#define SSP_STAT_TXFIFO_NOTFULL     SSP_SR_TNF
/** SSP status RX FIFO not empty bit */
#define SSP_STAT_RXFIFO_NOTEMPTY    SSP_SR_RNE
/** SSP status RX FIFO full bit */
#define SSP_STAT_RXFIFO_FULL        SSP_SR_RFF
/** SSP status SSP Busy bit */
#define SSP_STAT_BUSY               SSP_SR_BSY

/*********************************************************************//**
 * SSP Interrupt Configuration defines
 **********************************************************************/
/** Receive Overrun */
#define SSP_INTCFG_ROR      SSP_IMSC_ROR
/** Receive TimeOut */
#define SSP_INTCFG_RT       SSP_IMSC_RT
/** Rx FIFO is at least half full */
#define SSP_INTCFG_RX       SSP_IMSC_RX
/** Tx FIFO is at least half empty */
#define SSP_INTCFG_TX       SSP_IMSC_TX

/*********************************************************************//**
 * SSP Configured Interrupt Status defines
 **********************************************************************/
/** Receive Overrun */
#define SSP_INTSTAT_ROR     SSP_MIS_ROR
/** Receive TimeOut */
#define SSP_INTSTAT_RT      SSP_MIS_RT
/** Rx FIFO is at least half full */
#define SSP_INTSTAT_RX      SSP_MIS_RX
/** Tx FIFO is at least half empty */
#define SSP_INTSTAT_TX      SSP_MIS_TX

/*********************************************************************//**
 * SSP Raw Interrupt Status defines
 **********************************************************************/
/** Receive Overrun */
#define SSP_INTSTAT_RAW_ROR     SSP_RIS_ROR
/** Receive TimeOut */
#define SSP_INTSTAT_RAW_RT      SSP_RIS_RT
/** Rx FIFO is at least half full */
#define SSP_INTSTAT_RAW_RX      SSP_RIS_RX
/** Tx FIFO is at least half empty */
#define SSP_INTSTAT_RAW_TX      SSP_RIS_TX

/*********************************************************************//**
 * SSP Interrupt Clear defines
 **********************************************************************/
/** Writing a 1 to this bit clears the "frame was received when
 * RxFIFO was full" interrupt */
#define SSP_INTCLR_ROR      SSP_ICR_ROR
/** Writing a 1 to this bit clears the "Rx FIFO was not empty and
 * has not been read for a timeout period" interrupt */
#define SSP_INTCLR_RT       SSP_ICR_RT

/*********************************************************************//**
 * SSP DMA defines
 **********************************************************************/
/** SSP bit for enabling RX DMA */
#define SSP_DMA_RX      SSP_DMA_RXDMA_EN
/** SSP bit for enabling TX DMA */
#define SSP_DMA_TX      SSP_DMA_TXDMA_EN

/* SSP Status Implementation definitions */
#define SSP_STAT_DONE       (1UL<<8)        /**< Done */
#define SSP_STAT_ERROR      (1UL<<9)        /**< Error */

/**
 * @}
 */

/* Private Macros ------------------------------------------------------------- */
/** @defgroup SSP_Private_Macros SSP Private Macros
 * @{
 */

/* --------------------- BIT DEFINITIONS -------------------------------------- */
/*********************************************************************//**
 * Macro defines for CR0 register
 **********************************************************************/
/** SSP data size select, must be 4 bits to 16 bits */
#define SSP_CR0_DSS(n)          ((uint32_t)((n-1)&0xF))
/** SSP control 0 Motorola SPI mode */
#define SSP_CR0_FRF_SPI         ((uint32_t)(0<<4))
/** SSP control 0 TI synchronous serial mode */
#define SSP_CR0_FRF_TI          ((uint32_t)(1<<4))
/** SSP control 0 National Micro-wire mode */
#define SSP_CR0_FRF_MICROWIRE   ((uint32_t)(2<<4))
/** SPI clock polarity bit (used in SPI mode only), (1) = maintains the
   bus clock high between frames, (0) = low */
#define SSP_CR0_CPOL_HI     ((uint32_t)(1<<6))
/** SPI clock out phase bit (used in SPI mode only), (1) = captures data
   on the second clock transition of the frame, (0) = first */
#define SSP_CR0_CPHA_SECOND ((uint32_t)(1<<7))
/** SSP serial clock rate value load macro, divider rate is
   PERIPH_CLK / (cpsr * (SCR + 1)) */
#define SSP_CR0_SCR(n)      ((uint32_t)((n&0xFF)<<8))
/** SSP CR0 bit mask */
#define SSP_CR0_BITMASK     ((uint32_t)(0xFFFF))

/*********************************************************************//**
 * Macro defines for CR1 register
 **********************************************************************/
/** SSP control 1 loopback mode enable bit */
#define SSP_CR1_LBM_EN      ((uint32_t)(1<<0))
/** SSP control 1 enable bit */
#define SSP_CR1_SSP_EN      ((uint32_t)(1<<1))
/** SSP control 1 slave enable */
#define SSP_CR1_SLAVE_EN    ((uint32_t)(1<<2))
/** SSP control 1 slave out disable bit, disables transmit line in slave
   mode */
#define SSP_CR1_SO_DISABLE  ((uint32_t)(1<<3))
/** SSP CR1 bit mask */
#define SSP_CR1_BITMASK     ((uint32_t)(0x0F))

/*********************************************************************//**
 * Macro defines for DR register
 **********************************************************************/
/** SSP data bit mask */
#define SSP_DR_BITMASK(n)   ((n)&0xFFFF)

/*********************************************************************//**
 * Macro defines for SR register
 **********************************************************************/
/** SSP status TX FIFO Empty bit */
#define SSP_SR_TFE      ((uint32_t)(1<<0))
/** SSP status TX FIFO not full bit */
#define SSP_SR_TNF      ((uint32_t)(1<<1))
/** SSP status RX FIFO not empty bit */
#define SSP_SR_RNE      ((uint32_t)(1<<2))
/** SSP status RX FIFO full bit */
#define SSP_SR_RFF      ((uint32_t)(1<<3))
/** SSP status SSP Busy bit */
#define SSP_SR_BSY      ((uint32_t)(1<<4))
/** SSP SR bit mask */
#define SSP_SR_BITMASK  ((uint32_t)(0x1F))

/*********************************************************************//**
 * Macro defines for CPSR register
 **********************************************************************/
/** SSP clock prescaler */
#define SSP_CPSR_CPDVSR(n)  ((uint32_t)(n&0xFF))
/** SSP CPSR bit mask */
#define SSP_CPSR_BITMASK    ((uint32_t)(0xFF))

/*********************************************************************//**
 * Macro define for (IMSC) Interrupt Mask Set/Clear registers
 **********************************************************************/
/** Receive Overrun */
#define SSP_IMSC_ROR    ((uint32_t)(1<<0))
/** Receive TimeOut */
#define SSP_IMSC_RT     ((uint32_t)(1<<1))
/** Rx FIFO is at least half full */
#define SSP_IMSC_RX     ((uint32_t)(1<<2))
/** Tx FIFO is at least half empty */
#define SSP_IMSC_TX     ((uint32_t)(1<<3))
/** IMSC bit mask */
#define SSP_IMSC_BITMASK    ((uint32_t)(0x0F))

/*********************************************************************//**
 * Macro define for (RIS) Raw Interrupt Status registers
 **********************************************************************/
/** Receive Overrun */
#define SSP_RIS_ROR     ((uint32_t)(1<<0))
/** Receive TimeOut */
#define SSP_RIS_RT      ((uint32_t)(1<<1))
/** Rx FIFO is at least half full */
#define SSP_RIS_RX      ((uint32_t)(1<<2))
/** Tx FIFO is at least half empty */
#define SSP_RIS_TX      ((uint32_t)(1<<3))
/** RIS bit mask */
#define SSP_RIS_BITMASK ((uint32_t)(0x0F))

/*********************************************************************//**
 * Macro define for (MIS) Masked Interrupt Status registers
 **********************************************************************/
/** Receive Overrun */
#define SSP_MIS_ROR     ((uint32_t)(1<<0))
/** Receive TimeOut */
#define SSP_MIS_RT      ((uint32_t)(1<<1))
/** Rx FIFO is at least half full */
#define SSP_MIS_RX      ((uint32_t)(1<<2))
/** Tx FIFO is at least half empty */
#define SSP_MIS_TX      ((uint32_t)(1<<3))
/** MIS bit mask */
#define SSP_MIS_BITMASK ((uint32_t)(0x0F))

/*********************************************************************//**
 * Macro define for (ICR) Interrupt Clear registers
 **********************************************************************/
/** Writing a 1 to this bit clears the "frame was received when
 * RxFIFO was full" interrupt */
#define SSP_ICR_ROR     ((uint32_t)(1<<0))
/** Writing a 1 to this bit clears the "Rx FIFO was not empty and
 * has not been read for a timeout period" interrupt */
#define SSP_ICR_RT      ((uint32_t)(1<<1))
/** ICR bit mask */
#define SSP_ICR_BITMASK ((uint32_t)(0x03))

/*********************************************************************//**
 * Macro defines for DMACR register
 **********************************************************************/
/** SSP bit for enabling RX DMA */
#define SSP_DMA_RXDMA_EN    ((uint32_t)(1<<0))
/** SSP bit for enabling TX DMA */
#define SSP_DMA_TXDMA_EN    ((uint32_t)(1<<1))
/** DMACR   bit mask */
#define SSP_DMA_BITMASK     ((uint32_t)(0x03))

/**
 * @}
 */

/* Public Types --------------------------------------------------------------- */
/** @defgroup SSP_Public_Types SSP Public Types
 * @{
 */

/** @brief SSP configuration structure */
typedef struct {
    uint32_t Databit;       /** Databit number, should be SSP_DATABIT_x,
                            where x is in range from 4 - 16 */
    uint32_t CPHA;          /** Clock phase, should be:
                            - SSP_CPHA_FIRST: first clock edge
                            - SSP_CPHA_SECOND: second clock edge */
    uint32_t CPOL;          /** Clock polarity, should be:
                            - SSP_CPOL_HI: high level
                            - SSP_CPOL_LO: low level */
    uint32_t Mode;          /** SSP mode, should be:
                            - SSP_MASTER_MODE: Master mode
                            - SSP_SLAVE_MODE: Slave mode */
    uint32_t FrameFormat;   /** Frame Format:
                            - SSP_FRAME_SPI: Motorola SPI frame format
                            - SSP_FRAME_TI: TI frame format
                            - SSP_FRAME_MICROWIRE: National Microwire frame format */
    uint32_t ClockRate;     /** Clock rate,in Hz */
} SSP_CFG_Type;

/**
 * @brief SSP Transfer Type definitions
 */
typedef enum {
    SSP_TRANSFER_POLLING = 0,   /**< Polling transfer */
    SSP_TRANSFER_INTERRUPT      /**< Interrupt transfer */
} SSP_TRANSFER_Type;

/**
 * @brief SPI Data configuration structure definitions
 */
typedef struct {
    void *tx_data;              /**< Pointer to transmit data */
    uint32_t tx_cnt;            /**< Transmit counter */
    void *rx_data;              /**< Pointer to transmit data */
    uint32_t rx_cnt;            /**< Receive counter */
    uint32_t length;            /**< Length of transfer data */
    uint32_t status;            /**< Current status of SSP activity */
} SSP_DATA_SETUP_Type;

/**
 * @}
 */

/* Public Functions ----------------------------------------------------------- */
/** @defgroup SSP_Public_Functions SSP Public Functions
 * @{
 */

/* SSP Init/DeInit functions --------------------------------------------------*/
void SSP_Init(LPC_SSP_TypeDef *SSPx, SSP_CFG_Type *SSP_ConfigStruct);
void SSP_DeInit(LPC_SSP_TypeDef* SSPx);

/* SSP configure functions ----------------------------------------------------*/
void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct);

/* SSP enable/disable functions -----------------------------------------------*/
void SSP_Cmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState);
void SSP_LoopBackCmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState);
void SSP_SlaveOutputCmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState);
void SSP_DMACmd(LPC_SSP_TypeDef *SSPx, uint32_t DMAMode, FunctionalState NewState);

/* SSP get information functions ----------------------------------------------*/
FlagStatus SSP_GetStatus(LPC_SSP_TypeDef* SSPx, uint32_t FlagType);
uint8_t SSP_GetDataSize(LPC_SSP_TypeDef* SSPx);
IntStatus SSP_GetRawIntStatus(LPC_SSP_TypeDef *SSPx, uint32_t RawIntType);
uint32_t SSP_GetRawIntStatusReg(LPC_SSP_TypeDef *SSPx);
IntStatus SSP_GetIntStatus (LPC_SSP_TypeDef *SSPx, uint32_t IntType);

/* SSP transfer data functions ------------------------------------------------*/
void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data);
uint16_t SSP_ReceiveData(LPC_SSP_TypeDef* SSPx);
int32_t SSP_ReadWrite (LPC_SSP_TypeDef *SSPx, SSP_DATA_SETUP_Type *dataCfg, \
                        SSP_TRANSFER_Type xfType);

/* SSP IRQ function ------------------------------------------------------------*/
void SSP_IntConfig(LPC_SSP_TypeDef *SSPx, uint32_t IntType, FunctionalState NewState);
void SSP_ClearIntPending(LPC_SSP_TypeDef *SSPx, uint32_t IntType);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* __LPC_SSP_H_ */

/**
 * @}
 */

/* --------------------------------- End Of File ------------------------------ */


text:
import { of } from "rxjs";
import { distinctUntilKeyChanged, distinctUntilChanged } from "rxjs/operators";

const source1$ = of(1, 2, 3, 3, 3, 2, 3, "3");
// by default triple equal === operator, so we have 3 and '3' in the end
source1$.pipe(distinctUntilChanged()).subscribe(console.log);

// define our own equal function
source1$
  .pipe(distinctUntilChanged((x, y) => x == y))
  .subscribe(x => console.log("custom ", x)); // 3 only printed once at the end

const source2$ = of(
  { name: "asdf", id: 1 },
  { name: "asdf", id: 2 },
  { name: "asdf", id: 3 },
  { name: "asdf new", id: 4 }
);
// shortcut to compare only keys of objects (vs. define custom comparison func in distinctUntilChanged)
source2$.pipe(distinctUntilKeyChanged("name")).subscribe(console.log);

redpajama_set_name: RedPajamaGithub


text:
<?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="falcon" default="main" basedir=".">

    <property file="${basedir}/env.properties"/>
    <property environment="env"/>
    <property file="${basedir}/local.properties"/>
    <property file="${basedir}/build.properties"/>

    <property name="kit.prefix" value="apache-flex-falcon-${release.version}"/>
    <property name="kit.jx.prefix" value="apache-flex-falconjx-${release.version}"/>
    <property name="source.kit" value="${kit.prefix}-src"/>
    <property name="binary.kit" value="${kit.prefix}-bin"/>
    <property name="source.jx.kit" value="${kit.jx.prefix}-src"/>
    <property name="binary.jx.kit" value="${kit.jx.prefix}-bin"/>

    <target name="check-typedefs-home"
        description="Check FLEXJS_TYPEDEFS_HOME">

        <echo message="FLEXJS_TYPEDEFS_HOME is ${env.FLEXJS_TYPEDEFS_HOME}"/>

        <available file="${env.FLEXJS_TYPEDEFS_HOME}"
        type="dir"
        property="FLEXJS_TYPEDEFS_HOME"
        value="${env.FLEXJS_TYPEDEFS_HOME}" />

        <available file="${basedir}/../flex-typedefs"
        type="dir"
        property="FLEXJS_TYPEDEFS_HOME"
        value="${basedir}/../flex-typedefs" />

        <available file="${basedir}/flex-typedefs"
        type="dir"
        property="FLEXJS_TYPEDEFS_HOME"
        value="${basedir}/flex-typedefs" />

        <fail message="The environment variable FLEXJS_TYPEDEFS_HOME is not set to a directory"
        unless="FLEXJS_TYPEDEFS_HOME"/>

    </target>

    <!--
     Optional jars but should be in place for a real release build.

     For <grep> put AntelopeTasks_*.jar in this path.
     See version-update.

     For <rat> apache-rat-0.8.jar and apache-rat-tasks-0.8.jar should be in classpath.
     See rat-check.
     -->
    <path id="anttask.classpath">
        <fileset dir="${env.ANT_HOME}/lib">
            <include name="**/AntelopeTasks_*.jar"/>
            <include name="**/apache-rat*.jar"/>
        </fileset>
        <fileset dir="${user.home}">
            <include name=".ant/lib/**/AntelopeTasks_*.jar"/>
            <include name=".ant/lib/**/apache-rat*.jar"/>
        </fileset>
    </path>

    <target name="javadoc" description="Builds Falcon's Javadoc at generated/javadoc.">
        <!--<ant dir="compiler" target="javadoc"/>-->
    </target>

    <target name="eclipse" description="Prepares or updates Falcon's project(s) for use in Eclipse. This takes care of generating Java files for lexers, parsers, and BURMs.">
        <ant dir="compiler" target="eclipse"/>
        <ant dir="compiler.tests" target="eclipse"/>
    </target>

    <target name="sdk" description="Produces an set of jars in compiler/lib.">
        <ant dir="compiler-build-tools" />
        <ant dir="compiler-jburg-types" />
        <ant dir="compiler-test-utils" />
        <ant dir="compiler" />
    </target>

    <target name="main" depends="sdk, javadoc, tests" description="Default target - Builds a Falcon SDK, builds Falcon Javadoc, and runs tests."/>

    <target name="all" depends="main, jx, typedefs, oem, debugger, anttasks" description="Builds Falcon, then FalconJX"/>

    <target name="jx" depends="compiler.jx, compiler.jx.tests" description="Builds FalconJX" />

    <target name="typedefs" depends="check-typedefs-home, typedef.swcs, typedef.tests" description="Build typedefs and run tests"/>

    <target name="oem" depends="compiler.oem" description="Builds FB Integration JAR" />

    <target name="tests" description="Runs the tests." unless="skip.compiler.tests">
        <ant dir="compiler" target="test"/>
    </target>

    <target name="compiler.oem" depends="compiler.jx" description="Builds FB Integration JAR">
        <ant dir="flex-compiler-oem" target="main"/>
    </target>

    <target name="anttasks" description="Builds ant tasks JAR">
        <ant dir="flexjs-ant-tasks" target="jar"/>
    </target>

    <target name="debugger" description="Builds FDB JAR">
        <ant dir="debugger" target="jar"/>
    </target>

    <target name="compiler.jx" description="Builds FalconJX.">
        <ant dir="compiler-jx" target="main"/>
    </target>

    <target name="compiler.jx.tests" description="Runs the tests." unless="skip.compiler.jx.tests">
        <ant dir="compiler-jx" target="test"/>
    </target>

    <target name="ant.tests" description="Runs the tests." unless="skip.compiler.jx.tests">
        <ant dir="flexjs-ant-tasks" target="test"/>
    </target>

    <target name="copyLastSuccessfulBuild" description="Copies last flex-asjs build.">
        <ant dir="compiler-jx/src/test" target="copyLastSuccessfulBuild"/>
    </target>

    <target name="typedef.swcs">
        <property name="FALCON_HOME" value="${basedir}/compiler" />
        <property name="FALCONJX_HOME" value="${basedir}/compiler-jx" />
        <ant dir="${FLEXJS_TYPEDEFS_HOME}" />
    </target>
    <target name="typedef.swcs.clean" >
        <ant dir="${FLEXJS_TYPEDEFS_HOME}" target="clean"/>
    </target>
    <target name="typedef.swcs.wipe" >
        <ant dir="${FLEXJS_TYPEDEFS_HOME}" target="wipe"/>
    </target>
    <target name="typedef.tests">
        <ant dir="compiler-jx/src/test" target="extern.tests" />
    </target>

    <target name="clean" description="Cleans the build output but leaves any downloaded JARs.">
        <ant dir="compiler" target="clean"/>
        <ant dir="compiler/src/test" target="clean"/>
    </target>

    <target name="clean-all" description="Cleans the build output but leaves any downloaded JARs.">
        <ant dir="compiler" target="clean"/>
        <ant dir="compiler/src/test" target="clean"/>
        <ant dir="compiler-jx" target="clean"/>
        <ant dir="compiler-jx/src/test" target="clean"/>
        <ant dir="flex-compiler-oem" target="clean"/>
        <ant dir="flexjs-ant-tasks" target="clean"/>
        <ant dir="debugger" target="clean"/>
    </target>

    <target name="wipe" description="Wipes out everything that didn't come from Git.">
        <ant dir="compiler-build-tools" target="wipe"/>
        <ant dir="compiler-test-utils" target="wipe"/>
        <ant dir="compiler-jburg-types" target="wipe"/>
        <ant dir="compiler" target="wipe"/>
        <ant dir="compiler/src/tests" target="wipe"/>
    </target>

    <target name="wipe-all" description="Wipes out everything that didn't come from Git.">
        <ant dir="compiler-build-tools" target="wipe"/>
        <ant dir="compiler-jburg-types" target="wipe"/>
        <ant dir="compiler-test-utils" target="wipe"/>
        <ant dir="compiler" target="wipe"/>
        <ant dir="compiler/src/test" target="wipe"/>
		<ant dir="compiler-jx" target="super-clean"/>
        <ant dir="compiler-jx/src/test" target="wipe"/>
        <ant dir="flex-compiler-oem" target="wipe"/>
        <ant dir="flexjs-ant-tasks" target="wipe"/>
        <ant dir="debugger" target="clean"/>
        <delete dir="${basedir}/out" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/temp" failonerror="false" includeEmptyDirs="true"/>
        <!-- remove legacy folders if they exist -->
        <delete dir="${basedir}/compiler.jx" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/compiler/generated" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/externs" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <target name="maven-artifacts" description="Installs Falcon artifacts to a local maven repository">
        <ant dir="compiler" target="maven-artifacts"/>
    </target>

    <target name="check-flex-home" unless="mxmlc.jar.exists"
        description="Check FLEX_HOME for both a directory and an exe file">

        <echo message="FLEX_HOME is ${env.FLEX_HOME}"/>

        <available file="${env.FLEX_HOME}"
        type="dir"
        property="FLEX_SDK_HOME"
        value="${env.FLEX_HOME}" />

        <available file="${basedir}/../flex-sdk"
        type="dir"
        property="FLEX_SDK_HOME"
        value="${basedir}/../flex-sdk" />

        <fail message="The environment variable FLEX_HOME is not set to a directory"
        unless="FLEX_SDK_HOME"/>

        <condition property="mxmlc.jar.exists">
            <available file="${FLEX_SDK_HOME}/lib/mxmlc.jar" type="file"/>
        </condition>

        <fail message="The directory ${FLEX_SDK_HOME} does not contain mxmlc.jar"
        unless="mxmlc.jar.exists"/>
    </target>

    <!--
     Can set build.additional-packages to build additional-packages as part of a release.
     This does not build the docs.  Use doc-packages or asdoc-packages.
     -->
    <target name="release"
        depends="source-release,binary-release,rat-check"
        description="Creates source and binary kits for Apache Falcon and FalconJX."/>

    <target name="source-release"
        depends="wipe-all,check-flex-home,source-package"
        description="Packages the source release kit which is the official Apache release."/>

    <target name="binary-release"
        depends="setup-binary-release,all,binary-package,javadoc"
        description="Builds and packages the binary kit which is provided as a convenience."/>

    <!--
        Package up the Apache Flex sources.  Do not include empty directories.

        Note: even if cleaned, this will package up unversioned files that happen
        to be in the tree.

        FixMe: clean needs to clean - add code to detect unversioned files
    -->
    <target name="source-package" depends="stage-source,source-package-zip,source-package-tgz,stage-source-jx,source-package-jx-zip,source-package-jx-tgz"
        description="Package source files required to build in zip and tar-gzip file">
    </target>

    <!--
     Packages the source distribution with ZIP.
     -->
    <target name="source-package-zip" unless="no.zip">
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${source.kit}.zip" basedir="${basedir}/temp"/>
    </target>

    <!--
     Packages the source distribution with TAR-GZIP.
     -->
    <target name="source-package-tgz" unless="no.zip">
        <tar-gzip name="${source.kit}" />
    </target>

    <!--
     Packages the source distribution with ZIP.
     -->
    <target name="source-package-jx-zip" unless="no.zip">
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${source.jx.kit}.zip" basedir="${basedir}/temp"/>
    </target>

    <!--
     Packages the source distribution with TAR-GZIP.
     -->
    <target name="source-package-jx-tgz" unless="no.zip">
        <tar-gzip name="${source.jx.kit}" />
    </target>

    <target name="stage-source"
        description="Package source files required to build in zip file" >
        <antcall target="clean-temp"/>

        <copy todir="${basedir}/temp" includeEmptyDirs="false">
            <fileset dir="${basedir}">
                <include name="build.xml"/>
                <include name="build.properties"/>
                <include name="env-template.properties"/>
                <include name="README"/>
                <include name="README_MAVEN.txt"/>
                <include name="LICENSE"/>
                <include name="LICENSE.base"/>
                <include name="NOTICE"/>
                <include name="NOTICE.base"/>
                <include name="NOTICE.fdb"/>
                <include name="NOTICE.oem"/>
                <include name="RELEASE_NOTES"/>
                <include name="installer.xml"/>
                <include name="installer.properties/**"/>
                <include name="pom.xml"/>
                <include name="settings-template.xml"/>
                <include name="flexjs-maven-plugin/pom.xml"/>
                <include name="flexjs-maven-plugin/src/**"/>
            </fileset>
        </copy>

        <!-- compiler -->
        <antcall target="stage-compiler"/>

        <!-- flex-compiler-oem and fdb -->
        <antcall target="stage-fb-integration"/>

        <!-- flex ant tasks -->
        <antcall target="stage-ant-tasks"/>

        <!-- typedefs -->
        <antcall target="stage-typedefs"/>

        <!--
         Source files have Windows line endings.  Most UNIX editors can handle
         either type of line endings but the converse is often not true.
         -->
        <fixcrlf srcdir="${basedir}/temp" eol="crlf" fixlast="false">
            <exclude name="compiler/src/assembly/**"/>
            <exclude name="compiler-jx/src/assembly/**"/>
            <exclude name="compiler/target/**"/>
            <exclude name="**/assets/**"/>
            <exclude name="**/*.fla"/>
            <exclude name="**/*.flv"/>
            <exclude name="**/*.gif"/>
            <exclude name="**/*.jar"/>
            <exclude name="**/*.jpg"/>
            <exclude name="**/*.mp3"/>
            <exclude name="**/*.pbj"/>
            <exclude name="**/*.png"/>
            <exclude name="**/*.sh"/>
            <exclude name="**/*.swf"/>
            <exclude name="**/*.swc"/>
        </fixcrlf>
        <fixcrlf srcdir="${basedir}/temp/compiler/src/assembly" eol="crlf" fixlast="false">
            <include name="**.bat"/>
        </fixcrlf>

        <!--
         Unix shell scripts need the correct line endings.
         -->
        <fixcrlf srcdir="${basedir}/temp" eol="unix" fixlast="false">
            <include name="**.sh"/>
        </fixcrlf>
    </target>

    <target name="stage-compiler">
        <copy todir="${basedir}/temp/compiler" includeEmptyDirs="false">
            <fileset dir="${basedir}/compiler">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="in/**"/>
                <exclude name="lib/**"/>
                <exclude name="target/classes/**"/>
                <exclude name="target/test-classes/**"/>
                <exclude name="target/junit-temp/**"/>
                <exclude name="target/junit-reports/**"/>
                <exclude name="**/unittest.properties" />
            </fileset>
        </copy>
        <copy todir="${basedir}/temp/compiler-build-tools" includeEmptyDirs="false">
            <fileset dir="${basedir}/compiler-build-tools">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="in/**"/>
                <exclude name="lib/**"/>
                <exclude name="target/classes/**"/>
                <exclude name="target/test-classes/**"/>
                <exclude name="target/junit-temp/**"/>
                <exclude name="target/junit-reports/**"/>
                <exclude name="**/unittest.properties" />
            </fileset>
        </copy>
        <copy todir="${basedir}/temp/compiler-test-utils" includeEmptyDirs="false">
            <fileset dir="${basedir}/compiler-test-utils">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="in/**"/>
                <exclude name="lib/**"/>
                <exclude name="target/classes/**"/>
                <exclude name="target/test-classes/**"/>
                <exclude name="target/junit-temp/**"/>
                <exclude name="target/junit-reports/**"/>
                <exclude name="**/unittest.properties" />
            </fileset>
        </copy>
        <copy todir="${basedir}/temp/compiler-jburg-types" includeEmptyDirs="false">
            <fileset dir="${basedir}/compiler-jburg-types">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="in/**"/>
                <exclude name="lib/**"/>
                <exclude name="target/classes/**"/>
                <exclude name="target/test-classes/**"/>
                <exclude name="target/junit-temp/**"/>
                <exclude name="target/junit-reports/**"/>
                <exclude name="**/unittest.properties" />
            </fileset>
        </copy>

        <tstamp>
            <format property="build.number.date" pattern="yyyyMMdd" />
        </tstamp>
        <property name="build.version" value="${release.version}.${build.number.date}" />

        <!-- Update all Version.as files in the kit frameworks directory with build.number -->
        <!--<antcall target="version-update"/>-->
    </target>

    <target name="stage-fb-integration">
        <ant dir="${basedir}/debugger" target="downloads" />
        <delete>
            <fileset dir="${basedir}/debugger/target/downloads">
                <include name="*.tar.gz"/>
            </fileset>
        </delete>
        <copy todir="${basedir}/temp/debugger" includeEmptyDirs="false">
            <fileset dir="${basedir}/debugger">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="target/flex/**"/>
                <exclude name="target/flash/**"/>
                <exclude name="target/generated-sources/**"/>
                <exclude name="target/META-INF/**"/>
            </fileset>
        </copy>
        <ant dir="${basedir}/flex-compiler-oem" target="downloads" />
        <delete>
            <fileset dir="${basedir}/flex-compiler-oem/target/downloads">
                <include name="*.tar.gz"/>
            </fileset>
        </delete>
        <copy todir="${basedir}/temp/flex-compiler-oem" includeEmptyDirs="false">
            <fileset dir="${basedir}/flex-compiler-oem">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="target/classes/**"/>
            </fileset>
        </copy>
    </target>

    <target name="stage-ant-tasks">
        <copy todir="${basedir}/temp/flexjs-ant-tasks" includeEmptyDirs="false">
            <fileset dir="${basedir}/flexjs-ant-tasks">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="target/classes/**"/>
                <exclude name="target/flex/**"/>
                <exclude name="target/flash/**"/>
                <exclude name="target/generated-sources/**"/>
                <exclude name="target/META-INF/**"/>
            </fileset>
        </copy>
    </target>

    <target name="stage-typedefs" depends="check-typedefs-home">
        <copy todir="${basedir}/temp/flex-typedefs" includeEmptyDirs="false">
            <fileset dir="${FLEXJS_TYPEDEFS_HOME}">
                <include name="**"/>
                <exclude name="**/target/**" />
            </fileset>
        </copy>
    </target>

    <target name="stage-source-jx"
        description="Package jx source files with other falcon files required to build in zip file" >

        <copy tofile="${basedir}/temp/LICENSE" file="${basedir}/LICENSE.jx" overwrite="true"/>
        <copy todir="${basedir}/temp" >
            <fileset dir="${basedir}">
                <include name="README_JX"/>
                <include name="RELEASE_NOTES_JX"/>
                <include name="LICENSE.jx"/>
                <include name="LICENSE.jx.bin"/>
                <include name="NOTICE.jx"/>
            </fileset>
        </copy>

        <copy todir="${basedir}/temp/compiler-jx" includeEmptyDirs="false">
            <fileset dir="${basedir}/compiler-jx">
                <include name="**"/>
                <exclude name=".classpath" />
                <exclude name=".project" />
                <exclude name=".settings/**" />
                <exclude name="classes/**"/>
                <exclude name="in/**"/>
                <exclude name="lib/**"/>
                <exclude name="target/classes/**"/>
                <exclude name="target/test-classes/**"/>
                <exclude name="target/junit-temp/**"/>
                <exclude name="target/junit-results/**"/>
                <exclude name="**/unittest.properties" />
            </fileset>
        </copy>

        <!--
         Source files have Windows line endings.  Most UNIX editors can handle
         either type of line endings but the converse is often not true.
         -->
        <fixcrlf srcdir="${basedir}/temp" eol="crlf" fixlast="false">
            <exclude name="compiler/src/assembly/**"/>
            <exclude name="compiler-jx/src/assembly/**"/>
            <exclude name="**/assets/**"/>
            <exclude name="**/*.fla"/>
            <exclude name="**/*.flv"/>
            <exclude name="**/*.gif"/>
            <exclude name="**/*.jar"/>
            <exclude name="**/*.jpg"/>
            <exclude name="**/*.mp3"/>
            <exclude name="**/*.pbj"/>
            <exclude name="**/*.png"/>
            <exclude name="**/*.sh"/>
            <exclude name="**/*.swf"/>
            <exclude name="**/*.swc"/>
        </fixcrlf>
        <fixcrlf srcdir="${basedir}/temp/compiler/src/assembly" eol="crlf" fixlast="false">
            <include name="**.bat"/>
        </fixcrlf>
        <fixcrlf srcdir="${basedir}/temp/compiler-jx/src/assembly" eol="crlf" fixlast="false">
            <include name="**.bat"/>
        </fixcrlf>
        <fixcrlf srcdir="${basedir}/temp/compiler/src/assembly" eol="unix" fixlast="false">
            <include name="**"/>
            <exclude name="**.bat"/>
        </fixcrlf>
        <fixcrlf srcdir="${basedir}/temp/compiler-jx/src/assembly" eol="unix" fixlast="false">
            <include name="**"/>
            <exclude name="**.bat"/>
        </fixcrlf>
        <chmod dir="${basedir}/temp/compiler/src/assembly" excludes="**/*.bat" perm="+x" />
        <chmod dir="${basedir}/temp/compiler-jx/src/assembly" excludes="**/*.bat" perm="+x" />

        <!--
         Unix shell scripts need the correct line endings.
         -->
        <fixcrlf srcdir="${basedir}/temp" eol="unix" fixlast="false">
            <include name="**.sh"/>
        </fixcrlf>
    </target>

    <target name="setup-binary-release" depends="wipe-all"
        description="Set properties needed to turn on features for release sdk">
	    <!--
         For a release build, download everything fresh.
         Build changes to the downloads, might not be caught by the refresh logic.
         thirdparty-clean should leave this directory empty but just in case...
         -->
	    <delete dir="${basedir}/in" failonerror="false" includeEmptyDirs="true" />

    </target>

    <target name="binary-package"
        description="Package binary files in zip and tar-gzip file.">

        <antcall target="stage-source"/>

        <!-- these files are in addition to the remaining source files -->

        <!-- generated -->
        <copy todir="${basedir}/temp/compiler/lib">
            <fileset dir="${basedir}/compiler/lib">
                <include name="**"/>
                <exclude name="external/**"/>
                <exclude name="**/env.properties"/>
            </fileset>
        </copy>

        <antcall target="binary-package-zip"/>
        <antcall target="binary-package-tgz"/>

        <antcall target="stage-source-jx" />

        <copy todir="${basedir}/temp/flex-typedefs" includeEmptyDirs="false">
            <fileset dir="${FLEXJS_TYPEDEFS_HOME}">
                <include name="createjs/target/downloads/EaselJS-0.8.0/LICENSE.txt" />
                <include name="createjs/target/downloads/TweenJS-0.6.2/LICENSE.txt" />
            </fileset>
        </copy>

        <!-- concat the license file with the binary license file for the 3rd party deps -->
        <delete file="${basedir}/temp/LICENSE" />
        <concat destfile="${basedir}/temp/LICENSE">
            <filelist dir="${basedir}" files="LICENSE.jx,LICENSE.jx.bin"/>
        </concat>

        <!-- generated -->
        <mkdir dir="${basedir}/temp/js"/>
        <copy todir="${basedir}/temp/js">
            <fileset dir="${basedir}/compiler-jx">
                <include name="lib/**"/>
                <exclude name="lib/commons-io**"/>
                <exclude name="lib/flex-tool**"/>
                <exclude name="lib/google/**"/>
                <exclude name="lib/args4j**"/>
                <exclude name="lib/guava**"/>
                <exclude name="lib/org.json**"/>
                <exclude name="lib/junit**"/>
            </fileset>
        </copy>

        <!-- generated -->
        <mkdir dir="${basedir}/temp/js/libs"/>
        <copy tofile="${basedir}/temp/js/libs/js.swc" file="${FLEXJS_TYPEDEFS_HOME}/js/target/js.swc" />
        <copy tofile="${basedir}/temp/js/libs/cordova.swc" file="${FLEXJS_TYPEDEFS_HOME}/cordova/target/cordova.swc" />
        <copy tofile="${basedir}/temp/js/libs/createjs.swc" file="${FLEXJS_TYPEDEFS_HOME}/createjs/target/createjs.swc" />
        <copy tofile="${basedir}/temp/js/libs/google_maps.swc" file="${FLEXJS_TYPEDEFS_HOME}/google_maps/target/google_maps.swc" />
        <copy tofile="${basedir}/temp/js/libs/jasmine.swc" file="${FLEXJS_TYPEDEFS_HOME}/jasmine/target/jasmine.swc" />
        <copy tofile="${basedir}/temp/js/libs/jquery.swc" file="${FLEXJS_TYPEDEFS_HOME}/jquery/target/jquery-1.9.swc" />
        <copy tofile="${basedir}/temp/js/libs/GCL.swc" file="${FLEXJS_TYPEDEFS_HOME}/GCL/target/GCL.swc" />
        <copy tofile="${basedir}/temp/js/libs/node.swc" file="${FLEXJS_TYPEDEFS_HOME}/node/target/node.swc" />

        <!-- generated -->
        <mkdir dir="${basedir}/temp/flex-typedefs"/>
        <copy todir="${basedir}/temp/flex-typedefs" includeEmptyDirs="false">
            <fileset dir="${FLEXJS_TYPEDEFS_HOME}">
                <include name="**/**"/>
                <exclude name="**/externs.zip" />
                <exclude name="**/target/.plxarc" />
                <exclude name="**/target/failsafe-reports/**" />
                <exclude name="**/*.swc"/>
                <exclude name="**/*.as"/>
                <exclude name="createjs/target/**"/>
            </fileset>
        </copy>
        <echo>copy easel and tween</echo>
        <copy todir="${basedir}/temp/flex-typedefs" includeEmptyDirs="false">
            <fileset dir="${FLEXJS_TYPEDEFS_HOME}">
                <include name="createjs/target/downloads/Easel*/src/**"/>
                <include name="createjs/target/downloads/Tween*/src/**"/>
            </fileset>
        </copy>

        <antcall target="binary-package-jx-zip"/>
        <antcall target="binary-package-jx-tgz"/>

        <copy todir="${basedir}/out">
            <fileset dir="${basedir}">
                <include name="apache-flex-falcon-installer-config.xml"/>
                <include name="apache-flex-falconjx-installer-config.xml"/>
            </fileset>
        </copy>
    </target>

    <!--
     Packages the binary distribution with ZIP.
     -->
    <target name="binary-package-zip" unless="no.zip">
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${binary.kit}.zip" basedir="${basedir}/temp"/>
    </target>

    <!--
     Packages the binary distribution with TAR-GZIP.
     -->
    <target name="binary-package-tgz" unless="no.zip">
        <tar-gzip name="${binary.kit}" />
    </target>

    <!--
     Packages the binary distribution with ZIP.
     -->
    <target name="binary-package-jx-zip" unless="no.zip">
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${binary.jx.kit}.zip" basedir="${basedir}/temp"/>
    </target>

    <!--
     Packages the binary distribution with TAR-GZIP.
     -->
    <target name="binary-package-jx-tgz" unless="no.zip">
        <tar-gzip name="${binary.jx.kit}" />
    </target>

    <!--
     tar with gzip compression, the temp directory and put it in the out directory.
     The shell scripts in the bin directory (no extension) and other .sh files have
     mode set to execute.

     name - the basename name of the kit in out directory, without the .tar.gz extension
     -->
    <macrodef name="tar-gzip">
        <attribute name="name"/>
        <sequential>
            <mkdir dir="${basedir}/out"/>
            <tar destfile="${basedir}/out/@{name}.tar.gz"
                compression="gzip"
                longfile="gnu">
                <tarfileset dir="${basedir}/temp" prefix="@{name}">
                    <include name="**" />
                    <exclude name="**/*.sh" />
                </tarfileset>
                <tarfileset dir="${basedir}/temp" prefix="@{name}">
                    <include name="**/*.bat" />
                </tarfileset>
                <tarfileset dir="${basedir}/temp" prefix="@{name}" mode="755">
                    <include name="**/*.sh" />
                    <exclude name="**/*.bat" />
                </tarfileset>
            </tar>
        </sequential>
    </macrodef>

    <!--
     Run the Apache Rat audit tool against the source in the source kit.
     The report is written to rat.report.

     To check a subset of files run with -Drat.dir=<dir>.

     You need to place apache-rat-tasks-0.8.jar and apache-rat-0.8.jar in the
     anttask.classpath in order to do this.  If the jar isn't found, the report
     will not be generated.
     -->
    <target name="rat-check" depends="rat-taskdef" if="have.rattasks"
        description="Report on licenses in source kit.">

        <property name="rat.dir" value="${basedir}/temp"/>
        <antcall target="rat-unzip" />

        <property name="rat.report" value="${basedir}/rat.report"/>
        <echo message="Checking files at ${rat.dir}, report is ${rat.report}"/>

        <rat:report xmlns:rat="antlib:org.apache.rat.anttasks" reportFile="${rat.report}">
            <fileset dir="${rat.dir}">
                <!--          Start of binary files           -->
                <!-- exclude media (png, gif, jpg, mp3, flv) -->
                <exclude name="**/*.png"/>
                <exclude name="**/*.gif"/>
                <exclude name="**/*.jpg"/>
                <exclude name="**/*.mp3"/>
                <exclude name="**/*.flv"/>
                <exclude name="**/org.apache.flex.tools.FlexToolGroup"/>
                <exclude name="debugger/META-INF/MANIFEST.MF"/>
                <exclude name="flex-typedefs/target/maven-shared-archive-resources/META-INF/DEPENDENCIES"/>
                <exclude name="**/*.patch"/>
                <exclude name="LICENSE.jx.bin"/>
                <exclude name="README_JX"/>
                <exclude name="README_MAVEN.txt"/>
                <exclude name="RELEASE_NOTES_JX"/>
                <exclude name="NOTICE.jx"/>
                <exclude name="NOTICE.base"/>
                <exclude name="NOTICE.fdb"/>
                <exclude name="NOTICE.oem"/>
            </fileset>
        </rat:report>
    </target>

    <target name="rat-unzip" unless="no.zip">
        <antcall target="clean-temp" />
        <unzip src="${basedir}/out/${source.jx.kit}.zip" dest="${rat.dir}"/>
    </target>

    <target name="rat-taskdef" description="Rat taskdef">
        <available property="have.rattasks"
        resource="org/apache/rat/anttasks/antlib.xml"
        classpathref="anttask.classpath"/>

        <antcall target="have-rattasks"/>
        <antcall target="no-rattasks"/>
    </target>

    <target name="have-rattasks" if="have.rattasks">
        <typedef resource="org/apache/rat/anttasks/antlib.xml"
        uri="antlib:org.apache.rat.anttasks"
        classpathref="anttask.classpath"/>
    </target>

    <target name="no-rattasks" unless="have.rattasks">
        <echo message="Rat report not generated."/>
        <echo message="rat jars (apache-rat-*.jar, apache-rat-tasks-*.jar)"/>
        <echo message="not found in anttask.classpath"/>
    </target>

    <target name="clean-temp" unless="noclean.temp">
        <delete dir="${basedir}/temp" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <target name="create-md5" >
        <echo message="Generating MD5 hashes for release artifacts"/>
        <checksum algorithm="md5" file="${basedir}/out/${binary.kit}.tar.gz" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${binary.kit}.zip" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${source.kit}.tar.gz" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${source.kit}.zip" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${binary.jx.kit}.tar.gz" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${binary.jx.kit}.zip" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${source.jx.kit}.tar.gz" forceOverwrite="yes"/>
        <checksum algorithm="md5" file="${basedir}/out/${source.jx.kit}.zip" forceOverwrite="yes"/>
    </target>

    <target name="sign" >
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.kit}.zip" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.kit}.tar.gz" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.kit}.zip" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.kit}.tar.gz" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.jx.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.jx.kit}.zip" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.jx.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.jx.kit}.tar.gz" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.jx.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.jx.kit}.zip" />
        </exec>

        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.jx.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.jx.kit}.tar.gz" />
        </exec>
    </target>

    <!-- may not work on windows -->
    <target name="inject-asf-header" >
        <replaceregexp match="${generated.by.match}"
            replace="${asfheader}${generated.by.comment}"
            byline="false"
            flags="s">
            <fileset dir="${basedir}/temp">
                <include name="**/*.js" />
            </fileset>
        </replaceregexp>
    </target>

    <target name="sdk.dependent.tests" >
        <ant dir="compiler/src/test" target="sdk.dependent.tests" />
        <ant dir="compiler-jx/src/test" target="integration.tests.sdk" />
    </target>
    <target name="flexjs.dependent.tests" >
        <ant dir="compiler-jx/src/test" target="integration.tests.asjs" />
    </target>

</project>


text:
import java.lang.annotation.*;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(BarInheritedContainerContainer.class)
public @interface BarInheritedContainer {
    BarInherited[] value();
}


text:
find_path(Tcmalloc_INCLUDE_DIR google/tcmalloc.h)

if (USE_TCMALLOC)
  set(Tcmalloc_NAMES tcmalloc)
else ()
  set(Tcmalloc_NAMES tcmalloc_minimal tcmalloc)
endif ()

find_library(Tcmalloc_LIBRARY NAMES ${Tcmalloc_NAMES})

if (Tcmalloc_INCLUDE_DIR AND Tcmalloc_LIBRARY)
  set(Tcmalloc_FOUND TRUE)
  set( Tcmalloc_LIBRARIES ${Tcmalloc_LIBRARY} )
else ()
  set(Tcmalloc_FOUND FALSE)
  set( Tcmalloc_LIBRARIES )
endif ()

if (Tcmalloc_FOUND)
  message(STATUS "Found Tcmalloc: ${Tcmalloc_LIBRARY}")
else ()
  message(STATUS "Not Found Tcmalloc")
  if (Tcmalloc_FIND_REQUIRED)
    message(STATUS "Looked for Tcmalloc libraries named ${Tcmalloc_NAMES}.")
    message(FATAL_ERROR "Could NOT find Tcmalloc library")
  endif ()
endif ()

mark_as_advanced(
  Tcmalloc_LIBRARY
  Tcmalloc_INCLUDE_DIR
  )


text:
package org.keycloak.testsuite.i18n;

import java.util.Arrays;

import org.apache.http.impl.client.CloseableHttpClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
import org.junit.Assert;
import org.junit.Test;
import org.keycloak.OAuth2Constants;
import org.keycloak.adapters.HttpClientBuilder;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.locale.LocaleSelectorProvider;
import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.LanguageComboboxAwarePage;
import org.keycloak.testsuite.pages.LoginPage;

import javax.ws.rs.core.Response;
import org.jboss.arquillian.graphene.page.Page;
import org.keycloak.testsuite.ProfileAssume;
import org.keycloak.testsuite.pages.LoginPasswordUpdatePage;
import org.keycloak.testsuite.pages.OAuthGrantPage;
import org.keycloak.testsuite.util.IdentityProviderBuilder;
import org.openqa.selenium.Cookie;

/**
 * @author Michael Gerber
 * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
 */
public class LoginPageTest extends AbstractI18NTest {

    @Page
    protected AppPage appPage;

    @Page
    protected LoginPage loginPage;

    @Page
    protected LoginPasswordUpdatePage changePasswordPage;

    @Page
    protected OAuthGrantPage grantPage;

    @Override
    public void configureTestRealm(RealmRepresentation testRealm) {
        testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                .providerId("github")
                .alias("github")
                .build());
        testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                .providerId("saml")
                .alias("mysaml")
                .build());
        testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                .providerId("oidc")
                .alias("myoidc")
                .displayName("MyOIDC")
                .build());

    }

    @Test
    public void languageDropdown() {
        ProfileAssume.assumeCommunity();

        loginPage.open();
        Assert.assertEquals("English", loginPage.getLanguageDropdownText());

        switchLanguageToGermanAndBack("Username or email", "Benutzername oder E-Mail", loginPage);
    }

    @Test
    public void uiLocalesParameter() {
        loginPage.open();
        Assert.assertEquals("English", loginPage.getLanguageDropdownText());

        //test if cookie works
        oauth.uiLocales("de");
        loginPage.open();
        Assert.assertEquals("Deutsch", loginPage.getLanguageDropdownText());

        driver.manage().deleteAllCookies();
        loginPage.open();
        Assert.assertEquals("Deutsch", loginPage.getLanguageDropdownText());

        oauth.uiLocales("en de");
        driver.manage().deleteAllCookies();
        loginPage.open();
        Assert.assertEquals("English", loginPage.getLanguageDropdownText());

        oauth.uiLocales("fr de");
        driver.manage().deleteAllCookies();
        loginPage.open();
        Assert.assertEquals("Deutsch", loginPage.getLanguageDropdownText());
    }

    @Test
    public void acceptLanguageHeader() {
        ProfileAssume.assumeCommunity();

        CloseableHttpClient httpClient = (CloseableHttpClient) new HttpClientBuilder().build();
        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();

        loginPage.open();
        Response response = client.target(driver.getCurrentUrl()).request().acceptLanguage("de").get();
        Assert.assertTrue(response.readEntity(String.class).contains("Anmeldung bei test"));

        response = client.target(driver.getCurrentUrl()).request().acceptLanguage("en").get();
        Assert.assertTrue(response.readEntity(String.class).contains("Sign in to test"));

        client.close();
    }

    @Test
    public void testIdentityProviderCapitalization(){
        loginPage.open();
        Assert.assertEquals("GitHub", loginPage.findSocialButton("github").getText());
        Assert.assertEquals("mysaml", loginPage.findSocialButton("mysaml").getText());
        Assert.assertEquals("MyOIDC", loginPage.findSocialButton("myoidc").getText());

    }

    // KEYCLOAK-3887
    @Test
    public void languageChangeRequiredActions() {
        ProfileAssume.assumeCommunity();

        UserResource user = ApiUtil.findUserByUsernameId(testRealm(), "test-user@localhost");
        UserRepresentation userRep = user.toRepresentation();
        userRep.setRequiredActions(Arrays.asList(UserModel.RequiredAction.UPDATE_PASSWORD.toString()));
        user.update(userRep);

        loginPage.open();

        loginPage.login("test-user@localhost", "password");
        changePasswordPage.assertCurrent();
        Assert.assertEquals("English", changePasswordPage.getLanguageDropdownText());

        // Switch language
        switchLanguageToGermanAndBack("Update password", "Passwort aktualisieren", changePasswordPage);

        // Update password
        changePasswordPage.changePassword("password", "password");

        Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
        Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));
    }

    // KEYCLOAK-3887
    @Test
    public void languageChangeConsentScreen() {
        ProfileAssume.assumeCommunity();

        // Set client, which requires consent
        oauth.clientId("third-party");

        loginPage.open();

        loginPage.login("test-user@localhost", "password");

        grantPage.assertCurrent();
        Assert.assertEquals("English", grantPage.getLanguageDropdownText());

        // Switch language
        switchLanguageToGermanAndBack("Do you grant these access privileges?", "Wollen Sie diese Zugriffsrechte", changePasswordPage);

        // Confirm grant
        grantPage.accept();

        Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
        Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));

        // Revert client
        oauth.clientId("test-app");
    }

    @Test
    public void languageUserUpdates() {
        ProfileAssume.assumeCommunity();

        loginPage.open();
        loginPage.openLanguage("Deutsch");

        Assert.assertEquals("Deutsch", loginPage.getLanguageDropdownText());

        Cookie localeCookie = driver.manage().getCookieNamed(LocaleSelectorProvider.LOCALE_COOKIE);
        Assert.assertEquals("de", localeCookie.getValue());

        loginPage.login("test-user@localhost", "password");

        UserResource user = ApiUtil.findUserByUsernameId(testRealm(), "test-user@localhost");
        UserRepresentation userRep = user.toRepresentation();
        Assert.assertEquals("de", userRep.getAttributes().get("locale").get(0));

        appPage.logout();

        loginPage.open();

        Assert.assertEquals("Deutsch", loginPage.getLanguageDropdownText());

        userRep.getAttributes().remove("locale");
        user.update(userRep);

        loginPage.open();
        loginPage.login("test-user@localhost", "password");

        // User locale should not be updated due to previous cookie
        userRep = user.toRepresentation();
        Assert.assertNull(userRep.getAttributes());

        appPage.logout();

        loginPage.open();

        // Cookie should be removed as last user to login didn't have a locale
        localeCookie = driver.manage().getCookieNamed(LocaleSelectorProvider.LOCALE_COOKIE);
        Assert.assertNull(localeCookie);
    }

    private void switchLanguageToGermanAndBack(String expectedEnglishMessage, String expectedGermanMessage, LanguageComboboxAwarePage page) {
        // Switch language to Deutsch
        page.openLanguage("Deutsch");
        Assert.assertEquals("Deutsch", page.getLanguageDropdownText());
        String pageSource = driver.getPageSource();
        Assert.assertFalse(pageSource.contains(expectedEnglishMessage));
        Assert.assertTrue(pageSource.contains(expectedGermanMessage));

        // Revert language
        page.openLanguage("English");
        Assert.assertEquals("English", page.getLanguageDropdownText());
        pageSource = driver.getPageSource();
        Assert.assertTrue(pageSource.contains(expectedEnglishMessage));
        Assert.assertFalse(pageSource.contains(expectedGermanMessage));
    }
}


text:
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

// ==++==
//

//

//
// ==--==

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX                                                                           XX
XX                                vector<T>                                  XX
XX                                                                           XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#pragma once

#include "allocator.h"
#include "iterator.h"

namespace jitstd
{

template <typename T, typename Allocator = allocator<T> >
class vector
{
public:
    typedef Allocator allocator_type;
    typedef T* pointer;
    typedef T& reference;
    typedef const pointer const_pointer;
    typedef const reference const_reference;

    typedef size_t size_type;
    typedef ptrdiff_t difference_type;
    typedef T value_type;

    // nested classes
    class iterator : public jitstd::iterator<random_access_iterator_tag, T>
    {
        iterator(T* ptr);
    public:
        iterator();
        iterator(const iterator& it);

        iterator& operator++();
        iterator& operator++(int);
        iterator& operator--();
        iterator& operator--(int);
        iterator operator+(difference_type n);
        iterator operator-(difference_type n);
        size_type operator-(const iterator& that);
        bool operator==(const iterator& it);
        bool operator!=(const iterator& it);
        T& operator*();
        T* operator&();
        operator T*();

    private:
        friend class vector<T, Allocator>;
        pointer m_pElem;
    };

    class const_iterator : public jitstd::iterator<random_access_iterator_tag, T>
    {
    private:
        const_iterator(T* ptr);
        const_iterator();
    public:
        const_iterator(const const_iterator& it);

        const_iterator& operator++();
        const_iterator& operator++(int);
        const_iterator& operator--();
        const_iterator& operator--(int);
        const_iterator operator+(difference_type n);
        const_iterator operator-(difference_type n);
        size_type operator-(const const_iterator& that);
        bool operator==(const const_iterator& it) const;
        bool operator!=(const const_iterator& it) const;
        const T& operator*() const;
        const T* operator&() const;
        operator const T*() const;

    private:
        friend class vector<T, Allocator>;
        pointer m_pElem;
    };

    class reverse_iterator : public jitstd::iterator<random_access_iterator_tag, T>
    {
    private:
        reverse_iterator(T* ptr);
    public:
        reverse_iterator();
        reverse_iterator(const reverse_iterator& it);

        reverse_iterator& operator++();
        reverse_iterator& operator++(int);
        reverse_iterator& operator--();
        reverse_iterator& operator--(int);
        reverse_iterator operator+(difference_type n);
        reverse_iterator operator-(difference_type n);
        size_type operator-(const reverse_iterator& that);
        bool operator==(const reverse_iterator& it);
        bool operator!=(const reverse_iterator& it);
        T& operator*();
        T* operator&();
        operator T*();

    private:
        friend class vector<T, Allocator>;
        pointer m_pElem;
    };

    class const_reverse_iterator : public jitstd::iterator<random_access_iterator_tag, T>
    {
    private:
        const_reverse_iterator(T* ptr);
    public:
        const_reverse_iterator();
        const_reverse_iterator(const const_reverse_iterator& it);

        const_reverse_iterator& operator++();
        const_reverse_iterator& operator++(int);
        const_reverse_iterator& operator--();
        const_reverse_iterator& operator--(int);
        const_reverse_iterator operator+(difference_type n);
        const_reverse_iterator operator-(difference_type n);
        size_type operator-(const const_reverse_iterator& that);
        bool operator==(const const_reverse_iterator& it) const;
        bool operator!=(const const_reverse_iterator& it) const;
        const T& operator*() const;
        const T* operator&() const;
        operator const T*() const;

    private:
        friend class vector<T, Allocator>;
        pointer m_pElem;
    };

    // ctors
    explicit vector(const Allocator& allocator);
    explicit vector(size_type n, const T& value, const Allocator& allocator);

    template <typename InputIterator>
    vector(InputIterator first, InputIterator last, const Allocator& allocator);

    // cctors
    vector(const vector& vec);

    template <typename Alt, typename AltAllocator>
    explicit vector(const vector<Alt, AltAllocator>& vec);

    // dtor
    ~vector();

    template <class InputIterator>
    void assign(InputIterator first, InputIterator last);
    void assign(size_type size, const T& value);

    const_reference at(size_type n) const;
    reference at(size_type n);

    reference back();
    const_reference back() const;

    iterator begin();
    const_iterator begin() const;
    const_iterator cbegin() const;

    size_type capacity() const;

    void clear();
    bool empty() const;

    iterator end();
    const_iterator end() const;
    const_iterator cend() const;

    iterator erase(iterator position);
    iterator erase(iterator first, iterator last);

    reference front();
    const_reference front() const;

    allocator_type get_allocator() const;

    iterator insert(iterator position, const T& value);
    void insert(iterator position, size_type size, const T& value);

    template <typename InputIterator>
    void insert(iterator position, InputIterator first, InputIterator last);

    size_type max_size() const;

    vector& operator=(const vector& vec);
    template <typename Alt, typename AltAllocator>
    vector<T, Allocator>& operator=(const vector<Alt, AltAllocator>& vec);

    reference operator[](size_type n);
    const_reference operator[](size_type n) const;

    void pop_back();
    void push_back(const T& value);

    reverse_iterator rbegin();
    const_reverse_iterator rbegin() const;

    reverse_iterator rend();
    const_reverse_iterator rend() const;

    void reserve(size_type n);

    void resize(size_type sz, const T&);

    size_type size() const;

    void swap(vector<T, Allocator>& vec);

private:

    typename Allocator::template rebind<T>::allocator m_allocator;
    T* m_pArray;
    size_type m_nSize;
    size_type m_nCapacity;

    inline
    bool ensure_capacity(size_type capacity);

    template <typename InputIterator>
    void construct_helper(InputIterator first, InputIterator last, forward_iterator_tag);
    template <typename InputIterator>
    void construct_helper(InputIterator first, InputIterator last, int_not_an_iterator_tag);
    void construct_helper(size_type size, const T& value);

    template <typename InputIterator>
    void insert_helper(iterator iter, InputIterator first, InputIterator last, forward_iterator_tag);
    template <typename InputIterator>
    void insert_helper(iterator iter, InputIterator first, InputIterator last, int_not_an_iterator_tag);
    void insert_elements_helper(iterator iter, size_type size, const T& value);

    template <typename InputIterator>
    void assign_helper(InputIterator first, InputIterator last, forward_iterator_tag);
    template <typename InputIterator>
    void assign_helper(InputIterator first, InputIterator last, int_not_an_iterator_tag);

    template <typename Alt, typename AltAllocator>
    friend class vector;
};

}// namespace jit_std

// Implementation of vector.

namespace jitstd
{

namespace
{

template <typename InputIterator>
size_t iterator_difference(InputIterator first, const InputIterator& last)
{
    size_t size = 0;
    for (; first != last; ++first, ++size);
    return size;
}

}

template <typename T, typename Allocator>
vector<T, Allocator>::vector(const Allocator& allocator)
    : m_allocator(allocator)
    , m_pArray(NULL)
    , m_nSize(0)
    , m_nCapacity(0)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::vector(size_type size, const T& value, const Allocator& allocator)
    : m_allocator(allocator)
    , m_pArray(NULL)
    , m_nSize(0)
    , m_nCapacity(0)
{
    construct_helper(size, value);
}

template <typename T, typename Allocator>
template <typename InputIterator>
vector<T, Allocator>::vector(InputIterator first, InputIterator last, const Allocator& allocator)
    : m_allocator(allocator)
    , m_pArray(NULL)
    , m_nSize(0)
    , m_nCapacity(0)
{
    construct_helper(first, last, iterator_traits<InputIterator>::iterator_category());
}

template <typename T, typename Allocator>
template <typename Alt, typename AltAllocator>
vector<T, Allocator>::vector(const vector<Alt, AltAllocator>& vec)
    : m_allocator(vec.m_allocator)
    , m_pArray(NULL)
    , m_nSize(0)
    , m_nCapacity(0)
{
    ensure_capacity(vec.m_nSize);
    for (size_type i = 0, j = 0; i < vec.m_nSize; ++i, ++j)
    {
        new (m_pArray + i, placement_t()) T((T) vec.m_pArray[j]);
    }

    m_nSize = vec.m_nSize;
}

template <typename T, typename Allocator>
vector<T, Allocator>::vector(const vector<T, Allocator>& vec)
    : m_allocator(vec.m_allocator)
    , m_pArray(NULL)
    , m_nSize(0)
    , m_nCapacity(0)
{
    ensure_capacity(vec.m_nSize);
    for (size_type i = 0, j = 0; i < vec.m_nSize; ++i, ++j)
    {
        new (m_pArray + i, placement_t()) T(vec.m_pArray[j]);
    }

    m_nSize = vec.m_nSize;
}

template <typename T, typename Allocator>
vector<T, Allocator>::~vector()
{
    for (size_type i = 0; i < m_nSize; ++i)
    {
        m_pArray[i].~T();
    }
    m_allocator.deallocate(m_pArray, m_nCapacity);
    m_nSize = 0;
    m_nCapacity = 0;
}

// public methods

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::assign(InputIterator first, InputIterator last)
{
    construct_helper(first, last, iterator_traits<InputIterator>::iterator_category());
}

template <typename T, typename Allocator>
void vector<T, Allocator>::assign(size_type size, const T& value)
{
    ensure_capacity(size);
    for (int i = 0; i < size; ++i)
    {
        m_pArray[i] = value;
    }
    m_nSize = size;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reference
    vector<T, Allocator>::at(size_type i) const
{
    return operator[](i);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reference
    vector<T, Allocator>::at(size_type i)
{
    return operator[](i);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reference
    vector<T, Allocator>::back()
{
    return operator[](m_nSize - 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reference
    vector<T, Allocator>::back() const
{
    return operator[](m_nSize - 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator
    vector<T, Allocator>::begin()
{
    return iterator(m_pArray);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator
    vector<T, Allocator>::begin() const
{
    return const_iterator(m_pArray);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator
    vector<T, Allocator>::cbegin() const
{
    return const_iterator(m_pArray);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::capacity() const
{
    return m_nCapacity;
}

template <typename T, typename Allocator>
void vector<T, Allocator>::clear()
{
    for (size_type i = 0; i < m_nSize; ++i)
    {
        m_pArray[i].~T();
    }
    m_allocator.deallocate(m_pArray, m_nCapacity);
    m_pArray = NULL;
    m_nSize = 0;
    m_nCapacity = 0;
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::empty() const
{
    return m_nSize == 0;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator vector<T, Allocator>::end()
{
    return iterator(m_pArray + m_nSize);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator
    vector<T, Allocator>::end() const
{
    return const_iterator(m_pArray + m_nSize);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator vector<T, Allocator>::cend() const
{
    return const_iterator(m_pArray + m_nSize);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator
    vector<T, Allocator>::erase(
        typename vector<T, Allocator>::iterator position)
{
    return erase(position, position + 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator
    vector<T, Allocator>::erase(
        typename vector<T, Allocator>::iterator first,
        typename vector<T, Allocator>::iterator last)
{
    assert(m_nSize > 0);
    assert(first.m_pElem >= m_pArray);
    assert(last.m_pElem >= m_pArray);
    assert(first.m_pElem <= m_pArray + m_nSize);
    assert(last.m_pElem <= m_pArray + m_nSize);
    assert(last.m_pElem > first.m_pElem);

    pointer fptr = first.m_pElem;
    pointer lptr = last.m_pElem;
    pointer eptr = m_pArray + m_nSize;
    for (; lptr != eptr; ++lptr, fptr++)
    {
        (*fptr).~T();
        *fptr = *lptr;
    }
    m_nSize -= (size_type)(lptr - fptr);
    return first;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reference
    vector<T, Allocator>::front()
{
    return operator[](0);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reference
    vector<T, Allocator>::front() const
{
    return operator[](0);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::allocator_type
    vector<T, Allocator>::get_allocator() const
{
    return m_allocator;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator
    vector<T, Allocator>::insert(
        typename vector<T, Allocator>::iterator iter,
        const T& value)
{
    size_type pos = (size_type) (iter.m_pElem - m_pArray);
    insert_elements_helper(iter, 1, value);
    return iterator(m_pArray + pos);
}

template <typename T, typename Allocator>
void vector<T, Allocator>::insert(
    iterator iter,
    size_type size,
    const T& value)
{
    insert_elements_helper(iter, size, value);
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::insert(
    iterator iter,
    InputIterator first,
    InputIterator last)
{
    insert_helper(iter, first, last, iterator_traits<InputIterator>::iterator_category());
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::max_size() const
{
    return ((size_type) -1) >> 1;
}

template <typename T, typename Allocator>
template <typename Alt, typename AltAllocator>
vector<T, Allocator>& vector<T, Allocator>::operator=(const vector<Alt, AltAllocator>& vec)
{
    // We'll not observe copy-on-write for now.
    m_allocator = vec.m_allocator;
    ensure_capacity(vec.m_nSize);
    m_nSize = vec.m_nSize;
    for (size_type i = 0; i < m_nSize; ++i)
    {
        m_pArray[i] = (T) vec.m_pArray[i];
    }
    return *this;
}

template <typename T, typename Allocator>
vector<T, Allocator>& vector<T, Allocator>::operator=(const vector<T, Allocator>& vec)
{
    // We'll not observe copy-on-write for now.
    m_allocator = vec.m_allocator;
    ensure_capacity(vec.m_nSize);
    m_nSize = vec.m_nSize;
    for (size_type i = 0; i < m_nSize; ++i)
    {
        new (m_pArray + i, placement_t()) T(vec.m_pArray[i]);
    }
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reference vector<T, Allocator>::operator[](size_type n)
{
    return m_pArray[n];
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reference
    vector<T, Allocator>::operator[](size_type n) const
{
    return m_pArray[n];
}

template <typename T, typename Allocator>
void vector<T, Allocator>::pop_back()
{
    m_pArray[m_nSize - 1].~T();
    --m_nSize;
}

template <typename T, typename Allocator>
void vector<T, Allocator>::push_back(const T& value)
{
    ensure_capacity(m_nSize + 1);
    new (m_pArray + m_nSize, placement_t()) T(value);
    ++m_nSize;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator vector<T, Allocator>::rbegin()
{
    return reverse_iterator(m_pArray + m_nSize - 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator
    vector<T, Allocator>::rbegin() const
{
    return const_reverse_iterator(m_pArray + m_nSize - 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator
    vector<T, Allocator>::rend()
{
    return reverse_iterator(m_pArray - 1);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator
    vector<T, Allocator>::rend() const
{
    return const_reverse_iterator(m_pArray - 1);
}

template <typename T, typename Allocator>
void vector<T, Allocator>::reserve(size_type n)
{
    ensure_capacity(n);
}

template <typename T, typename Allocator>
void vector<T, Allocator>::resize(
    size_type sz,
    const T& c)
{
    for (; m_nSize > sz; m_nSize--)
    {
        m_pArray[m_nSize - 1].~T();
    }
    ensure_capacity(sz);
    for (; m_nSize < sz; m_nSize++)
    {
        new (m_pArray + m_nSize, placement_t()) T(c);
    }
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type vector<T, Allocator>::size() const
{
    return m_nSize;
}

template <typename T, typename Allocator>
void vector<T, Allocator>::swap(vector<T, Allocator>& vec)
{
    jitstd::swap(m_pArray, vec.m_pArray);
    jitstd::swap(m_nSize, vec.m_nSize);
    jitstd::swap(m_nCapacity, vec.m_nCapacity);
    jitstd::swap(m_nCapacity, vec.m_nCapacity);
    jitstd::swap(m_allocator, vec.m_allocator);
}

// =======================================================================================

template <typename T, typename Allocator>
void vector<T, Allocator>::construct_helper(size_type size, const T& value)
{
    ensure_capacity(size);

    for (size_type i = 0; i < size; ++i)
    {
        new (m_pArray + i, placement_t()) T(value);
    }

    m_nSize = size;
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::construct_helper(InputIterator first, InputIterator last, int_not_an_iterator_tag)
{
    construct_helper(first, last);
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::construct_helper(InputIterator first, InputIterator last, forward_iterator_tag)
{
    size_type size = iterator_difference(first, last);

    ensure_capacity(size);
    for (size_type i = 0; i < size; ++i)
    {
        new (m_pArray + i, placement_t()) T(*first);
        first++;
    }

    m_nSize = size;
}

// =======================================================================================

template <typename T, typename Allocator>
void vector<T, Allocator>::insert_elements_helper(iterator iter, size_type size, const T& value)
{
    assert(size < max_size());

    // m_pElem could be NULL then m_pArray would be NULL too.
    size_type pos = iter.m_pElem - m_pArray;

    assert(pos <= m_nSize); // <= could insert at end.
    assert(pos >= 0);

    ensure_capacity(m_nSize + size);

    for (int src = m_nSize - 1, dst = m_nSize + size - 1; src >= (int) pos; --src, --dst)
    {
        m_pArray[dst] = m_pArray[src];
    }

    for (size_type i = 0; i < size; ++i)
    {
        new (m_pArray + pos + i, placement_t()) T(value);
    }

    m_nSize += size;
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::insert_helper(iterator iter, InputIterator first, InputIterator last, int_not_an_iterator_tag)
{
    insert_elements_helper(iter, first, last);
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::insert_helper(iterator iter, InputIterator first, InputIterator last, forward_iterator_tag)
{
    // m_pElem could be NULL then m_pArray would be NULL too.
    size_type pos = iter.m_pElem - m_pArray;

    assert(pos <= m_nSize); // <= could insert at end.
    assert(pos >= 0);

    size_type size = iterator_difference(first, last);
    assert(size < max_size());

    ensure_capacity(m_nSize + size);

    pointer lst = m_pArray + m_nSize + size - 1;
    for (size_type i = pos; i < m_nSize; ++i)
    {
        *lst-- = m_pArray[i];
    }
    for (size_type i = 0; i < size; ++i, ++first)
    {
        m_pArray[pos + i] = *first;
    }

    m_nSize += size;
}

// =======================================================================================

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::assign_helper(InputIterator first, InputIterator last, forward_iterator_tag)
{
    size_type size = iterator_difference(first, last);

    ensure_capacity(size);
    for (size_type i = 0; i < size; ++i)
    {
        m_pArray[i] = *first;
        first++;
    }

    m_nSize = size;
}

template <typename T, typename Allocator>
template <typename InputIterator>
void vector<T, Allocator>::assign_helper(InputIterator first, InputIterator last, int_not_an_iterator_tag)
{
    assign_helper(first, last);
}

// =======================================================================================

template <typename T, typename Allocator>
bool vector<T, Allocator>::ensure_capacity(size_type newCap)
{
    if (newCap <= m_nCapacity)
    {
        return false;
    }

    // Double the alloc capacity based on size.
    size_type allocCap = m_nSize * 2;

    // Is it still not sufficient?
    if (allocCap < newCap)
    {
        allocCap = newCap;
    }

    // Allocate space.
    pointer ptr = m_allocator.allocate(allocCap);

    // Copy over.
    for (size_type i = 0; i < m_nSize; ++i)
    {
        new (ptr + i, placement_t()) T(m_pArray[i]);
    }

    // Deallocate currently allocated space.
    m_allocator.deallocate(m_pArray, m_nCapacity);

    // Update the pointers and capacity;
    m_pArray = ptr;
    m_nCapacity = allocCap;
    return true;
}

} // end of namespace jitstd.

// Implementation of vector iterators

namespace jitstd
{

// iterator
template <typename T, typename Allocator>
vector<T, Allocator>::iterator::iterator()
    : m_pElem(NULL)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::iterator::iterator(T* ptr)
    : m_pElem(ptr)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::iterator::iterator(const iterator& it)
    : m_pElem(it.m_pElem)
{
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator& vector<T, Allocator>::iterator::operator++()
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator& vector<T, Allocator>::iterator::operator++(int)
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator& vector<T, Allocator>::iterator::operator--()
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator& vector<T, Allocator>::iterator::operator--(int)
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator vector<T, Allocator>::iterator::operator+(difference_type n)
{
    return iterator(m_pElem + n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::iterator vector<T, Allocator>::iterator::operator-(difference_type n)
{
    return iterator(m_pElem - n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::iterator::operator-(
        const typename vector<T, Allocator>::iterator& that)
{
    return m_pElem - that.m_pElem;
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::iterator::operator==(const iterator& it)
{
    return (m_pElem == it.m_pElem);
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::iterator::operator!=(const iterator& it)
{
    return !operator==(it);
}

template <typename T, typename Allocator>
T& vector<T, Allocator>::iterator::operator*()
{
    return *m_pElem;
}

template <typename T, typename Allocator>
T* vector<T, Allocator>::iterator::operator&()
{
    return &m_pElem;
}

template <typename T, typename Allocator>
vector<T, Allocator>::iterator::operator T*()
{
    return &m_pElem;
}

// const_iterator
template <typename T, typename Allocator>
vector<T, Allocator>::const_iterator::const_iterator()
    : m_pElem(NULL)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_iterator::const_iterator(T* ptr)
    : m_pElem(ptr)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_iterator::const_iterator(const const_iterator& it)
    : m_pElem(it.m_pElem)
{
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator& vector<T, Allocator>::const_iterator::operator++()
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator& vector<T, Allocator>::const_iterator::operator++(int)
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator& vector<T, Allocator>::const_iterator::operator--()
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator& vector<T, Allocator>::const_iterator::operator--(int)
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator vector<T, Allocator>::const_iterator::operator+(difference_type n)
{
    return const_iterator(m_pElem + n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_iterator vector<T, Allocator>::const_iterator::operator-(difference_type n)
{
    return const_iterator(m_pElem - n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::const_iterator::operator-(
        const typename vector<T, Allocator>::const_iterator& that)
{
    return m_pElem - that.m_pElem;
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::const_iterator::operator==(const const_iterator& it) const
{
    return (m_pElem == it.m_pElem);
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::const_iterator::operator!=(const const_iterator& it) const
{
    return !operator==(it);
}

template <typename T, typename Allocator>
const T& vector<T, Allocator>::const_iterator::operator*() const
{
    return *m_pElem;
}

template <typename T, typename Allocator>
const T* vector<T, Allocator>::const_iterator::operator&() const
{
    return &m_pElem;
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_iterator::operator const T*() const
{
    return &m_pElem;
}

// reverse_iterator
template <typename T, typename Allocator>
vector<T, Allocator>::reverse_iterator::reverse_iterator()
    : m_pElem(NULL)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::reverse_iterator::reverse_iterator(T* ptr)
    : m_pElem(ptr)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::reverse_iterator::reverse_iterator(const reverse_iterator& it)
    : m_pElem(it.m_pElem)
{
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator& vector<T, Allocator>::reverse_iterator::operator++()
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator& vector<T, Allocator>::reverse_iterator::operator++(int)
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator& vector<T, Allocator>::reverse_iterator::operator--()
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator& vector<T, Allocator>::reverse_iterator::operator--(int)
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator vector<T, Allocator>::reverse_iterator::operator+(difference_type n)
{
    return reverse_iterator(m_pElem + n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::reverse_iterator vector<T, Allocator>::reverse_iterator::operator-(difference_type n)
{
    return reverse_iterator(m_pElem - n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::reverse_iterator::operator-(
        const typename vector<T, Allocator>::reverse_iterator& that)
{
    return m_pElem - that.m_pElem;
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::reverse_iterator::operator==(const reverse_iterator& it)
{
    return (m_pElem == it.m_pElem);
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::reverse_iterator::operator!=(const reverse_iterator& it)
{
    return !operator==(it);
}

template <typename T, typename Allocator>
T& vector<T, Allocator>::reverse_iterator::operator*()
{
    return *m_pElem;
}

template <typename T, typename Allocator>
T* vector<T, Allocator>::reverse_iterator::operator&()
{
    return &m_pElem;
}

template <typename T, typename Allocator>
vector<T, Allocator>::reverse_iterator::operator T*()
{
    return &m_pElem;
}

// const_reverse_iterator
template <typename T, typename Allocator>
vector<T, Allocator>::const_reverse_iterator::const_reverse_iterator()
    : m_pElem(NULL)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_reverse_iterator::const_reverse_iterator(T* ptr)
    : m_pElem(ptr)
{
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_reverse_iterator::const_reverse_iterator(const const_reverse_iterator& it)
    : m_pElem(it.m_pElem)
{
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator& vector<T, Allocator>::const_reverse_iterator::operator++()
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator& vector<T, Allocator>::const_reverse_iterator::operator++(int)
{
    --m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator& vector<T, Allocator>::const_reverse_iterator::operator--()
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator& vector<T, Allocator>::const_reverse_iterator::operator--(int)
{
    ++m_pElem;
    return *this;
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator vector<T, Allocator>::const_reverse_iterator::operator+(difference_type n)
{
    return const_reverse_iterator(m_pElem + n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::const_reverse_iterator vector<T, Allocator>::const_reverse_iterator::operator-(difference_type n)
{
    return const_reverse_iterator(m_pElem - n);
}

template <typename T, typename Allocator>
typename vector<T, Allocator>::size_type
    vector<T, Allocator>::const_reverse_iterator::operator-(
        const typename vector<T, Allocator>::const_reverse_iterator& that)
{
    return m_pElem - that.m_pElem;
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::const_reverse_iterator::operator==(const const_reverse_iterator& it) const
{
    return (m_pElem == it.m_pElem);
}

template <typename T, typename Allocator>
bool vector<T, Allocator>::const_reverse_iterator::operator!=(const const_reverse_iterator& it) const
{
    return !operator==(it);
}

template <typename T, typename Allocator>
const T& vector<T, Allocator>::const_reverse_iterator::operator*() const
{
    return *m_pElem;
}

template <typename T, typename Allocator>
const T* vector<T, Allocator>::const_reverse_iterator::operator&() const
{
    return &m_pElem;
}

template <typename T, typename Allocator>
vector<T, Allocator>::const_reverse_iterator::operator const T*() const
{
    return &m_pElem;
}

}