How to use jar_path method in localstack

Best Python code snippet using localstack_python

test_parameterparsing.py

Source:test_parameterparsing.py Github

copy

Full Screen

1import snykjar2def test_arg_parsing_works_for_single_dot():3 cl_args = ['.']4 args = snykjar.parse_command_line_args(cl_args)5 assert len(args.jar_path) == 16 assert args.jar_path[0] == '.'7 cl_args = ['--orgId=123', '.']8 args = snykjar.parse_command_line_args(cl_args)9 assert args.orgId == '123'10 assert len(args.jar_path) == 111 assert args.jar_path[0] == '.'12def test_arg_parsing_works_for_single_directory():13 cl_args = ['/Users/foo/some/directory']14 args = snykjar.parse_command_line_args(cl_args)15 assert len(args.jar_path) == 116 assert args.jar_path[0] == '/Users/foo/some/directory'17 cl_args = ['--orgId=123', '/Users/foo/some/directory']18 args = snykjar.parse_command_line_args(cl_args)19 assert args.orgId == '123'20 assert len(args.jar_path) == 121 assert args.jar_path[0] == '/Users/foo/some/directory'22def test_arg_parsing_works_for_single_jar():23 cl_args = ['somejar.jar']24 args = snykjar.parse_command_line_args(cl_args)25 assert len(args.jar_path) == 126 assert args.jar_path[0] == 'somejar.jar'27 cl_args = ['./somejar.jar']28 args = snykjar.parse_command_line_args(cl_args)29 assert len(args.jar_path) == 130 assert args.jar_path[0] == './somejar.jar'31 cl_args = ['/some/fully/qualified/path/somejar.jar']32 args = snykjar.parse_command_line_args(cl_args)33 assert len(args.jar_path) == 134 assert args.jar_path[0] == '/some/fully/qualified/path/somejar.jar'35 # Now with --orgId36 cl_args = ['--orgId=123', 'somejar.jar']37 args = snykjar.parse_command_line_args(cl_args)38 assert args.orgId == '123'39 assert len(args.jar_path) == 140 assert args.jar_path[0] == 'somejar.jar'41 cl_args = ['--orgId=123', './somejar.jar']42 args = snykjar.parse_command_line_args(cl_args)43 assert args.orgId == '123'44 assert len(args.jar_path) == 145 assert args.jar_path[0] == './somejar.jar'46 cl_args = ['--orgId=123', '/some/fully/qualified/path/somejar.jar']47 args = snykjar.parse_command_line_args(cl_args)48 assert args.orgId == '123'49 assert len(args.jar_path) == 150 assert args.jar_path[0] == '/some/fully/qualified/path/somejar.jar'51def test_arg_parsing_handles_multiple_jars():52 cl_args = ['somejar1.jar', 'somejar2.jar', 'somejar3.jar']53 args = snykjar.parse_command_line_args(cl_args)54 assert len(args.jar_path) == 355 assert args.jar_path[0] == cl_args[0]56 assert args.jar_path[1] == cl_args[1]57 assert args.jar_path[2] == cl_args[2]58 # Now with --orgId59 cl_args = ['--orgId=123', 'somejar1.jar', 'somejar2.jar', 'somejar3.jar']60 args = snykjar.parse_command_line_args(cl_args)61 assert args.orgId == '123'62 assert len(args.jar_path) == 363 assert args.jar_path[0] == 'somejar1.jar'64 assert args.jar_path[1] == 'somejar2.jar'65 assert args.jar_path[2] == 'somejar3.jar'66def test_arg_parsing_handles_outputPom_parameter():67 cl_args = ['--outputPom=output-pom.xml', 'somejar1.jar', 'somejar2.jar', 'somejar3.jar']68 args = snykjar.parse_command_line_args(cl_args)69 assert args.outputPom == 'output-pom.xml'70 assert len(args.jar_path) == 371 assert args.jar_path[0] == cl_args[1]72 assert args.jar_path[1] == cl_args[2]...

Full Screen

Full Screen

decompiler.py

Source:decompiler.py Github

copy

Full Screen

