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();
}
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class AllProfilesMojoTest method newPomProfile.
private Profile newPomProfile(String id, String source) {
Profile profile = new Profile();
profile.setId(id);
profile.setSource(source);
return profile;
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class AllProfilesMojoTest method testProfileFromSettings.
/**
* Tests the case when profiles are present in the settings.
*
* @throws Exception in case of errors.
*/
public void testProfileFromSettings() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
MavenProject project = new MavenProjectStub();
project.setActiveProfiles(Arrays.asList(newPomProfile("settings-1", "settings.xml")));
List<org.apache.maven.settings.Profile> settingsProfiles = new ArrayList<org.apache.maven.settings.Profile>();
settingsProfiles.add(newSettingsProfile("settings-1"));
settingsProfiles.add(newSettingsProfile("settings-2"));
setUpMojo(mojo, Arrays.<MavenProject>asList(project), settingsProfiles, "profiles-from-settings.txt");
mojo.execute();
String file = readFile("profiles-from-settings.txt");
assertTrue(file.contains("Profile Id: settings-1 (Active: true , Source: settings.xml)"));
assertTrue(file.contains("Profile Id: settings-2 (Active: false , Source: settings.xml)"));
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class MavenJDOMWriter method iterateProfile.
// -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
* Method iterateProfile
*
* @param counter
* @param childTag
* @param parentTag
* @param list
* @param parent
*/
protected void iterateProfile(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
boolean shouldExist = list != null && list.size() > 0;
Element element = updateElement(counter, parent, parentTag, shouldExist);
if (shouldExist) {
Iterator it = list.iterator();
Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
if (!elIt.hasNext()) {
elIt = null;
}
Counter innerCount = new Counter(counter.getDepth() + 1);
while (it.hasNext()) {
Profile value = (Profile) it.next();
Element el;
if (elIt != null && elIt.hasNext()) {
el = (Element) elIt.next();
if (!elIt.hasNext()) {
elIt = null;
}
} else {
el = factory.element(childTag, element.getNamespace());
insertAtPreferredLocation(element, el, innerCount);
}
updateProfile(value, childTag, innerCount, el);
innerCount.increaseCount();
}
if (elIt != null) {
while (elIt.hasNext()) {
elIt.next();
elIt.remove();
}
}
}
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class MavenProject4CopyConstructor method initializeParentFields.
// to prevent the MavenProject copy constructor from blowing up
private void initializeParentFields() {
// the pom should be located in the isolated dummy root
super.setFile(new File(getBasedir(), "pom.xml"));
super.setDependencyArtifacts(new HashSet<Artifact>());
super.setArtifacts(new HashSet<Artifact>());
super.setExtensionArtifacts(new HashSet<Artifact>());
super.setRemoteArtifactRepositories(new LinkedList<ArtifactRepository>());
super.setPluginArtifactRepositories(new LinkedList<ArtifactRepository>());
super.setCollectedProjects(new LinkedList<MavenProject>());
super.setActiveProfiles(new LinkedList<Profile>());
super.setOriginalModel(null);
super.setExecutionProject(this);
super.setBuild(getBuild());
}
Aggregations