mthmulders commented on a change in pull request #429: URL: https://github.com/apache/maven/pull/429#discussion_r565263359
########## File path: maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java ########## @@ -190,6 +190,8 @@ public void validateFileModel( Model m, ModelBuildingRequest request, ModelProbl { String prefix = "profiles.profile[" + profile.getId() + "]."; + validateId( prefix, "id", problems, Severity.ERROR, Version.V37, profile.getId(), null, m ); Review comment: > It has to be Version.V40. Done > [...] needs to be tightened in the future. I think [MNG-7052](https://issues.apache.org/jira/browse/MNG-7052) might resolve that as well. ########## File path: maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java ########## @@ -190,6 +190,8 @@ public void validateFileModel( Model m, ModelBuildingRequest request, ModelProbl { String prefix = "profiles.profile[" + profile.getId() + "]."; + validateId( prefix, "id", problems, Severity.ERROR, Version.V37, profile.getId(), null, m ); Review comment: > It has to be Version.V40. Done > [...] needs to be tightened in the future. I think [MNG-7052](https://issues.apache.org/jira/browse/MNG-7052) might resolve that as well. ########## File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ########## @@ -1507,41 +1506,41 @@ else if ( projectAction.startsWith( "+" ) ) } // Visible for testing - static ProfileActivation determineProfileActivation( final CommandLine commandLine ) + static void performProfileActivation( final CommandLine commandLine, + final ProfileActivation profileActivation ) { - final ProfileActivation result = new ProfileActivation(); - if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) ) { - String[] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); - if ( profileOptionValues != null ) + final String[] optionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); + + if ( optionValues == null ) { - for ( String profileOptionValue : profileOptionValues ) - { - StringTokenizer profileTokens = new StringTokenizer( profileOptionValue, "," ); + return; + } - while ( profileTokens.hasMoreTokens() ) + for ( final String optionValue : optionValues ) + { + for ( String token : optionValue.split( "," ) ) + { + String profileId = token.trim(); + boolean active = true; + if ( profileId.charAt( 0 ) == '-' || profileId.charAt( 0 ) == '!' ) { - String profileAction = profileTokens.nextToken().trim(); - - if ( profileAction.startsWith( "-" ) || profileAction.startsWith( "!" ) ) - { - result.deactivate( profileAction.substring( 1 ) ); - } - else if ( profileAction.startsWith( "+" ) ) - { - result.activate( profileAction.substring( 1 ) ); - } - else - { - result.activate( profileAction ); - } + active = false; + profileId = profileId.substring( 1 ); + } + else if ( token.charAt( 0 ) == '+' ) Review comment: We didn't, but the `+` was in the code already so we decided to keep it. ########## File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ########## @@ -1507,41 +1506,41 @@ else if ( projectAction.startsWith( "+" ) ) } // Visible for testing - static ProfileActivation determineProfileActivation( final CommandLine commandLine ) + static void performProfileActivation( final CommandLine commandLine, + final ProfileActivation profileActivation ) { - final ProfileActivation result = new ProfileActivation(); - if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) ) { - String[] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); - if ( profileOptionValues != null ) + final String[] optionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); + + if ( optionValues == null ) { - for ( String profileOptionValue : profileOptionValues ) - { - StringTokenizer profileTokens = new StringTokenizer( profileOptionValue, "," ); + return; + } - while ( profileTokens.hasMoreTokens() ) + for ( final String optionValue : optionValues ) + { + for ( String token : optionValue.split( "," ) ) + { + String profileId = token.trim(); + boolean active = true; + if ( profileId.charAt( 0 ) == '-' || profileId.charAt( 0 ) == '!' ) Review comment: Right now it could, but [MNG-7052](https://issues.apache.org/jira/browse/MNG-7052) should resolve that. ########## File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ########## @@ -1507,41 +1506,41 @@ else if ( projectAction.startsWith( "+" ) ) } // Visible for testing - static ProfileActivation determineProfileActivation( final CommandLine commandLine ) + static void performProfileActivation( final CommandLine commandLine, + final ProfileActivation profileActivation ) { - final ProfileActivation result = new ProfileActivation(); - if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) ) { - String[] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); - if ( profileOptionValues != null ) + final String[] optionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); + + if ( optionValues == null ) Review comment: Looking at the Commons CLI code, it is either null or it has items. But it is good to not rely on those implementation details anyway. ########## File path: maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java ########## @@ -0,0 +1,180 @@ +package org.apache.maven.execution; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Predicate; + +import static java.util.stream.Collectors.toSet; + +/** + * Container for storing the request from the user to activate or de-activate certain profiles and optionally fail the + * build if those profiles do not exist. + */ +public class ProfileActivation +{ + + private static class ActivationSettings + { + /** Should the profile be active? */ + final boolean active; + /** Should the build continue if the profile is not present? */ + final boolean optional; + + ActivationSettings( final boolean active, final boolean optional ) + { + this.active = active; + this.optional = optional; + } + } + + private final Map<String, ActivationSettings> activations = new HashMap<>(); + + /** + * Mimics the pre-Maven 4 "active profiles" list. + */ + @Deprecated + public List<String> getActiveProfiles() + { + return new ArrayList<>( getProfileIds( pa -> pa.active ) ); + } + + /** + * Mimics the pre-Maven 4 "inactive profiles" list. + */ + @Deprecated + public List<String> getInactiveProfiles() + { + return new ArrayList<>( getProfileIds( pa -> !pa.active ) ); + } + + /** + * Overwrites the active profiles based on a pre-Maven 4 "active profiles" list. + * @param activeProfileIds A {@link List} of profile IDs that must be activated. + */ + @Deprecated + public void overwriteActiveProfiles( List<String> activeProfileIds ) + { + getActiveProfiles().forEach( this.activations::remove ); + activeProfileIds.forEach( this::activateOptionalProfile ); + } + + /** + * Overwrites the inactive profiles based on a pre-Maven 4 "inactive profiles" list. + * @param inactiveProfileIds A {@link List} of profile IDs that must be deactivated. + */ + @Deprecated + public void overwriteInactiveProfiles( List<String> inactiveProfileIds ) + { + getInactiveProfiles().forEach( this.activations::remove ); + inactiveProfileIds.forEach( this::deactivateOptionalProfile ); + } + + /** + * Mark a profile as required and activated. + * @param id The identifier of the profile. + */ + public void activateRequiredProfile( String id ) + { + this.activations.put( id, new ActivationSettings( true, false ) ); Review comment: Done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org