Ejemplo n.º 1
0
def transform_log_str_to_xml_obj(code_str):
    # print("from here")
    # print(code_str)
    # code_str_components = code_str.split('(', 1)
    # caller_method = code_str_components[0]
    # caller_method = caller_method.replace('\\n', '').replace('\\t', '').replace('\\r', '')
    # formatted_code_str = caller_method + '(' + code_str_components[1]

    java_file_path = generate_c_file_of_str(code_str + ";")
    xml_name = filehelper.generate_random_file_name_with_extension('xml')
    methods = []
    try:
        shellhelper.run("srcml '{}' -o {}".format(java_file_path, xml_name))
        xml_p = Path(xml_name)
        xml_bytes = xml_p.read_bytes()
        parser = etree.XMLParser(huge_tree=True)
        xml_object = etree.fromstring(xml_bytes, parser=parser)
        methods = get_method_calls(xml_object)

    finally:
        xml_p.unlink()
        java_p = Path(java_file_path)
        java_p.unlink()
        if len(methods) > 0:
            return methods[0]
        else:
            return None
Ejemplo n.º 2
0
def get_methods_of_file(file_path: str):
    xml_name = filehelper.generate_random_file_name_with_extension('xml')
    methods = []
    try:
        shellhelper.run("cgum '{}' > {}".format(file_path, xml_name))
        xml_p = Path(xml_name)
        xml_bytes = xml_p.read_bytes()
        methods = get_methods_of_xml_bytes(xml_bytes)
    finally:
        xml_p.unlink()
        return methods
Ejemplo n.º 3
0
def get_java_loc(path: str, commit_id=None):
    if commit_id is None:
        output = shellhelper.run("cloc --include-lang=C '{}'".format(path))
    else:
        output = shellhelper.run("cloc --include-lang=C '{}' {}".format(
            path, commit_id),
                                 cwd=path)
    pattern = '.*C.*'
    m = re.search(pattern, output)
    result = LOC()
    if m is not None:
        line = m.group(0)
        result = _convert_cloc_line_to_object(line)

    return result
Ejemplo n.º 4
0
def is_origin_head_at_master(path: str):
    output = shellhelper.run("git branch -r | grep 'origin/HEAD'", cwd=path)
    output = ''.join(output.split())
    if output == 'origin/HEAD->origin/master':
        return True
    else:
        return False
Ejemplo n.º 5
0
def get_modified_line_counts(old_file, new_file):
    output = shellhelper.run("git diff --shortstat {} {}".format(
        old_file, new_file))
    added = 0
    deleted = 0
    modified = 0
    added_count = 0
    deleted_count = 0

    added_match = insertion_pattern.search(output)
    if added_match:
        added_count = int(added_match.group(1))
    deleted_match = deletion_pattern.search(output)
    if deleted_match:
        deleted_count = int(deleted_match.group(1))

    if added_count == deleted_count:
        modified = added_count
    elif added_count < deleted_count:
        modified = added_count
        deleted = deleted_count - added_count
    else:
        modified = deleted_count
        added = added_count - deleted_count

    return added, deleted, modified
Ejemplo n.º 6
0
def get_java_loc_diff(old_path: str, new_path: str):
    output = shellhelper.run(
        "cloc --diff --diff-timeout 1000 '{}' '{}'".format(old_path, new_path))
    pattern = '.*C(\s.*){4}'
    m = re.search(pattern, output)
    same = LOC()
    modified = LOC()
    added = LOC()
    removed = LOC()

    if m is not None:
        lines = m.group(0).split('\n')
        lines.pop(0)
        for line in lines:
            line_type = line.split()[0]
            loc_detail = _convert_cloc_line_to_object(line)
            if line_type == 'same':
                same = loc_detail
            elif line_type == 'modified':
                modified = loc_detail
            elif line_type == 'added':
                added = loc_detail
            elif line_type == 'removed':
                removed = loc_detail

    return {
        'same': same,
        'modified': modified,
        'added': added,
        'removed': removed
    }
Ejemplo n.º 7
0
def is_master_exists(path: str):
    output = shellhelper.run("git branch -r | grep -E 'origin/master$'",
                             cwd=path)
    output = ''.join(output.split())
    if len(output) > 0:
        return True
    else:
        return False
Ejemplo n.º 8
0
def get_code_churn_between_commits(path: str, old_commit, new_commit):
    output = shellhelper.run(
        "git diff --shortstat {} {} -- '*.java' | head -n 1".format(
            old_commit, new_commit),
        cwd=path)
    added_count = 0
    deleted_count = 0
    added_match = insertion_pattern.search(output)
    if added_match:
        added_count = int(added_match.group(1))
    deleted_match = deletion_pattern.search(output)
    if deleted_match:
        deleted_count = int(deleted_match.group(1))

    return added_count + deleted_count
Ejemplo n.º 9
0
def get_default_branch(path: str):
    output = shellhelper.run(
        "git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' | tr -d ' '",
        cwd=path)
    return output.strip()
Ejemplo n.º 10
0
def get_authors_num(path: str):
    output = shellhelper.run(
        "git log --format='%aN' | sort -u | wc -l | tr -d ' '", cwd=path)
    return int(output)
Ejemplo n.º 11
0
def get_first_commit_date(path: str):
    output = shellhelper.run(
        "git log --reverse --pretty='format: %ai' | head -n 1", cwd=path)
    datetime_str = output.strip()
    return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S %z')
Ejemplo n.º 12
0
def get_last_commit_date(path: str):
    # 2017-12-07 11:22:05 +0100
    output = shellhelper.run("git log --pretty='format: %ai' | head -n 1",
                             cwd=path)
    datetime_str = output.strip()
    return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S %z')
Ejemplo n.º 13
0
def get_repo_age_str(path: str):
    output = shellhelper.run(
        "git log --reverse --pretty=oneline --format='%ar' | head -n 1 | LC_ALL=C sed 's/ago//' | tr -d ' '",
        cwd=path)
    return output
Ejemplo n.º 14
0
def get_commits_num(path: str):
    output = shellhelper.run("git log --oneline $commit | wc -l | tr -d ' '",
                             cwd=path)
    return int(output)
Ejemplo n.º 15
0
def get_files_num(path: str):
    output = shellhelper.run("git ls-files | wc -l | tr -d ' '", cwd=path)
    return int(output)