@@ -100,61 +100,6 @@ def __init__(
100100 else :
101101 self .call_graph : DiGraph | None = None
102102
103- @staticmethod
104- def _download_or_update_code_analyzer (filepath : Path ) -> str :
105- """Downloads the codeanalyzer jar from the latest release on GitHub.
106-
107- Args:
108- filepath (Path): The path to save the codeanalyzer jar.
109-
110- Returns:
111- str: The path to the downloaded codeanalyzer jar file.
112- """
113- url = "https://api.github.com/repos/IBM/codenet-minerva-code-analyzer/releases/latest"
114- response = requests .get (url )
115- date_format = "%Y%m%dT%H%M%S"
116- if response .status_code == 200 :
117- for asset in response .json ().get ("assets" , []):
118- if asset ["name" ] == "codeanalyzer.jar" :
119- download_url = asset ["browser_download_url" ]
120- pattern = r"(\d{8}T\d{6})"
121- match = re .search (pattern , download_url )
122- if match :
123- datetime_str = match .group (0 )
124- else :
125- raise Exception (f"Release URL { download_url } does not contain a datetime pattern." )
126-
127- # Look for codeanalyzer.YYYYMMDDTHHMMSS.jar in the filepath
128- current_codeanalyzer_jars = [jarfile for jarfile in filepath .glob ("*.jar" )]
129- if not any (current_codeanalyzer_jars ):
130- logger .info (f"Codeanalzyer jar is not found. Downloading the latest version." )
131- filename = filepath / f"codeanalyzer.{ datetime_str } .jar"
132- urlretrieve (download_url , filename )
133- return filename .__str__ ()
134-
135- current_codeanalyzer_jar_name = current_codeanalyzer_jars [0 ]
136- match = re .search (pattern , current_codeanalyzer_jar_name .__str__ ())
137- if match :
138- current_datetime_str = match .group (0 )
139-
140- if datetime .strptime (datetime_str , date_format ) > datetime .strptime (current_datetime_str , date_format ):
141- logger .info (f"Codeanalzyer jar is outdated. Downloading the latest version." )
142- # Remove the older codeanalyzer jar
143- for jarfile in current_codeanalyzer_jars :
144- jarfile .unlink ()
145- # Download the newer codeanalyzer jar
146- filename = filepath / f"codeanalyzer.{ datetime_str } .jar"
147- urlretrieve (download_url , filename )
148- else :
149- filename = current_codeanalyzer_jar_name
150- logger .info (f"Codeanalzyer jar is already at the latest version." )
151- else :
152- filename = current_codeanalyzer_jar_name
153-
154- return filename .__str__ ()
155- else :
156- raise Exception (f"Failed to fetch release warn: { response .status_code } { response .text } " )
157-
158103 def _get_application (self ) -> JApplication :
159104 """Returns the application view of the Java code.
160105
@@ -185,13 +130,13 @@ def _get_codeanalyzer_exec(self) -> List[str]:
185130 if self .analysis_backend_path :
186131 analysis_backend_path = Path (self .analysis_backend_path )
187132 logger .info (f"Using codeanalyzer.jar from { analysis_backend_path } " )
188- codeanalyzer_exec = shlex .split (f"java -jar { analysis_backend_path / 'codeanalyzer.jar' } " )
133+ codeanalyzer_jar_file = next (analysis_backend_path .glob ("*.jar" ), None )
134+ if codeanalyzer_jar_file is None :
135+ raise CodeanalyzerExecutionException (f"No codeanalyzer jar found in { analysis_backend_path } " )
136+ codeanalyzer_exec = shlex .split (f"java -jar { analysis_backend_path / codeanalyzer_jar_file } " )
189137 else :
190- # Since the path to codeanalyzer.jar was not provided, we'll download the latest version from GitHub.
191138 with resources .as_file (resources .files ("cldk.analysis.java.codeanalyzer.jar" )) as codeanalyzer_jar_path :
192- # Download the codeanalyzer jar if it doesn't exist, update if it's outdated,
193- # do nothing if it's up-to-date.
194- codeanalyzer_jar_file = self ._download_or_update_code_analyzer (codeanalyzer_jar_path )
139+ codeanalyzer_jar_file = next (codeanalyzer_jar_path / "*.jar" , None )
195140 codeanalyzer_exec = shlex .split (f"java -jar { codeanalyzer_jar_file } " )
196141 return codeanalyzer_exec
197142
0 commit comments