Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7691] Lifecycle filter #1086

Draft
wants to merge 3 commits into
base: maven-3.9.x
Choose a base branch
from

Conversation

cstamas
Copy link
Member

@cstamas cstamas commented Apr 13, 2023

A rough concept how could it work: this skipper simply plugs into lifecycle calculator and skips (removes) filtered out MojoExecutions.

Expression is simple: G[:A[:g[:e]]] (comma separated)

Where G means "groupId" and can be:

  • "" (empty string) -- means "default plugin groupIds" (as in user settings)
  • "*" (asterisk) -- any
  • "string" -- string equality for groupId

A (artifactId), g (goal) and e (executionId) may have values:

  • "*" (asterisk) -- any (implied if not given)
  • "string" -- string equality for artifactId, goal or executionId respectively.

Examples:

  • -Dmaven.lifecycle.filter= (same as "" empty string) - any plugin in "default" plugin groups (by default org.apache.maven.plugins and org.codehaus.mojo)
  • -Dmaven.lifecycle.filter=:buildnumber-maven-plugin,:maven-enforcer-plugin -- buildnumber codehaus and enforcer ASF plugin
  • -Dmaven.lifecycle.filter=:*:*:enforce-java-version - any "default" plugin execution with execution ID of "enforce-java-version"
  • -Dmaven.lifecycle.filter=* - exclude all (funnily, maven will happily do nothing, no mojo will run)

Example invocations (only with relevant output):

$ mvn -f maven-core buildplan:list   // this is "original" plan
-----------------------------------------------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                        | VERSION  | GOAL                   | EXECUTION ID                                
-----------------------------------------------------------------------------------------------------------------------------------------
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-bytecode-version                    
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-maven-version                       
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-java-version                        
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | ensure-no-sonatype-cipher-and-sec-dispatcher
initialize             | buildnumber-maven-plugin      | 1.4      | create                 | create-buildnumber                          
generate-sources       | modello-maven-plugin          | 2.0.0    | java                   | modello                                     
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-reader            | modello                                     
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-writer            | modello                                     
verify                 | spotless-maven-plugin         | 2.28.0   | check                  | default                                     
verify                 | maven-checkstyle-plugin       | 3.2.0    | check                  | checkstyle-check                            
generate-resources     | maven-remote-resources-plugin | 1.7.0    | process                | process-resource-bundles                    
process-resources      | maven-resources-plugin        | 3.3.0    | resources              | default-resources                           
compile                | maven-compiler-plugin         | 3.10.1   | compile                | default-compile                             
process-test-classes   | animal-sniffer-maven-plugin   | 1.23     | check                  | check-java-compat                           
process-classes        | plexus-component-metadata             | 2.1.0    | generate-metadata      | default                                     
process-classes        | sisu-maven-plugin             | 0.3.5    | main-index             | index-project                               
process-test-resources | maven-resources-plugin        | 3.3.0    | testResources          | default-testResources                       
test-compile           | maven-compiler-plugin         | 3.10.1   | testCompile            | default-testCompile                         
process-test-classes   | plexus-component-metadata             | 2.1.0    | generate-test-metadata | default                                     
process-test-classes   | sisu-maven-plugin             | 0.3.5    | test-index             | index-project                               
test                   | maven-surefire-plugin         | 3.0.0-M7 | test                   | default-test                                
package                | maven-jar-plugin              | 3.3.0    | jar                    | default-jar                                 
package                | maven-site-plugin             | 3.12.1   | attach-descriptor      | attach-descriptor                           
install                | maven-install-plugin          | 3.1.0    | install                | default-install                             
deploy                 | maven-deploy-plugin           | 2.8.2    | deploy                 | default-deploy                              

