Search in sources :

Example 46 with 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)"));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) ArrayList(java.util.ArrayList) File(java.io.File) Profile(org.apache.maven.model.Profile)

Example 47 with Profile

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;
}
Also used : Profile(org.apache.maven.model.Profile)

Example 48 with 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());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Profile(org.apache.maven.model.Profile)

Example 49 with Profile

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);
    }
}
Also used : Profile(org.apache.maven.model.Profile)

Example 50 with 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());
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) IOException(java.io.IOException) Profile(org.apache.maven.model.Profile)

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