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 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 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());
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class AllProfilesMojo method addSettingsProfiles.
/**
* Adds the profiles from <code>settings.xml</code>.
*
* @param allProfiles Map to add the profiles to.
*/
private void addSettingsProfiles(Map<String, Profile> allProfiles) {
getLog().debug("Attempting to read profiles from settings.xml...");
for (org.apache.maven.settings.Profile settingsProfile : settingsProfiles) {
Profile profile = SettingsUtils.convertFromSettingsProfile(settingsProfile);
allProfiles.put(profile.getId(), profile);
}
}
use of org.apache.maven.model.Profile in project maven-plugins by apache.
the class AllProfilesMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException, MojoFailureException {
StringBuilder descriptionBuffer = new StringBuilder();
for (MavenProject project : projects) {
descriptionBuffer.append("Listing Profiles for Project: ").append(project.getId()).append(LS);
Map<String, Profile> allProfilesByIds = new HashMap<String, Profile>();
Map<String, Profile> activeProfilesByIds = new HashMap<String, Profile>();
addSettingsProfiles(allProfilesByIds);
addProjectPomProfiles(project, allProfilesByIds, activeProfilesByIds);
// now display
if (allProfilesByIds.isEmpty()) {
getLog().warn("No profiles detected!");
} else {
// active Profiles will be a subset of *all* profiles
allProfilesByIds.keySet().removeAll(activeProfilesByIds.keySet());
writeProfilesDescription(descriptionBuffer, activeProfilesByIds, true);
writeProfilesDescription(descriptionBuffer, allProfilesByIds, false);
}
}
if (output != null) {
try {
writeFile(output, descriptionBuffer);
} catch (IOException e) {
throw new MojoExecutionException("Cannot write profiles description to output: " + output, e);
}
getLog().info("Wrote descriptions to: " + output);
} else {
getLog().info(descriptionBuffer.toString());
}
}
Aggregations