@@ -46,7 +46,7 @@ public static String getGradleCommand() {
4646 String gradleSystemCommand = Arrays .stream (System .getenv ("PATH" ).split (System .getProperty ("path.separator" ))).map (path -> new File (path , System .getProperty ("os.name" ).toLowerCase ().contains ("windows" ) ? "gradle.bat" : "gradle" )).filter (File ::exists ).findFirst ().map (File ::getAbsolutePath ).orElse (null );
4747 File gradleWrapper = System .getProperty ("os.name" ).toLowerCase ().contains ("windows" ) ? new File (projectRootPom , "gradlew.bat" ) : new File (projectRootPom , "gradlew" );
4848
49- return commandExists (gradleWrapper .getAbsoluteFile ()).getKey () ? gradleWrapper .getAbsoluteFile ().toString () : gradleSystemCommand ;
49+ return commandExists (gradleWrapper .getAbsoluteFile ()).getKey () ? gradleWrapper .getAbsoluteFile () .toString () : gradleSystemCommand ;
5050 }
5151
5252 public static Path tempInitScript ;
@@ -159,13 +159,13 @@ public static boolean gradleBuild(String projectPath) {
159159 }
160160
161161 private static boolean buildProject (String projectPath , String build ) {
162- File pomFile = new File (projectPath , "pom.xml" );
162+ File pomFile = new File (String . valueOf ( Paths . get ( projectPath ). toAbsolutePath ()) , "pom.xml" );
163163 if (build == null ) {
164164 return true ;
165165 } else if (build .equals ("auto" )) {
166166 if (pomFile .exists ()) {
167167 Log .info ("Found pom.xml in the project directory. Using Maven to build the project." );
168- return mavenBuild (projectPath ); // Use Maven if pom.xml exists
168+ return mavenBuild (Paths . get ( projectPath ). toAbsolutePath (). toString () ); // Use Maven if pom.xml exists
169169 } else {
170170 Log .info ("Did not find a pom.xml in the project directory. Using Gradle to build the project." );
171171 return gradleBuild (projectPath ); // Otherwise, use Gradle
@@ -204,14 +204,14 @@ private static boolean mkLibDepDirs(String projectPath) {
204204 * Downloads library dependency jars of the given project so that the jars can be used
205205 * for type resolution during symbol table creation.
206206 *
207- * @param projectPath Path to the project under analysis
207+ * @param projectPath Path to the project under javaee
208208 * @return true if dependency download succeeds; false otherwise
209209 */
210210 public static boolean downloadLibraryDependencies (String projectPath , String projectRootPom ) throws IOException {
211211 // created download dir if it does not exist
212212 String projectRoot = projectRootPom != null ? projectRootPom : projectPath ;
213213
214- File pomFile = new File (projectRoot , "pom.xml" );
214+ File pomFile = new File (( new File ( projectRoot )). getAbsoluteFile () , "pom.xml" );
215215 if (pomFile .exists ()) {
216216 libDownloadPath = Paths .get (projectPath , "target" , LIB_DEPS_DOWNLOAD_DIR ).toAbsolutePath ();
217217 if (mkLibDepDirs (projectPath ))
@@ -231,21 +231,21 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
231231 ));
232232 }
233233 Log .info ("Found pom.xml in the project directory. Using Maven to download dependencies." );
234- String [] mavenCommand = {MAVEN_CMD , "--no-transfer-progress" , "-f" , Paths .get (projectRoot , "pom.xml" ).toString (), "dependency:copy-dependencies" , "-DoutputDirectory=" + libDownloadPath .toString ()};
234+ String [] mavenCommand = {MAVEN_CMD , "--no-transfer-progress" , "-f" , Paths .get (projectRoot , "pom.xml" ).toAbsolutePath (). toString (), "dependency:copy-dependencies" , "-DoutputDirectory=" + libDownloadPath .toString ()};
235235 return buildWithTool (mavenCommand );
236236 } else if (new File (projectRoot , "build.gradle" ).exists () || new File (projectRoot , "build.gradle.kts" ).exists ()) {
237- if (GRADLE_CMD == null || !commandExists (new File (GRADLE_CMD )).getKey ()) {
238- libDownloadPath = Paths .get (projectPath , "build" , LIB_DEPS_DOWNLOAD_DIR ).toAbsolutePath ();
239- if (mkLibDepDirs (projectPath ))
240- Log .debug ("Dependencies found/created in " + libDownloadPath );
241- else
242- throw new IllegalStateException ("Error creating library dependency directory in " + libDownloadPath );
237+ libDownloadPath = Paths .get (projectPath , "build" , LIB_DEPS_DOWNLOAD_DIR ).toAbsolutePath ();
238+ if (mkLibDepDirs (projectPath ))
239+ Log .debug ("Dependencies found/created in " + libDownloadPath );
240+ else
241+ throw new IllegalStateException ("Error creating library dependency directory in " + libDownloadPath );
243242
243+ if (GRADLE_CMD == null || !commandExists (new File (GRADLE_CMD )).getKey ()) {
244244 String msg = GRADLE_CMD == null ?
245245 "Could not find Gradle or valid Gradle Wrapper" :
246246 MessageFormat .format ("Could not verify that {0} exists" , GRADLE_CMD );
247247 Log .error (msg );
248- throw new IllegalStateException ("Unable to execute Maven command. " +
248+ throw new IllegalStateException ("Unable to execute Gradle command. " +
249249 (GRADLE_CMD == null ?
250250 "Could not find Gradle or valid Gradle Wrapper" :
251251 "Attempt failed with message\n " + commandExists (new File (GRADLE_CMD )).getValue ()
@@ -271,8 +271,10 @@ public static void cleanLibraryDependencies() {
271271 if (libDownloadPath != null ) {
272272 Log .info ("Cleaning up library dependency directory: " + libDownloadPath );
273273 try {
274- Files .walk (libDownloadPath ).filter (Files ::isRegularFile ).map (Path ::toFile ).forEach (File ::delete );
275- Files .delete (libDownloadPath );
274+ if (libDownloadPath .toFile ().getAbsoluteFile ().exists ()) {
275+ Files .walk (libDownloadPath ).filter (Files ::isRegularFile ).map (Path ::toFile ).forEach (File ::delete );
276+ Files .delete (libDownloadPath );
277+ }
276278 } catch (IOException e ) {
277279 Log .warn ("Unable to fully delete library dependency directory: " + e .getMessage ());
278280 }
@@ -285,4 +287,4 @@ public static void cleanLibraryDependencies() {
285287 }
286288 }
287289 }
288- }
290+ }
0 commit comments