Search in sources :

Example 21 with Profile

use of org.apache.maven.model.Profile in project che by eclipse.

the class MavenModelUtil method convertToMavenProfile.

private static Profile convertToMavenProfile(MavenProfile mavenProfile) {
    Profile result = new Profile();
    result.setId(mavenProfile.getId());
    result.setSource(mavenProfile.getSource());
    result.setModules(mavenProfile.getModules());
    result.setProperties(mavenProfile.getProperties());
    result.setBuild(new Build());
    result.setActivation(convertToMavenActivation(mavenProfile.getActivation()));
    convertToMavenBuildBase(mavenProfile.getBuild(), result.getBuild());
    return result;
}
Also used : MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.apache.maven.model.Build) Profile(org.apache.maven.model.Profile) MavenProfile(org.eclipse.che.maven.data.MavenProfile)

Example 22 with Profile

use of org.apache.maven.model.Profile in project buck by facebook.

the class Pom method merge.

private Model merge(Model first, @Nullable Model second) {
    if (second == null) {
        return first;
    }
    Model model = first.clone();
    //---- Values from ModelBase
    List<String> modules = second.getModules();
    if (modules != null) {
        for (String module : modules) {
            model.addModule(module);
        }
    }
    DistributionManagement distributionManagement = second.getDistributionManagement();
    if (distributionManagement != null) {
        model.setDistributionManagement(distributionManagement);
    }
    Properties properties = second.getProperties();
    if (properties != null) {
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            model.addProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }
    DependencyManagement dependencyManagement = second.getDependencyManagement();
    if (dependencyManagement != null) {
        model.setDependencyManagement(dependencyManagement);
    }
    List<Dependency> dependencies = second.getDependencies();
    if (dependencies != null) {
        for (Dependency dependency : dependencies) {
            model.addDependency(dependency);
        }
    }
    List<Repository> repositories = second.getRepositories();
    if (repositories != null) {
        for (Repository repository : repositories) {
            model.addRepository(repository);
        }
    }
    List<Repository> pluginRepositories = second.getPluginRepositories();
    if (pluginRepositories != null) {
        for (Repository pluginRepository : pluginRepositories) {
            model.addPluginRepository(pluginRepository);
        }
    }
    // Ignore reports, reporting, and locations
    //----- From Model
    Parent parent = second.getParent();
    if (parent != null) {
        model.setParent(parent);
    }
    Organization organization = second.getOrganization();
    if (organization != null) {
        model.setOrganization(organization);
    }
    List<License> licenses = second.getLicenses();
    Set<String> currentLicenseUrls = new HashSet<>();
    if (model.getLicenses() != null) {
        for (License license : model.getLicenses()) {
            currentLicenseUrls.add(license.getUrl());
        }
    }
    if (licenses != null) {
        for (License license : licenses) {
            if (!currentLicenseUrls.contains(license.getUrl())) {
                model.addLicense(license);
                currentLicenseUrls.add(license.getUrl());
            }
        }
    }
    List<Developer> developers = second.getDevelopers();
    Set<String> currentDevelopers = new HashSet<>();
    if (model.getDevelopers() != null) {
        for (Developer developer : model.getDevelopers()) {
            currentDevelopers.add(developer.getName());
        }
    }
    if (developers != null) {
        for (Developer developer : developers) {
            if (!currentDevelopers.contains(developer.getName())) {
                model.addDeveloper(developer);
                currentDevelopers.add(developer.getName());
            }
        }
    }
    List<Contributor> contributors = second.getContributors();
    Set<String> currentContributors = new HashSet<>();
    if (model.getContributors() != null) {
        for (Contributor contributor : model.getContributors()) {
            currentDevelopers.add(contributor.getName());
        }
    }
    if (contributors != null) {
        for (Contributor contributor : contributors) {
            if (!currentContributors.contains(contributor.getName())) {
                model.addContributor(contributor);
                currentContributors.add(contributor.getName());
            }
        }
    }
    List<MailingList> mailingLists = second.getMailingLists();
    if (mailingLists != null) {
        for (MailingList mailingList : mailingLists) {
            model.addMailingList(mailingList);
        }
    }
    Prerequisites prerequisites = second.getPrerequisites();
    if (prerequisites != null) {
        model.setPrerequisites(prerequisites);
    }
    Scm scm = second.getScm();
    if (scm != null) {
        model.setScm(scm);
    }
    String url = second.getUrl();
    if (url != null) {
        model.setUrl(url);
    }
    String description = second.getDescription();
    if (description != null) {
        model.setDescription(description);
    }
    IssueManagement issueManagement = second.getIssueManagement();
    if (issueManagement != null) {
        model.setIssueManagement(issueManagement);
    }
    CiManagement ciManagement = second.getCiManagement();
    if (ciManagement != null) {
        model.setCiManagement(ciManagement);
    }
    Build build = second.getBuild();
    if (build != null) {
        model.setBuild(build);
    }
    List<Profile> profiles = second.getProfiles();
    Set<String> currentProfileIds = new HashSet<>();
    if (model.getProfiles() != null) {
        for (Profile profile : model.getProfiles()) {
            currentProfileIds.add(profile.getId());
        }
    }
    if (profiles != null) {
        for (Profile profile : profiles) {
            if (!currentProfileIds.contains(profile.getId())) {
                model.addProfile(profile);
                currentProfileIds.add(profile.getId());
            }
        }
    }
    return model;
}
Also used : Organization(org.apache.maven.model.Organization) Parent(org.apache.maven.model.Parent) License(org.apache.maven.model.License) MailingList(org.apache.maven.model.MailingList) Developer(org.apache.maven.model.Developer) Contributor(org.apache.maven.model.Contributor) Properties(java.util.Properties) Profile(org.apache.maven.model.Profile) Prerequisites(org.apache.maven.model.Prerequisites) Build(org.apache.maven.model.Build) DependencyManagement(org.apache.maven.model.DependencyManagement) IssueManagement(org.apache.maven.model.IssueManagement) HashSet(java.util.HashSet) Dependency(org.apache.maven.model.Dependency) Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) CiManagement(org.apache.maven.model.CiManagement) DistributionManagement(org.apache.maven.model.DistributionManagement) Scm(org.apache.maven.model.Scm) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with Profile

