[MNG-4765] Failing to determine java version for profile....

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@987335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-08-19 22:26:55 +00:00
parent 62a4bb86ce
commit 2225bc7bbe
6 changed files with 243 additions and 176 deletions

View File

@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
@ -38,6 +39,7 @@
import org.apache.maven.model.building.UrlModelSource;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.component.annotations.Component;
@ -65,21 +67,65 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
private ProjectBuildingRequest toRequest( ProjectBuilderConfiguration configuration )
{
return projectBuilder.build( pomFile, configuration ).getProject();
DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
request.setResolveDependencies( false );
request.setLocalRepository( configuration.getLocalRepository() );
request.setBuildStartTime( configuration.getBuildStartTime() );
request.setUserProperties( configuration.getUserProperties() );
request.setSystemProperties( configuration.getExecutionProperties() );
ProfileManager profileManager = configuration.getGlobalProfileManager();
if ( profileManager != null )
{
request.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() );
request.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() );
}
return request;
}
public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration, boolean allowStubModel )
throws ProjectBuildingException
private ProjectBuildingRequest injectSession( ProjectBuildingRequest request )
{
normalizeToArtifactRepositories( configuration );
MavenSession session = legacySupport.getSession();
if ( session != null )
{
request.setOffline( session.isOffline() );
request.setSystemProperties( session.getSystemProperties() );
if ( request.getUserProperties().isEmpty() )
{
request.setUserProperties( session.getUserProperties() );
}
return projectBuilder.build( artifact, allowStubModel, configuration ).getProject();
MavenExecutionRequest req = session.getRequest();
if ( req != null )
{
request.setServers( req.getServers() );
request.setMirrors( req.getMirrors() );
request.setProxies( req.getProxies() );
request.setRemoteRepositories( req.getRemoteRepositories() );
request.setTransferListener( req.getTransferListener() );
request.setForceUpdate( req.isUpdateSnapshots() );
}
}
else
{
Properties props = new Properties();
EnvironmentUtils.addEnvVars( props );
props.putAll( System.getProperties() );
request.setSystemProperties( props );
}
return request;
}
private void normalizeToArtifactRepositories( ProjectBuilderConfiguration configuration )
@SuppressWarnings( "unchecked" )
private List<ArtifactRepository> normalizeToArtifactRepositories( List<?> repositories,
ProjectBuildingRequest request )
throws ProjectBuildingException
{
/*
@ -87,8 +133,6 @@ private void normalizeToArtifactRepositories( ProjectBuilderConfiguration config
* populate the builder configuration with model repositories instead of artifact repositories.
*/
List<?> repositories = configuration.getRemoteRepositories();
if ( repositories != null )
{
boolean normalized = false;
@ -102,9 +146,9 @@ private void normalizeToArtifactRepositories( ProjectBuilderConfiguration config
try
{
ArtifactRepository repo = repositorySystem.buildArtifactRepository( (Repository) repository );
repositorySystem.injectMirror( Arrays.asList( repo ), configuration.getMirrors() );
repositorySystem.injectProxy( Arrays.asList( repo ), configuration.getProxies() );
repositorySystem.injectAuthentication( Arrays.asList( repo ), configuration.getServers() );
repositorySystem.injectMirror( Arrays.asList( repo ), request.getMirrors() );
repositorySystem.injectProxy( Arrays.asList( repo ), request.getProxies() );
repositorySystem.injectAuthentication( Arrays.asList( repo ), request.getServers() );
repos.add( repo );
}
catch ( InvalidRepositoryException e )
@ -121,19 +165,66 @@ private void normalizeToArtifactRepositories( ProjectBuilderConfiguration config
if ( normalized )
{
configuration.setRemoteRepositories( repos );
return repos;
}
}
return (List<ArtifactRepository>) repositories;
}
private ProjectBuildingException transformError( ProjectBuildingException e )
{
if ( e.getCause() instanceof ModelBuildingException )
{
return new InvalidProjectModelException( e.getProjectId(), e.getMessage(), e.getPomFile() );
}
return e;
}
public MavenProject build( File pom, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
{
ProjectBuildingRequest request = injectSession( toRequest( configuration ) );
try
{
return projectBuilder.build( pom, request ).getProject();
}
catch ( ProjectBuildingException e )
{
throw transformError( e );
}
}
// This is used by the SITE plugin.
public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager )
public MavenProject build( File pom, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException
{
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration()
.setLocalRepository( localRepository );
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration();
configuration.setLocalRepository( localRepository );
configuration.setGlobalProfileManager( profileManager );
return build( project, configuration );
return build( pom, configuration );
}
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteRepositories,
ProjectBuilderConfiguration configuration, boolean allowStubModel )
throws ProjectBuildingException
{
ProjectBuildingRequest request = injectSession( toRequest( configuration ) );
request.setRemoteRepositories( normalizeToArtifactRepositories( remoteRepositories, request ) );
request.setProcessPlugins( false );
request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
try
{
return projectBuilder.build( artifact, allowStubModel, request ).getProject();
}
catch ( ProjectBuildingException e )
{
throw transformError( e );
}
}
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteRepositories,
@ -142,44 +233,8 @@ public MavenProject buildFromRepository( Artifact artifact, List<ArtifactReposit
{
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration();
configuration.setLocalRepository( localRepository );
configuration.setRemoteRepositories( remoteRepositories );
configuration.setProcessPlugins( false );
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
MavenSession session = legacySupport.getSession();
if ( session != null )
{
MavenExecutionRequest request = session.getRequest();
if ( request != null )
{
configuration.setServers( request.getServers() );
configuration.setMirrors( request.getMirrors() );
configuration.setProxies( request.getProxies() );
configuration.setTransferListener( request.getTransferListener() );
configuration.setForceUpdate( request.isUpdateSnapshots() );
}
configuration.setOffline( session.isOffline() );
configuration.setSystemProperties( session.getSystemProperties() );
configuration.setUserProperties( session.getUserProperties() );
}
else
{
configuration.setSystemProperties( System.getProperties() );
}
try
{
return buildFromRepository( artifact, configuration, allowStubModel );
}
catch ( ProjectBuildingException e )
{
if ( e.getCause() instanceof ModelBuildingException )
{
throw new InvalidProjectModelException( e.getProjectId(), e.getMessage(), e.getPomFile() );
}
throw e;
}
return buildFromRepository( artifact, remoteRepositories, configuration, allowStubModel );
}
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteRepositories,
@ -190,16 +245,19 @@ public MavenProject buildFromRepository( Artifact artifact, List<ArtifactReposit
}
/**
* This is used for pom-less execution like running archetype:generate.
*
* I am taking out the profile handling and the interpolation of the base directory until we
* spec this out properly.
* This is used for pom-less execution like running archetype:generate. I am taking out the profile handling and the
* interpolation of the base directory until we spec this out properly.
*/
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
{
ProjectBuildingRequest request = injectSession( toRequest( configuration ) );
request.setProcessPlugins( false );
request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
ModelSource modelSource = new UrlModelSource( getClass().getResource( "standalone.xml" ) );
MavenProject project = projectBuilder.build( modelSource, config ).getProject();
MavenProject project = projectBuilder.build( modelSource, request ).getProject();
project.setExecutionRoot( true );
return project;
}
@ -215,42 +273,38 @@ public MavenProject buildStandaloneSuperProject( ArtifactRepository localReposit
{
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration();
configuration.setLocalRepository( localRepository );
configuration.setProcessPlugins( false );
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
if ( profileManager != null )
{
configuration.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() );
configuration.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() );
}
configuration.setGlobalProfileManager( profileManager );
return buildStandaloneSuperProject( configuration );
}
public MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
public MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository,
ProfileManager profileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration();
configuration.setLocalRepository( localRepository );
configuration.setGlobalProfileManager( profileManager );
if ( profileManager != null )
ProjectBuildingRequest request = injectSession( toRequest( configuration ) );
request.setResolveDependencies( true );
try
{
configuration.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() );
configuration.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() );
return projectBuilder.build( pom, request ).getProject();
}
catch ( ProjectBuildingException e )
{
throw transformError( e );
}
configuration.setResolveDependencies( true );
return build( project, configuration );
}
public MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
public MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
return buildWithDependencies( project, localRepository, profileManager, null );
return buildWithDependencies( pom, localRepository, profileManager, null );
}
}