$ mvn -f maven-core buildplan:list -Dmaven.lifecycle.filter=*:modello-maven-plugin // exclude whole modello plugin
-----------------------------------------------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                        | VERSION  | GOAL                   | EXECUTION ID                                
-----------------------------------------------------------------------------------------------------------------------------------------
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-bytecode-version                    
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-maven-version                       
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-java-version                        
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | ensure-no-sonatype-cipher-and-sec-dispatcher
initialize             | buildnumber-maven-plugin      | 1.4      | create                 | create-buildnumber                          
verify                 | spotless-maven-plugin         | 2.28.0   | check                  | default                                     
verify                 | maven-checkstyle-plugin       | 3.2.0    | check                  | checkstyle-check                            
generate-resources     | maven-remote-resources-plugin | 1.7.0    | process                | process-resource-bundles                    
process-resources      | maven-resources-plugin        | 3.3.0    | resources              | default-resources                           
compile                | maven-compiler-plugin         | 3.10.1   | compile                | default-compile                             
process-test-classes   | animal-sniffer-maven-plugin   | 1.23     | check                  | check-java-compat                           
process-classes        | plexus-component-metadata             | 2.1.0    | generate-metadata      | default                                     
process-classes        | sisu-maven-plugin             | 0.3.5    | main-index             | index-project                               
process-test-resources | maven-resources-plugin        | 3.3.0    | testResources          | default-testResources                       
test-compile           | maven-compiler-plugin         | 3.10.1   | testCompile            | default-testCompile                         
process-test-classes   | plexus-component-metadata             | 2.1.0    | generate-test-metadata | default                                     
process-test-classes   | sisu-maven-plugin             | 0.3.5    | test-index             | index-project                               
test                   | maven-surefire-plugin         | 3.0.0-M7 | test                   | default-test                                
package                | maven-jar-plugin              | 3.3.0    | jar                    | default-jar                                 
package                | maven-site-plugin             | 3.12.1   | attach-descriptor      | attach-descriptor                           
install                | maven-install-plugin          | 3.1.0    | install                | default-install                             
deploy                 | maven-deploy-plugin           | 2.8.2    | deploy                 | default-deploy                              

$ mvn -f maven-core buildplan:list -Dmaven.lifecycle.filter=*:modello-maven-plugin:java // exclude java mojo
-----------------------------------------------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                        | VERSION  | GOAL                   | EXECUTION ID                                
-----------------------------------------------------------------------------------------------------------------------------------------
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-bytecode-version                    
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-maven-version                       
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-java-version                        
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | ensure-no-sonatype-cipher-and-sec-dispatcher
initialize             | buildnumber-maven-plugin      | 1.4      | create                 | create-buildnumber                          
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-reader            | modello                                     
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-writer            | modello                                     
verify                 | spotless-maven-plugin         | 2.28.0   | check                  | default                                     
verify                 | maven-checkstyle-plugin       | 3.2.0    | check                  | checkstyle-check                            
generate-resources     | maven-remote-resources-plugin | 1.7.0    | process                | process-resource-bundles                    
process-resources      | maven-resources-plugin        | 3.3.0    | resources              | default-resources                           
compile                | maven-compiler-plugin         | 3.10.1   | compile                | default-compile                             
process-test-classes   | animal-sniffer-maven-plugin   | 1.23     | check                  | check-java-compat                           
process-classes        | plexus-component-metadata             | 2.1.0    | generate-metadata      | default                                     
process-classes        | sisu-maven-plugin             | 0.3.5    | main-index             | index-project                               
process-test-resources | maven-resources-plugin        | 3.3.0    | testResources          | default-testResources                       
test-compile           | maven-compiler-plugin         | 3.10.1   | testCompile            | default-testCompile                         
process-test-classes   | plexus-component-metadata             | 2.1.0    | generate-test-metadata | default                                     
process-test-classes   | sisu-maven-plugin             | 0.3.5    | test-index             | index-project                               
test                   | maven-surefire-plugin         | 3.0.0-M7 | test                   | default-test                                
package                | maven-jar-plugin              | 3.3.0    | jar                    | default-jar                                 
package                | maven-site-plugin             | 3.12.1   | attach-descriptor      | attach-descriptor                           
install                | maven-install-plugin          | 3.1.0    | install                | default-install                             
deploy                 | maven-deploy-plugin           | 2.8.2    | deploy                 | default-deploy                              

$ mvn -f maven-core buildplan:list -Dmaven.lifecycle.filter=*:maven-enforcer-plugin:enforce // exclude enforce mojo
---------------------------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                        | VERSION  | GOAL                   | EXECUTION ID            
---------------------------------------------------------------------------------------------------------------------
initialize             | buildnumber-maven-plugin      | 1.4      | create                 | create-buildnumber      
generate-sources       | modello-maven-plugin          | 2.0.0    | java                   | modello                 
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-reader            | modello                 
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-writer            | modello                 
verify                 | spotless-maven-plugin         | 2.28.0   | check                  | default                 
verify                 | maven-checkstyle-plugin       | 3.2.0    | check                  | checkstyle-check        
generate-resources     | maven-remote-resources-plugin | 1.7.0    | process                | process-resource-bundles
process-resources      | maven-resources-plugin        | 3.3.0    | resources              | default-resources       
compile                | maven-compiler-plugin         | 3.10.1   | compile                | default-compile         
process-test-classes   | animal-sniffer-maven-plugin   | 1.23     | check                  | check-java-compat       
process-classes        | plexus-component-metadata             | 2.1.0    | generate-metadata      | default                 
process-classes        | sisu-maven-plugin             | 0.3.5    | main-index             | index-project           
process-test-resources | maven-resources-plugin        | 3.3.0    | testResources          | default-testResources   
test-compile           | maven-compiler-plugin         | 3.10.1   | testCompile            | default-testCompile     
process-test-classes   | plexus-component-metadata             | 2.1.0    | generate-test-metadata | default                 
process-test-classes   | sisu-maven-plugin             | 0.3.5    | test-index             | index-project           
test                   | maven-surefire-plugin         | 3.0.0-M7 | test                   | default-test            
package                | maven-jar-plugin              | 3.3.0    | jar                    | default-jar             
package                | maven-site-plugin             | 3.12.1   | attach-descriptor      | attach-descriptor       
install                | maven-install-plugin          | 3.1.0    | install                | default-install         
deploy                 | maven-deploy-plugin           | 2.8.2    | deploy                 | default-deploy          

