diff --git a/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/pom.xml
new file mode 100644
index 0000000000..2ff272accf
--- /dev/null
+++ b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/pom.xml
@@ -0,0 +1,38 @@
+
+ 4.0.0
+ org.apache.maven.errortest
+ testReportActivatorLookupError-ext
+ 1
+
+
+
+
+
+ maven-surefire-plugin
+ 2.3.1
+
+
+ maven-deploy-plugin
+ 2.3
+
+
+ maven-install-plugin
+ 2.2
+
+
+ maven-resources-plugin
+ 2.2
+
+
+ maven-jar-plugin
+ 2.1
+
+
+ maven-compiler-plugin
+ 2.0.2
+
+
+
+
+
diff --git a/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/java/org/ext/App.java b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/java/org/ext/App.java
new file mode 100644
index 0000000000..85ab5c4075
--- /dev/null
+++ b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/java/org/ext/App.java
@@ -0,0 +1,13 @@
+package org.ext;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/resources/META-INF/plexus/components.xml b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/resources/META-INF/plexus/components.xml
new file mode 100644
index 0000000000..74a2963ced
--- /dev/null
+++ b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/ext/src/main/resources/META-INF/plexus/components.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ org.apache.maven.profiles.activation.ProfileActivator
+ faulty
+ org.ext.App
+
+
+ org.apache.maven.artifact.ArtifactResolver
+ artifactResolver
+
+
+
+
+
\ No newline at end of file
diff --git a/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/project/pom.xml b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/project/pom.xml
new file mode 100644
index 0000000000..3d6fc5c958
--- /dev/null
+++ b/maven-embedder/src/test/error-reporting-projects/testReportActivatorLookupError/project/pom.xml
@@ -0,0 +1,46 @@
+
+
+
+ 4.0.0
+ org.apache.maven.errortest
+ testReportActivatorLookupError
+ 1
+
+
+
+ test-profile
+
+
+ java.version
+
+
+
+
+
+
+
+
+ org.apache.maven.errortest
+ testReportActivatorLookupError-ext
+ 1
+
+
+
+
diff --git a/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java b/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java
index 36b79f3dc2..5e63c44d70 100644
--- a/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java
+++ b/maven-embedder/src/test/java/org/apache/maven/error/ErrorReporterPointcutTest.java
@@ -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()
diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProfileErrorReporterAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProfileErrorReporterAspect.aj
index 751cbe9b44..5f819f3cd8 100644
--- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProfileErrorReporterAspect.aj
+++ b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProfileErrorReporterAspect.aj
@@ -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 )
+ call( List PlexusContainer+.lookupList( .. ) )
+ && cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
+ && cflow( pMgr_isActiveExec( profile, context ) )
{
- getReporter().reportActivatorLookupError( model.getId(), pomFile, profile, cause );
+ getReporter().reportActivatorLookupError( model, pomFile, profile, context, cause );
}
- protected pointcut profileActivatorCall( ProfileActivator activator ):
- call( * ProfileActivator+.*( .. ) )
- && target( activator )
- && notWithinAspect();
+ private pointcut pAdv_getArtifactRepositoriesFromActiveProfiles_1( Model model, File pomFile ):
+ execution( LinkedHashSet ProfileAdvisor+.getArtifactRepositoriesFromActiveProfiles( Model, File, ProfileManager ) )
+ && args( model, pomFile, * );
- private pointcut applyActivatedProfiles_ActivatorThrown( ProfileActivator activator,
- Model model,
- File pomFile,
- Profile profile,
- ProfileActivationContext context ):
- profileActivatorCall( activator )
- && cflow( pAdv_applyActivatedProfiles( model, pomFile ) )
- && cflow( pMgr_isActiveExec( profile, context ) )
- && notWithinAspect();
+ 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 );
}
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
index 0e0aa52959..475f57eead 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
@@ -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,68 +170,92 @@ public class DefaultProfileManager
}
}
- /* (non-Javadoc)
- * @see org.apache.maven.profiles.ProfileManager#getActiveProfiles()
- */
public List getActiveProfiles()
throws ProfileActivationException
{
- List activeFromPom = new ArrayList();
- List activeExternal = new ArrayList();
+ return getActiveProfiles( null );
+ }
- for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
+ public List getActiveProfiles( Model model )
+ throws ProfileActivationException
+ {
+ MavenRealmManager realmManager = profileActivationContext.getRealmManager();
+
+ ClassRealm projectRealm = null;
+ ClassRealm oldLookupRealm = null;
+
+ if ( ( model != null ) && ( realmManager != null ) )
{
- Map.Entry entry = (Entry) it.next();
-
- String profileId = (String) entry.getKey();
- Profile profile = (Profile) entry.getValue();
-
- boolean shouldAdd = false;
- if ( profileActivationContext.isExplicitlyActive( profileId ) )
- {
- shouldAdd = true;
- }
- else if ( !profileActivationContext.isExplicitlyInactive( profileId ) && isActive( profile, profileActivationContext ) )
- {
- shouldAdd = true;
- }
-
- if ( shouldAdd )
- {
- if ( "pom".equals( profile.getSource() ) )
- {
- activeFromPom.add( profile );
- }
- else
- {
- activeExternal.add( profile );
- }
- }
+ projectRealm = realmManager.getProjectRealm( ModelUtils.getGroupId( model ), model.getArtifactId(), ModelUtils.getVersion( model ) );
+ oldLookupRealm = container.setLookupRealm( projectRealm );
}
- if ( activeFromPom.isEmpty() )
+ try
{
- List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
+ List activeFromPom = new ArrayList();
+ List activeExternal = new ArrayList();
- for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
+ for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{
- String profileId = (String) it.next();
+ Map.Entry entry = (Entry) it.next();
- Profile profile = (Profile) profilesById.get( profileId );
+ String profileId = (String) entry.getKey();
+ Profile profile = (Profile) entry.getValue();
- if ( profile != null )
+ boolean shouldAdd = false;
+ if ( profileActivationContext.isExplicitlyActive( profileId ) )
{
- activeFromPom.add( profile );
+ shouldAdd = true;
+ }
+ else if ( !profileActivationContext.isExplicitlyInactive( profileId ) && isActive( profile, profileActivationContext ) )
+ {
+ shouldAdd = true;
+ }
+
+ if ( shouldAdd )
+ {
+ if ( "pom".equals( profile.getSource() ) )
+ {
+ activeFromPom.add( profile );
+ }
+ else
+ {
+ activeExternal.add( profile );
+ }
}
}
+
+ if ( activeFromPom.isEmpty() )
+ {
+ List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
+
+ for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
+ {
+ String profileId = (String) it.next();
+
+ Profile profile = (Profile) profilesById.get( profileId );
+
+ if ( profile != null )
+ {
+ activeFromPom.add( profile );
+ }
+ }
+ }
+
+ List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
+
+ allActive.addAll( activeExternal );
+ allActive.addAll( activeFromPom );
+
+ return allActive;
+ }
+ finally
+ {
+ if ( projectRealm != null )
+ {
+ container.setLookupRealm( oldLookupRealm );
+ }
}
-
- List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
-
- allActive.addAll( activeExternal );
- allActive.addAll( activeFromPom );
-
- return allActive;
}
private boolean isActive( Profile profile, ProfileActivationContext context )
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
index 0498c8bd2f..4a4510e567 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
@@ -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;
}
\ No newline at end of file
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
index a3f6f47388..b4ae7f6abc 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
@@ -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,
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java b/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
index e8f456eaa5..37c8e20441 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
@@ -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,
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
index b63d5dfb68..7847705abc 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
@@ -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
- {
- activeProfiles = Collections.EMPTY_LIST;
+ List activated = profileAdvisor.applyActivatedProfiles( superModel, null, false, profileManager.getProfileActivationContext() );
+ if ( !activated.isEmpty() )
+ {
+ 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 );
diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
index cdbe3e9edf..bb062bcfd7 100644
--- a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
@@ -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;
+ }
+
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java b/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
index 6c47e3b060..26fdfe8b89 100644
--- a/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
@@ -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 );
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java b/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java
index e79ca0e474..0d955c9ee2 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java
+++ b/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java
@@ -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() );
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java b/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java
index 95fb6f7f61..77e2faea40 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java
+++ b/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java
@@ -55,7 +55,7 @@ public interface ProjectErrorReporter
*
*/
void reportActivatorError( ProfileActivator activator,
- String projectId,
+ Model model,
File pomFile,
Profile profile,
ProfileActivationContext context,
@@ -77,9 +77,10 @@ public interface ProjectErrorReporter
* <------ ProjectBuildingException
*
*/
- void reportActivatorLookupError( String projectId,
+ void reportActivatorLookupError( Model model,
File pomFile,
Profile profile,
+ ProfileActivationContext context,
ComponentLookupException cause );
/**
@@ -131,7 +132,7 @@ public interface ProjectErrorReporter
*
*/
void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
- String projectId,
+ Model model,
File pomFile,
InvalidRepositoryException cause );