View File

@ -19,51 +19,88 @@
* under the License.
*/
import java.util.List;
import java.util.Date;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.profiles.ProfileManager;
@Deprecated
public class DefaultProjectBuilderConfiguration
extends DefaultProjectBuildingRequest
implements ProjectBuilderConfiguration
{
private ProfileManager globalProfileManager;
private ArtifactRepository localRepository;
private Properties userProperties;
private Properties executionProperties = System.getProperties();
private Date buildStartTime;
public DefaultProjectBuilderConfiguration()
{
setProcessPlugins( false );
setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
}
public ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager )
{
this.globalProfileManager = globalProfileManager;
return this;
}
public ProfileManager getGlobalProfileManager()
{
return globalProfileManager;
}
public ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository )
{
super.setLocalRepository( localRepository );
this.localRepository = localRepository;
return this;
}
public ProjectBuilderConfiguration setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
public ArtifactRepository getLocalRepository()
{
super.setRemoteRepositories( remoteRepositories );
return localRepository;
}
public ProjectBuilderConfiguration setUserProperties( Properties userProperties )
{
this.userProperties = userProperties;
return this;
}
public Properties getUserProperties()
{
if ( userProperties == null )
{
userProperties = new Properties();
}
return userProperties;
}
public Properties getExecutionProperties()
{
return executionProperties;
}
public ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties )
{
super.setSystemProperties( executionProperties );
this.executionProperties = executionProperties;
return this;
}
public ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins )
public Date getBuildStartTime()
{
super.setProcessPlugins( processPlugins );
return this;
return buildStartTime;
}
public ProjectBuilderConfiguration setValidationLevel( int validationLevel )
public ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime )
{
super.setValidationLevel( validationLevel );
this.buildStartTime = buildStartTime;
return this;
}

