You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "michael-o (via GitHub)" <gi...@apache.org> on 2023/03/16 07:58:21 UTC

[GitHub] [maven-dependency-analyzer] michael-o commented on a diff in pull request #81: Prefer JDK classes to Plexus utils

michael-o commented on code in PR #81:
URL: https://github.com/apache/maven-dependency-analyzer/pull/81#discussion_r1138253560


##########
src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtils.java:
##########
@@ -108,41 +106,30 @@ private static void acceptJar( URL url, ClassFileVisitor visitor )
     private static void acceptDirectory( File directory, ClassFileVisitor visitor )
         throws IOException
     {
-        if ( !directory.isDirectory() )
+    
+        List<Path> classFiles = Files.walk( directory.toPath() )
+            .filter( path -> path.toFile().getName().endsWith( ".class" ) )
+            .collect( Collectors.toList() );
+            
+        for ( Path path : classFiles )
         {
-            throw new IllegalArgumentException( "File is not a directory" );
-        }
-
-        DirectoryScanner scanner = new DirectoryScanner();
-
-        scanner.setBasedir( directory );
-        scanner.setIncludes( new String[] { "**/*.class" } );
-
-        scanner.scan();
-
-        String[] paths = scanner.getIncludedFiles();
-
-        for ( String path : paths )
-        {
-            path = path.replace( File.separatorChar, '/' );
-
-            File file = new File( directory, path );
-
-            try ( InputStream in = new FileInputStream( file ) )
+            try ( InputStream in = Files.newInputStream( path ) )
             {
-                visitClass( path, in, visitor );
+                visitClass( directory, path, in, visitor );
             }
         }
     }
 
-    private static void visitClass( String path, InputStream in, ClassFileVisitor visitor )
+    private static void visitClass( File baseDirectory, Path path, InputStream in, ClassFileVisitor visitor )
     {
-        if ( !path.endsWith( ".class" ) )
-        {
-            throw new IllegalArgumentException( "Path is not a class" );
-        }
+        // getPath() returns a String, not a java.nio.file.Path
+        String stringPath = path.toFile().getPath().substring( baseDirectory.getPath().length() + 1 );

Review Comment:
   Same here



##########
src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtils.java:
##########
@@ -108,41 +106,30 @@ private static void acceptJar( URL url, ClassFileVisitor visitor )
     private static void acceptDirectory( File directory, ClassFileVisitor visitor )
         throws IOException
     {
-        if ( !directory.isDirectory() )
+    
+        List<Path> classFiles = Files.walk( directory.toPath() )
+            .filter( path -> path.toFile().getName().endsWith( ".class" ) )

Review Comment:
   Why not `#getFileName()#toString()`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org