From 3929bd0e456f9da027cd071638aaf0ca95dbf678 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Wed, 17 Sep 2008 14:42:57 +0000 Subject: [PATCH] Reverted back previous checkin, which broke something in the assembly plugin. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@696326 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultBuildExtensionScanner.java | 28 ++--- .../maven/plugin/DefaultPluginManager.java | 10 +- .../maven/profiles/DefaultProfileManager.java | 13 ++ .../injection/DefaultProfileInjector.java | 3 +- .../project/DefaultMavenProjectBuilder.java | 114 ++++++++---------- .../ArtifactModelContainerFactory.java | 22 +--- 6 files changed, 78 insertions(+), 112 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java index 3004c1ff7d..fe7aca1419 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java @@ -29,7 +29,6 @@ import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.profiles.ProfileManager; -import org.apache.maven.profiles.Profile; import org.apache.maven.profiles.activation.DefaultProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationContext; import org.apache.maven.project.MavenProject; @@ -147,24 +146,23 @@ public class DefaultBuildExtensionScanner execProps.putAll( config.getExecutionProperties() ); } - execProps.putAll( inheritedInterpolationValues ); + if ( inheritedInterpolationValues != null ) + { + execProps.putAll( inheritedInterpolationValues ); + } + else + { + inheritedInterpolationValues = new HashMap(); + } config.setExecutionProperties( execProps ); - //INTERPOLATION + //INTERPOLATION List interpolatorProperties = new ArrayList(); - /* - for(Profile profile : (List) request.getActiveProfiles()) - { - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( profile.getProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); - } - */ - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); - - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), - PomInterpolatorTag.USER_PROPERTIES.name())); + interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), + PomInterpolatorTag.SYSTEM_PROPERTIES.name())); + interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), + PomInterpolatorTag.USER_PROPERTIES.name())); if(config.getBuildStartTime() != null) { interpolatorProperties.add(new InterpolatorProperty("${build.timestamp}", diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 959edeb090..318247b36a 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -20,7 +20,6 @@ package org.apache.maven.plugin; */ import org.apache.maven.ArtifactFilterManager; -import org.apache.maven.profiles.Profile; import org.apache.maven.path.PathTranslator; import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.artifact.Artifact; @@ -558,15 +557,8 @@ public class DefaultPluginManager if ( dom != null ) { try - { + { List interpolatorProperties = new ArrayList(); - /* - for(Profile profile : (List) project.getActiveProfiles()) - { - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( profile.getProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); - } - */ interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties(), PomInterpolatorTag.SYSTEM_PROPERTIES.name())); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(), 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 c5b6ecf0a9..c780cec799 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 @@ -341,6 +341,19 @@ public class DefaultProfileManager return profileActivationContext.getActiveByDefaultProfileIds(); } + private static String getVersion( Model model ) + { + Parent parent = model.getParent(); + + String version = model.getVersion(); + if ( ( parent != null ) && ( version == null ) ) + { + version = parent.getVersion(); + } + + return version; + } + public static String getGroupId( Model model ) { Parent parent = model.getParent(); diff --git a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java index e54c24691d..fbf5356477 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java @@ -70,7 +70,8 @@ public class DefaultProfileInjector injectBuild( profile, model ); Properties props = new Properties(); - + props.putAll( model.getProperties() ); + props.putAll( profile.getProperties() ); model.setProperties( props ); } 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 a426dd0202..35710a3087 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 @@ -42,7 +42,10 @@ import org.apache.maven.profiles.activation.ProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.build.ProfileAdvisor; import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.project.builder.*; +import org.apache.maven.project.builder.PomArtifactResolver; +import org.apache.maven.project.builder.ProjectBuilder; +import org.apache.maven.project.builder.PomInterpolatorTag; +import org.apache.maven.project.builder.PomClassicTransformer; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.project.workspace.ProjectWorkspace; @@ -133,30 +136,12 @@ public class DefaultMavenProjectBuilder if ( project == null ) { - List activeProfiles; - try - { - activeProfiles = getActiveProfilesFromModel(new PomClassicDomainModel( - new FileInputStream( projectDescriptor )).getModel(), config, projectDescriptor, true); - } catch (IOException e) - { - throw new ProjectBuildingException("", e.getMessage()); - } - - Properties activeProfileProperties = new Properties(); - for(Profile profile : activeProfiles) - { - activeProfileProperties.putAll(profile.getProperties()); - } - project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( config.getLocalRepository(), repositoryHelper.buildArtifactRepositories( - getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config, - activeProfileProperties ); + getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config ); project.setFile( projectDescriptor ); - - project = buildMavenProject( project.getModel(), config, projectDescriptor, project.getParentFile(), activeProfiles); + project = buildInternal( project.getModel(), config, projectDescriptor, project.getParentFile(), true ); Build build = project.getBuild(); // NOTE: setting this script-source root before path translation, because @@ -210,27 +195,9 @@ public class DefaultMavenProjectBuilder artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories( getSuperProject( config, artifact.getFile(), false ).getModel() ) ); - - List activeProfiles; - try - { - activeProfiles = this.getActiveProfilesFromModel(new PomClassicDomainModel( - new FileInputStream( artifact.getFile())).getModel(), config, artifact.getFile(), true); - } catch (IOException e) - { - throw new ProjectBuildingException("", e.getMessage()); - } - - Properties activeProfileProperties = new Properties(); - for(Profile profile : activeProfiles) - { - activeProfileProperties.putAll(profile.getProperties()); - } - project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( - config.getLocalRepository(), artifactRepositories, artifactResolver ), config, activeProfileProperties ); - project = buildMavenProject( project.getModel(), config, artifact.getFile(), project.getParentFile(), - activeProfiles); + config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); + project = buildInternal( project.getModel(), config, artifact.getFile(), project.getParentFile(), false ); } artifact.setFile( f ); @@ -429,9 +396,9 @@ public class DefaultMavenProjectBuilder return logger; } - private List getActiveProfilesFromModel(Model model, ProjectBuilderConfiguration config, - File projectDescriptor, boolean isReactorProject) - throws ProjectBuildingException + private MavenProject buildInternal( Model model, ProjectBuilderConfiguration config, File projectDescriptor, + File parentDescriptor, boolean isReactorProject ) + throws ProjectBuildingException { String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); @@ -456,21 +423,6 @@ public class DefaultMavenProjectBuilder profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false ); } - - List projectProfiles = new ArrayList(); - projectProfiles.addAll( profileAdvisor.applyActivatedProfiles( model, projectDescriptor, - isReactorProject, profileActivationContext ) ); - projectProfiles.addAll( profileAdvisor.applyActivatedExternalProfiles( model, projectDescriptor, - externalProfileManager ) ); - return projectProfiles; - } - - private MavenProject buildMavenProject( Model model, ProjectBuilderConfiguration config, File projectDescriptor, - File parentDescriptor, List projectProfiles ) - throws ProjectBuildingException - { - String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); - MavenProject project; try { @@ -481,6 +433,11 @@ public class DefaultMavenProjectBuilder throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e ); } + List projectProfiles = new ArrayList(); + projectProfiles.addAll( profileAdvisor.applyActivatedProfiles( project.getModel(), project.getFile(), + isReactorProject, profileActivationContext ) ); + projectProfiles.addAll( profileAdvisor.applyActivatedExternalProfiles( project.getModel(), project.getFile(), + externalProfileManager ) ); project.setActiveProfiles( projectProfiles ); projectWorkspace.storeProjectByCoordinate( project ); @@ -522,7 +479,35 @@ public class DefaultMavenProjectBuilder "Maven super-POM contains an invalid repository!", e ); } - superProject.setActiveProfiles( getActiveProfilesFromModel(model, config, projectDescriptor, isReactorProject) ); + String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); + + ProfileActivationContext profileActivationContext; + ProfileManager externalProfileManager = config.getGlobalProfileManager(); + if ( externalProfileManager != null ) + { + // used to trigger the caching of SystemProperties in the container context... + try + { + externalProfileManager.getActiveProfiles(); + } + catch ( ProfileActivationException e ) + { + throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", + projectDescriptor, e ); + } + profileActivationContext = externalProfileManager.getProfileActivationContext(); + } + else + { + profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false ); + } + + List superProjectProfiles = new ArrayList(); + superProjectProfiles.addAll( profileAdvisor.applyActivatedProfiles( model, projectDescriptor, isReactorProject, + profileActivationContext ) ); + superProjectProfiles.addAll( + profileAdvisor.applyActivatedExternalProfiles( model, projectDescriptor, externalProfileManager ) ); + superProject.setActiveProfiles( superProjectProfiles ); return superProject; } @@ -574,7 +559,7 @@ public class DefaultMavenProjectBuilder } private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, PomArtifactResolver resolver, - ProjectBuilderConfiguration config, Properties profileProperties ) + ProjectBuilderConfiguration config ) throws ProjectBuildingException { if ( projectDescriptor == null ) @@ -592,11 +577,6 @@ public class DefaultMavenProjectBuilder PomInterpolatorTag.SYSTEM_PROPERTIES.name())); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), PomInterpolatorTag.USER_PROPERTIES.name())); - if(profileProperties != null) - { - interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties( profileProperties, - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); - } if(config.getBuildStartTime() != null) { @@ -617,7 +597,7 @@ public class DefaultMavenProjectBuilder { throw new ProjectBuildingException( projectId, "File = " + projectDescriptor.getAbsolutePath(), e ); } - mavenProject.getProperties().putAll(profileProperties); + return mavenProject; } diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java index fc1546c389..c490c6ce9f 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java @@ -165,18 +165,7 @@ public final class ArtifactModelContainerFactory return ModelContainerAction.NOP; } } - else - { - if ( c.type.equals( type ) ) - { - return ModelContainerAction.DELETE; - } - else - { - return ModelContainerAction.NOP; - } - } - //TODO Verify - PluginManagement Section may make versions equal + return ModelContainerAction.DELETE;//TODO Verify - PluginManagement Section may make versions equal } if ( c.version.equals( version ) ) @@ -192,14 +181,7 @@ public final class ArtifactModelContainerFactory } else { - if ( c.type.equals( type ) ) - { - return ModelContainerAction.DELETE; - } - else - { - return ModelContainerAction.NOP; - } + return ModelContainerAction.DELETE; } } else