Removed support for profiles.xml

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@748226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-02-26 17:46:01 +00:00
parent c002a8d22e
commit 29e80ac703
4 changed files with 18 additions and 311 deletions

View File

@ -1,156 +0,0 @@
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.Iterator;
import java.util.List;
public class ProfilesConversionUtils
{
public static final String PROFILES_XML_SOURCE = "profiles.xml";
private ProfilesConversionUtils()
{
}
public static Profile convertFromProfileXmlProfile( org.apache.maven.profiles.Profile profileXmlProfile )
{
Profile profile = new Profile();
profile.setId( profileXmlProfile.getId() );
profile.setSource( PROFILES_XML_SOURCE );
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 ( Iterator it = repos.iterator(); it.hasNext(); )
{
profile
.addRepository(
convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it.next() ) );
}
}
List pluginRepos = profileXmlProfile.getPluginRepositories();
if ( pluginRepos != null )
{
for ( Iterator it = pluginRepos.iterator(); it.hasNext(); )
{
profile.addPluginRepository( convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it
.next() ) );
}
}
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;
}
}

View File

@ -20,16 +20,11 @@ package org.apache.maven.profiles.build;
*/
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.ProfilesConversionUtils;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.injection.ProfileInjector;
@ -44,13 +39,9 @@ import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@Component(role = ProfileAdvisor.class)
@ -71,16 +62,16 @@ public class DefaultProfileAdvisor
private Logger logger;
public List applyActivatedProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
public List applyActivatedProfiles(Model model,
ProfileActivationContext activationContext)
throws ProjectBuildingException
{
ProfileManager profileManager = buildProfileManager( model, pomFile, useProfilesXml, activationContext );
ProfileManager profileManager = buildProfileManager( model, activationContext );
return applyActivatedProfiles( model, pomFile, profileManager );
return applyActivatedProfiles( model, profileManager );
}
public List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
public List applyActivatedExternalProfiles(Model model, ProfileManager externalProfileManager)
throws ProjectBuildingException
{
if ( externalProfileManager == null )
@ -88,10 +79,10 @@ public class DefaultProfileAdvisor
return Collections.EMPTY_LIST;
}
return applyActivatedProfiles( model, projectDir, externalProfileManager );
return applyActivatedProfiles( model, externalProfileManager );
}
private List applyActivatedProfiles( Model model, File pomFile, ProfileManager profileManager )
private List applyActivatedProfiles( Model model, ProfileManager profileManager )
throws ProjectBuildingException
{
List activeProfiles;
@ -118,7 +109,7 @@ public class DefaultProfileAdvisor
String projectId = ArtifactUtils.versionlessKey( groupId, artifactId );
throw new ProjectBuildingException( projectId, e.getMessage(), pomFile, e );
throw new ProjectBuildingException(projectId, e.getMessage());
}
for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
@ -136,133 +127,17 @@ public class DefaultProfileAdvisor
return activeProfiles;
}
private ProfileManager buildProfileManager( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
private ProfileManager buildProfileManager(Model model,
ProfileActivationContext profileActivationContext)
throws ProjectBuildingException
{
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
profileManager.addProfiles( model.getProfiles() );
if ( useProfilesXml && ( pomFile != null ) )
{
loadExternalProjectProfiles( profileManager, model, pomFile );
}
return profileManager;
}
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile,
ProfileManager profileManager )
throws ProjectBuildingException
{
if ( profileManager == null )
{
return new LinkedHashSet();
}
List activeExternalProfiles;
{
try
{
activeExternalProfiles = profileManager.getActiveProfiles( model );
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( model.getId(),
"Failed to compute active profiles for repository aggregation.",
pomFile, e );
}
LinkedHashSet remoteRepositories = new LinkedHashSet();
for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); )
{
Profile externalProfile = (Profile) i.next();
if ( externalProfile.getRepositories() != null )
{
for ( Iterator repoIterator = externalProfile.getRepositories().iterator();
repoIterator.hasNext(); )
{
Repository mavenRepo = (Repository) repoIterator.next();
ArtifactRepository artifactRepo;
try
{
artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( model.getId(), e.getMessage(), e );
}
remoteRepositories.add( artifactRepo );
}
}
}
return remoteRepositories;
}
}
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException
{
ProfileManager profileManager = buildProfileManager( model, pomFile, useProfilesXml, activationContext );
return getArtifactRepositoriesFromActiveProfiles( model, pomFile, profileManager );
}
private void loadExternalProjectProfiles( ProfileManager profileManager, Model model, File pomFile )
throws ProjectBuildingException
{
if ( pomFile != null )
{
File projectDir = pomFile.getParentFile();
try
{
ProfilesRoot root = profilesBuilder.buildProfiles( projectDir );
if ( root != null )
{
List<String> active = root.getActiveProfiles();
if ( ( active != null ) && !active.isEmpty() )
{
ProfileActivationContext ctx = profileManager.getProfileActivationContext();
for ( String profileId : active )
{
ctx.setActive( profileId );
}
}
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile );
profileManager.addProfile( converted );
}
}
}
catch ( IOException e )
{
throw new ProjectBuildingException( model.getId(),
"Cannot read profiles.xml resource from directory: " + projectDir,
pomFile, e );
}
catch ( XmlPullParserException e )
{
throw new ProjectBuildingException( model.getId(),
"Cannot parse profiles.xml resource from directory: " + projectDir,
pomFile, e );
}
}
}
public void contextualize( Context context )
throws ContextException
{

View File

@ -36,18 +36,11 @@ public interface ProfileAdvisor
String ROLE = ProfileAdvisor.class.getName();
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, ProfileManager profileManager )
List applyActivatedProfiles(Model model,
ProfileActivationContext activationContext)
throws ProjectBuildingException;
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException;
List applyActivatedProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException;
List applyActivatedExternalProfiles( Model model, File pomFile, ProfileManager externalProfileManager )
List applyActivatedExternalProfiles(Model model, ProfileManager externalProfileManager)
throws ProjectBuildingException;
}

View File

@ -137,7 +137,7 @@ public class DefaultMavenProjectBuilder
project.setFile( projectDescriptor );
project = buildWithProfiles( project.getModel(), config, projectDescriptor, project.getParentFile(), true );
project = buildWithProfiles( project.getModel(), config, projectDescriptor, project.getParentFile());
Build build = project.getBuild();
// NOTE: setting this script-source root before path translation, because
@ -217,7 +217,7 @@ public class DefaultMavenProjectBuilder
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
project = readModelFromLocalPath( "unknown", artifact.getFile(), new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, repositorySystem ), config );
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile(), false );
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() );
artifact.setFile( f );
project.setVersion( artifact.getVersion() );
@ -301,7 +301,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject buildWithProfiles( Model model, ProjectBuilderConfiguration config, File projectDescriptor,
File parentDescriptor, boolean isReactorProject )
File parentDescriptor )
throws ProjectBuildingException
{
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
@ -331,14 +331,9 @@ public class DefaultMavenProjectBuilder
List<Profile> projectProfiles = new ArrayList<Profile>();
projectProfiles.addAll( profileAdvisor.applyActivatedProfiles( model,
isReactorProject ? projectDescriptor : null,
isReactorProject, profileActivationContext ) );
projectProfiles.addAll( profileAdvisor.applyActivatedProfiles( model, profileActivationContext ) );
projectProfiles.addAll( profileAdvisor.applyActivatedExternalProfiles( model,
isReactorProject ? projectDescriptor
: null,
externalProfileManager ) );
projectProfiles.addAll( profileAdvisor.applyActivatedExternalProfiles( model, externalProfileManager ) );
MavenProject project;