16
16
17
17
def get_bytecode_version (class_file ):
18
18
result = subprocess .run (["javap" , "-verbose" , class_file ], capture_output = True , text = True )
19
+
19
20
for line in result .stdout .splitlines ():
20
21
if "major version" in line :
21
22
return line .split (":" )[- 1 ].strip ()
22
23
23
24
24
- def main ( ):
25
+ def check_artifact_bytecode ( desired_java_version , desired_bytecode_version ):
25
26
jar_path = get_artifact_path ("jar" )
26
- # Java 8 == bytecode version 52.0 (defined in the local.javalibrary.gradle.kts)
27
- # https://javaalmanac.io/bytecode/versions/
28
- desired_java_version = "8"
29
- desired_bytecode_version = "52"
30
27
31
- print (
32
- f"Verify if the first class in { jar_path } is compiled to bytecode { desired_bytecode_version } (Java { desired_java_version } )" )
28
+ print ( f"Verify if the first class in { jar_path } is compiled to bytecode { desired_bytecode_version } (Java { desired_java_version } )" )
33
29
34
30
checked = False # Variable to track if we've already checked a .class file
35
31
36
32
try :
37
- # Unzip the jar file to the temporary directory
33
+ # Unzip the get_artifact_path jar file to the temporary directory
38
34
subprocess .run (["unzip" , "-qq" , jar_path , "-d" , build_dir ], check = True )
39
35
40
36
# Walk the directory to find all .class files
@@ -55,12 +51,14 @@ def main():
55
51
if checked :
56
52
print (f"SUCCESS: First class has correct bytecode version: { desired_bytecode_version } " )
57
53
else :
58
- print ("WARNING: No .class file found to check." )
54
+ print ("ERROR: No .class file found to check the artifact." )
55
+ sys .exit (1 )
59
56
60
57
finally :
61
58
# Clean up the temporary directory
62
59
shutil .rmtree (build_dir )
63
60
64
61
65
- if __name__ == "__main__" :
66
- main ()
62
+ # Java 8 == bytecode version 52.0 (defined in the local.javalibrary.gradle.kts)
63
+ # https://javaalmanac.io/bytecode/versions/
64
+ check_artifact_bytecode ("8" , "52" )
0 commit comments