Exemplo n.º 1
0
def emit_java_classes(target, source, env):
#    raw_input("emit_java_classes")
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')
    install_dir  = env['CLASSINSTALLDIR']
    source_path  = env['SOURCEDIR']
    tlist = []
    for f in source:
	try:
	    pkg_dir, classes = parse_java_file(os.path.abspath(str(f)))
	    if pkg_dir:
		tlist += [f.Dir(os.path.join(install_dir, pkg_dir)).File(c+class_suffix) for c in classes]
	    elif classes:
		tlist += [f.Dir(os.path.join(install_dir, os.path.dirname(str(f)))).File(env['ESCAPE'](c+class_suffix)) for c in classes]
	    else:
		# This is an odd end case:  no package and no classes.
		# Just do our best based on the source file name.
		base = str(f)[:-len(java_suffix)]
		tlist += [f.Dir(os.path.join(install_dir, os.path.dirname(str(f)))).File(base+class_suffix)]
	except IOError:
	    # File doesn't exist and therefore can't be parsed. Bummer.
	    # Have to make do with a best guess
	    tlist += [os.path.join(install_dir, str(f)[len(source_path)+1:-len(java_suffix)]) + class_suffix]
    slist = [file for file in source]
    return tlist, slist
Exemplo n.º 2
0
def emit_java_classes(target, source, env):
    classdir = target[0]
    tlist, slist = default_java_emitter(target, source, env)
    if env.has_key('APP_PACKAGE'):
        out = []
        sourcedir = source[0]
        for s in slist:
            base = s.name.replace('.java', '.class')
            classname = env['APP_PACKAGE'] + s.name.replace('.java', '')
            jf = sourcedir.File(env['APP_PACKAGE'].replace('.', '/') + '/' + s.name)
            if os.path.exists(jf.abspath):
                version = env.get('JAVAVERSION', '1.4')
                pkg_dir, classes = parse_java_file(jf.rfile().get_abspath(), version)
                for c in classes:
                    t = classdir.File(pkg_dir + '/' + str(c) + '.class')
                    t.attributes.java_classdir = classdir
                    t.attributes.java_sourcedir = s.dir
                    t.attributes.java_classname = str(c)
                    out.append(t)
            else:
                t = classdir.File(env['APP_PACKAGE'].replace('.', '/') + '/' + base)
                t.attributes.java_classdir = classdir
                t.attributes.java_sourcedir = s.dir
                t.attributes.java_classname = classname
                out.append(t)
        return out, slist
    else:
        return tlist, slist
Exemplo n.º 3
0
def emit_java_classes(target, source, env):
    """
    Set correct path for .class files from generated java source files
    """
    classdir = target[0]
    tlist, slist = _DEFAULT_JAVA_EMITTER(target, source, env)
    if 'APP_PACKAGE' in env:
        out = []
        for entry in slist:
            classname = env['APP_PACKAGE'] + entry.name.replace('.java', '')
            java_file = source[0].File(os.path.join(
                    env['APP_PACKAGE'].replace('.', '/'), entry.name))
            if os.path.exists(java_file.abspath):
                version = env.get('JAVAVERSION', '1.4')
                pkg_dir, classes = parse_java_file(
                                java_file.rfile().get_abspath(), version)
                for output in classes:
                    class_file = classdir.File(
                                os.path.join(pkg_dir, str(output) + '.class'))
                    class_file.attributes.java_classdir = classdir
                    class_file.attributes.java_sourcedir = entry.dir
                    class_file.attributes.java_classname = str(output)
                    out.append(class_file)
            else:
                class_file = classdir.File(os.path.join(
                        env['APP_PACKAGE'].replace('.', '/'),
                        entry.name.replace('.java', '.class')))
                class_file.attributes.java_classdir = classdir
                class_file.attributes.java_sourcedir = entry.dir
                class_file.attributes.java_classname = classname
                out.append(class_file)
        return out, slist
    else:
        return tlist, slist
Exemplo n.º 4
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    slist = []
    js = _my_normcase(java_suffix)
    for sdir in source:

        def visit(arg, dirname, names, js=js, dirnode=sdir.rdir()):
            java_files = filter(
                lambda n, js=js: _my_normcase(n[-len(js):]) == js, names)
            # The on-disk entries come back in arbitrary order.  Sort them
            # so our target and source lists are determinate.
            java_files.sort()
            mydir = dirnode.Dir(dirname)
            java_paths = map(lambda f, d=mydir: d.File(f), java_files)
            arg.extend(java_paths)

        os.path.walk(sdir.rdir().get_abspath(), visit, slist)

    tlist = []
    for f in slist:
        pkg_dir, classes = parse_java_file(f.get_abspath())
        if pkg_dir:
            for c in classes:
                t = target[0].Dir(pkg_dir).File(c + class_suffix)
                t.attributes.java_classdir = target[0]
                t.attributes.java_classname = classname(pkg_dir + os.sep + c)
                tlist.append(t)
        elif classes:
            for c in classes:
                t = target[0].File(c + class_suffix)
                t.attributes.java_classdir = target[0]
                t.attributes.java_classname = classname(c)
                tlist.append(t)
        else:
            # This is an odd end case:  no package and no classes.
            # Just do our best based on the source file name.
            base = str(f)[:-len(java_suffix)]
            t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = target[0]
            t.attributes.java_classname = classname(base)
            tlist.append(t)

    return tlist, slist