use of org.apache.maven.model.Profile in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method applyProfiles.

public static ProfileApplicationResult applyProfiles(MavenModel model, File basedir, MavenExplicitProfiles explicitProfiles, Collection<String> alwaysOnProfiles) throws RemoteException {
    Model nativeModel = MavenModelConverter.toNativeModel(model);
    Collection<String> enabledProfiles = explicitProfiles.getEnabledProfiles();
    Collection<String> disabledProfiles = explicitProfiles.getDisabledProfiles();
    List<Profile> activatedPom = new ArrayList<Profile>();
    List<Profile> activatedExternal = new ArrayList<Profile>();
    List<Profile> activeByDefault = new ArrayList<Profile>();
    List<Profile> rawProfiles = nativeModel.getProfiles();
    List<Profile> expandedProfilesCache = null;
    List<Profile> deactivatedProfiles = new ArrayList<Profile>();
    for (int i = 0; i < rawProfiles.size(); i++) {
        Profile eachRawProfile = rawProfiles.get(i);
        if (disabledProfiles.contains(eachRawProfile.getId())) {
            deactivatedProfiles.add(eachRawProfile);
            continue;
        }
        boolean shouldAdd = enabledProfiles.contains(eachRawProfile.getId()) || alwaysOnProfiles.contains(eachRawProfile.getId());
        Activation activation = eachRawProfile.getActivation();
        if (activation != null) {
            if (activation.isActiveByDefault()) {
                activeByDefault.add(eachRawProfile);
            }
            // expand only if necessary
            if (expandedProfilesCache == null)
                expandedProfilesCache = doInterpolate(nativeModel, basedir).getProfiles();
            Profile eachExpandedProfile = expandedProfilesCache.get(i);
            for (ProfileActivator eachActivator : getProfileActivators(basedir)) {
                try {
                    if (eachActivator.canDetermineActivation(eachExpandedProfile) && eachActivator.isActive(eachExpandedProfile)) {
                        shouldAdd = true;
                        break;
                    }
                } catch (ProfileActivationException e) {
                    Maven3ServerGlobals.getLogger().warn(e);
                }
            }
        }
        if (shouldAdd) {
            if (MavenConstants.PROFILE_FROM_POM.equals(eachRawProfile.getSource())) {
                activatedPom.add(eachRawProfile);
            } else {
                activatedExternal.add(eachRawProfile);
            }
        }
    }
    List<Profile> activatedProfiles = new ArrayList<Profile>(activatedPom.isEmpty() ? activeByDefault : activatedPom);
    activatedProfiles.addAll(activatedExternal);
    for (Profile each : activatedProfiles) {
        new DefaultProfileInjector().injectProfile(nativeModel, each, null, null);
    }
    return new ProfileApplicationResult(MavenModelConverter.convertModel(nativeModel, null), new MavenExplicitProfiles(collectProfilesIds(activatedProfiles), collectProfilesIds(deactivatedProfiles)));
}
Also used : Activation(org.apache.maven.model.Activation) Profile(org.apache.maven.model.Profile) DefaultProfileInjector(org.apache.maven.model.profile.DefaultProfileInjector) Model(org.apache.maven.model.Model)

