mirror of https://github.com/apache/maven.git
Adding more unit tests for error reporting. Almost done with project-based errors now.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@612333 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47b1dda978
commit
1c235317d7
|
@ -0,0 +1,38 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.errortest</groupId>
|
||||
<artifactId>testReportActivatorLookupError-ext</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package org.ext;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0"?>
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
|
||||
<role-hint>faulty</role-hint>
|
||||
<implementation>org.ext.App</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.ArtifactResolver</role>
|
||||
<field-name>artifactResolver</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
|
@ -0,0 +1,46 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.errortest</groupId>
|
||||
<artifactId>testReportActivatorLookupError</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>test-profile</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>java.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.errortest</groupId>
|
||||
<artifactId>testReportActivatorLookupError-ext</artifactId>
|
||||
<version>1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
|
@ -754,11 +754,17 @@ public class ErrorReporterPointcutTest
|
|||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( projectDir )
|
||||
.setShowErrors( true )
|
||||
.setErrorReporter( reporter )
|
||||
// .setErrorReporter( new DummyCoreErrorReporter() )
|
||||
.setGoals( Arrays.asList( new String[] {
|
||||
"initialize"
|
||||
} ) );
|
||||
|
||||
maven.execute( request );
|
||||
MavenExecutionResult result = maven.execute( request );
|
||||
|
||||
// if ( result.hasExceptions() )
|
||||
// {
|
||||
// reportExceptions( result, projectDir );
|
||||
// }
|
||||
|
||||
reporterCtl.verify();
|
||||
}
|
||||
|
@ -766,33 +772,39 @@ public class ErrorReporterPointcutTest
|
|||
public void testReportActivatorLookupError()
|
||||
throws IOException
|
||||
{
|
||||
// if ( !checkOnline() )
|
||||
if ( !checkOnline() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
File projectDir = prepareProjectDir();
|
||||
|
||||
buildTestAccessory( new File( projectDir, "ext" ) );
|
||||
|
||||
File project = new File( projectDir, "project" );
|
||||
|
||||
reporter.reportActivatorLookupError( null, null, null, null, null );
|
||||
reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
reporterCtl.setVoidCallable();
|
||||
|
||||
reporterCtl.replay();
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project )
|
||||
.setShowErrors( true )
|
||||
.setErrorReporter( reporter )
|
||||
// .setErrorReporter( new DummyCoreErrorReporter() )
|
||||
.setGoals( Arrays.asList( new String[] {
|
||||
"initialize"
|
||||
} ) );
|
||||
|
||||
MavenExecutionResult result = maven.execute( request );
|
||||
|
||||
// if ( result.hasExceptions() )
|
||||
// {
|
||||
// return;
|
||||
// reportExceptions( result, project );
|
||||
// }
|
||||
//
|
||||
// File projectDir = prepareProjectDir();
|
||||
//
|
||||
// buildTestAccessory( new File( projectDir, "ext" ) );
|
||||
//
|
||||
// File project = new File( projectDir, "project" );
|
||||
//
|
||||
// reporter.reportActivatorLookupError( null, null, null, null );
|
||||
// reporterCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
// reporterCtl.setVoidCallable();
|
||||
//
|
||||
// reporterCtl.replay();
|
||||
//
|
||||
// MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( project )
|
||||
// .setShowErrors( true )
|
||||
// .setErrorReporter( reporter )
|
||||
// .setGoals( Arrays.asList( new String[] {
|
||||
// "initialize"
|
||||
// } ) );
|
||||
//
|
||||
// maven.execute( request );
|
||||
//
|
||||
// reporterCtl.verify();
|
||||
|
||||
reporterCtl.verify();
|
||||
}
|
||||
|
||||
public void testReportBadDependencyVersion()
|
||||
|
|
|
@ -8,8 +8,10 @@ import org.apache.maven.model.Repository;
|
|||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.profiles.build.DefaultProfileAdvisor;
|
||||
import org.apache.maven.profiles.build.ProfileAdvisor;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.profiles.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.MavenProfilesBuilder;
|
||||
import org.apache.maven.profiles.ProfilesRoot;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -32,29 +34,19 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
extends AbstractProjectErrorReporterAspect
|
||||
{
|
||||
|
||||
protected pointcut componentLookupException( ComponentLookupException cause ):
|
||||
handler( ComponentLookupException )
|
||||
&& args( cause )
|
||||
&& notWithinAspect();
|
||||
private pointcut within_pMgr_isActiveExec( Profile profile, ProfileActivationContext context ):
|
||||
withincode( boolean DefaultProfileManager.isActive( Profile, ProfileActivationContext ) )
|
||||
&& args( profile, context );
|
||||
|
||||
private pointcut pMgr_isActiveExec( Profile profile, ProfileActivationContext context ):
|
||||
execution( boolean DefaultProfileManager.isActive( Profile, ProfileActivationContext ) )
|
||||
&& args( profile, context )
|
||||
&& notWithinAspect();
|
||||
&& args( profile, context );
|
||||
|
||||
private pointcut pAdv_applyActivatedProfiles( Model model, File pomFile ):
|
||||
execution( private List DefaultProfileAdvisor.applyActivatedProfiles( Model, File, .. ) )
|
||||
&& args( model, pomFile, .. )
|
||||
&& notWithinAspect();
|
||||
|
||||
private pointcut applyActivatedProfiles_ComponentLookupException( Model model,
|
||||
File pomFile,
|
||||
Profile profile ):
|
||||
call( List PlexusContainer+.lookupList( .. ) )
|
||||
&& cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, ProfileActivationContext ) )
|
||||
&& notWithinAspect();
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
|
@ -68,27 +60,48 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// <-- ProfileActivationException
|
||||
// <------ ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( Model model, File pomFile, Profile profile )
|
||||
after( Model model, File pomFile, Profile profile, ProfileActivationContext context )
|
||||
throwing( ComponentLookupException cause ):
|
||||
applyActivatedProfiles_ComponentLookupException( model, pomFile, profile )
|
||||
{
|
||||
getReporter().reportActivatorLookupError( model.getId(), pomFile, profile, cause );
|
||||
}
|
||||
|
||||
protected pointcut profileActivatorCall( ProfileActivator activator ):
|
||||
call( * ProfileActivator+.*( .. ) )
|
||||
&& target( activator )
|
||||
&& notWithinAspect();
|
||||
|
||||
private pointcut applyActivatedProfiles_ActivatorThrown( ProfileActivator activator,
|
||||
Model model,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context ):
|
||||
profileActivatorCall( activator )
|
||||
call( List PlexusContainer+.lookupList( .. ) )
|
||||
&& cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, context ) )
|
||||
&& notWithinAspect();
|
||||
{
|
||||
getReporter().reportActivatorLookupError( model, pomFile, profile, context, cause );
|
||||
}
|
||||
|
||||
private pointcut pAdv_getArtifactRepositoriesFromActiveProfiles_1( Model model, File pomFile ):
|
||||
execution( LinkedHashSet ProfileAdvisor+.getArtifactRepositoriesFromActiveProfiles( Model, File, ProfileManager ) )
|
||||
&& args( model, pomFile, * );
|
||||
|
||||
private pointcut pAdv_getArtifactRepositoriesFromActiveProfiles_2( Model model, File pomFile ):
|
||||
execution( LinkedHashSet ProfileAdvisor+.getArtifactRepositoriesFromActiveProfiles( Model, File, boolean, ProfileActivationContext ) )
|
||||
&& args( model, pomFile, *, * );
|
||||
|
||||
private pointcut pAdv_getArtifactRepos( Model model, File pomFile ):
|
||||
pAdv_getArtifactRepositoriesFromActiveProfiles_1( model, pomFile )
|
||||
|| pAdv_getArtifactRepositoriesFromActiveProfiles_2( model, pomFile );
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
// DefaultProfileAdvisor.applyActivatedProfiles(..)
|
||||
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
|
||||
// --> DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
|
||||
// --> DefaultProfileManager.getActiveProfiles(..)
|
||||
// --> DefaultProfileManager.isActive(..) (private)
|
||||
// --> PlexusContainer.lookupList(..)
|
||||
// <-- ComponentLookupException
|
||||
// <-- ProfileActivationException
|
||||
// <------ ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( Model model, File pomFile, Profile profile, ProfileActivationContext context )
|
||||
throwing( ComponentLookupException cause ):
|
||||
call( List PlexusContainer+.lookupList( .. ) )
|
||||
&& cflow( pAdv_getArtifactRepos( model, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, context ) )
|
||||
{
|
||||
getReporter().reportActivatorLookupError( model, pomFile, profile, context, cause );
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
|
@ -105,9 +118,12 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// =========================================================================
|
||||
after( ProfileActivator activator, Model model, File pomFile, Profile profile, ProfileActivationContext context )
|
||||
throwing( ProfileActivationException cause ):
|
||||
applyActivatedProfiles_ActivatorThrown( activator, model, pomFile, profile, context )
|
||||
call( * ProfileActivator+.*( .. ) )
|
||||
&& target( activator )
|
||||
&& cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, context ) )
|
||||
{
|
||||
getReporter().reportActivatorError( activator, model.getId(), pomFile, profile, context, cause );
|
||||
getReporter().reportActivatorError( activator, model, pomFile, profile, context, cause );
|
||||
}
|
||||
|
||||
private pointcut pAdv_loadExternalProjectProfiles( Model model, File pomFile ):
|
||||
|
@ -115,14 +131,6 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
&& args( *, model, pomFile )
|
||||
&& notWithinAspect();
|
||||
|
||||
private pointcut loadExternalProfiles_profileBuilding( Model model,
|
||||
File pomFile,
|
||||
File projectDir ):
|
||||
call( ProfilesRoot MavenProfilesBuilder+.buildProfiles( File ) )
|
||||
&& cflow( pAdv_loadExternalProjectProfiles( model, pomFile ) )
|
||||
&& args( projectDir )
|
||||
&& notWithinAspect();
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
|
@ -136,7 +144,9 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// =========================================================================
|
||||
after( Model model, File pomFile, File projectDir )
|
||||
throwing( IOException cause ):
|
||||
loadExternalProfiles_profileBuilding( model, pomFile, projectDir )
|
||||
call( ProfilesRoot MavenProfilesBuilder+.buildProfiles( File ) )
|
||||
&& cflow( pAdv_loadExternalProjectProfiles( model, pomFile ) )
|
||||
&& args( projectDir )
|
||||
{
|
||||
getReporter().reportErrorLoadingExternalProfilesFromFile( model, pomFile, projectDir, cause );
|
||||
}
|
||||
|
@ -154,7 +164,9 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// =========================================================================
|
||||
after( Model model, File pomFile, File projectDir )
|
||||
throwing( XmlPullParserException cause ):
|
||||
loadExternalProfiles_profileBuilding( model, pomFile, projectDir )
|
||||
call( ProfilesRoot MavenProfilesBuilder+.buildProfiles( File ) )
|
||||
&& cflow( pAdv_loadExternalProjectProfiles( model, pomFile ) )
|
||||
&& args( projectDir )
|
||||
{
|
||||
getReporter().reportErrorLoadingExternalProfilesFromFile( model, pomFile, projectDir, cause );
|
||||
}
|
||||
|
@ -164,45 +176,6 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
&& args( *, pomFile, projectId )
|
||||
&& notWithinAspect();
|
||||
|
||||
private pointcut getArtifactRepositoriesFromActiveProfiles_ComponentLookupException( String projectId,
|
||||
File pomFile,
|
||||
Profile profile ):
|
||||
call( List PlexusContainer+.lookupList( .. ) )
|
||||
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, ProfileActivationContext ) )
|
||||
&& notWithinAspect();
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
// DefaultProfileAdvisor.applyActivatedProfiles(..)
|
||||
// DefaultProfileAdvisor.applyActivatedExternalProfiles(..)
|
||||
// --> DefaultProfileAdvisor.getArtifactRepositoriesFromActiveProfiles(..)
|
||||
// --> DefaultProfileManager.getActiveProfiles(..)
|
||||
// --> DefaultProfileManager.isActive(..) (private)
|
||||
// --> PlexusContainer.lookupList(..)
|
||||
// <-- ComponentLookupException
|
||||
// <-- ProfileActivationException
|
||||
// <------ ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( String projectId, File pomFile, Profile profile )
|
||||
throwing( ComponentLookupException cause ):
|
||||
getArtifactRepositoriesFromActiveProfiles_ComponentLookupException( projectId, pomFile, profile )
|
||||
{
|
||||
getReporter().reportActivatorLookupError( projectId, pomFile, profile, cause );
|
||||
}
|
||||
|
||||
private pointcut getArtifactRepositoriesFromActiveProfiles_ActivatorThrown( ProfileActivator activator,
|
||||
String projectId,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context ):
|
||||
profileActivatorCall( activator )
|
||||
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, context ) )
|
||||
&& within( DefaultProfileManager )
|
||||
&& notWithinAspect();
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
|
@ -216,22 +189,17 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// <------ ProfileActivationException
|
||||
// <------ ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( ProfileActivator activator, String projectId, File pomFile, Profile profile, ProfileActivationContext context )
|
||||
after( ProfileActivator activator, Model model, File pomFile, Profile profile, ProfileActivationContext context )
|
||||
throwing( ProfileActivationException cause ):
|
||||
getArtifactRepositoriesFromActiveProfiles_ActivatorThrown( activator, projectId, pomFile, profile, context )
|
||||
call( * ProfileActivator+.*( .. ) )
|
||||
&& target( activator )
|
||||
&& cflow( pAdv_getArtifactRepos( model, pomFile ) )
|
||||
&& cflow( pMgr_isActiveExec( profile, context ) )
|
||||
&& within( DefaultProfileManager )
|
||||
{
|
||||
getReporter().reportActivatorError( activator, projectId, pomFile, profile, context, cause );
|
||||
getReporter().reportActivatorError( activator, model, pomFile, profile, context, cause );
|
||||
}
|
||||
|
||||
private pointcut getArtifactRepositoriesFromActiveProfiles_InvalidRepository( Repository repo,
|
||||
String projectId,
|
||||
File pomFile ):
|
||||
call( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
|
||||
&& args( repo )
|
||||
&& cflow( pAdv_getArtifactRepositoriesFromActiveProfiles( projectId, pomFile ) )
|
||||
&& within( DefaultProfileAdvisor )
|
||||
&& notWithinAspect();
|
||||
|
||||
// =========================================================================
|
||||
// Call Stack:
|
||||
// =========================================================================
|
||||
|
@ -242,11 +210,14 @@ public privileged aspect ProfileErrorReporterAspect
|
|||
// <-- InvalidRepositoryException
|
||||
// <-- ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( Repository repo, String projectId, File pomFile )
|
||||
after( Repository repo, Model model, File pomFile )
|
||||
throwing( InvalidRepositoryException cause ):
|
||||
getArtifactRepositoriesFromActiveProfiles_InvalidRepository( repo, projectId, pomFile )
|
||||
call( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
|
||||
&& args( repo )
|
||||
&& cflow( pAdv_getArtifactRepos( model, pomFile ) )
|
||||
&& within( DefaultProfileAdvisor )
|
||||
{
|
||||
getReporter().reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( repo, projectId, pomFile, cause );
|
||||
getReporter().reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( repo, model, pomFile, cause );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,14 +20,17 @@ package org.apache.maven.profiles;
|
|||
*/
|
||||
|
||||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.profiles.activation.ProfileActivator;
|
||||
import org.apache.maven.project.ModelUtils;
|
||||
import org.apache.maven.realm.DefaultMavenRealmManager;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
@ -167,11 +170,27 @@ public class DefaultProfileManager
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.maven.profiles.ProfileManager#getActiveProfiles()
|
||||
*/
|
||||
public List getActiveProfiles()
|
||||
throws ProfileActivationException
|
||||
{
|
||||
return getActiveProfiles( null );
|
||||
}
|
||||
|
||||
public List getActiveProfiles( Model model )
|
||||
throws ProfileActivationException
|
||||
{
|
||||
MavenRealmManager realmManager = profileActivationContext.getRealmManager();
|
||||
|
||||
ClassRealm projectRealm = null;
|
||||
ClassRealm oldLookupRealm = null;
|
||||
|
||||
if ( ( model != null ) && ( realmManager != null ) )
|
||||
{
|
||||
projectRealm = realmManager.getProjectRealm( ModelUtils.getGroupId( model ), model.getArtifactId(), ModelUtils.getVersion( model ) );
|
||||
oldLookupRealm = container.setLookupRealm( projectRealm );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
List activeFromPom = new ArrayList();
|
||||
List activeExternal = new ArrayList();
|
||||
|
@ -230,6 +249,14 @@ public class DefaultProfileManager
|
|||
|
||||
return allActive;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( projectRealm != null )
|
||||
{
|
||||
container.setLookupRealm( oldLookupRealm );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isActive( Profile profile, ProfileActivationContext context )
|
||||
throws ProfileActivationException
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.profiles;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
|
@ -59,6 +60,9 @@ public interface ProfileManager
|
|||
|
||||
void setProfileActivationContext( ProfileActivationContext profileActivationContext );
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link ProfileManager#getActiveProfiles(Model)} instead.
|
||||
*/
|
||||
List getActiveProfiles()
|
||||
throws ProfileActivationException;
|
||||
|
||||
|
@ -80,4 +84,7 @@ public interface ProfileManager
|
|||
* @deprecated Use {@link ProfileActivationContext} methods instead.
|
||||
*/
|
||||
List getIdsActivatedByDefault();
|
||||
|
||||
List getActiveProfiles( Model model )
|
||||
throws ProfileActivationException;
|
||||
}
|
|
@ -110,7 +110,7 @@ public class DefaultProfileAdvisor
|
|||
{
|
||||
try
|
||||
{
|
||||
activeProfiles = profileManager.getActiveProfiles();
|
||||
activeProfiles = profileManager.getActiveProfiles( model );
|
||||
}
|
||||
catch ( ProfileActivationException e )
|
||||
{
|
||||
|
@ -164,9 +164,9 @@ public class DefaultProfileAdvisor
|
|||
return profileManager;
|
||||
}
|
||||
|
||||
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( ProfileManager profileManager,
|
||||
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
|
||||
File pomFile,
|
||||
String modelId )
|
||||
ProfileManager profileManager )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
||||
|
@ -179,12 +179,12 @@ public class DefaultProfileAdvisor
|
|||
{
|
||||
try
|
||||
{
|
||||
activeExternalProfiles = profileManager.getActiveProfiles();
|
||||
activeExternalProfiles = profileManager.getActiveProfiles( model );
|
||||
}
|
||||
catch ( ProfileActivationException e )
|
||||
{
|
||||
throw new ProjectBuildingException(
|
||||
modelId,
|
||||
model.getId(),
|
||||
"Failed to compute active profiles for repository aggregation.",
|
||||
pomFile, e );
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class DefaultProfileAdvisor
|
|||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ProjectBuildingException( modelId, e.getMessage(), e );
|
||||
throw new ProjectBuildingException( model.getId(), e.getMessage(), e );
|
||||
}
|
||||
|
||||
remoteRepositories.add( artifactRepo );
|
||||
|
@ -230,7 +230,7 @@ public class DefaultProfileAdvisor
|
|||
useProfilesXml,
|
||||
activationContext );
|
||||
|
||||
return getArtifactRepositoriesFromActiveProfiles( profileManager, pomFile, model.getId() );
|
||||
return getArtifactRepositoriesFromActiveProfiles( model, pomFile, profileManager );
|
||||
}
|
||||
|
||||
private void loadExternalProjectProfiles( ProfileManager profileManager,
|
||||
|
|
|
@ -38,9 +38,9 @@ public interface ProfileAdvisor
|
|||
|
||||
String ROLE = ProfileAdvisor.class.getName();
|
||||
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( ProfileManager profileManager,
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
|
||||
File pomFile,
|
||||
String modelId )
|
||||
ProfileManager profileManager )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
|
||||
|
|
|
@ -225,14 +225,20 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
superModel = ModelUtils.cloneModel( superModel );
|
||||
|
||||
List activeProfiles;
|
||||
List activeProfiles = new ArrayList();
|
||||
if ( profileManager != null )
|
||||
{
|
||||
activeProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager );
|
||||
}
|
||||
else
|
||||
List activated = profileAdvisor.applyActivatedProfiles( superModel, null, false, profileManager.getProfileActivationContext() );
|
||||
if ( !activated.isEmpty() )
|
||||
{
|
||||
activeProfiles = Collections.EMPTY_LIST;
|
||||
activeProfiles.addAll( activated );
|
||||
}
|
||||
|
||||
activated = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager );
|
||||
if ( !activated.isEmpty() )
|
||||
{
|
||||
activeProfiles.addAll( activated );
|
||||
}
|
||||
}
|
||||
|
||||
MavenProject project = new MavenProject( superModel );
|
||||
|
@ -593,13 +599,13 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
LinkedHashSet activeInSuperPom = new LinkedHashSet();
|
||||
List activated = profileAdvisor.applyActivatedExternalProfiles( superModel, projectDescriptor, externalProfileManager );
|
||||
List activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, validProfilesXmlLocation, profileActivationContext );
|
||||
if ( !activated.isEmpty() )
|
||||
{
|
||||
activeInSuperPom.addAll( activated );
|
||||
}
|
||||
|
||||
activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, validProfilesXmlLocation, profileActivationContext );
|
||||
activated = profileAdvisor.applyActivatedExternalProfiles( superModel, projectDescriptor, externalProfileManager );
|
||||
if ( !activated.isEmpty() )
|
||||
{
|
||||
activeInSuperPom.addAll( activated );
|
||||
|
|
|
@ -1121,4 +1121,30 @@ public final class ModelUtils
|
|||
return new ArrayList( depsMap.values() );
|
||||
}
|
||||
|
||||
public static String getGroupId( Model model )
|
||||
{
|
||||
Parent parent = model.getParent();
|
||||
|
||||
String groupId = model.getGroupId();
|
||||
if ( ( parent != null ) && ( groupId == null ) )
|
||||
{
|
||||
groupId = parent.getGroupId();
|
||||
}
|
||||
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public static String getVersion( Model model )
|
||||
{
|
||||
Parent parent = model.getParent();
|
||||
|
||||
String version = model.getVersion();
|
||||
if ( ( parent != null ) && ( version == null ) )
|
||||
{
|
||||
version = parent.getVersion();
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -291,9 +291,9 @@ public class DefaultModelLineageBuilder
|
|||
context = new DefaultProfileActivationContext( System.getProperties(), false );
|
||||
}
|
||||
|
||||
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( profileManager,
|
||||
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model,
|
||||
pomFile,
|
||||
model.getId() );
|
||||
profileManager );
|
||||
|
||||
getLogger().debug( "Got external-profile repositories: " + profileRepos );
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ public class DefaultProjectErrorReporter
|
|||
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorErrorWhileApplyingProfiles(org.apache.maven.profiles.activation.ProfileActivator, org.apache.maven.model.Model, java.io.File, org.apache.maven.model.Profile, org.apache.maven.profiles.activation.ProfileActivationContext, org.apache.maven.profiles.activation.ProfileActivationException)
|
||||
*/
|
||||
public void reportActivatorError( ProfileActivator activator,
|
||||
String projectId,
|
||||
Model model,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context,
|
||||
|
@ -139,9 +139,9 @@ public class DefaultProjectErrorReporter
|
|||
writer.write( NEWLINE );
|
||||
writer.write( cause.getMessage() );
|
||||
|
||||
addStandardInfo( projectId, pomFile, writer );
|
||||
addStandardInfo( model.getId(), pomFile, writer );
|
||||
addTips( ProjectErrorTips.getTipsForActivatorError( activator,
|
||||
projectId,
|
||||
model.getId(),
|
||||
pomFile,
|
||||
profile,
|
||||
context,
|
||||
|
@ -153,9 +153,10 @@ public class DefaultProjectErrorReporter
|
|||
/**
|
||||
* @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorLookupError(java.lang.String, java.io.File, org.apache.maven.model.Profile, org.codehaus.plexus.component.repository.exception.ComponentLookupException)
|
||||
*/
|
||||
public void reportActivatorLookupError( String projectId,
|
||||
public void reportActivatorLookupError( Model model,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context,
|
||||
ComponentLookupException cause )
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
|
@ -174,8 +175,8 @@ public class DefaultProjectErrorReporter
|
|||
writer.write( NEWLINE );
|
||||
writer.write( cause.getMessage() );
|
||||
|
||||
addStandardInfo( projectId, pomFile, writer );
|
||||
addTips( ProjectErrorTips.getTipsForActivatorLookupError( projectId,
|
||||
addStandardInfo( model.getId(), pomFile, writer );
|
||||
addTips( ProjectErrorTips.getTipsForActivatorLookupError( model.getId(),
|
||||
pomFile,
|
||||
profile,
|
||||
cause ), writer );
|
||||
|
@ -252,7 +253,7 @@ public class DefaultProjectErrorReporter
|
|||
* @see org.apache.maven.project.error.ProjectErrorReporter#reportInvalidRepositoryWhileGettingRepositoriesFromProfiles(org.apache.maven.model.Repository, java.lang.String, java.io.File, org.apache.maven.artifact.InvalidRepositoryException)
|
||||
*/
|
||||
public void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
|
||||
String projectId,
|
||||
Model model,
|
||||
File pomFile,
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
|
@ -271,8 +272,8 @@ public class DefaultProjectErrorReporter
|
|||
writer.write( NEWLINE );
|
||||
writer.write( cause.getMessage() );
|
||||
|
||||
addStandardInfo( projectId, pomFile, writer );
|
||||
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, projectId, pomFile, cause ),
|
||||
addStandardInfo( model.getId(), pomFile, writer );
|
||||
addTips( ProjectErrorTips.getTipsForInvalidRepositorySpec( repo, model.getId(), pomFile, cause ),
|
||||
writer );
|
||||
|
||||
registerBuildError( cause, writer.toString(), cause.getCause() );
|
||||
|
|
|
@ -55,7 +55,7 @@ public interface ProjectErrorReporter
|
|||
* </pre>
|
||||
*/
|
||||
void reportActivatorError( ProfileActivator activator,
|
||||
String projectId,
|
||||
Model model,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context,
|
||||
|
@ -77,9 +77,10 @@ public interface ProjectErrorReporter
|
|||
* <------ ProjectBuildingException
|
||||
* </pre>
|
||||
*/
|
||||
void reportActivatorLookupError( String projectId,
|
||||
void reportActivatorLookupError( Model model,
|
||||
File pomFile,
|
||||
Profile profile,
|
||||
ProfileActivationContext context,
|
||||
ComponentLookupException cause );
|
||||
|
||||
/**
|
||||
|
@ -131,7 +132,7 @@ public interface ProjectErrorReporter
|
|||
* </pre>
|
||||
*/
|
||||
void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
|
||||
String projectId,
|
||||
Model model,
|
||||
File pomFile,
|
||||
InvalidRepositoryException cause );
|
||||
|
||||
|
|
Loading…
Reference in New Issue