Exemplo n.º 5
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    slist = []
    js = _my_normcase(java_suffix)
    for sdir in source:
        def visit(arg, dirname, names, js=js, dirnode=sdir.rdir()):
            java_files = filter(lambda n, js=js:
                                _my_normcase(n[-len(js):]) == js,
                                names)
            # The on-disk entries come back in arbitrary order.  Sort them
            # so our target and source lists are determinate.
            java_files.sort()
            mydir = dirnode.Dir(dirname)
            java_paths = map(lambda f, d=mydir: d.File(f), java_files)
            arg.extend(java_paths)
        os.path.walk(sdir.rdir().get_abspath(), visit, slist)

    tlist = []
    for f in slist:
        pkg_dir, classes = parse_java_file(f.get_abspath())
        if pkg_dir:
            for c in classes:
                t = target[0].Dir(pkg_dir).File(c+class_suffix)
                t.attributes.java_classdir = target[0]
                t.attributes.java_classname = classname(pkg_dir + os.sep + c)
                tlist.append(t)
        elif classes:
            for c in classes:
                t = target[0].File(c+class_suffix)
                t.attributes.java_classdir = target[0]
                t.attributes.java_classname = classname(c)
                tlist.append(t)
        else:
            # This is an odd end case:  no package and no classes.
            # Just do our best based on the source file name.
            base = str(f)[:-len(java_suffix)]
            t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = target[0]
            t.attributes.java_classname = classname(base)
            tlist.append(t)

    return tlist, slist
Exemplo n.º 6
0
def emit_java_classes(target, source, env):
    #    raw_input("emit_java_classes")
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')
    install_dir = env['CLASSINSTALLDIR']
    source_path = env['SOURCEDIR']
    tlist = []
    for f in source:
        try:
            pkg_dir, classes = parse_java_file(os.path.abspath(str(f)))
            if pkg_dir:
                tlist += [
                    f.Dir(os.path.join(install_dir,
                                       pkg_dir)).File(c + class_suffix)
                    for c in classes
                ]
            elif classes:
                tlist += [
                    f.Dir(os.path.join(install_dir, os.path.dirname(
                        str(f)))).File(env['ESCAPE'](c + class_suffix))
                    for c in classes
                ]
            else:
                # This is an odd end case:  no package and no classes.
                # Just do our best based on the source file name.
                base = str(f)[:-len(java_suffix)]
                tlist += [
                    f.Dir(os.path.join(install_dir, os.path.dirname(
                        str(f)))).File(base + class_suffix)
                ]
        except IOError:
            # File doesn't exist and therefore can't be parsed. Bummer.
            # Have to make do with a best guess
            tlist += [
                os.path.join(install_dir,
                             str(f)[len(source_path) + 1:-len(java_suffix)]) +
                class_suffix
            ]
    slist = [file for file in source]
    return tlist, slist
