You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/02/21 22:49:27 UTC

[GitHub] [maven-dependency-analyzer] slawekjaranowski opened a new pull request #52: [MSHARED-1036] Analyze project classes only once

slawekjaranowski opened a new pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52


   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MSHARED) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes. Also be sure having selected the correct component.
    - [ ] Each commit in the pull request should have a meaningful subject line and body.
    - [ ] Format the pull request title like `[MSHARED-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MSHARED-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [ ] You have run the integration tests successfully (`mvn -Prun-its clean verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   


-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811632962



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -33,9 +33,11 @@
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Optional;

Review comment:
       https://maven.apache.org/developers/compatibility-plan.html
   Since June 2020 Java 8 is used in Maven plugins ... so we don't stop it
   
   Now I don't use Optional ... of course it is some type of taste, one likes Optional and other likes standard if 😄 




-- 
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



[GitHub] [maven-dependency-analyzer] michael-o commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811928151



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()
+            .filter( klass -> !mainDependencyClasses.contains( klass ) )

Review comment:
       True, `clazz` is more common




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski merged pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski merged pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52


   


-- 
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



[GitHub] [maven-dependency-analyzer] elharo commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811469731



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -276,12 +254,7 @@ else if ( file != null && file.isDirectory() )
 
             if ( artifact != null )
             {
-                Set<String> classesFromArtifact = usedArtifacts.get( artifact );
-                if ( classesFromArtifact == null )
-                {
-                    classesFromArtifact = new HashSet<String>();
-                    usedArtifacts.put( artifact, classesFromArtifact );
-                }
+                Set<String> classesFromArtifact = usedArtifacts.computeIfAbsent( artifact, k -> new HashSet<>() );

Review comment:
       This one's more borderline, though I still find the old version clearer. 
   
   That said, is anything actually changing here? If this isn't relevant to fixing the issue at hand, then we should try to avoid unnecessary churn that obscures what's actually changing in this PR.  

##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -33,9 +33,11 @@
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Optional;

Review comment:
       Are we requiring Java 8 these days? 

##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,68 +209,38 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()
+            .filter( klass -> !mainDependencyClasses.contains( klass ) )
+            .collect( Collectors.toSet() );
     }
 
-    private Set<String> buildDependencyClasses( MavenProject project )
+    private Set<String> buildMainDependencyClasses( MavenProject project )
         throws IOException
     {
-
         String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> dependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        dependencyClasses.addAll( buildDependencyClasses( testOutputDirectory ) );
-
-        return dependencyClasses;
+        return buildDependencyClasses( outputDirectory );
     }
 
-    private Set<String> buildMainDependencyClasses( MavenProject project )
+    private Set<String> buildTestDependencyClasses( MavenProject project )
         throws IOException
     {
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> dependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        return dependencyClasses;
+        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
+        return buildDependencyClasses( testOutputDirectory );
     }
 
     private Set<String> buildDependencyClasses( String path )
         throws IOException
     {
         URL url = new File( path ).toURI().toURL();
-
         return dependencyAnalyzer.analyze( url );
     }
 
     private Set<Artifact> buildDeclaredArtifacts( MavenProject project )
     {
-        Set<Artifact> declaredArtifacts = project.getDependencyArtifacts();
-
-        if ( declaredArtifacts == null )
-        {
-            declaredArtifacts = Collections.emptySet();
-        }
-
-        return declaredArtifacts;
+        return Optional.ofNullable( project.getDependencyArtifacts() ).orElseGet( Collections::emptySet );

Review comment:
       This is less clear and harder to read than the code it replaces. Please revert. 




-- 
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



[GitHub] [maven-dependency-analyzer] elharo commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811895120



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()

Review comment:
       By any chance do we already depend on Apache Commons Colelctions? If so, consider using SetUtils.difference which would read clearer. If not, add a comment like
   
   // Find classes used by tests not also used by the model code
   
   Or you could just use Set.removeAll to pull the mainDependencyClasses out and leave the test onlly classes behind. That's probably simplest.  
   

##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,

Review comment:
       I think this method can be static now

##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()
+            .filter( klass -> !mainDependencyClasses.contains( klass ) )

Review comment:
       clazz is a little more common in my experience, as a fill-in for class. Though here it's just a string so perhaps className instead? 

##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,

Review comment:
       perhaps change "build" to "list" or "find" since you're not creating the objects here, which builder methods usually do




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r812040761



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()

Review comment:
       use `Set.removeAll`




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r812040338



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,
+                                                        Set<String> testDependencyClasses )
     {
-        Set<String> testOnlyDependencyClasses = new HashSet<>();
-
-        String outputDirectory = project.getBuild().getOutputDirectory();
-        Set<String> nonTestDependencyClasses = new HashSet<>( buildDependencyClasses( outputDirectory ) );
-
-        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
-        Set<String> testDependencyClasses = new HashSet<>( buildDependencyClasses( testOutputDirectory ) );
-
-        for ( String testString : testDependencyClasses )
-        {
-            if ( !nonTestDependencyClasses.contains( testString ) )
-            {
-                testOnlyDependencyClasses.add( testString );
-            }
-        }
-
-        return testOnlyDependencyClasses;
+        return testDependencyClasses.stream()
+            .filter( klass -> !mainDependencyClasses.contains( klass ) )

Review comment:
       use `Set.removeAll`




-- 
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



[GitHub] [maven-dependency-analyzer] elharo commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811479598



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -33,9 +33,11 @@
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Optional;

Review comment:
       Fair enough, though my day job supports Java 7, and I'm still being asked to debug issues involving Java 6 in open source. Developers like to jump to the latest and greatest but customers hate this.
   
   My comments about not using lambdas and Optional without a very good reason still apply though. 




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r811474988



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -33,9 +33,11 @@
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Optional;

Review comment:
       Yes we are requiring Java 8 these days. 
   The year is 2022 today and the latest Java LTS is version 17.




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r812041293



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,

Review comment:
       now build new instance ... so don't remove




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #52: [MSHARED-1036] Analyze project classes only once

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #52:
URL: https://github.com/apache/maven-dependency-analyzer/pull/52#discussion_r812041496



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
##########
@@ -201,48 +206,26 @@ else if ( file != null && file.isDirectory() )
         return artifactClassMap;
     }
 
-    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    private Set<String> buildTestOnlyDependencyClasses( Set<String> mainDependencyClasses,

Review comment:
       ok,




-- 
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