HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/sos/report/plugins/__pycache__/jars.cpython-39.opt-1.pyc
a

\��h��@s^ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
Gdd�dee	�ZdS)�N)�partial)�Plugin�RedHatPlugin�	PluginOptc@s^eZdZdZdZdZeddedd�edd	d
d�gZdZ	d
Z
dd�Zdd�Zdd�Z
dd�ZdS)�Jarsz1Collect information about available Java archives�jars)�java�append-locations�z,colon-delimited list of additional JAR paths)�defaultZval_type�desc�all-known-locationsFzscan all known paths)rr)z/usr/share/javaz
/usr/lib/java)z/optz
/usr/localz/var/libcCs�dgi}g}ttj�}|�d�r.|ttj�7}|�d�}|rJ||�d�7}|D]D}t�|�D]4\}}}|D]$}	|�||	�}
|�	|
�rj|�
|
�qjq\qN|D]:}|�|�}|�|�}
|s�|
r�||
|d�}|d�
|�q�t
j|ddd�}|j|d	d
d�dS)Nrr
r	�:)�path�sha1�maven_id�)�,�: )�indentZ
separatorsz	jars.jsonT)Zplug_dir)�listr�
jar_locationsZ
get_option�extra_jar_locations�split�os�walkZ	path_join�is_jar�append�get_maven_id�
get_jar_id�json�dumpsZadd_string_as_file)�self�resultsZ	jar_pathsZ	locationsZuser_locations�location�dirpath�_�	filenames�filenamer�jar_pathr�jar_id�recordZresults_str�r,�;/usr/lib/python3.9/site-packages/sos/report/plugins/jars.py�setup1s2





�z
Jars.setupc
Cs�tj�|�r�t�|�r�zLt�|��.}d|��vrBWd�WdSWd�n1sV0YWn@ttjfy�}z"|�	d|�d|���WYd}~n
d}~00dS)z�Check 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.MFNTzCould not determine if z is a JAR: F)
rr�isfile�zipfile�
is_zipfile�ZipFile�namelist�IOErrorZ
BadZipfile�	_log_info)r"r�file�errr,r,r-rTs4�zJars.is_jarc
spi}�z(t�|���}t�d���fdd�|��D�}t|�dkrTWd�WdS|�|d���}|��D]~}|��}|�	d�slz6|�
d�\}}|�d	���}|�d	���}|||<Wqlty�YWd�Wd�WdS0qlWd�n1�s0YWd�n1�s"0YWn<t
�yj}	z"|�d
|�d|	���WYd}	~	n
d}	~	00|S)z�Extract 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|]}��|�r|�qSr,)�match)�.0�x�Zrgxr,r-�
<listcomp>p�z%Jars.get_maven_id.<locals>.<listcomp>�Nr�#�=�utf8z)Could not extract Maven coordinates from r)r0r2�re�compiler3�len�open�	readlines�strip�
startswithr�decode�
ValueErrorr4r5)
r"r)Zpropsr6�resultZprops_f�line�key�valuer7r,r;r-res.

j�zJars.get_maven_idc
Cs�d}zbt|dd��:}t��}tt|jd�d�D]}|�|�q.Wd�n1sR0Y|��}Wn:ty�}z"|�	d|�d|���WYd}~n
d}~00|S)	zHCompute JAR id.

        Returns sha1 hash of a given JAR file.
        r
�rb)�modeir=NzCould not compute JAR id for r)
rE�hashlibr�iterr�read�updateZ	hexdigestr4r5)r"r)r*r6Zdigest�bufr7r,r,r-r�s*,zJars.get_jar_idN)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesr�strZoption_listrrr.rrrr,r,r,r-rs ���
#r)rQr rrBr0�	functoolsrZsos.report.pluginsrrrrr,r,r,r-�<module>s