$ mvn -f maven-core buildplan:list -Dmaven.lifecycle.filter=:maven-enforcer-plugin:enforce:enforce-maven-version // exclude enforce maven execution
-----------------------------------------------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                        | VERSION  | GOAL                   | EXECUTION ID                                
-----------------------------------------------------------------------------------------------------------------------------------------
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-bytecode-version                    
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | enforce-java-version                        
validate               | maven-enforcer-plugin         | 3.1.0    | enforce                | ensure-no-sonatype-cipher-and-sec-dispatcher
initialize             | buildnumber-maven-plugin      | 1.4      | create                 | create-buildnumber                          
generate-sources       | modello-maven-plugin          | 2.0.0    | java                   | modello                                     
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-reader            | modello                                     
generate-sources       | modello-maven-plugin          | 2.0.0    | xpp3-writer            | modello                                     
verify                 | spotless-maven-plugin         | 2.28.0   | check                  | default                                     
verify                 | maven-checkstyle-plugin       | 3.2.0    | check                  | checkstyle-check                            
generate-resources     | maven-remote-resources-plugin | 1.7.0    | process                | process-resource-bundles                    
process-resources      | maven-resources-plugin        | 3.3.0    | resources              | default-resources                           
compile                | maven-compiler-plugin         | 3.10.1   | compile                | default-compile                             
process-test-classes   | animal-sniffer-maven-plugin   | 1.23     | check                  | check-java-compat                           
process-classes        | plexus-component-metadata             | 2.1.0    | generate-metadata      | default                                     
process-classes        | sisu-maven-plugin             | 0.3.5    | main-index             | index-project                               
process-test-resources | maven-resources-plugin        | 3.3.0    | testResources          | default-testResources                       
test-compile           | maven-compiler-plugin         | 3.10.1   | testCompile            | default-testCompile                         
process-test-classes   | plexus-component-metadata             | 2.1.0    | generate-test-metadata | default                                     
process-test-classes   | sisu-maven-plugin             | 0.3.5    | test-index             | index-project                               
test                   | maven-surefire-plugin         | 3.0.0-M7 | test                   | default-test                                
package                | maven-jar-plugin              | 3.3.0    | jar                    | default-jar                                 
package                | maven-site-plugin             | 3.12.1   | attach-descriptor      | attach-descriptor                           
install                | maven-install-plugin          | 3.1.0    | install                | default-install                             
deploy                 | maven-deploy-plugin           | 2.8.2    | deploy                 | default-deploy                              


https://issues.apache.org/jira/browse/MNG-7691

A rough concept how could it work: this skipper simply plugs into
lifecycle calculator and skips (removes) filtered out MojoExecutions.

Expression is simple: G[:A[:g[:e]]]

Where G means "groupId" and can be:
* "" (empty string) -- means "default plugin groupIds" (as in user settings)
* "*" (asterisk) -- any
* "string" -- string equality for groupId

A (artifactId), g (goal) and e (executionId) may have values:
* "*" (asterisk) -- any
* "string" -- string equality for artifactId, goal or executionId respectively.
@cstamas cstamas self-assigned this Apr 13, 2023
@gnodet
Copy link
Contributor

gnodet commented Apr 14, 2023

The proposed syntax is problematic to me as it's not coherent with the one displayed to the user.
Users now see:

