Search in sources :

Example 6 with Activation

use of org.apache.maven.model.Activation 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 7 with Activation

use of org.apache.maven.model.Activation 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 8 with Activation

use of org.apache.maven.model.Activation in project tesb-studio-se by Talend.

the class CreateMavenBundlePom method addProfileForCloud.

/**
 * skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
Also used : Build(org.apache.maven.model.Build) Activation(org.apache.maven.model.Activation) ActivationProperty(org.apache.maven.model.ActivationProperty) Profile(org.apache.maven.model.Profile)

Example 9 with Activation

use of org.apache.maven.model.Activation in project tesb-studio-se by Talend.

the class CreateMavenDataServicePom method addProfileForCloud.

/**
 * DOC skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
Also used : Build(org.apache.maven.model.Build) Activation(org.apache.maven.model.Activation) ActivationProperty(org.apache.maven.model.ActivationProperty) Profile(org.apache.maven.model.Profile)

Aggregations

Activation (org.apache.maven.model.Activation)9 Profile (org.apache.maven.model.Profile)6 ActivationProperty (org.apache.maven.model.ActivationProperty)3 Model (org.apache.maven.model.Model)3 IOException (java.io.IOException)2 ActivationFile (org.apache.maven.model.ActivationFile)2 Build (org.apache.maven.model.Build)2 DefaultProfileInjector (org.apache.maven.model.profile.DefaultProfileInjector)2 EnvarBasedValueSource (org.codehaus.plexus.interpolation.EnvarBasedValueSource)2 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)2 MapBasedValueSource (org.codehaus.plexus.interpolation.MapBasedValueSource)2 RegexBasedInterpolator (org.codehaus.plexus.interpolation.RegexBasedInterpolator)2 DefaultProfileInjector (org.apache.maven.project.injection.DefaultProfileInjector)1 MavenActivation (org.eclipse.che.maven.data.MavenActivation)1