Search in sources :

Example 1 with Activation

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

the class MavenModelUtil method convertToMavenActivation.

private static Activation convertToMavenActivation(MavenActivation activation) {
    if (activation != null) {
        Activation result = new Activation();
        result.setActiveByDefault(activation.isActiveByDefault());
        result.setFile(convertToMavenActivationFile(activation.getFile()));
        result.setJdk(activation.getJdk());
        result.setOs(convertToMavenActivationOs(activation.getOs()));
        result.setProperty(convertToMavenActivationProperty(activation.getProperty()));
        return result;
    }
    return null;
}
Also used : MavenActivation(org.eclipse.che.maven.data.MavenActivation) Activation(org.apache.maven.model.Activation)

Example 2 with Activation

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

the class MyFileProfileActivator method isActive.

public boolean isActive(Profile profile) {
    Activation activation = profile.getActivation();
    ActivationFile actFile = activation.getFile();
    if (actFile != null) {
        // check if the file exists, if it does then the profile will be active
        String fileString = actFile.getExists();
        RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
        try {
            interpolator.addValueSource(new EnvarBasedValueSource());
        } catch (IOException e) {
        // ignored
        }
        interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));
        try {
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return fileExists(fileString);
            }
            // check if the file is missing, if it is then the profile will be active
            fileString = actFile.getMissing();
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return !fileExists(fileString);
            }
        } catch (InterpolationException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
            } else {
                logger.warn("Failed to interpolate missing file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information.");
            }
        }
    }
    return false;
}
Also used : ActivationFile(org.apache.maven.model.ActivationFile) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Activation(org.apache.maven.model.Activation) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource)

Example 3 with Activation

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

the class Maven2ServerEmbedderImpl method applyProfiles.

public static ProfileApplicationResult applyProfiles(MavenModel model, File basedir, MavenExplicitProfiles explicitProfiles, Collection<String> alwaysOnProfiles) throws RemoteException {
    Model nativeModel = Maven2ModelConverter.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) {
                    Maven2ServerGlobals.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().inject(each, nativeModel);
    }
    return new ProfileApplicationResult(Maven2ModelConverter.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.project.injection.DefaultProfileInjector) Model(org.apache.maven.model.Model)

Example 4 with Activation

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

the class MyFileProfileActivator method isActive.

public boolean isActive(Profile profile) {
    Activation activation = profile.getActivation();
    ActivationFile actFile = activation.getFile();
    if (actFile != null) {
        // check if the file exists, if it does then the profile will be active
        String fileString = actFile.getExists();
        RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
        try {
            interpolator.addValueSource(new EnvarBasedValueSource());
        } catch (IOException e) {
        // ignored
        }
        interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));
        try {
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return fileExists(fileString);
            }
            // check if the file is missing, if it is then the profile will be active
            fileString = actFile.getMissing();
            if (StringUtils.isNotEmpty(fileString)) {
                fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
                return !fileExists(fileString);
            }
        } catch (InterpolationException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e);
            } else {
                logger.warn("Failed to interpolate missing file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information.");
            }
        }
    }
    return false;
}
Also used : ActivationFile(org.apache.maven.model.ActivationFile) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Activation(org.apache.maven.model.Activation) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource)

Example 5 with Activation

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

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