Search in sources :

Example 11 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class AllProfilesMojo method addProjectPomProfiles.

// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
     * Adds the profiles from <code>pom.xml</code> and all of its parents.
     *
     * @param project could be null
     * @param allProfiles Map to add the profiles to.
     */
private void addProjectPomProfiles(MavenProject project, Map<String, Profile> allProfiles) {
    if (project == null) {
        // shouldn't happen as this mojo requires a project
        getLog().debug("No pom.xml found to read Profiles from.");
        return;
    }
    getLog().debug("Attempting to read profiles from pom.xml...");
    for (Profile profile : project.getModel().getProfiles()) {
        allProfiles.put(profile.getId(), profile);
    }
    MavenProject parent = project.getParent();
    while (parent != null) {
        for (Profile profile : parent.getModel().getProfiles()) {
            allProfiles.put(profile.getId(), profile);
        }
        parent = parent.getParent();
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Profile(org.apache.maven.model.Profile)

Example 12 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class AllProfilesMojoTest method newPomProfile.

private Profile newPomProfile(String id, String source) {
    Profile profile = new Profile();
    profile.setId(id);
    profile.setSource(source);
    return profile;
}
Also used : Profile(org.apache.maven.model.Profile)

Example 13 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class AllProfilesMojoTest method testProfileFromSettings.

/**
     * Tests the case when profiles are present in the settings.
     * 
     * @throws Exception in case of errors.
     */
public void testProfileFromSettings() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
    AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
    MavenProject project = new MavenProjectStub();
    project.setActiveProfiles(Arrays.asList(newPomProfile("settings-1", "settings.xml")));
    List<org.apache.maven.settings.Profile> settingsProfiles = new ArrayList<org.apache.maven.settings.Profile>();
    settingsProfiles.add(newSettingsProfile("settings-1"));
    settingsProfiles.add(newSettingsProfile("settings-2"));
    setUpMojo(mojo, Arrays.<MavenProject>asList(project), settingsProfiles, "profiles-from-settings.txt");
    mojo.execute();
    String file = readFile("profiles-from-settings.txt");
    assertTrue(file.contains("Profile Id: settings-1 (Active: true , Source: settings.xml)"));
    assertTrue(file.contains("Profile Id: settings-2 (Active: false , Source: settings.xml)"));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) ArrayList(java.util.ArrayList) File(java.io.File) Profile(org.apache.maven.model.Profile)

Example 14 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class MavenJDOMWriter method iterateProfile.

// -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iterateProfile
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iterateProfile(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            Profile value = (Profile) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updateProfile(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : Element(org.jdom.Element) Iterator(java.util.Iterator) Profile(org.apache.maven.model.Profile)

Example 15 with Profile

use of org.apache.maven.model.Profile in project maven-plugins by apache.

the class MavenProject4CopyConstructor method initializeParentFields.

// to prevent the MavenProject copy constructor from blowing up
private void initializeParentFields() {
    // the pom should be located in the isolated dummy root         
    super.setFile(new File(getBasedir(), "pom.xml"));
    super.setDependencyArtifacts(new HashSet<Artifact>());
    super.setArtifacts(new HashSet<Artifact>());
    super.setExtensionArtifacts(new HashSet<Artifact>());
    super.setRemoteArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setPluginArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setCollectedProjects(new LinkedList<MavenProject>());
    super.setActiveProfiles(new LinkedList<Profile>());
    super.setOriginalModel(null);
    super.setExecutionProject(this);
    super.setBuild(getBuild());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Profile(org.apache.maven.model.Profile)

Aggregations

Profile (org.apache.maven.model.Profile)15 Model (org.apache.maven.model.Model)5 File (java.io.File)4 MavenProject (org.apache.maven.project.MavenProject)4 Activation (org.apache.maven.model.Activation)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Build (org.apache.maven.model.Build)2 Dependency (org.apache.maven.model.Dependency)2 DefaultProfileInjector (org.apache.maven.model.profile.DefaultProfileInjector)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenProfile (org.eclipse.che.maven.data.MavenProfile)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1