Search in sources :

Example 6 with MavenProjectStub

use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.

the class AllProfilesMojoTest method testProfileFromPom.

/**
     * Tests the case when profiles are present in the POM and in a parent POM.
     * 
     * @throws Exception in case of errors.
     */
public void testProfileFromPom() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
    AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
    MavenProjectStub project = new MavenProjectStub();
    project.getModel().setProfiles(Arrays.asList(newPomProfile("pro-1", "pom"), newPomProfile("pro-2", "pom")));
    project.setParent(new MavenProjectStub());
    project.getParent().getModel().setProfiles(Arrays.asList(newPomProfile("pro-3", "pom")));
    project.setActiveProfiles(Arrays.asList(newPomProfile("pro-1", "pom")));
    setUpMojo(mojo, Arrays.<MavenProject>asList(project), Collections.<org.apache.maven.settings.Profile>emptyList(), "profiles-from-pom.txt");
    mojo.execute();
    String file = readFile("profiles-from-pom.txt");
    assertTrue(file.contains("Profile Id: pro-1 (Active: true , Source: pom)"));
    assertTrue(file.contains("Profile Id: pro-2 (Active: false , Source: pom)"));
    assertTrue(file.contains("Profile Id: pro-3 (Active: false , Source: pom)"));
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) File(java.io.File)

Example 7 with MavenProjectStub

use of org.apache.maven.plugin.testing.stubs.MavenProjectStub 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 8 with MavenProjectStub

use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.

the class TestGetMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("markers", false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
    assert testPom.exists();
    mojo = (GetMojo) lookupMojo("get", testPom);
    assertNotNull(mojo);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(newMavenSession(new MavenProjectStub()));
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
    setVariableValueToObject(mojo, "session", legacySupport.getSession());
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File)

Example 9 with MavenProjectStub

use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.

the class ProjectInfoReportUtilsTest method getMavenProjectStub.

private MavenProject getMavenProjectStub(boolean https) {
    final DistributionManagement distributionManagement = new DistributionManagement();
    DeploymentRepository repository = new DeploymentRepository();
    repository.setId("localhost");
    repository.setUrl((https ? "https" : "http") + "://localhost:" + port);
    distributionManagement.setRepository(repository);
    distributionManagement.setSnapshotRepository(repository);
    return new MavenProjectStub() {

        @Override
        public DistributionManagement getDistributionManagement() {
            return distributionManagement;
        }
    };
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DeploymentRepository(org.apache.maven.model.DeploymentRepository) DistributionManagement(org.apache.maven.model.DistributionManagement)

Aggregations

MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)9 File (java.io.File)5 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)2 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)2 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DefaultArtifactFactory (org.apache.maven.artifact.factory.DefaultArtifactFactory)1 DefaultArtifactHandlerManager (org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager)1 MavenSession (org.apache.maven.execution.MavenSession)1 Build (org.apache.maven.model.Build)1 DeploymentRepository (org.apache.maven.model.DeploymentRepository)1 DistributionManagement (org.apache.maven.model.DistributionManagement)1 Profile (org.apache.maven.model.Profile)1 LegacySupport (org.apache.maven.plugin.LegacySupport)1 JavaEntityTags (org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags)1 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)1 DependencyArtifactStubFactory (org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)1