Ejemplo n.º 1
0
def cli(parser, options, rest):
    if len(rest) != 3:
        parser.error("wrong number of arguments.")

    left = unpack_classfile(rest[1])
    right = unpack_classfile(rest[2])

    return cli_classes_diff(parser, options, left, right)
Ejemplo n.º 2
0
def cli(parser, options, rest):
    if len(rest) != 3:
        parser.error("wrong number of arguments.")

    left = unpack_classfile(rest[1])
    right = unpack_classfile(rest[2])

    return cli_classes_diff(parser, options, left, right)
 def __get_from_class_file(self, import_name, subpath):
     for file_path, class_info in self.__class_files.iteritems():
         if subpath in file_path:
             if not class_info:
                 class_info = unpack_classfile(file_path)
                 self.__class_files[file_path] = class_info
             if import_name in class_info.pretty_this():
                 yield class_info
Ejemplo n.º 4
0
def cli_json_class(options, classfile):
    from javatools import unpack_classfile
    from json import dump
    from sys import stdout

    info = unpack_classfile(classfile)
    data = cli_simplify_classinfo(options, info)
    dump(data, stdout, sort_keys=True, indent=2)
Ejemplo n.º 5
0
def load(which):
    fn = get_class_fn(which)
    return jt.unpack_classfile(fn)
Ejemplo n.º 6
0
    def get_classinfo(self, entry):
        from javatools import unpack_classfile
        from os.path import join

        return unpack_classfile(join(self.base_path,entry))
Ejemplo n.º 7
0
def process(list_projs):
    pid = os.getpid()
    print('Starting process', pid, '...')

    # Logging code
    FORMAT = '[%(levelname)s] (%(threadName)s) %(message)s'
    logging.basicConfig(level=logging.DEBUG, format=FORMAT)
    file_handler = logging.FileHandler(os.path.join(LOGS_PATH, 'LOG-' + str(pid) + '.log'))
    file_handler.setFormatter(logging.Formatter(FORMAT))
    logging.getLogger().addHandler(file_handler)

    proj_counter = 0

    # TODO Make script start from a list of files intead of the results of JBF
    with open(OUTPUT_FILE % pid, 'w') as output_file:
        output_file.write('proj_name,n_class_files,reachable_mains,reachable_methods,with_junit,passed_junit\n')

        for full_proj_folder in list_projs:
            # print(full_proj_folder)
            proj_counter += 1

            if not os.path.exists(str(pid)):
                os.makedirs(str(pid))
            else:
                raise Exception('Folder ' + str(pid) + ' already exists!')
            jar_paths = handle_dependencies(full_proj_folder, str(pid))
            # print(jar_paths)

            # These counts are class files/per project
            reachable_mains = 0
            reachable_methods = 0  # Per class file with main() found
            with_junit = 0
            passed_junit = 0
            n_class_files = 0

            # Search for Class files
            for root, dirnames, filenames in os.walk(full_proj_folder):
                for filename in filenames:
                    if filename.endswith('.class'):
                        full_filename = os.path.join(root, filename)
                        # print('Analyzing file', full_filename)

                        try:
                            n_class_files += 1
                            ci = unpack_classfile(full_filename)
    
                            # Search for main methods and run the respective class files
                            main_methods = main_search_string in [m.get_name() for m in ci.methods]
                            if main_methods:
                                # print('Has main:', full_filename)
                                reachable_mains += 1
                                res = 0 # reachable_methods_from_main(root, filename, jar_paths, str(pid))
                                # res = run_main(root, filename)
                                reachable_methods += res
    
                            # Search for junit and run the respective class files
                            junit_imports = [m for m in ci.get_requires() if junit_search_string in m]
                            if len(junit_imports) > 0:
                                # print('Has junit:', full_filename)

                                with_junit += 1
                                # res = all_junit_tests(root, filename, jar_paths)

                                if res:
                                    # print('All tests OK!')
                                    passed_junit += 1

                        except:
                            continue
            shutil.rmtree(str(pid))

            result = full_proj_folder + ',' + str(n_class_files) + ',' + str(reachable_mains) + ',' + str(
                reachable_methods) + ',' + str(with_junit) + ',' + str(passed_junit)

            if (proj_counter % 10) == 0:
                print('-----------------------------------------')
                print('Process', pid, 'analyzed', proj_counter, '/', len(list_projs), 'projects...')
                print(result)

            output_file.write(result + '\n')
Ejemplo n.º 8
0
    def get_classinfo(self, entry):
        from javatools import unpack_classfile
        from os.path import join

        return unpack_classfile(join(self.base_path, entry))
Ejemplo n.º 9
0
def cli_print_class(options, classfile):
    from javatools import unpack_classfile

    info = unpack_classfile(classfile)
    return cli_print_classinfo(options, info)
Ejemplo n.º 10
0
    def collect_impl(self):
        if self.is_change():
            linfo = unpack_classfile(self.left_fn())
            rinfo = unpack_classfile(self.right_fn())

            yield JavaClassReport(linfo, rinfo, self.reporter)
Ejemplo n.º 11
0
def load(which):
    fn = get_class_fn(which)
    return jt.unpack_classfile(fn)
Ejemplo n.º 12
0
    def collect_impl(self):
        if self.is_change():
            linfo = unpack_classfile(self.left_fn())
            rinfo = unpack_classfile(self.right_fn())

            yield JavaClassReport(linfo, rinfo, self.reporter)
def cli_json_class(options, classfile):
    info = unpack_classfile(classfile)
    data = cli_simplify_classinfo(options, info)
    dump(data, stdout, sort_keys=True, indent=2)
def cli_print_class(options, classfile):
    info = unpack_classfile(classfile)
    return cli_print_classinfo(options, info)
Ejemplo n.º 15
0
def cli_json_class(options, classfile):
    info = unpack_classfile(classfile)
    data = cli_simplify_classinfo(options, info)
    dump(data, stdout, sort_keys=True, indent=2)
Ejemplo n.º 16
0
def cli_print_class(options, classfile):
    info = unpack_classfile(classfile)
    return cli_print_classinfo(options, info)