Search in sources :

Example 26 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 27 with Profile

use of org.apache.maven.model.Profile in project felix 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, Collection list, String parentTag, 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 28 with Profile

use of org.apache.maven.model.Profile in project pom-manipulation-ext by release-engineering.

the class Project method getResolvedProfilePlugins.

/**
 * This method will scan the plugins in the potentially active Profiles in this project and
 * return a fully resolved list. Note that while updating the {@link Plugin} reference
 * returned will be reflected in the Model as it is the same object, if you wish to
 * remove or add items to the Model then you must use {@link #getModel()}
 *
 * @param session MavenSessionHandler, used by {@link PropertyResolver}
 * @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin}
 * @throws ManipulationException if an error occurs
 */
public HashMap<Profile, HashMap<ProjectVersionRef, Plugin>> getResolvedProfilePlugins(MavenSessionHandler session) throws ManipulationException {
    if (resolvedProfilePlugins == null) {
        resolvedProfilePlugins = new HashMap<>();
        for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
            HashMap<ProjectVersionRef, Plugin> profileDeps = new HashMap<>();
            if (profile.getBuild() != null) {
                resolvePlugins(session, profile.getBuild().getPlugins(), profileDeps);
            }
            resolvedProfilePlugins.put(profile, profileDeps);
        }
    }
    return resolvedProfilePlugins;
}
Also used : HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) Plugin(org.apache.maven.model.Plugin)

Example 29 with Profile

use of org.apache.maven.model.Profile in project pom-manipulation-ext by release-engineering.

the class Project method updateProfiles.

public void updateProfiles(List<Profile> remoteProfiles) {
    final List<Profile> profiles = model.getProfiles();
    if (!remoteProfiles.isEmpty()) {
        for (Profile profile : remoteProfiles) {
            final Iterator<Profile> i = profiles.iterator();
            while (i.hasNext()) {
                final Profile p = i.next();
                if (profile.getId().equals(p.getId())) {
                    logger.debug("Removing local profile {} ", p);
                    i.remove();
                // Don't break out of the loop so we can check for active profiles
                }
                // of activeByDefault. Therefore replace the activation.
                if (p.getActivation() != null && p.getActivation().isActiveByDefault()) {
                    logger.warn("Profile {} is activeByDefault", p);
                    final Activation replacement = new Activation();
                    final ActivationProperty replacementProp = new ActivationProperty();
                    replacementProp.setName("!disableProfileActivation");
                    replacement.setProperty(replacementProp);
                    p.setActivation(replacement);
                }
            }
            logger.debug("Adding profile {}", profile);
            profiles.add(profile);
        }
        logger.info("Clearing resolved profile caches to trigger rescanning...");
        resolvedProfileDependencies = null;
        allResolvedProfileDependencies = null;
        resolvedProfileManagedDependencies = null;
        resolvedProfileManagedPlugins = null;
        resolvedProfilePlugins = null;
    }
}
Also used : Activation(org.apache.maven.model.Activation) ActivationProperty(org.apache.maven.model.ActivationProperty) Profile(org.apache.maven.model.Profile)

Example 30 with Profile

use of org.apache.maven.model.Profile in project pom-manipulation-ext by release-engineering.

the class Project method getAllResolvedProfileDependencies.

/**
 * This method will scan the dependencies in the potentially active Profiles in this project and
 * return a fully resolved list. Note that this will return all dependencies including managed
 * i.e. those with a group, artifact and potentially empty version.
 *
 * Note that while updating the {@link Dependency} reference returned will be reflected in the
 * Model as it is the same object, if you wish to remove or add items to the Model then you
 * must use {@link #getModel()}
 *
 * @param session MavenSessionHandler, used by {@link PropertyResolver}
 * @return a list of fully resolved {@link ArtifactRef} to the original {@link Dependency}
 * @throws ManipulationException if an error occurs
 */
public HashMap<Profile, HashMap<ArtifactRef, Dependency>> getAllResolvedProfileDependencies(MavenSessionHandler session) throws ManipulationException {
    if (allResolvedProfileDependencies == null) {
        allResolvedProfileDependencies = new HashMap<>();
        for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
            HashMap<ArtifactRef, Dependency> profileDeps = new HashMap<>();
            resolveDeps(session, profile.getDependencies(), true, profileDeps);
            allResolvedProfileDependencies.put(profile, profileDeps);
        }
    }
    return allResolvedProfileDependencies;
}
Also used : HashMap(java.util.HashMap) Dependency(org.apache.maven.model.Dependency) Profile(org.apache.maven.model.Profile) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)

Aggregations

Profile (org.apache.maven.model.Profile)52 HashMap (java.util.HashMap)12 Model (org.apache.maven.model.Model)12 ArrayList (java.util.ArrayList)9 Dependency (org.apache.maven.model.Dependency)8 HashSet (java.util.HashSet)7 DependencyManagement (org.apache.maven.model.DependencyManagement)7 File (java.io.File)6 Activation (org.apache.maven.model.Activation)6 MavenProject (org.apache.maven.project.MavenProject)6 Project (org.commonjava.maven.ext.common.model.Project)6 Build (org.apache.maven.model.Build)5 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)5 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)5 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)3 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3