
    Vi+                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S S	KJs  Jr  S S
KJr  S SKJr  \" SS9 " S S\5      5       rg	)    )	dataclass)Path)	FrozenSet)List)Optional)Set)Tuple)UnionN)SubprojectMatcher)TargetT)frozenc            	       *   \ rS rSrSrSS/rSS/rSr\R                  " \R                  " 5       5      rS\S	\4S
 jrS\S\\   S	\\\   \\   4   4S jrS\\   S	\\\   \\   \\   4   4S jrS\\   S	\\\R.                     \\   4   4S jrSrg)GradleMatcher   a  
Matcher for gradle project root directories. Matches projects based on gradle.lockfile,
settings.gradle, or build.gradle (for single-project builds only). build.gradle files
that are encountered in a subdirectory of another gradle project are assumed to be part
of the containing project unless they contain a gradle.lockfile or a settings.gradle.

Does not support gradle directories that use `include` and `includeFlat` to customize
the shape of the project directory: gradle.lockfile, settings.gradle, or build.gradle
must be located at the root of the gradle project.

For more information on the various shapes of gradle projects, see
https://docs.gradle.org/current/userguide/intro_multi_project_builds.htm
zbuild.gradlezbuild.gradle.ktszsettings.gradlezsettings.gradle.ktszgradle.lockfilepathreturnc                 h    UR                   / U R                  QU R                  QU R                  P;   $ N)nameBUILD_FILENAMESSETTINGS_FILENAMESLOCKFILE_FILENAME)selfr   s     i/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/semdep/matchers/gradle.pyis_matchGradleMatcher.is_match0   sD    yy 
!!
$$
 ""
 
 	
    lockfile_path
candidatesc                    U R                    Vs/ s H  o1R                  U-  PM     nnU R                   Vs/ s H  o1R                  U-  PM     nnSnSnU H  nX;   d  M
  Un  O   U H  n	X;   d  M
  U	n  Xv4$    Xv4$ s  snf s  snf )z
Finds the corresponding settings.gradle and build.gradle files for the given
lockfile, if they exist.

Returns (settings_path, build_path) if each path exists in candidates.
N)r   parentr   )
r   r   r   xpossible_build_pathspossible_settings_paths
build_pathsettings_pathpossible_build_pathpossible_settings_paths
             r   _lockfile_to_settings_and_build-GradleMatcher._lockfile_to_settings_and_build7   s     CGBVBVWBVQ 4 4q 8BVW.2.E.E#
.E  1$.E 	  #
 &*
