diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation')
7 files changed, 588 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java new file mode 100644 index 00000000..5d6a8bf6 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java @@ -0,0 +1,35 @@ +package org.apache.maven.profiles.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; + +@Deprecated +public abstract class DetectedProfileActivator + implements ProfileActivator +{ + public boolean canDetermineActivation( Profile profile ) + { + return canDetectActivation( profile ); + } + + protected abstract boolean canDetectActivation( Profile profile ); + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java new file mode 100644 index 00000000..de4ba2ed --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java @@ -0,0 +1,109 @@ +package org.apache.maven.profiles.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.IOException; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationFile; +import org.apache.maven.model.Profile; +import org.codehaus.plexus.interpolation.EnvarBasedValueSource; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.MapBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; +import org.codehaus.plexus.logging.LogEnabled; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + +@Deprecated +public class FileProfileActivator + extends DetectedProfileActivator + implements LogEnabled +{ + private Logger logger; + + protected boolean canDetectActivation( Profile profile ) + { + return profile.getActivation() != null && profile.getActivation().getFile() != null; + } + + public boolean isActive( Profile profile ) + { + Activation activation = profile.getActivation(); + + ActivationFile actFile = activation.getFile(); + + if ( actFile != null ) + { + // check if the file exists, if it does then the profile will be active + String fileString = actFile.getExists(); + + RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); + try + { + interpolator.addValueSource( new EnvarBasedValueSource() ); + } + catch ( IOException e ) + { + // ignored + } + interpolator.addValueSource( new MapBasedValueSource( System.getProperties() ) ); + + try + { + if ( StringUtils.isNotEmpty( fileString ) ) + { + fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" ); + return FileUtils.fileExists( fileString ); + } + + // check if the file is missing, if it is then the profile will be active + fileString = actFile.getMissing(); + + if ( StringUtils.isNotEmpty( fileString ) ) + { + fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" ); + return !FileUtils.fileExists( fileString ); + } + } + catch ( InterpolationException e ) + { + if ( logger.isDebugEnabled() ) + { + logger.debug( "Failed to interpolate missing file location for profile activator: " + fileString, + e ); + } + else + { + logger.warn( "Failed to interpolate missing file location for profile activator: " + fileString + + ". Run in debug mode (-X) for more information." ); + } + } + } + + return false; + } + + public void enableLogging( Logger logger ) + { + this.logger = logger; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java new file mode 100644 index 00000000..dfae95f6 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java @@ -0,0 +1,97 @@ +package org.apache.maven.profiles.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.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Activation; +import org.apache.maven.model.Profile; +import org.codehaus.plexus.util.StringUtils; + +@Deprecated +public class JdkPrefixProfileActivator + extends DetectedProfileActivator +{ + private static final String JDK_VERSION = System.getProperty( "java.version" ); + + public boolean isActive( Profile profile ) + throws ProfileActivationException + { + Activation activation = profile.getActivation(); + + String jdk = activation.getJdk(); + + // null case is covered by canDetermineActivation(), so we can do a straight startsWith() here. + if ( jdk.startsWith( "[" ) || jdk.startsWith( "(" ) ) + { + try + { + return matchJdkVersionRange( jdk ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new ProfileActivationException( "Invalid JDK version in profile '" + profile.getId() + "': " + + e.getMessage() ); + } + } + + boolean reverse = false; + + if ( jdk.startsWith( "!" ) ) + { + reverse = true; + jdk = jdk.substring( 1 ); + } + + if ( getJdkVersion().startsWith( jdk ) ) + { + return !reverse; + } + else + { + return reverse; + } + } + + private boolean matchJdkVersionRange( String jdk ) + throws InvalidVersionSpecificationException + { + VersionRange jdkVersionRange = VersionRange.createFromVersionSpec( convertJdkToMavenVersion( jdk ) ); + DefaultArtifactVersion jdkVersion = new DefaultArtifactVersion( convertJdkToMavenVersion( getJdkVersion() ) ); + return jdkVersionRange.containsVersion( jdkVersion ); + } + + private String convertJdkToMavenVersion( String jdk ) + { + return jdk.replaceAll( "_", "-" ); + } + + protected String getJdkVersion() + { + return JDK_VERSION; + } + + protected boolean canDetectActivation( Profile profile ) + { + return profile.getActivation() != null && StringUtils.isNotEmpty( profile.getActivation().getJdk() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java new file mode 100644 index 00000000..7464a303 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java @@ -0,0 +1,161 @@ +package org.apache.maven.profiles.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.codehaus.plexus.util.Os; + +@Deprecated +public class OperatingSystemProfileActivator + implements ProfileActivator +{ + + public boolean canDetermineActivation( Profile profile ) + { + Activation activation = profile.getActivation(); + return activation != null && activation.getOs() != null; + } + + public boolean isActive( Profile profile ) + { + Activation activation = profile.getActivation(); + ActivationOS os = activation.getOs(); + + boolean result = ensureAtLeastOneNonNull( os ); + + if ( result && os.getFamily() != null ) + { + result = determineFamilyMatch( os.getFamily() ); + } + if ( result && os.getName() != null ) + { + result = determineNameMatch( os.getName() ); + } + if ( result && os.getArch() != null ) + { + result = determineArchMatch( os.getArch() ); + } + if ( result && os.getVersion() != null ) + { + result = determineVersionMatch( os.getVersion() ); + } + return result; + } + + 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 ); + + if ( reverse ) + { + return !result; + } + else + { + return 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 ); + + if ( reverse ) + { + return !result; + } + else + { + return 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 ); + + if ( reverse ) + { + return !result; + } + else + { + return 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 ); + + if ( reverse ) + { + return !result; + } + else + { + return result; + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivationException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivationException.java new file mode 100644 index 00000000..7fc372cb --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivationException.java @@ -0,0 +1,39 @@ +package org.apache.maven.profiles.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. + */ + +@Deprecated +public class ProfileActivationException + extends Exception +{ + + private static final long serialVersionUID = -90820222109103638L; + + public ProfileActivationException( String message, Throwable cause ) + { + super( message, cause ); + } + + public ProfileActivationException( String message ) + { + super( message ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java new file mode 100644 index 00000000..d0a9ecb5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java @@ -0,0 +1,33 @@ +package org.apache.maven.profiles.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; + +@Deprecated +public interface ProfileActivator +{ + final String ROLE = ProfileActivator.class.getName(); + + boolean canDetermineActivation( Profile profile ); + + boolean isActive( Profile profile ) + throws ProfileActivationException; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java new file mode 100644 index 00000000..a03267dc --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java @@ -0,0 +1,114 @@ +package org.apache.maven.profiles.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.Properties; +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Profile; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.StringUtils; + +@Deprecated +public class SystemPropertyProfileActivator + extends DetectedProfileActivator implements Contextualizable +{ + private Properties properties; + + public void contextualize( Context context ) + throws ContextException + { + properties = (Properties) context.get( "SystemProperties" ); + } + + protected boolean canDetectActivation( Profile profile ) + { + return profile.getActivation() != null && profile.getActivation().getProperty() != null; + } + + public boolean isActive( Profile profile ) + throws ProfileActivationException + { + Activation activation = profile.getActivation(); + + ActivationProperty property = activation.getProperty(); + + if ( property != null ) + { + String name = property.getName(); + boolean reverseName = false; + + if ( name == null ) + { + throw new ProfileActivationException( "The property name is required to activate the profile '" + + profile.getId() + "'" ); + } + + if ( name.startsWith( "!" ) ) + { + reverseName = true; + name = name.substring( 1 ); + } + + String sysValue = properties.getProperty( 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 ); + + if ( reverseValue ) + { + return !result; + } + else + { + return result; + } + } + else + { + boolean result = StringUtils.isNotEmpty( sysValue ); + + if ( reverseName ) + { + return !result; + } + else + { + return result; + } + } + } + + return false; + } + +} |