Exemplo n.º 7
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    target[0].must_be_same(SCons.Node.FS.Dir)
    classdir = target[0]

    s = source[0].rentry().disambiguate()
    if isinstance(s, SCons.Node.FS.File):
        sourcedir = s.dir.rdir()
    elif isinstance(s, SCons.Node.FS.Dir):
        sourcedir = s.rdir()
    else:
        raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % s.__class__)

    slist = []
    js = _my_normcase(java_suffix)
    for entry in source:
        entry = entry.rentry().disambiguate()
        if isinstance(entry, SCons.Node.FS.File):
            slist.append(entry)
        elif isinstance(entry, SCons.Node.FS.Dir):
            result = SCons.Util.OrderedDict()
            dirnode = entry.rdir()
            def find_java_files(arg, dirpath, filenames):
                java_files = sorted([n for n in filenames
                                       if _my_normcase(n).endswith(js)])
                mydir = dirnode.Dir(dirpath)
                java_paths = [mydir.File(f) for f in java_files]
                for jp in java_paths:
                     arg[jp] = True
            for dirpath, dirnames, filenames in os.walk(dirnode.get_abspath()):
               find_java_files(result, dirpath, filenames)
            entry.walk(find_java_files, result)

            slist.extend(list(result.keys()))
        else:
            raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % entry.__class__)

    version = env.get('JAVAVERSION', '1.4')
    full_tlist = []
    for f in slist:
        tlist = []
        source_file_based = True
        pkg_dir = None
        if not f.is_derived():
            pkg_dir, classes = parse_java_file(f.rfile().get_abspath(), version)
            if classes:
                source_file_based = False
                if pkg_dir:
                    d = target[0].Dir(pkg_dir)
                    p = pkg_dir + os.sep
                else:
                    d = target[0]
                    p = ''
                for c in classes:
                    t = d.File(c + class_suffix)
                    t.attributes.java_classdir = classdir
                    t.attributes.java_sourcedir = sourcedir
                    t.attributes.java_classname = classname(p + c)
                    tlist.append(t)

        if source_file_based:
            base = f.name[:-len(java_suffix)]
            if pkg_dir:
                t = target[0].Dir(pkg_dir).File(base + class_suffix)
            else:
                t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = classdir
            t.attributes.java_sourcedir = f.dir
            t.attributes.java_classname = classname(base)
            tlist.append(t)

        for t in tlist:
            t.set_specific_source([f])

        full_tlist.extend(tlist)

    return full_tlist, slist
Exemplo n.º 8
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    target[0].must_be_same(SCons.Node.FS.Dir)
    classdir = target[0]

    s = source[0].rentry().disambiguate()
    if isinstance(s, SCons.Node.FS.File):
        sourcedir = s.dir.rdir()
    elif isinstance(s, SCons.Node.FS.Dir):
        sourcedir = s.rdir()
    else:
        raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % s.__class__)

    slist = []
    js = _my_normcase(java_suffix)
    for entry in source:
        entry = entry.rentry().disambiguate()
        if isinstance(entry, SCons.Node.FS.File):
            slist.append(entry)
        elif isinstance(entry, SCons.Node.FS.Dir):
            result = SCons.Util.OrderedDict()
            dirnode = entry.rdir()
            def find_java_files(arg, dirpath, filenames):
                java_files = sorted([n for n in filenames
                                       if _my_normcase(n).endswith(js)])
                mydir = dirnode.Dir(dirpath)
                java_paths = [mydir.File(f) for f in java_files]
                for jp in java_paths:
                     arg[jp] = True
            for dirpath, dirnames, filenames in os.walk(dirnode.get_abspath()):
               find_java_files(result, dirpath, filenames)
            entry.walk(find_java_files, result)

            slist.extend(list(result.keys()))
        else:
            raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % entry.__class__)

    version = env.get('JAVAVERSION', '1.4')
    full_tlist = []
    for f in slist:
        tlist = []
        source_file_based = True
        pkg_dir = None
        if not f.is_derived():
            pkg_dir, classes = parse_java_file(f.rfile().get_abspath(), version)
            if classes:
                source_file_based = False
                if pkg_dir:
                    d = target[0].Dir(pkg_dir)
                    p = pkg_dir + os.sep
                else:
                    d = target[0]
                    p = ''
                for c in classes:
                    t = d.File(c + class_suffix)
                    t.attributes.java_classdir = classdir
                    t.attributes.java_sourcedir = sourcedir
                    t.attributes.java_classname = classname(p + c)
                    tlist.append(t)

        if source_file_based:
            base = f.name[:-len(java_suffix)]
            if pkg_dir:
                t = target[0].Dir(pkg_dir).File(base + class_suffix)
            else:
                t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = classdir
            t.attributes.java_sourcedir = f.dir
            t.attributes.java_classname = classname(base)
            tlist.append(t)

        for t in tlist:
            t.set_specific_source([f])

        full_tlist.extend(tlist)

    return full_tlist, slist