(,#7"00
 $8 '>"%3 6((	 '> ((  X#
s
   A>Bdep_source_filesc                 ~   [        5       n[        5       n[        5       nU H  nUR                  nUR                  U R                  ;   a  UR	                  U5        M<  UR                  U R
                  ;   a  UR	                  U5        Mi  UR                  U R                  :X  d  M  UR	                  U5        M     X#U4$ )z
Classifies the provided source files as settings.gradle, build.gradle, and lockfiles

Returns a tuple of (settings.gradle, build.gradle, lockfiles)
)setfpathr   r   addr   r   )r   r+   settings_filesbuild_files	lockfilestargetr   s          r   _sort_source_files GradleMatcher._sort_source_filesQ   s     %(E!$"u	&F<<DyyD000%d555""4(d444d# ' I55r   c                 d  ^ U R                  U5      u  p#n/ n[        5       n[        5       n[        5       n[        S U 5       5      n	U GH  n
U
R                  nUR	                  U5        U R                  X5      u  mn[        R                  " [        R                  " [        R                  " 5       5      [        R                  " [        U
5      5      S9nUb  UR	                  U5        Tb  UR	                  T5        S nUb  UR                  S:X  a  [        R                  " 5       O[        R                  " 5       n[        R                  " [        R                   " U5      [        R                  " [        U5      5      S9nO\TbY  [        R                  " [        R                   " [        R"                  " 5       5      [        R                  " [        T5      5      S9nUbx  UR%                  [        R&                  " [        R                  " [        U5      5      [        R(                  " [        R*                  " X45      5      U R,                  S95        GM  UR%                  [        R&                  " [        R                  " [        U5      5      [        R(                  " [        R.                  " U5      5      U R,                  S95        GM     U GH  mTU;   a  M  TR                  nU	R1                  U4S jU R2                   5       5      n[5        U5      S:  a  [7        S U 5       5      nUR	                  U5        UR                  S:X  a  [        R                  " 5       O[        R                  " 5       n[        R                  " [        R                   " U5      [        R                  " [        U5      5      S9nOY[        R                  " [        R                   " [        R"                  " 5       5      [        R                  " [        T5      5      S9nUR	                  U5        UR	                  T5        UR%                  [        R&                  " [        R                  " [        U5      5      [        R(                  " [        R8                  " U5      5      U R,                  S95        GM     U GH]  nX;   a  M  [5        UR1                  UR:                  5      5      S:  a  M5  UR                  S:X  a  [        R                  " 5       O[        R                  " 5       nUR%                  [        R&                  " [        R                  " [        UR                  5      5      [        R(                  " [        R8                  " [        R                  " [        R                   " U5      [        R                  " [        U5      5      S95      5      U R,                  S95        UR	                  UR                  5        UR	                  U5        GM`     U[        XG-  U-  5      4$ )Nc              3   8   #    U  H  oR                   v   M     g 7fr   )r.   ).0r3   s     r   	<genexpr>1GradleMatcher.make_subprojects.<locals>.<genexpr>w   s     K:J||:Js   )kindr   z.kts)root_dirdependency_source	ecosystemc              3   B   >#    U  H  nTR                   U-  v   M     g 7fr   )r!   )r8   r"   r&   s     r   r9   r:      s       22FQ$$q(2Fs   r   c              3   $   #    U  H  ov   M     g 7fr    )r8   r"   s     r   r9   r:      s     '?;a;s   )r4   r-   	frozensetr!   r/   r)   outLockfileLockfileKindGradleLockfileFpathstrsuffixBuildGradleKtsBuildGradleManifestManifestKindSettingsGradleappend
SubprojectDependencySourceManifestLockfile	ECOSYSTEMLockfileOnlyintersectionr   lennextManifestOnlyparents)r   r+   r0   r1   r2   subprojects	root_dirsused_settings_pathsused_build_pathsr   r   project_rootr%   lockfilemanifestr;   build_pathsfirst_build_pathr&   s                     @r   make_subprojectsGradleMatcher.make_subprojectsg   s    261H1H2
.Y -/  #u	),&)e K:JKK
&M(//LMM,'(,(L(L)%M: ||%%c&8&8&:;YYs=12H % $$Z0(#''6/3H% "((F2 &&(*  <<))$/3z?3 * <<))#*<*<*>?3}#56
 #""NN!$3|+<!=*-*>*>00(1EF+ #'.. ""NN!$3|+<!=*-*>*>,,X6+ #'..i 'B ,M 33(//L$11 2262F2F2 K ;!##''?;'?#?  !$$%56 (..&8 &&(* 
 <<))$/3'7#89
 <<))#*<*<*>?3}#56
 MM,'##M2 YYs<'89&)&:&:3;K;KH;U&V"nnC ,X &J-9))**<*<=>B  $$. ""$__&   YYs:+<+<'=>&)&:&:((LL%(%5%5d%;%(YYs:%?' #nn MM*++,  ,A &D I+.>>
 
 	
r   rA   N)__name__
__module____qualname____firstlineno____doc__r   r   r   rC   	EcosystemMavenrS   r   boolr   r   r	   r   r)   r   r   r4   r   rP   rc   __static_attributes__rA   r   r   r   r      s     &'9:O+-BC)ciik*I
T 
d 
)!)/8)	x~x~-	.)46 )& 16	s4y#d)SY.	/6,b
 )& 1b
	tCNN#Yt_4	5b
r   r   )dataclassesr   pathlibr   typingr   r   r   r   r	   r
   ,semgrep.semgrep_interfaces.semgrep_output_v1semgrep_interfacessemgrep_output_v1rC   semdep.matchers.baser   semgrep.typesr   r   rA   r   r   <module>rv      sO    "        : : 2   $m
% m
 m
r   