diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles')
12 files changed, 1175 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java new file mode 100644 index 00000000..4745749b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java @@ -0,0 +1,93 @@ +package org.apache.maven.profiles; + +/* + * 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.profiles.io.xpp3.ProfilesXpp3Reader; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.interpolation.EnvarBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; + +@Deprecated +@Component( role = MavenProfilesBuilder.class ) +public class DefaultMavenProfilesBuilder + extends AbstractLogEnabled + implements MavenProfilesBuilder +{ + private static final String PROFILES_XML_FILE = "profiles.xml"; + + public ProfilesRoot buildProfiles( File basedir ) + throws IOException, XmlPullParserException + { + File profilesXml = new File( basedir, PROFILES_XML_FILE ); + + ProfilesRoot profilesRoot = null; + + if ( profilesXml.exists() ) + { + ProfilesXpp3Reader reader = new ProfilesXpp3Reader(); + Reader profileReader = null; + try + { + profileReader = ReaderFactory.newXmlReader( profilesXml ); + + StringWriter sWriter = new StringWriter(); + + IOUtil.copy( profileReader, sWriter ); + + String rawInput = sWriter.toString(); + + try + { + RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); + interpolator.addValueSource( new EnvarBasedValueSource() ); + + rawInput = interpolator.interpolate( rawInput, "settings" ); + } + catch ( Exception e ) + { + getLogger().warn( "Failed to initialize environment variable resolver. Skipping environment " + + "substitution in " + PROFILES_XML_FILE + "." ); + getLogger().debug( "Failed to initialize envar resolver. Skipping resolution.", e ); + } + + StringReader sReader = new StringReader( rawInput ); + + profilesRoot = reader.read( sReader ); + } + finally + { + IOUtil.close( profileReader ); + } + } + + return profilesRoot; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java new file mode 100644 index 00000000..3b99e9e2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -0,0 +1,248 @@ +package org.apache.maven.profiles; + +/* + * 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.Profile; +import org.apache.maven.model.building.ModelProblem; +import org.apache.maven.model.building.ModelProblemCollector; +import org.apache.maven.model.profile.DefaultProfileActivationContext; +import org.apache.maven.model.profile.ProfileSelector; +import org.apache.maven.profiles.activation.ProfileActivationException; +import org.codehaus.plexus.MutablePlexusContainer; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.logging.Logger; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.apache.maven.model.building.ModelProblemCollectorRequest; + +@Deprecated +public class DefaultProfileManager + implements ProfileManager +{ + + @Requirement + private Logger logger; + + @Requirement + private ProfileSelector profileSelector; + + private List activatedIds = new ArrayList(); + + private List deactivatedIds = new ArrayList(); + + private List defaultIds = new ArrayList(); + + private Map profilesById = new LinkedHashMap(); + + private Properties requestProperties; + + /** + * @deprecated without passing in the system properties, the SystemPropertiesProfileActivator will not work + * correctly in embedded envirnments. + */ + public DefaultProfileManager( PlexusContainer container ) + { + this( container, null ); + } + + /** + * the properties passed to the profile manager are the props that + * are passed to maven, possibly containing profile activator properties + * + */ + public DefaultProfileManager( PlexusContainer container, Properties props ) + { + try + { + this.profileSelector = container.lookup( ProfileSelector.class ); + this.logger = ( (MutablePlexusContainer) container ).getLogger(); + } + catch ( ComponentLookupException e ) + { + throw new IllegalStateException( e ); + } + this.requestProperties = props; + } + + public Properties getRequestProperties() + { + return requestProperties; + } + + public Map getProfilesById() + { + return profilesById; + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#addProfile(org.apache.maven.model.Profile) + */ + public void addProfile( Profile profile ) + { + String profileId = profile.getId(); + + Profile existing = (Profile) profilesById.get( profileId ); + if ( existing != null ) + { + logger.warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() + + ") with new instance from source: " + profile.getSource() ); + } + + profilesById.put( profile.getId(), profile ); + + Activation activation = profile.getActivation(); + + if ( activation != null && activation.isActiveByDefault() ) + { + activateAsDefault( profileId ); + } + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.lang.String) + */ + public void explicitlyActivate( String profileId ) + { + if ( !activatedIds.contains( profileId ) ) + { + logger.debug( "Profile with id: \'" + profileId + "\' has been explicitly activated." ); + + activatedIds.add( profileId ); + } + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List) + */ + public void explicitlyActivate( List profileIds ) + { + for ( Object profileId1 : profileIds ) + { + String profileId = (String) profileId1; + + explicitlyActivate( profileId ); + } + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.lang.String) + */ + public void explicitlyDeactivate( String profileId ) + { + if ( !deactivatedIds.contains( profileId ) ) + { + logger.debug( "Profile with id: \'" + profileId + "\' has been explicitly deactivated." ); + + deactivatedIds.add( profileId ); + } + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List) + */ + public void explicitlyDeactivate( List profileIds ) + { + for ( Object profileId1 : profileIds ) + { + String profileId = (String) profileId1; + + explicitlyDeactivate( profileId ); + } + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#getActiveProfiles() + */ + public List getActiveProfiles() + throws ProfileActivationException + { + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); + context.setActiveProfileIds( activatedIds ); + context.setInactiveProfileIds( deactivatedIds ); + context.setSystemProperties( System.getProperties() ); + context.setUserProperties( requestProperties ); + + final List<ProfileActivationException> errors = new ArrayList<ProfileActivationException>(); + + List<Profile> profiles = + profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector() + { + + public void add( ModelProblemCollectorRequest req ) + { + if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) ) + { + errors.add( new ProfileActivationException( req.getMessage(), req.getException() ) ); + } + } + } ); + + if ( !errors.isEmpty() ) + { + throw errors.get( 0 ); + } + + return profiles; + } + + /* (non-Javadoc) + * @see org.apache.maven.profiles.ProfileManager#addProfiles(java.util.List) + */ + public void addProfiles( List profiles ) + { + for ( Object profile1 : profiles ) + { + Profile profile = (Profile) profile1; + + addProfile( profile ); + } + } + + public void activateAsDefault( String profileId ) + { + if ( !defaultIds.contains( profileId ) ) + { + defaultIds.add( profileId ); + } + } + + public List getExplicitlyActivatedIds() + { + return activatedIds; + } + + public List getExplicitlyDeactivatedIds() + { + return deactivatedIds; + } + + public List getIdsActivatedByDefault() + { + return defaultIds; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java new file mode 100644 index 00000000..32fb6aaa --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java @@ -0,0 +1,37 @@ +package org.apache.maven.profiles; + +/* + * 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.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; + +/** + * @author jdcasey + */ +@Deprecated +public interface MavenProfilesBuilder +{ + String ROLE = MavenProfilesBuilder.class.getName(); + + ProfilesRoot buildProfiles( File basedir ) + throws IOException, XmlPullParserException; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java new file mode 100644 index 00000000..ddda3d7f --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java @@ -0,0 +1,58 @@ +package org.apache.maven.profiles; + +/* + * 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.profiles.activation.ProfileActivationException; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +@Deprecated +public interface ProfileManager +{ + + void addProfile( Profile profile ); + + void explicitlyActivate( String profileId ); + + void explicitlyActivate( List profileIds ); + + void explicitlyDeactivate( String profileId ); + + void explicitlyDeactivate( List profileIds ); + + List getActiveProfiles() + throws ProfileActivationException; + + void addProfiles( List profiles ); + + Map getProfilesById(); + + List getExplicitlyActivatedIds(); + + List getExplicitlyDeactivatedIds(); + + List getIdsActivatedByDefault(); + + Properties getRequestProperties(); + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java new file mode 100644 index 00000000..72527b09 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java @@ -0,0 +1,151 @@ +package org.apache.maven.profiles; + +/* + * 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.ActivationFile; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Profile; +import org.apache.maven.model.Repository; + +import java.util.List; + +@Deprecated +public class ProfilesConversionUtils +{ + private ProfilesConversionUtils() + { + } + + public static Profile convertFromProfileXmlProfile( org.apache.maven.profiles.Profile profileXmlProfile ) + { + Profile profile = new Profile(); + + profile.setId( profileXmlProfile.getId() ); + + profile.setSource( "profiles.xml" ); + + org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation(); + + if ( profileActivation != null ) + { + Activation activation = new Activation(); + + activation.setActiveByDefault( profileActivation.isActiveByDefault() ); + + activation.setJdk( profileActivation.getJdk() ); + + org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty(); + + if ( profileProp != null ) + { + ActivationProperty prop = new ActivationProperty(); + + prop.setName( profileProp.getName() ); + prop.setValue( profileProp.getValue() ); + + activation.setProperty( prop ); + } + + + ActivationOS profileOs = profileActivation.getOs(); + + if ( profileOs != null ) + { + org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS(); + + os.setArch( profileOs.getArch() ); + os.setFamily( profileOs.getFamily() ); + os.setName( profileOs.getName() ); + os.setVersion( profileOs.getVersion() ); + + activation.setOs( os ); + } + + org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile(); + + if ( profileFile != null ) + { + ActivationFile file = new ActivationFile(); + + file.setExists( profileFile.getExists() ); + file.setMissing( profileFile.getMissing() ); + + activation.setFile( file ); + } + + profile.setActivation( activation ); + } + + profile.setProperties( profileXmlProfile.getProperties() ); + + List repos = profileXmlProfile.getRepositories(); + if ( repos != null ) + { + for ( Object repo : repos ) + { + profile.addRepository( convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) repo ) ); + } + } + + List pluginRepos = profileXmlProfile.getPluginRepositories(); + if ( pluginRepos != null ) + { + for ( Object pluginRepo : pluginRepos ) + { + profile.addPluginRepository( + convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) pluginRepo ) ); + } + } + + return profile; + } + + private static Repository convertFromProfileXmlRepository( org.apache.maven.profiles.Repository profileXmlRepo ) + { + Repository repo = new Repository(); + + repo.setId( profileXmlRepo.getId() ); + repo.setLayout( profileXmlRepo.getLayout() ); + repo.setName( profileXmlRepo.getName() ); + repo.setUrl( profileXmlRepo.getUrl() ); + + if ( profileXmlRepo.getSnapshots() != null ) + { + repo.setSnapshots( convertRepositoryPolicy( profileXmlRepo.getSnapshots() ) ); + } + if ( profileXmlRepo.getReleases() != null ) + { + repo.setReleases( convertRepositoryPolicy( profileXmlRepo.getReleases() ) ); + } + + return repo; + } + + private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy( RepositoryPolicy profileXmlRepo ) + { + org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy(); + policy.setEnabled( profileXmlRepo.isEnabled() ); + policy.setUpdatePolicy( profileXmlRepo.getUpdatePolicy() ); + policy.setChecksumPolicy( profileXmlRepo.getChecksumPolicy() ); + return policy; + } + +} 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; + } + +} |