Search in sources :

Example 51 with Profile

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

the class DefaultPomManager method mergeProfiles.

private void mergeProfiles(Model model, Model generatedModel) {
    @SuppressWarnings("unchecked") List<Profile> generatedProfiles = generatedModel.getProfiles();
    if (generatedProfiles != null && generatedProfiles.size() > 0) {
        @SuppressWarnings("unchecked") List<Profile> modelProfiles = model.getProfiles();
        Map<String, Profile> modelProfileIdMap = new HashMap<String, Profile>();
        if (modelProfiles == null) {
            modelProfiles = new ArrayList<Profile>();
            model.setProfiles(modelProfiles);
        } else if (modelProfiles.size() > 0) {
            // add profile ids from the model for later lookups to the modelProfileIds set
            for (Profile modelProfile : modelProfiles) {
                modelProfileIdMap.put(modelProfile.getId(), modelProfile);
            }
        }
        for (Profile generatedProfile : generatedProfiles) {
            String generatedProfileId = generatedProfile.getId();
            if (!modelProfileIdMap.containsKey(generatedProfileId)) {
                model.addProfile(generatedProfile);
            } else {
                getLogger().warn("Try to merge profiles with id " + generatedProfileId);
                mergeModelBase((Profile) modelProfileIdMap.get(generatedProfileId), generatedProfile);
                mergeProfileBuild((Profile) modelProfileIdMap.get(generatedProfileId), generatedProfile);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Profile(org.apache.maven.model.Profile)

Example 52 with Profile

use of org.apache.maven.model.Profile in project maven-archetype 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) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) Profile(org.apache.maven.model.Profile)

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