View File

@ -33,11 +33,11 @@
public interface MavenProjectBuilder
{
MavenProject build( File projectFile, ProjectBuilderConfiguration configuration )
MavenProject build( File pom, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException;
//TODO maven-site-plugin -- Vincent, Dennis and Lukas are checking but this doesn't appear to be required anymore.
MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager )
MavenProject build( File pom, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException;
//TODO remote-resources-plugin
@ -62,11 +62,11 @@ MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository,
ProfileManager globalProfileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository,
ProfileManager globalProfileManager )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;

View File

@ -0,0 +1,52 @@
package org.apache.maven.project;
/*
* 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.Date;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.profiles.ProfileManager;
@Deprecated
public interface ProjectBuilderConfiguration
{
ArtifactRepository getLocalRepository();
ProfileManager getGlobalProfileManager();
Properties getUserProperties();
Properties getExecutionProperties();
ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager );
ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository );
ProjectBuilderConfiguration setUserProperties( Properties userProperties );
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
Date getBuildStartTime();
ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime );
}

View File

@ -261,12 +261,12 @@ public Object getValue( String expression )
valueSources.add( modelValueSource1 );
valueSources.add( new MapBasedValueSource( config.getUserProperties() ) );
valueSources.add( new MapBasedValueSource( modelProperties ) );
valueSources.add( new MapBasedValueSource( config.getSystemProperties() ) );
valueSources.add( new MapBasedValueSource( config.getExecutionProperties() ) );
valueSources.add( new AbstractValueSource( false )
{
public Object getValue( String expression )
{
return config.getSystemProperties().getProperty( "env." + expression );
return config.getExecutionProperties().getProperty( "env." + expression );
}
} );
valueSources.add( modelValueSource2 );

View File

@ -1,76 +0,0 @@
package org.apache.maven.project;
/*
* 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.List;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Profile;
@Deprecated
public interface ProjectBuilderConfiguration
extends ProjectBuildingRequest
{
ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository );
ArtifactRepository getLocalRepository();
ProjectBuilderConfiguration setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
List<ArtifactRepository> getRemoteRepositories();
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
Properties getSystemProperties();
void setProject( MavenProject mavenProject );
MavenProject getProject();
ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins );
boolean isProcessPlugins();
// Profiles
/**
* Set any active profiles that the {@link ProjectBuilder} should consider while constructing
* a {@link MavenProject}.
*/
void setActiveProfileIds( List<String> activeProfileIds );
List<String> getActiveProfileIds();
void setInactiveProfileIds( List<String> inactiveProfileIds );
List<String> getInactiveProfileIds();
/**
* Add a {@link org.apache.maven.model.Profile} that has come from an external source. This may be from a custom
* configuration like the MavenCLI settings.xml file, or from a custom dialog in an IDE integration like M2Eclipse.
* @param profile
*/
void addProfile( Profile profile );
void setProfiles( List<Profile> profiles );
List<Profile> getProfiles();
}