Example 24 with Profile

use of org.apache.maven.model.Profile in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method applyProfiles.

public static ProfileApplicationResult applyProfiles(MavenModel model, File basedir, MavenExplicitProfiles explicitProfiles, Collection<String> alwaysOnProfiles) throws RemoteException {
    Model nativeModel = MavenModelConverter.toNativeModel(model);
    Collection<String> enabledProfiles = explicitProfiles.getEnabledProfiles();
    Collection<String> disabledProfiles = explicitProfiles.getDisabledProfiles();
    List<Profile> activatedPom = new ArrayList<Profile>();
    List<Profile> activatedExternal = new ArrayList<Profile>();
    List<Profile> activeByDefault = new ArrayList<Profile>();
    List<Profile> rawProfiles = nativeModel.getProfiles();
    List<Profile> expandedProfilesCache = null;
    List<Profile> deactivatedProfiles = new ArrayList<Profile>();
    for (int i = 0; i < rawProfiles.size(); i++) {
        Profile eachRawProfile = rawProfiles.get(i);
        if (disabledProfiles.contains(eachRawProfile.getId())) {
            deactivatedProfiles.add(eachRawProfile);
            continue;
        }
        boolean shouldAdd = enabledProfiles.contains(eachRawProfile.getId()) || alwaysOnProfiles.contains(eachRawProfile.getId());
        Activation activation = eachRawProfile.getActivation();
        if (activation != null) {
            if (activation.isActiveByDefault()) {
                activeByDefault.add(eachRawProfile);
            }
            // expand only if necessary
            if (expandedProfilesCache == null)
                expandedProfilesCache = doInterpolate(nativeModel, basedir).getProfiles();
            Profile eachExpandedProfile = expandedProfilesCache.get(i);
            for (ProfileActivator eachActivator : getProfileActivators(basedir)) {
                try {
                    if (eachActivator.canDetermineActivation(eachExpandedProfile) && eachActivator.isActive(eachExpandedProfile)) {
                        shouldAdd = true;
                        break;
                    }
                } catch (ProfileActivationException e) {
                    Maven3ServerGlobals.getLogger().warn(e);
                }
            }
        }
        if (shouldAdd) {
            if (MavenConstants.PROFILE_FROM_POM.equals(eachRawProfile.getSource())) {
                activatedPom.add(eachRawProfile);
            } else {
                activatedExternal.add(eachRawProfile);
            }
        }
    }
    List<Profile> activatedProfiles = new ArrayList<Profile>(activatedPom.isEmpty() ? activeByDefault : activatedPom);
    activatedProfiles.addAll(activatedExternal);
    for (Profile each : activatedProfiles) {
        new DefaultProfileInjector().injectProfile(nativeModel, each, null, null);
    }
    return new ProfileApplicationResult(MavenModelConverter.convertModel(nativeModel, null), new MavenExplicitProfiles(collectProfilesIds(activatedProfiles), collectProfilesIds(deactivatedProfiles)));
}
Also used : Activation(org.apache.maven.model.Activation) Profile(org.apache.maven.model.Profile) DefaultProfileInjector(org.apache.maven.model.profile.DefaultProfileInjector) Model(org.apache.maven.model.Model)

Example 25 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)

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