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/05/27 07:46:10 UTC

[GitHub] [maven-enforcer] josephw opened a new pull request, #152: MENFORCER-420: cache dependencies across rules

josephw opened a new pull request, #152:
URL: https://github.com/apache/maven-enforcer/pull/152

   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MENFORCER) 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.
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Format the pull request title like `[MENFORCER-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MENFORCER-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.
    - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] 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.
   
    - [x] 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-enforcer] josephw commented on a diff in pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
josephw commented on code in PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#discussion_r883358525


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java:
##########
@@ -120,6 +120,36 @@ protected CharSequence getErrorMessage( Artifact artifact )
         return "Found Banned Dependency: " + artifact.getId() + System.lineSeparator();
     }
 
+    private Set<Artifact> getDependenciesToCheck( EnforcerRuleHelper helper, ProjectBuildingRequest buildingRequest )
+    {
+        if ( helper == null )
+        {
+            return getDependenciesToCheck( buildingRequest );
+        }
+
+        String cacheKey = buildingRequest.getProject().getId() + "_" + searchTransitive;
+
+        // check in the cache
+        if ( helper.getContainer().getContext().contains( cacheKey ) )

Review Comment:
   This behaviour works for us, but I'm not clear whether it's a suitable place for a cache. [This post from the mailing list](https://lists.apache.org/thread/12vv716gcxo97nyzcb00qt19wx10l2m4) suggests:
   > Most of these cache would seem to be relevant at the "MavenExecution"
   level, i.e. we could choose to ditch all of this at the end of each
   build without loosing any real performance.
   
   Is there a better place now to get a cache with that lifecycle?



-- 
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-enforcer] slawekjaranowski commented on pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#issuecomment-1141397738

   GH builds special code PR+current master - after rebase with master I have the same strange error .... jdk 11
   
   ```
   Caused by: java.lang.NullPointerException
       at com.sun.tools.javac.main.JavaCompiler.readSourceFile (JavaCompiler.java:841)
       at com.sun.tools.javac.processing.JavacProcessingEnvironment$ImplicitCompleter.complete (JavacProcessingEnvironment.java:1535)
       at com.sun.tools.javac.code.Symbol.complete (Symbol.java:642)
   ```
   
   cause is missing dependencies for `javax.annotation.Nonnull` annotation.
   Please check - I think that for private method we don't need such.


-- 
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-enforcer] slawekjaranowski commented on pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#issuecomment-1140499713

   Please 
    - run `mvn -Prun-its clean verify`
    - squash to one  final commit
    - put jira issue in brackets square in commit message
   


-- 
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-enforcer] josephw commented on a diff in pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
josephw commented on code in PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#discussion_r884346819


##########
enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java:
##########
@@ -131,4 +132,13 @@ List<?> getComponentList ( String role )
      * @return the container
      */
     PlexusContainer getContainer();
+
+    /**
+     * Gets a cached value, or uses the provided producer to compute it.
+     *
+     * @param key a key to identify the value stored
+     * @param producer a supplier for the value if it's not already present
+     * @return a previously-cached or freshly-computed value
+     */
+    Object getCache( String key, Supplier<?> producer );

Review Comment:
   I considered this; it's a nicer API signature. However, there's no enforcement that keys are distinct, so getting a cache response that had previously been produced by a `Supplier` of a different `<T>` would lead to types that were inconsistent with the generics.
   
   I could make this more elaborate (e.g. passing in a `Class` and enforcing that), but I went with a version that I think makes the necessary runtime check clearer.



-- 
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-enforcer] slawekjaranowski commented on a diff in pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on code in PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#discussion_r884274320


##########
enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java:
##########
@@ -131,4 +132,13 @@ List<?> getComponentList ( String role )
      * @return the container
      */
     PlexusContainer getContainer();
+
+    /**
+     * Gets a cached value, or uses the provided producer to compute it.
+     *
+     * @param key a key to identify the value stored
+     * @param producer a supplier for the value if it's not already present
+     * @return a previously-cached or freshly-computed value
+     */
+    Object getCache( String key, Supplier<?> producer );

Review Comment:
   What do you think about use generic here?, eg
   
   ```
   <T> T getCache( String key, Supplier<T> producer );
   ```
   
   of course we have cast in method implementation, but it will be in one place, not in every place where method will be used.
   
   



-- 
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-enforcer] slawekjaranowski merged pull request #152: [MENFORCER-420] cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski merged PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152


-- 
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-enforcer] slawekjaranowski commented on pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#issuecomment-1141397739

   GH builds special code PR+current master - after rebase with master I have the same strange error .... jdk 11
   
   ```
   Caused by: java.lang.NullPointerException
       at com.sun.tools.javac.main.JavaCompiler.readSourceFile (JavaCompiler.java:841)
       at com.sun.tools.javac.processing.JavacProcessingEnvironment$ImplicitCompleter.complete (JavacProcessingEnvironment.java:1535)
       at com.sun.tools.javac.code.Symbol.complete (Symbol.java:642)
   ```
   
   cause is missing dependencies for `javax.annotation.Nonnull` annotation.
   Please check - I think that for private method we don't need such.


-- 
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-enforcer] josephw commented on pull request #152: [MENFORCER-420] cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
josephw commented on PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#issuecomment-1141513406

   > cause is missing dependencies for `javax.annotation.Nonnull` annotation. Please check - I think that for private method we don't need such.
   
   Good call; dropped.
   


-- 
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-enforcer] slawekjaranowski commented on a diff in pull request #152: MENFORCER-420: cache dependencies across rules

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on code in PR #152:
URL: https://github.com/apache/maven-enforcer/pull/152#discussion_r883926656


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java:
##########
@@ -120,6 +120,36 @@ protected CharSequence getErrorMessage( Artifact artifact )
         return "Found Banned Dependency: " + artifact.getId() + System.lineSeparator();
     }
 
+    private Set<Artifact> getDependenciesToCheck( EnforcerRuleHelper helper, ProjectBuildingRequest buildingRequest )
+    {
+        if ( helper == null )
+        {
+            return getDependenciesToCheck( buildingRequest );
+        }
+
+        String cacheKey = buildingRequest.getProject().getId() + "_" + searchTransitive;
+
+        // check in the cache
+        if ( helper.getContainer().getContext().contains( cacheKey ) )

Review Comment:
   I added comments in jira.



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