1import zipfile2import subprocess3import shutil4import argparse5from pathlib import *6java_decompiler_path = "src/java-decompiler.jar"7jar_path = "ezjson.jar"8output_path = "result/"9def check_path():10 p = Path(java_decompiler_path)11 if p.is_file() == False:12 print("ERROR:\tdecompile tool is not exists")13 return False14 p1 = Path(jar_path)15 if p1.is_file() == False:16 print("ERROR:\tjar source is not exists")17 return False18 p2 = Path(output_path)19 if p2.is_dir() == False:20 print("ERROR:\toutput path is not exists")21 return False22 return True23def getJarName(jar_path):24 return jar_path.split("/")[-1]25#从jar反编译出java文件26def decompiler_jar():27 cmd_txt = "java -cp {} org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true {} {}".format(java_decompiler_path,jar_path,output_path)28 _subProcess = subprocess.getstatusoutput(cmd_txt)29 if _subProcess[0] != 0:30 print(_subProcess[1])31 else:32 print(_subProcess[1])33 print("INFO:\tDecompiler class to java file successfully")34 with zipfile.ZipFile(Path(output_path).joinpath(getJarName(jar_path)),mode='r') as zfile:35 for file in zfile.namelist():36 zfile.extract(file,Path(output_path).joinpath(getJarName(jar_path).rstrip('.jar')+"_tmp"))37 Path(output_path).joinpath(getJarName(jar_path)).unlink()38# 根据反编译生成的文件,调整源码位置和依赖配置,生成一份项目源代码(可打包)39# maven项目40def gen():41 #copy demo to des42 demo = "src/maven_demo"43 res = Path("result/").joinpath(getJarName(jar_path).rstrip(".jar"))44 shutil.copytree(demo,res)45 src_path = Path(output_path).joinpath(getJarName(jar_path).rstrip('.jar')+"_tmp")46 src = src_path.joinpath("BOOT-INF/classes/com")47 des = res.joinpath("src/main/java/com")48 shutil.copytree(src,des)49 shutil.move(src_path.joinpath("BOOT-INF/classes/application.properties"),res.joinpath("src/main/resources/application.properties"))50 51 meta_inf_path = src_path.joinpath("META-INF/maven/")52 pom_path = ""53 for i in meta_inf_path.glob("**/*"):54 if "pom.xml" in str(i):55 pom_path = i56 if pom_path != "":57 shutil.move(pom_path,res.joinpath("pom.xml"))58 shutil.rmtree(src_path)59 else:60 print("pom.xml is not exists")61if __name__ == '__main__':62 63 epilog = r'''Example:64 python3 decompiler.py -jar ./ezjson.jar -o ./result/65 '''66 parse = argparse.ArgumentParser(epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)67 parse.add_argument('-jar', '--jar', help='jar包路径')68 parse.add_argument('-o', '--out', help='输入存放反编译后文件的目录')69 args = parse.parse_args()70 jar_path = args.jar71 output_path = args.out72 if jar_path is not None and output_path is not None: 73 decompiler_jar()74 gen()75 else:...

Full Screen

Full Screen

javac.py

Source:javac.py Github

copy

Full Screen

1import shutil2import tempfile3from pathlib import Path4from os import pathsep5COMPILER_OPTIONS = ["-target", "11", "-source", "11"]6def _to_jar_(jar_path: Path, root: Path):7 from java.io import ByteArrayOutputStream8 from java.util.jar import JarEntry, JarOutputStream9 out = ByteArrayOutputStream()10 with JarOutputStream(out) as jar:11 for p in root.glob("**/*.class"):12 p = p.resolve()13 jar.putNextEntry(JarEntry(str(p.relative_to(root).as_posix())))14 jar.write(p.read_bytes())15 jar.closeEntry()16 jar_path.write_bytes(out.toByteArray())17def java_compile(src_path: Path, jar_path: Path):18 """19 Compiles the provided Java source20 :param src_path: The path to the java file or the root directory of the java source files21 :param jar_path: The path to write the output jar to22 """23 from java.lang import System24 from java.nio.file import Path as JPath25 from javax.tools import StandardLocation, ToolProvider26 with tempfile.TemporaryDirectory() as out:27 outdir = Path(out).resolve()28 compiler = ToolProvider.getSystemJavaCompiler()29 fman = compiler.getStandardFileManager(None, None, None)30 cp = [JPath @ (Path(p)) for p in System.getProperty("java.class.path").split(pathsep)]31 fman.setLocationFromPaths(StandardLocation.CLASS_PATH, cp)32 if src_path.is_dir():33 fman.setLocationFromPaths(StandardLocation.SOURCE_PATH, [JPath @ (src_path.resolve())])34 fman.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, [JPath @ (outdir)])35 sources = None36 if src_path.is_file():37 sources = fman.getJavaFileObjectsFromPaths([JPath @ (src_path)])38 else:39 glob = src_path.glob("**/*.java")40 sources = fman.getJavaFileObjectsFromPaths([JPath @ (p) for p in glob])41 task = compiler.getTask(None, fman, None, COMPILER_OPTIONS, None, sources)42 if not task.call():43 # errors printed to stderr44 return45 if jar_path.suffix == '.jar':46 jar_path.parent.mkdir(exist_ok=True, parents=True)47 _to_jar_(jar_path, outdir)48 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful