Search in sources :

Example 1 with Profile

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

the class MavenModelUtil method convertProfiles.

private static List<MavenProfile> convertProfiles(List<Profile> profiles) {
    List<MavenProfile> result = new ArrayList<>();
    if (profiles != null) {
        for (Profile profile : profiles) {
            if (profile.getId() == null) {
                continue;
            }
            MavenProfile mavenProfile = new MavenProfile(profile.getId(), profile.getSource());
            List<String> modules = profile.getModules();
            if (modules == null) {
                mavenProfile.setModules(Collections.emptyList());
            } else {
                mavenProfile.setModules(modules);
            }
            mavenProfile.setActivation(convertActivation(profile.getActivation()));
            if (profile.getBuild() != null) {
                convertBaseBuild(profile.getBuild(), mavenProfile.getBuild());
            }
            result.add(mavenProfile);
        }
    }
    return result;
}
Also used : MavenProfile(org.eclipse.che.maven.data.MavenProfile) ArrayList(java.util.ArrayList) Profile(org.apache.maven.model.Profile) MavenProfile(org.eclipse.che.maven.data.MavenProfile)

Example 2 with Profile

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

use of org.apache.maven.model.Profile in project unleash-maven-plugin by shillner.

the class CheckPluginVersions method getSnapshotsFromAllProfiles.

private Set<ArtifactCoordinates> getSnapshotsFromAllProfiles(MavenProject project, PomPropertyResolver propertyResolver) {
    Set<ArtifactCoordinates> snapshots = Sets.newHashSet();
    List<Profile> profiles = project.getModel().getProfiles();
    if (profiles != null) {
        for (Profile profile : profiles) {
            snapshots.addAll(getSnapshotsFromManagement(profile, propertyResolver));
            snapshots.addAll(getSnapshots(profile, propertyResolver));
        }
    }
    return snapshots;
}
Also used : ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) Profile(org.apache.maven.model.Profile)

Example 4 with Profile

use of org.apache.maven.model.Profile in project unleash-maven-plugin by shillner.

the class CheckDependencyVersions method getSnapshotsFromAllProfiles.

private Set<ArtifactCoordinates> getSnapshotsFromAllProfiles(MavenProject project, PomPropertyResolver propertyResolver) {
    Set<ArtifactCoordinates> snapshots = Sets.newHashSet();
    List<Profile> profiles = project.getModel().getProfiles();
    if (profiles != null) {
        for (Profile profile : profiles) {
            snapshots.addAll(getSnapshotsFromManagement(profile, propertyResolver));
            snapshots.addAll(getSnapshots(profile, propertyResolver));
        }
    }
    filterMultiModuleDependencies(snapshots);
    return snapshots;
}
Also used : ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) Profile(org.apache.maven.model.Profile)

Example 5 with Profile

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

the class ProjectVersionEnforcingManipulator method applyChanges.

/**
 * For each project in the current build set, reset the version if using project.version
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final ProjectVersionEnforcingState state = session.getState(ProjectVersionEnforcingState.class);
    if (!session.isEnabled() || !session.anyStateEnabled(State.activeByDefault) || state == null || !state.isEnabled()) {
        logger.debug("Project version enforcement is disabled.");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    for (final Project project : projects) {
        final Model model = project.getModel();
        if (model.getPackaging().equals("pom")) {
            enforceProjectVersion(project, model.getDependencies(), changed);
            if (model.getDependencyManagement() != null) {
                enforceProjectVersion(project, model.getDependencyManagement().getDependencies(), changed);
            }
            final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
            if (profiles != null) {
                for (final Profile profile : profiles) {
                    enforceProjectVersion(project, profile.getDependencies(), changed);
                    if (profile.getDependencyManagement() != null) {
                        enforceProjectVersion(project, profile.getDependencyManagement().getDependencies(), changed);
                    }
                }
            }
        }
    }
    if (!changed.isEmpty()) {
        logger.warn("Using ${project.version} in pom files may lead to unexpected errors with inheritance.");
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ProjectVersionEnforcingState(org.commonjava.maven.ext.core.state.ProjectVersionEnforcingState) Model(org.apache.maven.model.Model) Profile(org.apache.maven.model.Profile) HashSet(java.util.HashSet)

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