<commit_before>#!/usr/bin/env python3

# 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.

import os
import shutil
import subprocess
import argparse
import concurrent.futures


def generate_report(module_path, report_orig_path, report_out_path):
    is_dir = os.path.isdir(module_path)
    if not is_dir:
        print("{} is not a directory".format(module_path))
        return

    os.makedirs(report_out_path, exist_ok=True)

    try:
        print("Generating report for {}".format(module_path))
        # This command prints lots of false errors. Here, we redirect stdout and stderr to avoid them.
        command = "mvn -Ddependency.locations.enabled=false -Ddependency.details.enabled=false project-info-reports:dependencies"
        subprocess.check_output(command, cwd=module_path, shell=True)
        command = "cp -r {} {}".format(report_orig_path, report_out_path)
        subprocess.check_output(command, cwd=module_path, shell=True)
        print("Generated report for {} in {}".format(module_path, report_out_path))
    except Exception as e:
        print("Encountered error [{}] when generating report for {}".format(e, module_path))<commit_msg>Debugs Flaky License dependency Reports generation (#12744)<commit_after>#!/usr/bin/env python3

# 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.

import os
import shutil
import subprocess
import argparse
import concurrent.futures


def generate_report(module_path, report_orig_path, report_out_path):
    is_dir = os.path.isdir(module_path)
    if not is_dir:
        print("{} is not a directory".format(module_path))
        return

    os.makedirs(report_out_path, exist_ok=True)

    try:
        print("Generating report for {}".format(module_path))
        # This command prints lots of false errors. Here, we redirect stdout and stderr to avoid them.
        command = "mvn -Ddependency.locations.enabled=false -Ddependency.details.enabled=false project-info-reports:dependencies"
        subprocess.check_output(command, cwd=module_path, shell=True)
        command = "cp -r {} {}".format(report_orig_path, report_out_path)
        subprocess.check_output(command, cwd=module_path, shell=True)
        print("Generated report for {} in {}".format(module_path, report_out_path))
    except subprocess.CalledProcessError as e:
        print("Encountered error [{}] with the following output when generating report for {}".format(e, module_path))
        print(e.output.decode('utf-8'))
    except Exception as e:
        print("Encountered error [{}] when generating report for {}".format(e, module_path))
{'fraction_non_alphanumeric': 0.08473736372646185, 'fraction_numerical': 0.003964321110009911, 'mean_word_length': 4.149234693877551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4039887', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1075, 'n_words': 414}