Exemplo n.º 9
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    target[0].must_be_same(SCons.Node.FS.Dir)
    classdir = target[0]

    s = source[0].rentry().disambiguate()
    if isinstance(s, SCons.Node.FS.File):
        sourcedir = s.dir.rdir()
    elif isinstance(s, SCons.Node.FS.Dir):
        sourcedir = s.rdir()
    else:
        raise SCons.Errors.UserError(
            "Java source must be File or Dir, not '%s'" % s.__class__)

    slist = []
    js = _my_normcase(java_suffix)
    find_java = lambda n, js=js, ljs=len(js): _my_normcase(n[-ljs:]) == js
    for entry in source:
        entry = entry.rentry().disambiguate()
        if isinstance(entry, SCons.Node.FS.File):
            slist.append(entry)
        elif isinstance(entry, SCons.Node.FS.Dir):
            result = SCons.Util.OrderedDict()

            def visit(arg, dirname, names, fj=find_java, dirnode=entry.rdir()):
                java_files = filter(fj, names)
                # The on-disk entries come back in arbitrary order.  Sort
                # them so our target and source lists are determinate.
                java_files.sort()
                mydir = dirnode.Dir(dirname)
                java_paths = map(lambda f, d=mydir: d.File(f), java_files)
                for jp in java_paths:
                    arg[jp] = True

            os.path.walk(entry.rdir().get_abspath(), visit, result)
            entry.walk(visit, result)

            slist.extend(result.keys())
        else:
            raise SCons.Errors.UserError(
                "Java source must be File or Dir, not '%s'" % entry.__class__)

    version = env.get('JAVAVERSION', '1.4')
    full_tlist = []
    for f in slist:
        tlist = []
        source_file_based = True
        pkg_dir = None
        if not f.is_derived():
            pkg_dir, classes = parse_java_file(f.rfile().get_abspath(),
                                               version)
            if classes:
                source_file_based = False
                if pkg_dir:
                    d = target[0].Dir(pkg_dir)
                    p = pkg_dir + os.sep
                else:
                    d = target[0]
                    p = ''
                for c in classes:
                    t = d.File(c + class_suffix)
                    t.attributes.java_classdir = classdir
                    t.attributes.java_sourcedir = sourcedir
                    t.attributes.java_classname = classname(p + c)
                    tlist.append(t)

        if source_file_based:
            base = f.name[:-len(java_suffix)]
            if pkg_dir:
                t = target[0].Dir(pkg_dir).File(base + class_suffix)
            else:
                t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = classdir
            t.attributes.java_sourcedir = f.dir
            t.attributes.java_classname = classname(base)
            tlist.append(t)

        for t in tlist:
            t.set_specific_source([f])

        full_tlist.extend(tlist)

    return full_tlist, slist
Exemplo n.º 10
0
def emit_java_classes(target, source, env):
    """Create and return lists of source java files
    and their corresponding target class files.
    """
    java_suffix = env.get('JAVASUFFIX', '.java')
    class_suffix = env.get('JAVACLASSSUFFIX', '.class')

    target[0].must_be_same(SCons.Node.FS.Dir)
    classdir = target[0]

    s = source[0].rentry().disambiguate()
    if isinstance(s, SCons.Node.FS.File):
        sourcedir = s.dir.rdir()
    elif isinstance(s, SCons.Node.FS.Dir):
        sourcedir = s.rdir()
    else:
        raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % s.__class__)

    slist = []
    js = _my_normcase(java_suffix)
    find_java = lambda n, js=js, ljs=len(js): _my_normcase(n[-ljs:]) == js
    for entry in source:
        entry = entry.rentry().disambiguate()
        if isinstance(entry, SCons.Node.FS.File):
            slist.append(entry)
        elif isinstance(entry, SCons.Node.FS.Dir):
            result = SCons.Util.OrderedDict()
            def visit(arg, dirname, names, fj=find_java, dirnode=entry.rdir()):
                java_files = filter(fj, names)
                # The on-disk entries come back in arbitrary order.  Sort
                # them so our target and source lists are determinate.
                java_files.sort()
                mydir = dirnode.Dir(dirname)
                java_paths = map(lambda f, d=mydir: d.File(f), java_files)
                for jp in java_paths:
                     arg[jp] = True

            os.path.walk(entry.rdir().get_abspath(), visit, result)
            entry.walk(visit, result)

            slist.extend(result.keys())
        else:
            raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % entry.__class__)

    version = env.get('JAVAVERSION', '1.4')
    full_tlist = []
    for f in slist:
        tlist = []
        source_file_based = True
        pkg_dir = None
        if not f.is_derived():
            pkg_dir, classes = parse_java_file(f.rfile().get_abspath(), version)
            if classes:
                source_file_based = False
                if pkg_dir:
                    d = target[0].Dir(pkg_dir)
                    p = pkg_dir + os.sep
                else:
                    d = target[0]
                    p = ''
                for c in classes:
                    t = d.File(c + class_suffix)
                    t.attributes.java_classdir = classdir
                    t.attributes.java_sourcedir = sourcedir
                    t.attributes.java_classname = classname(p + c)
                    tlist.append(t)

        if source_file_based:
            base = f.name[:-len(java_suffix)]
            if pkg_dir:
                t = target[0].Dir(pkg_dir).File(base + class_suffix)
            else:
                t = target[0].File(base + class_suffix)
            t.attributes.java_classdir = classdir
            t.attributes.java_sourcedir = f.dir
            t.attributes.java_classname = classname(base)
            tlist.append(t)

        for t in tlist:
            t.set_specific_source([f])

        full_tlist.extend(tlist)

    return full_tlist, slist