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;
}
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)));
}
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;
}
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;
}
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;
}
Aggregations