# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

VERSION='0.1'
APPNAME='ndnjs'

YUICOMPRESSOR_URL="http://github.com/downloads/yui/yuicompressor/"
YUICOMPRESSOR_NAME="yuicompressor-2.4.7"

CLOSURE_COMPILER="http://closure-compiler.googlecode.com/files/compiler-20121212.zip"

from waflib import Task, TaskGen, Utils, Logs
import urllib, subprocess, os, shutil

def options (opt):
    opt.add_option('--js-path', action='store',dest='js_path',
                   help='''Path to install combined and compressed .js files''')
    opt.add_option('--yui',action='store_true',default=False,dest='yui',
                   help='''Download and use yuicompressor-2.4.7 (http://yui.github.com/yuicompressor/)''')
    opt.add_option('--compiler',action='store_true',default=False,dest='compiler',
                   help='''Download and use closure-compiler-r2388 (https://code.google.com/p/closure-compiler/)''')

def configure (conf):
    if conf.options.yui:
        conf.start_msg ("Checking for yuicompressor")
        if os.path.exists('tools/yuicompressor.jar'):
            conf.end_msg('tools/yuicompressor.jar')
            conf.env.HAVE_YUI = 1
        else:
            conf.end_msg('not found','YELLOW')
            url="%s%s.zip" % (YUICOMPRESSOR_URL, YUICOMPRESSOR_NAME)
            Logs.info ("Downloading yuicompressor from %s..." % url)
            urllib.urlretrieve (url, "build/yuicompressor.zip")

            filename='%s/build/%s.jar' % (YUICOMPRESSOR_NAME,YUICOMPRESSOR_NAME)
            subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/yuicompressor.zip',
                                    filename, '-d', 'tools/'])
            os.rename ("tools/%s.jar" % YUICOMPRESSOR_NAME, "tools/yuicompressor.jar")
            conf.env.HAVE_YUI = 1

    if conf.options.compiler:
        conf.start_msg ("Checking for closure-compiler")
        if os.path.exists('tools/compiler.jar'):
            conf.end_msg('tools/compiler.jar')
            conf.env.HAVE_COMPILER = 1
        else:
            conf.end_msg('not found','YELLOW')
            Logs.info ("Downloading closure-compiler from %s..." % CLOSURE_COMPILER)
            urllib.urlretrieve (CLOSURE_COMPILER, "build/closure-compiler.zip")

            subprocess.check_call (['unzip', '-qq', '-o', '-j', 'build/closure-compiler.zip', 'compiler.jar', '-d', 'tools/'])
            conf.env.HAVE_COMPILER = 1

    if conf.options.js_path:
        conf.env.JS_PATH = conf.options.js_path

def build (bld):
    securityLib = ["contrib/securityLib/sha256.js",
                   "contrib/securityLib/base64.js",
                   "contrib/securityLib/rsa.js",
                   "contrib/securityLib/rsa2.js",
                   "contrib/securityLib/rsapem-1.1.js",
                   "contrib/securityLib/rsasign-1.2.js",
                   "contrib/securityLib/asn1hex-1.1.js",
                   "contrib/securityLib/x509-1.1.js",
                   "contrib/securityLib/jsbn.js",
                   "contrib/securityLib/jsbn2.js"]

    ndnjs = ["js/Closure.js",
             "js/WebSocketTransport.js",
             "js/util/CCNProtocolDTags.js",
             "js/util/CCNTime.js",
             "js/util/ExponentialReExpressClosure.js",
             "js/Name.js",
             "js/ContentObject.js",
             "js/encoding/DateFormat.js",
             "js/Interest.js",
             "js/Key.js",
             "js/PublisherID.js",
             "js/PublisherPublicKeyDigest.js",
             "js/FaceInstance.js",
             "js/ForwardingEntry.js",
             "js/encoding/DynamicUint8Array.js",
             "js/encoding/BinaryXMLEncoder.js",
             "js/encoding/BinaryXMLDecoder.js",
             "js/encoding/BinaryXMLStructureDecoder.js",
             "js/encoding/DataUtils.js",
             "js/encoding/EncodingUtils.js",
             "js/security/KeyManager.js",
             "js/security/Witness.js"] + securityLib + ["js/NDN.js"]

    ndnjs = bld (features="combine",
                 target="ndn",
                 source=ndnjs)

    if bld.env['HAVE_YUI']:
        ndnjs.yui = True

    if bld.env['HAVE_COMPILER']:
        ndnjs.compiler = True

    if bld.env['JS_PATH']:
        ndnjs.install_path = bld.env['JS_PATH']


@TaskGen.extension('.js')
def js_hook(self, node):
    node.sig=Utils.h_file (node.abspath())

@TaskGen.feature('combine')
@TaskGen.after_method('process_source')
def apply_combine(self):
    out = "%s.js" % self.target
    tasks = []
    task = self.create_task ('combine', self.source)
    task.set_outputs (task.generator.path.find_or_declare (out))
    tasks.append (task)

    if getattr(self, 'yui', False):
        out_yui = "%s.min.yui.js" % self.target
        yui = self.create_task ('yuicompressor')
        yui.combine = task
        yui.set_outputs (yui.generator.path.find_or_declare (out_yui))
        tasks.append (yui)

    if getattr(self, 'compiler', False):
        out_min = "%s.min.js" % self.target
        compiler = self.create_task ('closure_compiler')
        compiler.combine = task
        compiler.set_outputs (yui.generator.path.find_or_declare (out_min))
        tasks.append (compiler)

    try:
        for task in tasks:
            self.bld.install_files (self.install_path, task.outputs[:], env=self.env)
    except:
        pass

class combine (Task.Task):
    def run(self):
        outFile = self.outputs[0]
        self.outputs[0].write ("", "w") # make file empty
        for inFile in self.inputs:
            self.outputs[0].write (inFile.read (), 'a')

class yuicompressor (Task.Task):
    after="combine"
    color='PINK'
    def __str__(self):
        src_str=self.combine.outputs[0].nice_path()
        tgt_str=self.outputs[0].nice_path()
        return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)

    def run(self):
        return self.exec_command(['java',
                                  '-jar', '../tools/yuicompressor.jar',
                                  '-o', self.outputs[0].abspath(),
                                  self.combine.outputs[0].abspath()])

class closure_compiler (Task.Task):
    after="combine"
    color='PINK'
    def __str__(self):
        src_str=self.combine.outputs[0].nice_path()
        tgt_str=self.outputs[0].nice_path()
        return'%s: %s -> %s\n'%(self.__class__.__name__.replace('_task',''),src_str,tgt_str)

    def run(self):
        return self.exec_command(['java',
                                  '-jar', '../tools/compiler.jar',
                                  '--js', self.combine.outputs[0].abspath(),
                                  '--js_output_file', self.outputs[0].abspath()])
