Index: /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/ActiveProfile.java =================================================================== --- /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/ActiveProfile.java (revision 0) +++ /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/ActiveProfile.java (revision 0) @@ -0,0 +1,43 @@ +package org.apache.maven.artifact.ant; + + +/** + * Container for activating profiles + * + * @author Pete Muir + * + */ +public class ActiveProfile { + + /** + * If specified, the named property must be defined. Same as if on + * + */ + private String _if; + + /** + * Profile Id to activate + */ + private String id; + + public String getIf() + { + return _if; + } + + public void setIf(String iftrue) + { + this._if = iftrue; + } + + public String getId() + { + return id; + } + + public void setId(String name) + { + this.id = name; + } + +} Index: /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/Pom.java =================================================================== --- /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/Pom.java (revision 582272) +++ /Users/pmuir/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/Pom.java (working copy) @@ -37,6 +37,8 @@ import org.apache.maven.model.Reporting; import org.apache.maven.model.Scm; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.profiles.DefaultProfileManager; +import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -53,7 +55,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; /** @@ -80,6 +84,8 @@ private MavenProject mavenProject; private File file; + + private List activeProfiles = new ArrayList(); /** * The property interceptor. @@ -129,6 +135,16 @@ { this.file = file; } + + public List getActiveProfiles() + { + return activeProfiles; + } + + public void addActiveProfile(ActiveProfile activeProfile) + { + this.activeProfiles.add(activeProfile); + } void initialise( MavenProjectBuilder builder, ArtifactRepository localRepository ) { @@ -145,8 +161,8 @@ try { - // TODO: should the profiles be constructed and passed in here? From Ant, or perhaps settings? - mavenProject = builder.build( file, localRepository, null ); + ProfileManager profileManager = createProfileManager(); + mavenProject = builder.build( file, localRepository, profileManager ); } catch ( ProjectBuildingException e ) { @@ -159,6 +175,21 @@ } } + private ProfileManager createProfileManager() + { + ProfileManager profileManager = new DefaultProfileManager(getContainer(), getSettings()); + Iterator it = getActiveProfiles().iterator(); + while (it.hasNext()) + { + ActiveProfile activeProfile = (ActiveProfile) it.next(); + if (activeProfile.getIf() == null || (getProject().getProperty(activeProfile.getIf()) != null)) + { + profileManager.explicitlyActivate(activeProfile.getId()); + } + } + return profileManager; + } + private void checkParentPom() { Model model = null;