[INFO] 
[INFO] --- checkstyle:3.0.0:check (checkstyle-check) @ core-it-suite ---
[INFO] 
[INFO] --- enforcer:3.1.0:enforce (enforce-bytecode-version) @ core-it-suite ---
[INFO] Adding ignore: module-info
[INFO] 
[INFO] --- enforcer:3.1.0:enforce (enforce-maven-version) @ core-it-suite ---
[INFO] 
[INFO] --- enforcer:3.1.0:enforce (enforce-java-version) @ core-it-suite ---
[INFO] 
[INFO] --- remote-resources:1.7.0:process (process-resource-bundles) @ core-it-suite ---
[WARN] The POM for org.apache.maven.wagon:wagon-http-lightweight:jar:1.0-beta-6 is invalid, transitive dependencies (if any) will not be available, enable verbose output (-X) for more details

so we need to use a syntax which actually supports what is displayed such as enforcer:3.1.0:enforce.
So it should be coherent with:

@cstamas
Copy link
Member Author

cstamas commented Apr 14, 2023

I disagree here. Plugin prefix may be duplicated AFAIK, as it may be specified at plugin build time (not "derived" from artifact ID, like xxx-maven-plugin => xxx prefix) not even due that, but even using same "expected" artifactId in different groupId will result with same prefix (example: parser-maven-plugin is a very "expected" name for some plugin that parses something, in whichever groupId it resides). And nothing stops two plugins having G1:A1 and G2:A2 (where any combination of inequality may be, so basically we talk about two different artifacts)but still have same prefix. Prefix is used mostly for "manual" invocation of plugin(to "shorten" it, instead of G:A type just prefix, but one has to be aware that for prefix to work, the groupId of plugin must be added to default groupIds of Maven), but to "address" the plugin, IMHO prefix is simply not precise enough.

@cstamas
Copy link
Member Author

cstamas commented Apr 14, 2023

To demonstrate: https://github.com/cstamas/plugin-clash/blob/main/README.md (and project that creates two different GA plugins and use them in build). Hence, IMHO any coherence with console output would be misleading: prefix cannot uniquely identify a plugin

@gnodet
Copy link
Contributor

gnodet commented Apr 14, 2023

To demonstrate: https://github.com/cstamas/plugin-clash/blob/main/README.md (and project that creates two different GA plugins and use them in build). Hence, IMHO any coherence with console output would be misleading: prefix cannot uniquely identify a plugin

I'm not sure how that's relevant. Your syntax supports wildcards, which definitely cannot uniquely identify a plugin. My points is not to restrict the supported syntax to pluginPrefix[:version]:goal and groupId:artifactId[:version]:goal, but to support it. And I would also support the optional e after, i.e. pluginPrefix[:version]:goal[:executionId] and groupId:artifactId[:version]:goal[:executionId], but more importantly, at least support pluginPrefix:version:goal so that people can simply copy/paste from the console to skip a given plugin goal, instead of having to find out the groupId:artifactId.

For example, how can you simply relate spotless:2.28.0:apply (default) from the console output to com.diffplug.spotless:spotless-maven-plugin:apply when that plugin is defined in a parent outside of the project ?

I'd like to find a syntax that would support just copy/pasting the output from the console, certainly not be limited to that.

@gnodet
Copy link
Contributor

gnodet commented Apr 21, 2023

I propose the following syntax: ([G]:A]|P)[:v][:g[@e]]
The use of @ will make the syntax compatible with the DefaultLifecycleExecutionPlanCalculator and will remove some ambiguities.
Which should support:

  • G:A: org.apache.maven.plugins:enforcer-maven-plugin
  • :A: :enforcer-maven-plugin
  • P: enforcer
  • P:v:g: enforcer:3.1.0:enforce
  • P:v:g@e: enforcer:3.1.0:enforce@enforce-maven-version

@cstamas
Copy link
Member Author

cstamas commented Apr 21, 2023

I like it. Will apply needed changes.

@cstamas
Copy link
Member Author

cstamas commented Apr 21, 2023

One question remaining i was thinking about:

  • Can we make syntax "pom properties" friendly?
  • Should we make syntax pom properties friendly?
  • The idea would be to completely "buy out" current skip param for all Mojos... (Again, should we do it at all?) As if we do, these could be usable in profiles, main properties, just like today the "normal" skips are

@gnodet
Copy link
Contributor

gnodet commented Apr 21, 2023

One question remaining i was thinking about:

  • Can we make syntax "pom properties" friendly?
  • Should we make syntax pom properties friendly?
  • The idea would be to completely "buy out" current skip param for all Mojos... (Again, should we do it at all?) As if we do, these could be usable in profiles, main properties, just like today the "normal" skips are

If passed as an argument / option, it will be subject to interpolation with #1062

@michael-o michael-o removed their request for review June 8, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants