3 ܓi@s^ddlZddlZddlZddlZddlZddlmZddlmZm Z m Z Gdddee Z dS)N)partial)Plugin RedHatPlugin PluginOptc@s^eZdZdZdZdZeddeddedd d d gZdZ dZ ddZ ddZ ddZ ddZdS)Jarsz1Collect information about available Java archivesjarsjavazappend-locationsz,colon-delimited list of additional JAR paths)defaultZval_typedesczall-known-locationsFzscan all known paths)r r /usr/share/java /usr/lib/java/opt /usr/local/var/libcCsdgi}g}ttj}|jdr.|ttj7}|jd}|rJ||jd7}xT|D]L}xFtj|D]8\}}}x,|D]$} |j|| } |j | rp|j | qpWq`WqPWxB|D]:} |j | } |j | } | s| r| | | d}|dj |qWt j|dd d }|j|d d d dS)Nrzall-known-locationszappend-locations:)pathsha1maven_id,: )indentZ separatorsz jars.jsonT)Zplug_dir)rr)listr jar_locationsZ get_optionextra_jar_locationssplitoswalkZ path_joinis_jarappend get_maven_id get_jar_idjsondumpsZadd_string_as_file)selfresultsZ jar_pathsZ locationsZuser_locationslocationdirpath_ filenamesfilenamerjar_pathrjar_idrecordZ results_strr//usr/lib/python3.6/jars.pysetup1s0          z Jars.setupcCstjj|rtj|ry*tj|}d|jkr4dSWdQRXWn>ttjfk r~}z|j d|d|WYdd}~XnXdS)zCheck whether given file is a JAR file. JARs are ZIP files which usually include a manifest at the canonical location 'META-INF/MANIFEST.MF'. zMETA-INF/MANIFEST.MFTNzCould not determine if z is a JAR: F) rrisfilezipfileZ is_zipfileZipFilenamelistIOErrorZ BadZipfile _log_info)r%rfileerrr/r/r0rTs  $z Jars.is_jarc si}ytj|}tjdfdd|jD}t|dkrBdS|j|dv}xn|jD]b}|j}|j ds\y6|j d\}}|j d j}|j d j}|||<Wq\t k rdSXq\WWdQRXWdQRXWn:t k r} z|jd |d | WYdd} ~ XnX|S) zExtract Maven coordinates from a given JAR file, if possible. JARs build by Maven (most popular Java build system) contain 'pom.properties' file. We can extract Maven coordinates from there. z*META-INF/maven/[^/]+/[^/]+/pom.properties$csg|]}j|r|qSr/)match).0x)rgxr/r0 psz%Jars.get_maven_id..Nr#=utf8z)Could not extract Maven coordinates from z: )r3r4recompiler5lenopen readlinesstrip startswithrdecode ValueErrorr6r7) r%r,Zpropsr8resultZprops_flinekeyvaluer9r/)r=r0r!es,     "$zJars.get_maven_idcCsd}yRt|dd4}tj}x$tt|jddD]}|j|q0WWdQRX|j}Wn8tk r}z|j d|d|WYdd}~XnX|S) zHCompute JAR id. Returns sha1 hash of a given JAR file. r rb)modeiNzCould not compute JAR id for z: ) rFhashlibriterrreadupdateZ hexdigestr6r7)r%r,r-r8ZdigestZbufr9r/r/r0r"s (zJars.get_jar_idN)r)r r )rrr)__name__ __module__ __qualname__Z short_descZ plugin_nameZprofilesrstrZ option_listrrr1rr!r"r/r/r/r0rs  #r) rSr#rrCr3 functoolsrZsos.report.pluginsrrrrr/r/r/r0 s