

def prepare_jar(root_dir, artifact_name):
    "\n    Zips compiled java, scala and python files in a jar. Python files are added to the root\n    directory, because that's how python can find those files. Only class files, LICENSE, README,\n    and POM are added\n    "
    pwd = os.getcwd()
    jar = zipfile.PyZipFile((artifact_name + 'jar'), 'w')
    os.chdir(root_dir)
    files = os.listdir('.')
    if (os.path.isdir(os.path.join('src', 'main', 'scala')) or os.path.isdir(os.path.join('src', 'main', 'java'))):
        existing_jars = []
        for (root, dirnames, filenames) in os.walk('.'):
            for filename in fnmatch.filter(filenames, '*.jar'):
                if (('lib' not in filename) and ('sbt' not in filename) and ('assembly' not in filename)):
                    existing_jars.append(os.path.join(root, filename))
        if (len(existing_jars) == 0):
            show_error_and_exit('Your directory contains java or scala code but a jar could not be found. Please build your spark package before calling zip.\nIf the jar is in a directory like lib/, zip omits those jars. Please move your jar elsewhere to use zip properly.')
        elif (len(existing_jars) > 1):
            show_error_and_exit('Your directory contains multiple jars. We only need your package jar, not the assembly jar, nor any jars that your package depends on.\nIf there are dependency jars in your folder, please place them under lib/ and add them to your pom or sbt build file.')
        old_jar = zipfile.ZipFile(existing_jars[0])
        for f in old_jar.namelist():
            old_jar_content = old_jar.open(f, 'r')
            pwd.writestr(f, old_jar_content.read())
            old_jar_content.close()
    jar.write(get_license_file_name('.'))
    jar.write('README.md')
    if ('python' in files):
        os.chdir(os.path.join('.', 'python'))
        jar.writepy('.')
        if os.path.isfile('requirements.txt'):
            jar.write('requirements.txt')
        python_dirs = [p for p in os.listdir('.') if (os.path.isdir(p) and ('bin' not in p) and ('doc' not in p) and ('.git' not in p) and ('lib' not in p))]
        for dir in python_dirs:
            jar.writepy(dir)
    jar.close()
    os.chdir(pwd)

dataset/ETHPy150Open databricks/spark-package-cmd-tool/python/spark_package/spark_package.py prepare_jar/VarMisuse@250/627 `jar`->`pwd`