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 54800d058b..0a296ce6f2 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
@@ -68,7 +68,6 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.builder.PomInterpolatorTag;
@@ -156,9 +155,6 @@ public class DefaultPluginManager
@Requirement
private PluginRepository pluginRepository;
- @Requirement
- private ProjectBuilder projectBuilder;
-
public DefaultPluginManager()
{
pluginDescriptorBuilder = new PluginDescriptorBuilder();
diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java
index 8726c196d8..0b74386d09 100644
--- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java
+++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java
@@ -40,7 +40,6 @@ import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.repository.MavenRepositorySystem;
@@ -568,7 +567,7 @@ public class DefaultMavenExecutionRequestPopulator
ProfileActivationContext activationContext = request.getProfileActivationContext();
if ( activationContext == null )
{
- activationContext = new DefaultProfileActivationContext( request.getProperties(), false );
+ activationContext = new ProfileActivationContext( request.getProperties(), false );
}
activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() );
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 322f1517fa..223e048be8 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
@@ -24,7 +24,6 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-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.shared.model.ModelContainer;
@@ -87,7 +86,7 @@ public class DefaultProfileManager
private ProfileActivationContext createDefaultActivationContext()
{
- return new DefaultProfileActivationContext(System.getProperties(), false );
+ return new ProfileActivationContext(System.getProperties(), false );
}
public ProfileActivationContext getProfileActivationContext()
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java
deleted file mode 100644
index b534bef97e..0000000000
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package org.apache.maven.profiles.activation;
-
-/*
- * 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.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-public class DefaultProfileActivationContext
- implements ProfileActivationContext
-{
-
- private boolean isCustomActivatorFailureSuppressed;
-
- private final Properties executionProperties;
-
- List explicitlyActive;
-
- List explicitlyInactive;
-
- private List activeByDefault;
-
- public DefaultProfileActivationContext( Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
- {
- this.executionProperties = executionProperties;
- this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed;
- }
-
- public Properties getExecutionProperties()
- {
- return executionProperties;
- }
-
- public boolean isCustomActivatorFailureSuppressed()
- {
- return isCustomActivatorFailureSuppressed;
- }
-
- public void setCustomActivatorFailureSuppressed( boolean suppressed )
- {
- isCustomActivatorFailureSuppressed = suppressed;
- }
-
- public List getExplicitlyActiveProfileIds()
- {
- if ( explicitlyActive == null )
- {
- return Collections.EMPTY_LIST;
- }
-
- return explicitlyActive;
- }
-
- public void setExplicitlyActiveProfileIds( List active )
- {
- explicitlyActive = active;
- }
-
- public List getExplicitlyInactiveProfileIds()
- {
- if ( explicitlyInactive == null )
- {
- return Collections.EMPTY_LIST;
- }
-
- return explicitlyInactive;
- }
-
- public void setExplicitlyInactiveProfileIds( List inactive )
- {
- explicitlyInactive = inactive;
- }
-
- public void setActive( String profileId )
- {
- if ( explicitlyActive == null )
- {
- explicitlyActive = new ArrayList();
- }
-
- explicitlyActive.add( profileId );
- }
-
- public void setInactive( String profileId )
- {
- if ( explicitlyInactive == null )
- {
- explicitlyInactive = new ArrayList();
- }
-
- explicitlyInactive.add( profileId );
- }
-
- public boolean isExplicitlyActive( String profileId )
- {
- return ( explicitlyActive != null ) && explicitlyActive.contains( profileId );
- }
-
- public boolean isExplicitlyInactive( String profileId )
- {
- return ( explicitlyInactive != null ) && explicitlyInactive.contains( profileId );
- }
-
- public List getActiveByDefaultProfileIds()
- {
- if ( activeByDefault == null )
- {
- return Collections.EMPTY_LIST;
- }
-
- return activeByDefault;
- }
-
- public boolean isActiveByDefault( String profileId )
- {
- return ( activeByDefault != null ) && activeByDefault.contains( profileId );
- }
-
- public void setActiveByDefault( String profileId )
- {
- if ( activeByDefault == null )
- {
- activeByDefault = new ArrayList();
- }
-
- activeByDefault.add( profileId );
- }
-
- public void setActiveByDefaultProfileIds( List activeByDefault )
- {
- this.activeByDefault = activeByDefault;
- }
-
-}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
index fb35313231..128646b604 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
@@ -20,40 +20,133 @@ package org.apache.maven.profiles.activation;
*/
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
-public interface ProfileActivationContext
+public class ProfileActivationContext
{
- List getExplicitlyActiveProfileIds();
+ private boolean isCustomActivatorFailureSuppressed;
- List getExplicitlyInactiveProfileIds();
+ private final Properties executionProperties;
- Properties getExecutionProperties();
+ List explicitlyActive;
- boolean isCustomActivatorFailureSuppressed();
+ List explicitlyInactive;
- void setCustomActivatorFailureSuppressed( boolean suppressed );
+ private List activeByDefault;
- void setExplicitlyActiveProfileIds( List inactive );
+ public ProfileActivationContext( Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
+ {
+ this.executionProperties = executionProperties;
+ this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed;
+ }
- void setExplicitlyInactiveProfileIds( List inactive );
+ public Properties getExecutionProperties()
+ {
+ return executionProperties;
+ }
- void setActive( String profileId );
+ public boolean isCustomActivatorFailureSuppressed()
+ {
+ return isCustomActivatorFailureSuppressed;
+ }
- void setInactive( String profileId );
+ public void setCustomActivatorFailureSuppressed( boolean suppressed )
+ {
+ isCustomActivatorFailureSuppressed = suppressed;
+ }
- boolean isExplicitlyActive( String profileId );
+ public List getExplicitlyActiveProfileIds()
+ {
+ if ( explicitlyActive == null )
+ {
+ return Collections.EMPTY_LIST;
+ }
- boolean isExplicitlyInactive( String profileId );
+ return explicitlyActive;
+ }
- List getActiveByDefaultProfileIds();
+ public void setExplicitlyActiveProfileIds( List active )
+ {
+ explicitlyActive = active;
+ }
- void setActiveByDefaultProfileIds( List activeByDefault );
+ public List getExplicitlyInactiveProfileIds()
+ {
+ if ( explicitlyInactive == null )
+ {
+ return Collections.EMPTY_LIST;
+ }
- void setActiveByDefault( String profileId );
+ return explicitlyInactive;
+ }
- boolean isActiveByDefault( String profileId );
+ public void setExplicitlyInactiveProfileIds( List inactive )
+ {
+ explicitlyInactive = inactive;
+ }
+
+ public void setActive( String profileId )
+ {
+ if ( explicitlyActive == null )
+ {
+ explicitlyActive = new ArrayList();
+ }
+
+ explicitlyActive.add( profileId );
+ }
+
+ public void setInactive( String profileId )
+ {
+ if ( explicitlyInactive == null )
+ {
+ explicitlyInactive = new ArrayList();
+ }
+
+ explicitlyInactive.add( profileId );
+ }
+
+ public boolean isExplicitlyActive( String profileId )
+ {
+ return ( explicitlyActive != null ) && explicitlyActive.contains( profileId );
+ }
+
+ public boolean isExplicitlyInactive( String profileId )
+ {
+ return ( explicitlyInactive != null ) && explicitlyInactive.contains( profileId );
+ }
+
+ public List getActiveByDefaultProfileIds()
+ {
+ if ( activeByDefault == null )
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ return activeByDefault;
+ }
+
+ public boolean isActiveByDefault( String profileId )
+ {
+ return ( activeByDefault != null ) && activeByDefault.contains( profileId );
+ }
+
+ public void setActiveByDefault( String profileId )
+ {
+ if ( activeByDefault == null )
+ {
+ activeByDefault = new ArrayList();
+ }
+
+ activeByDefault.add( profileId );
+ }
+
+ public void setActiveByDefaultProfileIds( List activeByDefault )
+ {
+ this.activeByDefault = activeByDefault;
+ }
}
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 56639aec1f..b2ea337416 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
@@ -20,599 +20,150 @@ package org.apache.maven.profiles.injection;
*/
import org.apache.maven.model.*;
-import org.apache.maven.project.ModelUtils;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.builder.*;
+import org.apache.maven.shared.model.ModelProperty;
+import org.apache.maven.shared.model.ModelMarshaller;
+import org.apache.maven.shared.model.ModelTransformerContext;
import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlSerializer;
+import org.codehaus.plexus.util.xml.pull.MXSerializer;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.ReaderFactory;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
+import java.io.*;
+import java.lang.reflect.Method;
/**
* Inject profile data into a Model, using the profile as the dominant data source, and
* persisting results of the injection in the Model.
- *
- * This will look similar to the ModelUtils/DefaultModelInheritanceAssembler code, but
- * they are distinct. In model inheritance, the child provides data dominance AND persists
- * the results of the merge...sort of a 'merge-out' system.
- *
- * In this system, the profile is dominant, but the model receives the merge result...sort
- * of a 'merge-in' system. The two pieces of code look like they could be combined with a
- * set of flags to determine which direction to merge 'to', but there are enough differences
- * in the code to justify the extra code involved with separating them, in order to simplify
- * the logic.
*/
@Component(role = ProfileInjector.class)
public class DefaultProfileInjector
implements ProfileInjector
{
- public void inject( Profile profile, Model model )
+ public Model inject( Profile profile, Model model )
{
-
- model.setDependencies( injectDependencies( profile.getDependencies(), model.getDependencies() ) );
-
- injectModules( profile, model );
-
- model.setRepositories( ModelUtils.mergeRepositoryLists( profile.getRepositories(), model.getRepositories() ) );
- model.setPluginRepositories( ModelUtils.mergeRepositoryLists( profile.getPluginRepositories(), model.getPluginRepositories() ) );
-
- injectReporting( profile, model );
-
- injectDependencyManagement( profile, model );
-
- injectDistributionManagement( profile, model );
-
- injectBuild( profile, model );
-
- Properties props = new Properties();
- props.putAll( model.getProperties() );
- props.putAll( profile.getProperties() );
-
- model.setProperties( props );
- }
-
- private void injectBuild( Profile profile, Model model )
- {
- BuildBase profileBuild = profile.getBuild();
- Build modelBuild = model.getBuild();
-
- // if the parent build is null, obviously we cannot inherit from it...
- if ( profileBuild != null )
+ //TODO: Using reflection now. Need to replace with custom mapper
+ StringWriter writer = new StringWriter();
+ XmlSerializer serializer = new MXSerializer();
+ serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
+ serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
+ try
{
- if ( modelBuild == null )
- {
- modelBuild = new Build();
- model.setBuild( modelBuild );
- }
+ serializer.setOutput( writer );
+ serializer.startDocument("UTF-8", null );
+ } catch (IOException e) {
- if ( profileBuild.getDirectory() != null )
- {
- modelBuild.setDirectory( profileBuild.getDirectory() );
- }
-
- if ( profileBuild.getDefaultGoal() != null )
- {
- modelBuild.setDefaultGoal( profileBuild.getDefaultGoal() );
- }
-
- if ( profileBuild.getFinalName() != null )
- {
- modelBuild.setFinalName( profileBuild.getFinalName() );
- }
-
- ModelUtils.mergeFilterLists( modelBuild.getFilters(), profileBuild.getFilters() );
- mergeResourceLists( modelBuild.getResources(), profileBuild.getResources() );
- mergeResourceLists( modelBuild.getTestResources(), profileBuild.getTestResources() );
-
- injectPlugins( profileBuild, modelBuild );
-
- // Plugin management :: aggregate
- PluginManagement profilePM = profileBuild.getPluginManagement();
- PluginManagement modelPM = modelBuild.getPluginManagement();
-
- if ( modelPM == null )
- {
- modelBuild.setPluginManagement( profilePM );
- }
- else
- {
- injectPlugins( profilePM, modelPM );
- }
- }
- }
-
- /**
- * This should be the resulting ordering of plugins after injection:
- *
- * Given:
- *
- * model: X -> A -> B -> D -> E
- * profile: Y -> A -> C -> D -> F
- *
- * Result:
- *
- * X -> Y -> A -> B -> C -> D -> E -> F
- */
- protected void injectPlugins( PluginContainer profileContainer, PluginContainer modelContainer )
- {
- if ( ( profileContainer == null ) || ( modelContainer == null ) )
- {
- // nothing to do...
- return;
}
- List modelPlugins = modelContainer.getPlugins();
+ try {
+ MavenXpp3Writer w = new MavenXpp3Writer();
+ Class c = Class.forName("org.apache.maven.model.io.xpp3.MavenXpp3Writer");
- if ( modelPlugins == null )
- {
- modelContainer.setPlugins( profileContainer.getPlugins() );
+ Class partypes[] = new Class[3];
+ partypes[0] = Profile.class;
+ partypes[1] = String.class;
+ partypes[2] = XmlSerializer.class;
+
+ Method meth = c.getDeclaredMethod(
+ "writeProfile", partypes);
+ meth.setAccessible(true);
+
+ Object arglist[] = new Object[3];
+ arglist[0] = profile;
+ arglist[1] = "profile";
+ arglist[2] = serializer;
+
+ meth.invoke(w, arglist);
+ serializer.endDocument();
}
- else if ( profileContainer.getPlugins() != null )
+ catch (Exception e)
{
- List mergedPlugins = new ArrayList();
+ return null;
+ }
+ Set uris = new HashSet(PomTransformer.URIS);
+ uris.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration);
- Map profilePlugins = profileContainer.getPluginsAsMap();
+ List p;
+ try
+ {
+ p = ModelMarshaller.marshallXmlToModelProperties(new ByteArrayInputStream(writer.getBuffer().toString().getBytes()),
+ ProjectUri.Profiles.xUri, uris);
+ } catch (IOException e) {
+ return null;
+ }
- for ( Iterator it = modelPlugins.iterator(); it.hasNext(); )
+ List transformed = new ArrayList();
+ for(ModelProperty mp : p)
{
- Plugin modelPlugin = (Plugin) it.next();
-
- Plugin profilePlugin = (Plugin) profilePlugins.get( modelPlugin.getKey() );
-
- if ( ( profilePlugin != null ) && !mergedPlugins.contains( profilePlugin ) )
+ if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
+ && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri) )
{
- Plugin mergedPlugin = modelPlugin;
-
- injectPluginDefinition( profilePlugin, modelPlugin );
-
- mergedPlugins.add( mergedPlugin );
+ transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
+ mp.getResolvedValue()));
}
}
- List results = ModelUtils.orderAfterMerge( mergedPlugins, modelPlugins, profileContainer.getPlugins() );
+ PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
+ ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
- modelContainer.setPlugins( results );
-
- modelContainer.flushPluginMap();
+ PomClassicDomainModel transformedDomainModel;
+ try {
+ transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( Arrays.asList( new PomClassicDomainModel(transformed), convertToDomainModel(model)),
+ transformer,
+ transformer,
+ Collections.EMPTY_LIST,
+ null,
+ null ) );
+ return convertFromInputStreamToModel(transformedDomainModel.getInputStream());
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
}
+
+
}
- private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
+ private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
{
- if ( ( profilePlugin == null ) || ( modelPlugin == null ) )
+ if ( model == null )
{
- // nothing to do.
- return;
+ throw new IllegalArgumentException( "model: null" );
}
-
- if ( profilePlugin.isExtensions() )
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer out = null;
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ try
{
- modelPlugin.setExtensions( true );
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
}
-
- if ( profilePlugin.getVersion() != null )
+ finally
{
- modelPlugin.setVersion( profilePlugin.getVersion() );
- }
-
- modelPlugin.setDependencies(
- injectDependencies( profilePlugin.getDependencies(), modelPlugin.getDependencies() ) );
-
- // merge the lists of goals that are not attached to an
- injectConfigurationContainer( profilePlugin, modelPlugin );
-
- // from here to the end of the method is dealing with merging of the section.
- List modelExecutions = modelPlugin.getExecutions();
-
- if ( ( modelExecutions == null ) || modelExecutions.isEmpty() )
- {
- modelPlugin.setExecutions( profilePlugin.getExecutions() );
- }
- else
- {
- Map executions = new LinkedHashMap();
-
- Map profileExecutions = profilePlugin.getExecutionsAsMap();
-
- for ( Iterator it = modelExecutions.iterator(); it.hasNext(); )
+ if ( out != null )
{
- PluginExecution modelExecution = (PluginExecution) it.next();
-
- PluginExecution profileExecution = (PluginExecution) profileExecutions.get( modelExecution.getId() );
-
- if ( profileExecution != null )
- {
- injectConfigurationContainer( profileExecution, modelExecution );
-
- if ( profileExecution.getPhase() != null )
- {
- modelExecution.setPhase( profileExecution.getPhase() );
- }
-
- List profileGoals = profileExecution.getGoals();
- List modelGoals = modelExecution.getGoals();
-
- List goals = new ArrayList();
-
- if ( ( modelGoals != null ) && !modelGoals.isEmpty() )
- {
- goals.addAll( modelGoals );
- }
-
- if ( profileGoals != null )
- {
- for ( Iterator goalIterator = profileGoals.iterator(); goalIterator.hasNext(); )
- {
- String goal = (String) goalIterator.next();
-
- if ( !goals.contains( goal ) )
- {
- goals.add( goal );
- }
- }
- }
-
- modelExecution.setGoals( goals );
- }
-
- executions.put( modelExecution.getId(), modelExecution );
+ out.close();
}
-
- for ( Iterator it = profileExecutions.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- String id = (String) entry.getKey();
-
- if ( !executions.containsKey( id ) )
- {
- executions.put( id, entry.getValue() );
- }
- }
-
- modelPlugin.setExecutions( new ArrayList( executions.values() ) );
-
- modelPlugin.flushExecutionMap();
}
-
+ return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
}
- /**
- * Merge two DOMs. Copy the dominant DOM so the original one is left unchanged.
- *
- * Use this method instead of a direct call to {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}.
- * Profiles are dominant, thus they are merge targets, but they may be merged in several times
- * (e.g. if they are inherited). So with the second merge, you don't get the profile's original
- * DOM, but an already merged one.
- *
- * @param dominant Dominant DOM
- * @param recessive Recessive DOM
- * @return Merged DOM
- */
- private Xpp3Dom merge( Xpp3Dom dominant, Xpp3Dom recessive )
+ private static Model convertFromInputStreamToModel(InputStream inputStream) throws IOException
{
- Xpp3Dom dominantCopy = ( dominant == null ) ? null : new Xpp3Dom( dominant );
- return Xpp3Dom.mergeXpp3Dom( dominantCopy, recessive );
+
+ try
+ {
+ return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+
}
- private void injectConfigurationContainer( ConfigurationContainer profileContainer,
- ConfigurationContainer modelContainer )
- {
- Xpp3Dom configuration = (Xpp3Dom) profileContainer.getConfiguration();
- Xpp3Dom parentConfiguration = (Xpp3Dom) modelContainer.getConfiguration();
-
- configuration = merge( configuration, parentConfiguration );
-
- modelContainer.setConfiguration( configuration );
- }
-
- /**
- * Append modules specified in the profile to the end of the list supplied by the model, if
- * they don't already exist.
- */
- private void injectModules( Profile profile, Model model )
- {
- List modules = new ArrayList();
-
- List modelModules = model.getModules();
-
- if ( ( modelModules != null ) && !modelModules.isEmpty() )
- {
- modules.addAll( modelModules );
- }
-
- List profileModules = profile.getModules();
-
- if ( profileModules != null )
- {
- for ( Iterator it = profileModules.iterator(); it.hasNext(); )
- {
- String module = (String) it.next();
-
- if ( !modules.contains( module ) )
- {
- modules.add( module );
- }
- }
- }
-
- model.setModules( modules );
- }
-
- private void injectDistributionManagement( Profile profile, Model model )
- {
- DistributionManagement pDistMgmt = profile.getDistributionManagement();
- DistributionManagement mDistMgmt = model.getDistributionManagement();
-
- if ( mDistMgmt == null )
- {
- model.setDistributionManagement( pDistMgmt );
- }
- else if ( pDistMgmt != null )
- {
- if ( pDistMgmt.getRepository() != null )
- {
- mDistMgmt.setRepository( pDistMgmt.getRepository() );
- }
-
- if ( pDistMgmt.getSnapshotRepository() != null )
- {
- mDistMgmt.setSnapshotRepository( pDistMgmt.getSnapshotRepository() );
- }
-
- if ( StringUtils.isNotEmpty( pDistMgmt.getDownloadUrl() ) )
- {
- mDistMgmt.setDownloadUrl( pDistMgmt.getDownloadUrl() );
- }
-
- if ( pDistMgmt.getRelocation() != null )
- {
- mDistMgmt.setRelocation( pDistMgmt.getRelocation() );
- }
-
- if ( pDistMgmt.getSite() != null )
- {
- mDistMgmt.setSite( pDistMgmt.getSite() );
- }
-
- // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
- }
- }
-
- private void injectDependencyManagement( Profile profile, Model model )
- {
- DependencyManagement modelDepMgmt = model.getDependencyManagement();
-
- DependencyManagement profileDepMgmt = profile.getDependencyManagement();
-
- if ( profileDepMgmt != null )
- {
- if ( modelDepMgmt == null )
- {
- model.setDependencyManagement( profileDepMgmt );
- }
- else
- {
- Map depsMap = new LinkedHashMap();
-
- List deps = modelDepMgmt.getDependencies();
-
- if ( deps != null )
- {
- for ( Iterator it = deps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- deps = profileDepMgmt.getDependencies();
-
- if ( deps != null )
- {
- for ( Iterator it = deps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- modelDepMgmt.setDependencies( new ArrayList( depsMap.values() ) );
- }
- }
- }
-
- private void injectReporting( Profile profile, Model model )
- {
- // Reports :: aggregate
- Reporting profileReporting = profile.getReporting();
- Reporting modelReporting = model.getReporting();
-
- if ( profileReporting != null )
- {
- if ( modelReporting == null )
- {
- model.setReporting( profileReporting );
- }
- else
- {
- if ( StringUtils.isEmpty( modelReporting.getOutputDirectory() ) )
- {
- modelReporting.setOutputDirectory( profileReporting.getOutputDirectory() );
- }
-
- Map mergedReportPlugins = new LinkedHashMap();
-
- Map profileReportersByKey = profileReporting.getReportPluginsAsMap();
-
- List modelReportPlugins = modelReporting.getPlugins();
-
- if ( modelReportPlugins != null )
- {
- for ( Iterator it = modelReportPlugins.iterator(); it.hasNext(); )
- {
- ReportPlugin modelReportPlugin = (ReportPlugin) it.next();
-
- String inherited = modelReportPlugin.getInherited();
-
- if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
- {
- ReportPlugin profileReportPlugin = (ReportPlugin) profileReportersByKey
- .get( modelReportPlugin.getKey() );
-
- ReportPlugin mergedReportPlugin = modelReportPlugin;
-
- if ( profileReportPlugin != null )
- {
- mergedReportPlugin = profileReportPlugin;
-
- mergeReportPlugins( profileReportPlugin, modelReportPlugin );
- }
- else if ( StringUtils.isEmpty( inherited ) )
- {
- mergedReportPlugin.unsetInheritanceApplied();
- }
-
- mergedReportPlugins.put( mergedReportPlugin.getKey(), mergedReportPlugin );
- }
- }
- }
-
- for ( Iterator it = profileReportersByKey.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- String key = (String) entry.getKey();
-
- if ( !mergedReportPlugins.containsKey( key ) )
- {
- mergedReportPlugins.put( key, entry.getValue() );
- }
- }
-
- modelReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
-
- modelReporting.flushReportPluginMap();
- }
- }
- }
-
- private void mergeReportPlugins( ReportPlugin dominant, ReportPlugin recessive )
- {
- if ( StringUtils.isEmpty( recessive.getVersion() ) )
- {
- recessive.setVersion( dominant.getVersion() );
- }
-
- Xpp3Dom dominantConfig = (Xpp3Dom) dominant.getConfiguration();
- Xpp3Dom recessiveConfig = (Xpp3Dom) recessive.getConfiguration();
-
- recessive.setConfiguration( merge( dominantConfig, recessiveConfig ) );
-
- Map mergedReportSets = new LinkedHashMap();
-
- Map dominantReportSetsById = dominant.getReportSetsAsMap();
-
- for ( Iterator it = recessive.getReportSets().iterator(); it.hasNext(); )
- {
- ReportSet recessiveReportSet = (ReportSet) it.next();
-
- ReportSet dominantReportSet = (ReportSet) dominantReportSetsById.get( recessiveReportSet.getId() );
-
- ReportSet merged = recessiveReportSet;
-
- if ( dominantReportSet != null )
- {
- merged = recessiveReportSet;
-
- Xpp3Dom dominantRSConfig = (Xpp3Dom) dominantReportSet.getConfiguration();
- Xpp3Dom mergedRSConfig = (Xpp3Dom) merged.getConfiguration();
-
- merged.setConfiguration( merge( dominantRSConfig, mergedRSConfig ) );
-
- List mergedReports = merged.getReports();
-
- if ( mergedReports == null )
- {
- mergedReports = new ArrayList();
-
- merged.setReports( mergedReports );
- }
-
- List dominantRSReports = dominantReportSet.getReports();
-
- if ( dominantRSReports != null )
- {
- for ( Iterator reportIterator = dominantRSReports.iterator(); reportIterator.hasNext(); )
- {
- String report = (String) reportIterator.next();
-
- if ( !mergedReports.contains( report ) )
- {
- mergedReports.add( report );
- }
- }
- }
-
- mergedReportSets.put( merged.getId(), merged );
- }
- }
-
- for ( Iterator rsIterator = dominantReportSetsById.entrySet().iterator(); rsIterator.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) rsIterator.next();
-
- String key = (String) entry.getKey();
-
- if ( !mergedReportSets.containsKey( key ) )
- {
- mergedReportSets.put( key, entry.getValue() );
- }
- }
-
- recessive.setReportSets( new ArrayList( mergedReportSets.values() ) );
-
- recessive.flushReportSetMap();
- }
-
- private List injectDependencies( List profileDeps, List modelDeps )
- {
- Map depsMap = new LinkedHashMap();
-
- if ( modelDeps != null )
- {
- for ( Iterator it = modelDeps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- if ( profileDeps != null )
- {
- for ( Iterator it = profileDeps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- return new ArrayList( depsMap.values() );
- }
-
- private static void mergeResourceLists( List childResources, List parentResources )
- {
- for ( Iterator i = parentResources.iterator(); i.hasNext(); )
- {
- Resource r = (Resource) i.next();
- if ( !childResources.contains( r ) )
- {
- childResources.add( r );
- }
- }
- }
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/injection/ProfileInjector.java b/maven-project/src/main/java/org/apache/maven/profiles/injection/ProfileInjector.java
index b2ba7a8daf..956b437359 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/injection/ProfileInjector.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/injection/ProfileInjector.java
@@ -26,6 +26,6 @@ public interface ProfileInjector
{
String ROLE = ProfileInjector.class.getName();
- void inject( Profile profile, Model model );
+ Model inject( Profile profile, 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 82b0af02c6..3edfe96ad7 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
@@ -19,13 +19,9 @@ package org.apache.maven.project;
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
@@ -38,23 +34,30 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.profiles.ProfileManager;
-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.build.ProfileAdvisor;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.builder.PomInterpolatorTag;
+import org.apache.maven.project.builder.*;
+import org.apache.maven.project.builder.profile.ProfileContext;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.repository.MavenRepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
-import org.apache.maven.shared.model.InterpolatorProperty;
+import org.apache.maven.shared.model.*;
+import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@@ -74,7 +77,7 @@ public class DefaultMavenProjectBuilder
private MavenRepositorySystem repositorySystem;
@Requirement
- private ProjectBuilder projectBuilder;
+ List listeners;
private Logger logger;
@@ -117,7 +120,7 @@ public class DefaultMavenProjectBuilder
List artifactRepositories = new ArrayList();
try
{
- artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel().getRepositories() ) );
+ artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( getSuperModel().getRepositories() ) );
}
catch ( InvalidRepositoryException e )
{
@@ -185,7 +188,7 @@ public class DefaultMavenProjectBuilder
List artifactRepositories = new ArrayList( remoteArtifactRepositories );
try
{
- artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel().getRepositories() ) );
+ artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( getSuperModel().getRepositories() ) );
}
catch ( InvalidRepositoryException e )
{
@@ -231,7 +234,7 @@ public class DefaultMavenProjectBuilder
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
throws ProjectBuildingException
{
- Model superModel = projectBuilder.getSuperModel();
+ Model superModel = getSuperModel();
MavenProject project = null;
@@ -322,7 +325,7 @@ public class DefaultMavenProjectBuilder
}
else
{
- profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
+ profileActivationContext = new ProfileActivationContext( config.getExecutionProperties(), false );
}
List projectProfiles = new ArrayList();
@@ -382,7 +385,7 @@ public class DefaultMavenProjectBuilder
try
{
- mavenProject = projectBuilder.buildFromLocalPath( projectDescriptor, interpolatorProperties, resolver, config, this );
+ mavenProject = buildFromLocalPath( projectDescriptor, interpolatorProperties, resolver, config, this );
}
catch ( IOException e )
{
@@ -439,4 +442,424 @@ public class DefaultMavenProjectBuilder
setBuildOutputDirectoryOnParent( parent );
}
}
+
+ public PomClassicDomainModel buildModel( File pom,
+ Collection interpolatorProperties,
+ PomArtifactResolver resolver )
+ throws IOException
+ {
+ return buildModel( pom, interpolatorProperties, null, null, resolver );
+ }
+
+ private PomClassicDomainModel buildModel(File pom,
+ Collection interpolatorProperties,
+ Collection activeProfileIds, Collection inactiveProfileIds,
+ PomArtifactResolver resolver)
+ throws IOException
+ {
+ if ( pom == null )
+ {
+ throw new IllegalArgumentException( "pom: null" );
+ }
+
+ if ( resolver == null )
+ {
+ throw new IllegalArgumentException( "resolver: null" );
+ }
+
+ if(activeProfileIds == null)
+ {
+ activeProfileIds = new ArrayList();
+ }
+ if ( inactiveProfileIds == null )
+ {
+ inactiveProfileIds = new ArrayList();
+ }
+
+ List properties;
+ if ( interpolatorProperties == null )
+ {
+ properties = new ArrayList();
+ }
+ else
+ {
+ properties = new ArrayList( interpolatorProperties );
+ }
+
+ PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
+ domainModel.setProjectDirectory( pom.getParentFile() );
+ List domainModels = new ArrayList();
+ domainModels.add( domainModel );
+
+ //Process Profile on most specialized child model
+ ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(domainModel.getModelProperties(),
+ PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
+
+ Collection profileContainers = profileContext.getActiveProfiles();
+
+ for(ModelContainer mc : profileContainers)
+ {
+ List transformed = new ArrayList();
+ //transformed.add(new ModelProperty(ProjectUri.xUri, null));
+ for(ModelProperty mp : mc.getProperties())
+ {
+ if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
+ && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri) )
+ {
+ transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
+ mp.getResolvedValue()));
+ }
+ }
+ domainModels.add(new PomClassicDomainModel(transformed));
+ }
+
+ File parentFile = null;
+ int lineageCount = 0;
+ if ( domainModel.getParentId() != null )
+ {
+ List mavenParents;
+ if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
+ {
+ mavenParents =
+ getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
+ activeProfileIds, inactiveProfileIds );
+ }
+ else
+ {
+ mavenParents =
+ getDomainModelParentsFromRepository( domainModel, resolver, properties, activeProfileIds,
+ inactiveProfileIds );
+ }
+
+ if ( mavenParents.size() > 0 )
+ {
+ PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
+ parentFile = dm.getFile();
+ domainModel.setParentFile( parentFile );
+ lineageCount = mavenParents.size();
+ }
+
+ domainModels.addAll( mavenParents );
+ }
+
+ domainModels.add( convertToDomainModel( getSuperModel() ) );
+
+ PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
+
+ ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
+
+ PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
+ transformer,
+ transformer,
+ Collections.EMPTY_LIST,
+ properties,
+ listeners ) );
+ // Lineage count is inclusive to add the POM read in itself.
+ transformedDomainModel.setLineageCount( lineageCount + 1 );
+ transformedDomainModel.setParentFile( parentFile );
+
+ return transformedDomainModel;
+ }
+
+ private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
+ {
+ if ( model == null )
+ {
+ throw new IllegalArgumentException( "model: null" );
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer out = null;
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ try
+ {
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
+ return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
+ }
+
+ public MavenProject buildFromLocalPath(File pom,
+ Collection interpolatorProperties,
+ PomArtifactResolver resolver,
+ ProjectBuilderConfiguration projectBuilderConfiguration,
+ MavenProjectBuilder mavenProjectBuilder)
+ throws IOException
+ {
+
+ List activeProfileIds = (projectBuilderConfiguration != null &&
+ projectBuilderConfiguration.getGlobalProfileManager() != null &&
+ projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext() != null) ?
+ projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyActiveProfileIds() : new ArrayList();
+
+ List inactiveProfileIds =
+ ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null &&
+ projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext() != null ) ?
+ projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds() : new ArrayList();
+
+ PomClassicDomainModel domainModel = buildModel( pom,
+ interpolatorProperties,
+ activeProfileIds, inactiveProfileIds,
+ resolver );
+
+ try
+ {
+ MavenProject mavenProject = new MavenProject( convertFromInputStreamToModel(domainModel.getInputStream()),
+ repositorySystem,
+ mavenProjectBuilder,
+ projectBuilderConfiguration );
+
+ mavenProject.setParentFile( domainModel.getParentFile() );
+
+ return mavenProject;
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ }
+
+ private static Model convertFromInputStreamToModel(InputStream inputStream) throws IOException
+ {
+
+ try
+ {
+ return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+
+ }
+
+ /**
+ * Returns true if the relative path of the specified parent references a pom, otherwise returns false.
+ *
+ * @param relativePath the parent model info
+ * @param projectDirectory the project directory of the child pom
+ * @return true if the relative path of the specified parent references a pom, otherwise returns fals
+ */
+ private boolean isParentLocal( String relativePath, File projectDirectory )
+ {
+ try
+ {
+ File f = new File( projectDirectory, relativePath ).getCanonicalFile();
+
+ if ( f.isDirectory() )
+ {
+ f = new File( f, "pom.xml" );
+ }
+
+ return f.isFile();
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ }
+
+ private List getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
+ PomArtifactResolver artifactResolver,
+ List properties,
+ Collection activeProfileIds,
+ Collection inactiveProfileIds )
+ throws IOException
+ {
+ List domainModels = new ArrayList();
+
+ String parentId = domainModel.getParentId();
+
+ if ( parentId == null )
+ {
+ return domainModels;
+ }
+
+ Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
+ domainModel.getParentArtifactId(), domainModel.getParentVersion() );
+
+ artifactResolver.resolve( artifactParent );
+
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
+
+ if ( !parentDomainModel.matchesParentOf( domainModel ) )
+ {
+ logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
+ ": Child ID = " + domainModel.getId() );
+ return domainModels;
+ }
+
+ domainModels.add( parentDomainModel );
+
+ //Process Profiles
+ ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(),
+ PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
+ Collection profileContainers = profileContext.getActiveProfiles();
+
+ for(ModelContainer mc : profileContainers)
+ {
+ List transformed = new ArrayList();
+ transformed.add(new ModelProperty(ProjectUri.xUri, null));
+ for(ModelProperty mp : mc.getProperties())
+ {
+ if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
+ && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri) )
+ {
+ transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
+ mp.getResolvedValue()));
+ }
+ }
+
+ domainModels.add(new PomClassicDomainModel(transformed));
+ }
+
+ domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver, properties,
+ activeProfileIds, inactiveProfileIds ) );
+ return domainModels;
+ }
+
+ /**
+ * Returns list of domain model parents of the specified domain model. The parent domain models are part
+ *
+ * @param domainModel
+ * @param artifactResolver
+ * @param projectDirectory
+ * @return
+ * @throws IOException
+ */
+ private List getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
+ PomArtifactResolver artifactResolver,
+ File projectDirectory,
+ List properties,
+ Collection activeProfileIds,
+ Collection inactiveProfileIds )
+ throws IOException
+ {
+ List domainModels = new ArrayList();
+
+ String parentId = domainModel.getParentId();
+
+ if ( parentId == null )
+ {
+ return domainModels;
+ }
+
+ File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile();
+ if ( parentFile.isDirectory() )
+ {
+ parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
+ }
+
+ if ( !parentFile.isFile() )
+ {
+ throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
+ }
+
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
+ parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
+
+ //Process Profiles
+ ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(),
+ PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
+ Collection profileContainers = profileContext.getActiveProfiles();
+
+ for(ModelContainer mc : profileContainers)
+ {
+ List transformed = new ArrayList();
+ transformed.add(new ModelProperty(ProjectUri.xUri, null));
+ for(ModelProperty mp : mc.getProperties())
+ {
+ if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
+ && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri))
+ {
+ transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
+ mp.getResolvedValue()));
+ }
+ }
+ domainModels.add(new PomClassicDomainModel(transformed));
+ }
+
+ if ( !parentDomainModel.matchesParentOf( domainModel ) )
+ {
+ logger.info( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
+ + parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
+ + domainModel.getParentId() );
+
+ List parentDomainModels =
+ getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
+ inactiveProfileIds );
+
+ if(parentDomainModels.size() == 0)
+ {
+ throw new IOException("Unable to find parent pom on local path or repo: "
+ + domainModel.getParentId());
+ }
+
+ domainModels.addAll( parentDomainModels );
+ return domainModels;
+ }
+
+ domainModels.add( parentDomainModel );
+ if ( domainModel.getParentId() != null )
+ {
+ if ( isParentLocal(parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
+ {
+ domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
+ parentFile.getParentFile(), properties,
+ activeProfileIds, inactiveProfileIds ) );
+ }
+ else
+ {
+ domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver,
+ properties, activeProfileIds,
+ inactiveProfileIds ) );
+ }
+ }
+
+ return domainModels;
+ }
+
+ private DomainModel superDomainModel;
+
+ // Super Model Handling
+
+ private static final String MAVEN_MODEL_VERSION = "4.0.0";
+
+ private MavenXpp3Reader modelReader = new MavenXpp3Reader();
+
+ private Model superModel;
+
+ public Model getSuperModel()
+ {
+ if ( superModel != null )
+ {
+ return superModel;
+ }
+
+ Reader reader = null;
+
+ try
+ {
+ reader = ReaderFactory.newXmlReader( getClass().getClassLoader().getResource( "org/apache/maven/project/pom-" + MAVEN_MODEL_VERSION + ".xml" ) );
+
+ superModel = modelReader.read( reader, true );
+ }
+ catch ( Exception e )
+ {
+ // Not going to happen we're reading the super pom embedded in the JAR
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return superModel;
+ }
+
}
\ No newline at end of file
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
deleted file mode 100644
index 0e06275cb8..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ /dev/null
@@ -1,492 +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.io.*;
-import java.util.*;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.InvalidRepositoryException;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.project.builder.*;
-import org.apache.maven.project.builder.profile.ProfileContext;
-import org.apache.maven.repository.MavenRepositorySystem;
-import org.apache.maven.shared.model.*;
-import org.apache.maven.shared.model.impl.DefaultModelDataSource;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.LogEnabled;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.WriterFactory;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-/**
- * Default implementation of the project builder.
- */
-@Component(role = ProjectBuilder.class)
-public class DefaultProjectBuilder
- implements ProjectBuilder, LogEnabled
-{
- @Requirement
- private MavenRepositorySystem repositorySystem;
-
- @Requirement
- List listeners;
-
- private Logger logger;
-
- public PomClassicDomainModel buildModel( File pom,
- Collection interpolatorProperties,
- PomArtifactResolver resolver )
- throws IOException
- {
- return buildModel( pom, interpolatorProperties, null, null, resolver );
- }
-
- private PomClassicDomainModel buildModel(File pom,
- Collection interpolatorProperties,
- Collection activeProfileIds, Collection inactiveProfileIds,
- PomArtifactResolver resolver)
- throws IOException
- {
- if ( pom == null )
- {
- throw new IllegalArgumentException( "pom: null" );
- }
-
- if ( resolver == null )
- {
- throw new IllegalArgumentException( "resolver: null" );
- }
-
- if(activeProfileIds == null)
- {
- activeProfileIds = new ArrayList();
- }
- if ( inactiveProfileIds == null )
- {
- inactiveProfileIds = new ArrayList();
- }
-
- List properties;
- if ( interpolatorProperties == null )
- {
- properties = new ArrayList();
- }
- else
- {
- properties = new ArrayList( interpolatorProperties );
- }
-
- PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
- domainModel.setProjectDirectory( pom.getParentFile() );
- List domainModels = new ArrayList();
- domainModels.add( domainModel );
-
- //Process Profile on most specialized child model
- ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(domainModel.getModelProperties(),
- PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
-
- Collection profileContainers = profileContext.getActiveProfiles();
-
- for(ModelContainer mc : profileContainers)
- {
- List transformed = new ArrayList();
- //transformed.add(new ModelProperty(ProjectUri.xUri, null));
- for(ModelProperty mp : mc.getProperties())
- {
- if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
- && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri) )
- {
- transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
- mp.getResolvedValue()));
- }
- }
- domainModels.add(new PomClassicDomainModel(transformed));
- }
-
- File parentFile = null;
- int lineageCount = 0;
- if ( domainModel.getParentId() != null )
- {
- List mavenParents;
- if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
- {
- mavenParents =
- getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
- activeProfileIds, inactiveProfileIds );
- }
- else
- {
- mavenParents =
- getDomainModelParentsFromRepository( domainModel, resolver, properties, activeProfileIds,
- inactiveProfileIds );
- }
-
- if ( mavenParents.size() > 0 )
- {
- PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
- parentFile = dm.getFile();
- domainModel.setParentFile( parentFile );
- lineageCount = mavenParents.size();
- }
-
- domainModels.addAll( mavenParents );
- }
-
- domainModels.add( convertToDomainModel( getSuperModel() ) );
-
- PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
-
- ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
-
- PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
- transformer,
- transformer,
- Collections.EMPTY_LIST,
- properties,
- listeners ) );
- // Lineage count is inclusive to add the POM read in itself.
- transformedDomainModel.setLineageCount( lineageCount + 1 );
- transformedDomainModel.setParentFile( parentFile );
-
- return transformedDomainModel;
- }
-
- private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
- {
- if ( model == null )
- {
- throw new IllegalArgumentException( "model: null" );
- }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer out = null;
- MavenXpp3Writer writer = new MavenXpp3Writer();
- try
- {
- out = WriterFactory.newXmlWriter( baos );
- writer.write( out, model );
- }
- finally
- {
- if ( out != null )
- {
- out.close();
- }
- }
- return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
- }
-
- public MavenProject buildFromLocalPath(File pom,
- Collection interpolatorProperties,
- PomArtifactResolver resolver,
- ProjectBuilderConfiguration projectBuilderConfiguration,
- MavenProjectBuilder mavenProjectBuilder)
- throws IOException
- {
-
- List activeProfileIds = (projectBuilderConfiguration != null &&
- projectBuilderConfiguration.getGlobalProfileManager() != null &&
- projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext() != null) ?
- projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyActiveProfileIds() : new ArrayList();
-
- List inactiveProfileIds =
- ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null &&
- projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext() != null ) ?
- projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds() : new ArrayList();
-
- PomClassicDomainModel domainModel = buildModel( pom,
- interpolatorProperties,
- activeProfileIds, inactiveProfileIds,
- resolver );
-
- try
- {
- MavenProject mavenProject = new MavenProject( convertFromInputStreamToModel(domainModel.getInputStream()),
- repositorySystem,
- mavenProjectBuilder,
- projectBuilderConfiguration );
-
- mavenProject.setParentFile( domainModel.getParentFile() );
-
- return mavenProject;
- }
- catch ( InvalidRepositoryException e )
- {
- throw new IOException( e.getMessage() );
- }
- }
-
- private static Model convertFromInputStreamToModel(InputStream inputStream) throws IOException
- {
-
- try
- {
- return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) );
- }
- catch ( XmlPullParserException e )
- {
- throw new IOException( e.getMessage() );
- }
-
- }
-
- /**
- * Returns true if the relative path of the specified parent references a pom, otherwise returns false.
- *
- * @param relativePath the parent model info
- * @param projectDirectory the project directory of the child pom
- * @return true if the relative path of the specified parent references a pom, otherwise returns fals
- */
- private boolean isParentLocal( String relativePath, File projectDirectory )
- {
- try
- {
- File f = new File( projectDirectory, relativePath ).getCanonicalFile();
-
- if ( f.isDirectory() )
- {
- f = new File( f, "pom.xml" );
- }
-
- return f.isFile();
- }
- catch ( IOException e )
- {
- return false;
- }
- }
-
- private List getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
- PomArtifactResolver artifactResolver,
- List properties,
- Collection activeProfileIds,
- Collection inactiveProfileIds )
- throws IOException
- {
- List domainModels = new ArrayList();
-
- String parentId = domainModel.getParentId();
-
- if ( parentId == null )
- {
- return domainModels;
- }
-
- Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
- domainModel.getParentArtifactId(), domainModel.getParentVersion() );
-
- artifactResolver.resolve( artifactParent );
-
- PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
-
- if ( !parentDomainModel.matchesParentOf( domainModel ) )
- {
- logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
- ": Child ID = " + domainModel.getId() );
- return domainModels;
- }
-
- domainModels.add( parentDomainModel );
-
- //Process Profiles
- ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(),
- PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
- Collection profileContainers = profileContext.getActiveProfiles();
-
- for(ModelContainer mc : profileContainers)
- {
- List transformed = new ArrayList();
- transformed.add(new ModelProperty(ProjectUri.xUri, null));
- for(ModelProperty mp : mc.getProperties())
- {
- if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
- && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri) )
- {
- transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
- mp.getResolvedValue()));
- }
- }
-
- domainModels.add(new PomClassicDomainModel(transformed));
- }
-
- domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver, properties,
- activeProfileIds, inactiveProfileIds ) );
- return domainModels;
- }
-
- /**
- * Returns list of domain model parents of the specified domain model. The parent domain models are part
- *
- * @param domainModel
- * @param artifactResolver
- * @param projectDirectory
- * @return
- * @throws IOException
- */
- private List getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
- PomArtifactResolver artifactResolver,
- File projectDirectory,
- List properties,
- Collection activeProfileIds,
- Collection inactiveProfileIds )
- throws IOException
- {
- List domainModels = new ArrayList();
-
- String parentId = domainModel.getParentId();
-
- if ( parentId == null )
- {
- return domainModels;
- }
-
- File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile();
- if ( parentFile.isDirectory() )
- {
- parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
- }
-
- if ( !parentFile.isFile() )
- {
- throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
- }
-
- PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
- parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
-
- //Process Profiles
- ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(),
- PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, inactiveProfileIds, properties);
- Collection profileContainers = profileContext.getActiveProfiles();
-
- for(ModelContainer mc : profileContainers)
- {
- List transformed = new ArrayList();
- transformed.add(new ModelProperty(ProjectUri.xUri, null));
- for(ModelProperty mp : mc.getProperties())
- {
- if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
- && !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri))
- {
- transformed.add(new ModelProperty(mp.getUri().replace(ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri),
- mp.getResolvedValue()));
- }
- }
- domainModels.add(new PomClassicDomainModel(transformed));
- }
-
- if ( !parentDomainModel.matchesParentOf( domainModel ) )
- {
- logger.info( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
- + parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
- + domainModel.getParentId() );
-
- List parentDomainModels =
- getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
- inactiveProfileIds );
-
- if(parentDomainModels.size() == 0)
- {
- throw new IOException("Unable to find parent pom on local path or repo: "
- + domainModel.getParentId());
- }
-
- domainModels.addAll( parentDomainModels );
- return domainModels;
- }
-
- domainModels.add( parentDomainModel );
- if ( domainModel.getParentId() != null )
- {
- if ( isParentLocal(parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
- {
- domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
- parentFile.getParentFile(), properties,
- activeProfileIds, inactiveProfileIds ) );
- }
- else
- {
- domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver,
- properties, activeProfileIds,
- inactiveProfileIds ) );
- }
- }
-
- return domainModels;
- }
-
- public void enableLogging( Logger logger )
- {
- this.logger = logger;
- }
-
- private DomainModel superDomainModel;
-
- private DomainModel getSuperDomainModel()
- throws IOException
- {
- if( superDomainModel == null )
- {
- superDomainModel = convertToDomainModel( getSuperModel() );
- }
- return ((PomClassicDomainModel) superDomainModel).createCopy();
- }
-
- // Super Model Handling
-
- private static final String MAVEN_MODEL_VERSION = "4.0.0";
-
- private MavenXpp3Reader modelReader = new MavenXpp3Reader();
-
- private Model superModel;
-
- public Model getSuperModel()
- {
- if ( superModel != null )
- {
- return superModel;
- }
-
- Reader reader = null;
-
- try
- {
- reader = ReaderFactory.newXmlReader( getClass().getClassLoader().getResource( "org/apache/maven/project/pom-" + MAVEN_MODEL_VERSION + ".xml" ) );
-
- superModel = modelReader.read( reader, true );
- }
- catch ( Exception e )
- {
- // Not going to happen we're reading the super pom embedded in the JAR
- }
- finally
- {
- IOUtil.close( reader );
- }
-
- return superModel;
- }
-}
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
index bb66ec3ad0..0648b27acc 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
@@ -18,9 +18,14 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.project.builder.PomClassicDomainModel;
+import org.apache.maven.shared.model.InterpolatorProperty;
+import org.apache.maven.model.Model;
import java.io.File;
+import java.io.IOException;
import java.util.List;
+import java.util.Collection;
public interface MavenProjectBuilder
{
@@ -47,4 +52,28 @@ public interface MavenProjectBuilder
MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration )
throws ProjectBuildingException;
+
+ PomClassicDomainModel buildModel( File pom,
+ Collection interpolatorProperties,
+ PomArtifactResolver resolver )
+ throws IOException;
+
+ /**
+ * Returns a maven project for the specified input stream.
+ *
+ * @param pom input stream of the model
+ * @param interpolatorProperties properties used for interpolation of properties within the model
+ * @param resolver artifact resolver used in resolving artifacts
+ * @param projectBuilderConfiguration
+ * @return a maven project for the specified input stream
+ * @throws IOException if there is a problem in the construction of the maven project
+ */
+ MavenProject buildFromLocalPath(File pom,
+ Collection interpolatorProperties,
+ PomArtifactResolver resolver,
+ ProjectBuilderConfiguration projectBuilderConfiguration,
+ MavenProjectBuilder mavenProjectBuilder)
+ throws IOException;
+
+ Model getSuperModel();
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/ProjectBuilder.java
deleted file mode 100644
index 8025b0144a..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/ProjectBuilder.java
+++ /dev/null
@@ -1,59 +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.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.shared.model.InterpolatorProperty;
-import org.apache.maven.project.builder.PomClassicDomainModel;
-
-/**
- * Provides services for building maven projects from models.
- */
-public interface ProjectBuilder
-{
- public PomClassicDomainModel buildModel( File pom,
- Collection interpolatorProperties,
- PomArtifactResolver resolver )
- throws IOException;
-
- /**
- * Returns a maven project for the specified input stream.
- *
- * @param pom input stream of the model
- * @param interpolatorProperties properties used for interpolation of properties within the model
- * @param resolver artifact resolver used in resolving artifacts
- * @param projectBuilderConfiguration
- * @return a maven project for the specified input stream
- * @throws IOException if there is a problem in the construction of the maven project
- */
- MavenProject buildFromLocalPath(File pom,
- Collection interpolatorProperties,
- PomArtifactResolver resolver,
- ProjectBuilderConfiguration projectBuilderConfiguration,
- MavenProjectBuilder mavenProjectBuilder)
- throws IOException;
-
- Model getSuperModel();
-}
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
index f27d1c5271..751bd369a6 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
@@ -19,11 +19,9 @@ package org.apache.maven.project.artifact;
* under the License.
*/
-import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -38,16 +36,10 @@ import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
-import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.model.Dependency;
import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Relocation;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.InvalidProjectModelException;
@@ -55,13 +47,11 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.validation.ModelValidationResult;
-import org.apache.maven.repository.MavenRepositoryWrapper;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.StringUtils;
/**
* @author Jason van Zyl
diff --git a/maven-project/src/test/java/org/apache/maven/profiles/injection/DefaultProfileInjectorTest.java b/maven-project/src/test/java/org/apache/maven/profiles/injection/DefaultProfileInjectorTest.java
index 11de3a2532..3ce4ca9028 100644
--- a/maven-project/src/test/java/org/apache/maven/profiles/injection/DefaultProfileInjectorTest.java
+++ b/maven-project/src/test/java/org/apache/maven/profiles/injection/DefaultProfileInjectorTest.java
@@ -41,117 +41,6 @@ public class DefaultProfileInjectorTest
extends TestCase
{
- public void testShouldUseMainPluginDependencyVersionOverManagedDepVersion()
- {
- PluginContainer profile = new PluginContainer();
- Plugin profilePlugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP );
- Dependency profileDep = createDependency( "g", "a", "2" );
- profilePlugin.addDependency( profileDep );
- profile.addPlugin( profilePlugin );
-
- PluginContainer model = new PluginContainer();
- Plugin plugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP );
- Dependency dep = createDependency( "g", "a", "1" );
- plugin.addDependency( dep );
- model.addPlugin( plugin );
-
- new DefaultProfileInjector().injectPlugins( profile, model );
-
- assertEquals( profileDep.getVersion(), ((Dependency) plugin.getDependencies().get( 0 ) ).getVersion() );
- }
-
- private Dependency createDependency( String gid,
- String aid,
- String ver )
- {
- Dependency dep = new Dependency();
- dep.setGroupId( gid );
- dep.setArtifactId( aid );
- dep.setVersion( ver );
-
- return dep;
- }
-
- /**
- * Test that this is the resulting ordering of plugins after merging:
- *
- * Given:
- *
- * model: X -> A -> B -> D -> E
- * profile: Y -> A -> C -> D -> F
- *
- * Result:
- *
- * X -> Y -> A -> B -> C -> D -> E -> F
- */
- public void testShouldPreserveOrderingOfPluginsAfterProfileMerge()
- {
- PluginContainer profile = new PluginContainer();
-
- profile.addPlugin( createPlugin( "group", "artifact", "1.0", Collections.EMPTY_MAP ) );
- profile.addPlugin( createPlugin( "group2", "artifact2", "1.0", Collections.singletonMap( "key", "value" ) ) );
-
- PluginContainer model = new PluginContainer();
-
- model.addPlugin( createPlugin( "group3", "artifact3", "1.0", Collections.EMPTY_MAP ) );
- model.addPlugin( createPlugin( "group2", "artifact2", "1.0", Collections.singletonMap( "key2", "value2" ) ) );
-
- new DefaultProfileInjector().injectPlugins( profile, model );
-
- List results = model.getPlugins();
-
- assertEquals( 3, results.size() );
-
- Plugin result1 = (Plugin) results.get( 0 );
-
- assertEquals( "group3", result1.getGroupId() );
- assertEquals( "artifact3", result1.getArtifactId() );
-
- Plugin result2 = (Plugin) results.get( 1 );
-
- assertEquals( "group", result2.getGroupId() );
- assertEquals( "artifact", result2.getArtifactId() );
-
- Plugin result3 = (Plugin) results.get( 2 );
-
- assertEquals( "group2", result3.getGroupId() );
- assertEquals( "artifact2", result3.getArtifactId() );
-
- Xpp3Dom result3Config = (Xpp3Dom) result3.getConfiguration();
-
- assertNotNull( result3Config );
-
- assertEquals( "value", result3Config.getChild( "key" ).getValue() );
- assertEquals( "value2", result3Config.getChild( "key2" ).getValue() );
- }
-
- private Plugin createPlugin( String groupId, String artifactId, String version, Map configuration )
- {
- Plugin plugin = new Plugin();
- plugin.setGroupId( groupId );
- plugin.setArtifactId( artifactId );
- plugin.setVersion( version );
-
- Xpp3Dom config = new Xpp3Dom( "configuration" );
-
- if( configuration != null )
- {
- for ( Iterator it = configuration.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- Xpp3Dom param = new Xpp3Dom( String.valueOf( entry.getKey() ) );
- param.setValue( String.valueOf( entry.getValue() ) );
-
- config.addChild( param );
- }
- }
-
- plugin.setConfiguration( config );
-
- return plugin;
- }
-
public void testProfilePluginConfigurationShouldOverrideCollidingModelPluginConfiguration()
{
Plugin mPlugin = new Plugin();
@@ -198,7 +87,7 @@ public class DefaultProfileInjectorTest
profile.setBuild( pBuild );
- new DefaultProfileInjector().inject( profile, model );
+ model = new DefaultProfileInjector().inject( profile, model );
Build rBuild = model.getBuild();
Plugin rPlugin = (Plugin) rBuild.getPlugins().get( 0 );
@@ -264,7 +153,7 @@ public class DefaultProfileInjectorTest
profile.setBuild( pBuild );
- new DefaultProfileInjector().inject( profile, model );
+ model = new DefaultProfileInjector().inject( profile, model );
Build rBuild = model.getBuild();
Plugin rPlugin = (Plugin) rBuild.getPlugins().get( 0 );
@@ -308,13 +197,14 @@ public class DefaultProfileInjectorTest
profile.addRepository( pRepository );
- new DefaultProfileInjector().inject( profile, model );
+ model = new DefaultProfileInjector().inject( profile, model );
- Repository rRepository = (Repository) model.getRepositories().get( 0 );
+ Repository rRepository = model.getRepositories().get( 0 );
assertEquals( "http://www.yahoo.com", rRepository.getUrl() );
}
+ /*
public void testShouldPreserveModelModulesWhenProfileHasNone()
{
Model model = new Model();
@@ -324,7 +214,7 @@ public class DefaultProfileInjectorTest
Profile profile = new Profile();
profile.setId( "testId" );
- new DefaultProfileInjector().inject( profile, model );
+ model = new DefaultProfileInjector().inject( profile, model );
List rModules = model.getModules();
@@ -332,10 +222,6 @@ public class DefaultProfileInjectorTest
assertEquals( "module1", rModules.get( 0 ) );
}
- // NOTE: The execution-id's are important, because they are NOT in
- // alphabetical order. The trunk version of Maven currently injects
- // profiles into a TreeMap, then calls map.values(), which puts the
- // executions in alphabetical order...the WRONG order.
public void testShouldPreserveOrderingOfProfileInjectedPluginExecutions()
{
Plugin profilePlugin = new Plugin();
@@ -376,7 +262,7 @@ public class DefaultProfileInjectorTest
Model model = new Model();
model.setBuild( build );
- new DefaultProfileInjector().inject( profile, model );
+ model = new DefaultProfileInjector().inject( profile, model );
List plugins = model.getBuild().getPlugins();
assertNotNull( plugins );
@@ -403,4 +289,5 @@ public class DefaultProfileInjectorTest
assertEquals( "y", e.getId() );
}
+ */
}
diff --git a/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
index 834b41985f..68105d38b5 100644
--- a/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
+++ b/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java
@@ -25,7 +25,6 @@ import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.codehaus.plexus.PlexusTestCase;
@@ -64,7 +63,7 @@ public class DefaultProfileManagerTest
defaultActivated.setActivation( defaultActivation );
Properties props = new Properties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
@@ -103,7 +102,7 @@ public class DefaultProfileManagerTest
defaultActivated.setActivation( defaultActivation );
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
@@ -133,7 +132,7 @@ public class DefaultProfileManagerTest
syspropActivated.setActivation( syspropActivation );
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
@@ -161,7 +160,7 @@ public class DefaultProfileManagerTest
syspropActivated.setActivation( syspropActivation );
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
@@ -192,7 +191,7 @@ public class DefaultProfileManagerTest
syspropActivated.setActivation( syspropActivation );
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
@@ -223,7 +222,7 @@ public class DefaultProfileManagerTest
osActivated.setActivation( osActivation );
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
diff --git a/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index fd607da3f4..e6578ef0c1 100644
--- a/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -23,7 +23,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.profiles.DefaultProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.project.validation.ModelValidationResult;
import org.codehaus.plexus.PlexusTestCase;
@@ -136,7 +135,7 @@ public abstract class AbstractMavenProjectTestCase
throws Exception
{
Properties props = System.getProperties();
- ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
+ ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProjectBuilderConfiguration pbc = new DefaultProjectBuilderConfiguration();
pbc.setLocalRepository( getLocalRepository() );
diff --git a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java
index 06253bb45a..398ab31ae9 100644
--- a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java
@@ -1,15 +1,10 @@
package org.apache.maven.project;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
-import org.apache.maven.profiles.DefaultProfileManager;
-import org.apache.maven.profiles.ProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
index 4e6b6af1b6..b609c3fcae 100644
--- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
@@ -25,7 +25,6 @@ import java.io.FileInputStream;
import java.util.*;
import org.apache.maven.profiles.DefaultProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -48,8 +47,6 @@ public class PomConstructionTest
private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins";
- private ProjectBuilder projectBuilder;
-
private MavenProjectBuilder mavenProjectBuilder;
private MavenRepositorySystem mavenTools;
@@ -66,7 +63,6 @@ public class PomConstructionTest
testDirectory = new File( getBasedir(), BASE_POM_DIR );
testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR );
mavenProjectBuilder = lookup( MavenProjectBuilder.class );
- projectBuilder = lookup( ProjectBuilder.class );
mavenTools = lookup( MavenRepositorySystem.class );
pomArtifactResolver = new PomArtifactResolver()
{
@@ -133,10 +129,10 @@ public class PomConstructionTest
{
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
PomArtifactResolver resolver = artifactResolver( "micromailer" );
- PomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
+ PomClassicDomainModel model = mavenProjectBuilder.buildModel( pom, null, resolver );
// This should be 2
//assertEquals( 2, model.getLineageCount() );
- PomTestWrapper tester = new PomTestWrapper( (PomClassicDomainModel) model );
+ PomTestWrapper tester = new PomTestWrapper( model );
assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
}
@@ -915,7 +911,7 @@ public class PomConstructionTest
{
pomFile = new File( pomFile, "pom.xml" );
}
- return new PomTestWrapper( pomFile, (PomClassicDomainModel) projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
+ return new PomTestWrapper( pomFile, mavenProjectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
}
private PomTestWrapper buildPomFromMavenProject( String pomPath, String profileId )
@@ -928,14 +924,14 @@ public class PomConstructionTest
}
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
config.setLocalRepository(new DefaultArtifactRepository("default", "", new DefaultRepositoryLayout()));
- ProfileActivationContext pCtx = new DefaultProfileActivationContext(null, true);
+ ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
if(profileId != null)
{
pCtx.setExplicitlyActiveProfileIds(Arrays.asList(profileId));
}
config.setGlobalProfileManager(new DefaultProfileManager(this.getContainer(), pCtx));
- return new PomTestWrapper( pomFile, projectBuilder.buildFromLocalPath( pomFile, null, pomArtifactResolver,
+ return new PomTestWrapper( pomFile, mavenProjectBuilder.buildFromLocalPath( pomFile, null, pomArtifactResolver,
config, mavenProjectBuilder ) );
}
diff --git a/maven-project/src/test/java/org/apache/maven/project/injection/TestProfileInjector.java b/maven-project/src/test/java/org/apache/maven/project/injection/TestProfileInjector.java
index 0396a896f6..c6a6be4520 100644
--- a/maven-project/src/test/java/org/apache/maven/project/injection/TestProfileInjector.java
+++ b/maven-project/src/test/java/org/apache/maven/project/injection/TestProfileInjector.java
@@ -29,9 +29,9 @@ public class TestProfileInjector
implements ProfileInjector
{
- public void inject( Profile profile, Model model )
+ public Model inject( Profile profile, Model model )
{
- // do nothing.
+ return null;
}
}