diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation')
5 files changed, 0 insertions, 769 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java deleted file mode 100644 index c0dcce23..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ /dev/null @@ -1,192 +0,0 @@ -package org.apache.maven.model.profile.activation; - -/* - * 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.io.File; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationFile; -import org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblemCollector; -import org.apache.maven.model.building.ModelProblem.Severity; -import org.apache.maven.model.building.ModelProblem.Version; -import org.apache.maven.model.building.ModelProblemCollectorRequest; -import org.apache.maven.model.path.PathTranslator; -import org.apache.maven.model.profile.ProfileActivationContext; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.interpolation.AbstractValueSource; -import org.codehaus.plexus.interpolation.MapBasedValueSource; -import org.codehaus.plexus.interpolation.RegexBasedInterpolator; -import org.codehaus.plexus.util.StringUtils; - -/** - * Determines profile activation based on the existence/absence of some file. - * File name interpolation support is limited to <code>${basedir}</code> (since Maven 3, - * see <a href="http://jira.codehaus.org/browse/MNG-2363">MNG-2363</a>), - * System properties and request properties. - * <code>${project.basedir}</code> is intentionally not supported as this form would suggest that other - * <code>${project.*}</code> expressions can be used, which is however beyond the design. - * - * @author Benjamin Bentmann - * @see ActivationFile - * @see org.apache.maven.model.validation.DefaultModelValidator#validateRawModel - */ -@Component( role = ProfileActivator.class, hint = "file" ) -public class FileProfileActivator - implements ProfileActivator -{ - - @Requirement - private PathTranslator pathTranslator; - - public FileProfileActivator setPathTranslator( PathTranslator pathTranslator ) - { - this.pathTranslator = pathTranslator; - return this; - } - - @Override - public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationFile file = activation.getFile(); - - if ( file == null ) - { - return false; - } - - String path; - boolean missing; - - if ( StringUtils.isNotEmpty( file.getExists() ) ) - { - path = file.getExists(); - missing = false; - } - else if ( StringUtils.isNotEmpty( file.getMissing() ) ) - { - path = file.getMissing(); - missing = true; - } - else - { - return false; - } - - RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); - - final File basedir = context.getProjectDirectory(); - - if ( basedir != null ) - { - interpolator.addValueSource( new AbstractValueSource( false ) - { - @Override - public Object getValue( String expression ) - { - /* - * NOTE: We intentionally only support ${basedir} and not ${project.basedir} as the latter form - * would suggest that other project.* expressions can be used which is however beyond the design. - */ - if ( "basedir".equals( expression ) ) - { - return basedir.getAbsolutePath(); - } - return null; - } - } ); - } - else if ( path.contains( "${basedir}" ) ) - { - return false; - } - - interpolator.addValueSource( new MapBasedValueSource( context.getProjectProperties() ) ); - - interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) ); - - interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) ); - - try - { - path = interpolator.interpolate( path, "" ); - } - catch ( Exception e ) - { - problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ) - .setMessage( "Failed to interpolate file location " + path + " for profile " + profile.getId() - + ": " + e.getMessage() ) - .setLocation( file.getLocation( missing ? "missing" : "exists" ) ) - .setException( e ) ); - return false; - } - - path = pathTranslator.alignToBaseDirectory( path, basedir ); - - // replace activation value with interpolated value - if ( missing ) - { - file.setMissing( path ); - } - else - { - file.setExists( path ); - } - - File f = new File( path ); - - if ( !f.isAbsolute() ) - { - return false; - } - - boolean fileExists = f.exists(); - - return missing ? !fileExists : fileExists; - } - - @Override - public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationFile file = activation.getFile(); - - if ( file == null ) - { - return false; - } - return true; - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java deleted file mode 100644 index e981bfd3..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.apache.maven.model.profile.activation; - -/* - * 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.Arrays; -import java.util.List; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblemCollector; -import org.apache.maven.model.building.ModelProblem.Severity; -import org.apache.maven.model.building.ModelProblem.Version; -import org.apache.maven.model.building.ModelProblemCollectorRequest; -import org.apache.maven.model.profile.ProfileActivationContext; -import org.codehaus.plexus.component.annotations.Component; - -/** - * Determines profile activation based on the version of the current Java runtime. - * - * @author Benjamin Bentmann - * @see Activation#getJdk() - */ -@Component( role = ProfileActivator.class, hint = "jdk-version" ) -public class JdkVersionProfileActivator - implements ProfileActivator -{ - - @Override - public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - String jdk = activation.getJdk(); - - if ( jdk == null ) - { - return false; - } - - String version = context.getSystemProperties().get( "java.version" ); - - if ( version == null || version.length() <= 0 ) - { - problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ) - .setMessage( "Failed to determine Java version for profile " + profile.getId() ) - .setLocation( activation.getLocation( "jdk" ) ) ); - return false; - } - - if ( jdk.startsWith( "!" ) ) - { - return !version.startsWith( jdk.substring( 1 ) ); - } - else if ( isRange( jdk ) ) - { - return isInRange( version, getRange( jdk ) ); - } - else - { - return version.startsWith( jdk ); - } - } - - @Override - public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - String jdk = activation.getJdk(); - - if ( jdk == null ) - { - return false; - } - return true; - } - - private static boolean isInRange( String value, List<RangeValue> range ) - { - int leftRelation = getRelationOrder( value, range.get( 0 ), true ); - - if ( leftRelation == 0 ) - { - return true; - } - - if ( leftRelation < 0 ) - { - return false; - } - - return getRelationOrder( value, range.get( 1 ), false ) <= 0; - } - - private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft ) - { - if ( rangeValue.value.length() <= 0 ) - { - return isLeft ? 1 : -1; - } - - value = value.replaceAll( "[^0-9\\.\\-\\_]", "" ); - - List<String> valueTokens = new ArrayList<String>( Arrays.asList( value.split( "[\\.\\-\\_]" ) ) ); - List<String> rangeValueTokens = new ArrayList<String>( Arrays.asList( rangeValue.value.split( "\\." ) ) ); - - addZeroTokens( valueTokens, 3 ); - addZeroTokens( rangeValueTokens, 3 ); - - for ( int i = 0; i < 3; i++ ) - { - int x = Integer.parseInt( valueTokens.get( i ) ); - int y = Integer.parseInt( rangeValueTokens.get( i ) ); - if ( x < y ) - { - return -1; - } - else if ( x > y ) - { - return 1; - } - } - if ( !rangeValue.closed ) - { - return isLeft ? -1 : 1; - } - return 0; - } - - private static void addZeroTokens( List<String> tokens, int max ) - { - while ( tokens.size() < max ) - { - tokens.add( "0" ); - } - } - - private static boolean isRange( String value ) - { - return value.startsWith( "[" ) || value.startsWith( "(" ); - } - - private static List<RangeValue> getRange( String range ) - { - List<RangeValue> ranges = new ArrayList<RangeValue>(); - - for ( String token : range.split( "," ) ) - { - if ( token.startsWith( "[" ) ) - { - ranges.add( new RangeValue( token.replace( "[", "" ), true ) ); - } - else if ( token.startsWith( "(" ) ) - { - ranges.add( new RangeValue( token.replace( "(", "" ), false ) ); - } - else if ( token.endsWith( "]" ) ) - { - ranges.add( new RangeValue( token.replace( "]", "" ), true ) ); - } - else if ( token.endsWith( ")" ) ) - { - ranges.add( new RangeValue( token.replace( ")", "" ), false ) ); - } - else if ( token.length() <= 0 ) - { - ranges.add( new RangeValue( "", false ) ); - } - } - if ( ranges.size() < 2 ) - { - ranges.add( new RangeValue( "99999999", false ) ); - } - return ranges; - } - - private static class RangeValue - { - private String value; - - private boolean closed; - - RangeValue( String value, boolean closed ) - { - this.value = value.trim(); - this.closed = closed; - } - - @Override - public String toString() - { - return value; - } - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java deleted file mode 100644 index 30abb1fa..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.apache.maven.model.profile.activation; - -/* - * 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 org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationOS; -import org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblemCollector; -import org.apache.maven.model.profile.ProfileActivationContext; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.util.Os; - -/** - * Determines profile activation based on the operating system of the current runtime platform. - * - * @author Benjamin Bentmann - * @see ActivationOS - */ -@Component( role = ProfileActivator.class, hint = "os" ) -public class OperatingSystemProfileActivator - implements ProfileActivator -{ - - @Override - public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationOS os = activation.getOs(); - - if ( os == null ) - { - return false; - } - - boolean active = ensureAtLeastOneNonNull( os ); - - if ( active && os.getFamily() != null ) - { - active = determineFamilyMatch( os.getFamily() ); - } - if ( active && os.getName() != null ) - { - active = determineNameMatch( os.getName() ); - } - if ( active && os.getArch() != null ) - { - active = determineArchMatch( os.getArch() ); - } - if ( active && os.getVersion() != null ) - { - active = determineVersionMatch( os.getVersion() ); - } - - return active; - } - - @Override - public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationOS os = activation.getOs(); - - if ( os == null ) - { - return false; - } - return true; - } - - private boolean ensureAtLeastOneNonNull( ActivationOS os ) - { - return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null; - } - - private boolean determineVersionMatch( String version ) - { - String test = version; - boolean reverse = false; - - if ( test.startsWith( "!" ) ) - { - reverse = true; - test = test.substring( 1 ); - } - - boolean result = Os.isVersion( test ); - - return reverse ? !result : result; - } - - private boolean determineArchMatch( String arch ) - { - String test = arch; - boolean reverse = false; - - if ( test.startsWith( "!" ) ) - { - reverse = true; - test = test.substring( 1 ); - } - - boolean result = Os.isArch( test ); - - return reverse ? !result : result; - } - - private boolean determineNameMatch( String name ) - { - String test = name; - boolean reverse = false; - - if ( test.startsWith( "!" ) ) - { - reverse = true; - test = test.substring( 1 ); - } - - boolean result = Os.isName( test ); - - return reverse ? !result : result; - } - - private boolean determineFamilyMatch( String family ) - { - String test = family; - boolean reverse = false; - - if ( test.startsWith( "!" ) ) - { - reverse = true; - test = test.substring( 1 ); - } - - boolean result = Os.isFamily( test ); - - return reverse ? !result : result; - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java deleted file mode 100644 index 0547e742..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.apache.maven.model.profile.activation; - -/* - * 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 org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblemCollector; -import org.apache.maven.model.profile.ProfileActivationContext; - -/** - * Determines whether a profile should be activated. - * - * @author Benjamin Bentmann - */ -public interface ProfileActivator -{ - - /** - * Determines whether the specified profile is active in the given activator context. - * - * @param profile The profile whose activation status should be determined, must not be {@code null}. - * @param context The environmental context used to determine the activation status of the profile, must not be - * {@code null}. - * @param problems The container used to collect problems (e.g. bad syntax) that were encountered, must not be - * {@code null}. - * @return {@code true} if the profile is active, {@code false} otherwise. - */ - boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ); - - /** - * Determines whether specified activation method is present in configuration or not. It should help to have AND - * between activation conditions - * Need for solving http://jira.codehaus.org/browse/MNG-4565 - * @param profile The profile whose activation status should be determined, must not be {@code null}. - * @param context The environmental context used to determine the activation status of the profile, must not be - * {@code null}. - * @param problems The container used to collect problems (e.g. bad syntax) that were encountered, must not be - * {@code null}. - * @return {@code true} if the profile is active, {@code false} otherwise. - */ - boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ); - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java deleted file mode 100644 index ba7886f0..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.apache.maven.model.profile.activation; - -/* - * 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 org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationProperty; -import org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblemCollector; -import org.apache.maven.model.building.ModelProblem.Severity; -import org.apache.maven.model.building.ModelProblem.Version; -import org.apache.maven.model.building.ModelProblemCollectorRequest; -import org.apache.maven.model.profile.ProfileActivationContext; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.util.StringUtils; - -/** - * Determines profile activation based on the existence or value of some execution property. - * - * @author Benjamin Bentmann - * @see ActivationProperty - */ -@Component( role = ProfileActivator.class, hint = "property" ) -public class PropertyProfileActivator - implements ProfileActivator -{ - - @Override - public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationProperty property = activation.getProperty(); - - if ( property == null ) - { - return false; - } - - String name = property.getName(); - boolean reverseName = false; - - if ( name != null && name.startsWith( "!" ) ) - { - reverseName = true; - name = name.substring( 1 ); - } - - if ( name == null || name.length() <= 0 ) - { - problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ) - .setMessage( "The property name is required to activate the profile " + profile.getId() ) - .setLocation( property.getLocation( "" ) ) ); - return false; - } - - String sysValue = context.getUserProperties().get( name ); - if ( sysValue == null ) - { - sysValue = context.getSystemProperties().get( name ); - } - - String propValue = property.getValue(); - if ( StringUtils.isNotEmpty( propValue ) ) - { - boolean reverseValue = false; - if ( propValue.startsWith( "!" ) ) - { - reverseValue = true; - propValue = propValue.substring( 1 ); - } - - // we have a value, so it has to match the system value... - boolean result = propValue.equals( sysValue ); - - return reverseValue ? !result : result; - } - else - { - boolean result = StringUtils.isNotEmpty( sysValue ); - - return reverseName ? !result : result; - } - } - - @Override - public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) - { - Activation activation = profile.getActivation(); - - if ( activation == null ) - { - return false; - } - - ActivationProperty property = activation.getProperty(); - - if ( property == null ) - { - return false; - } - return true; - } - -} |