Search in sources :

Example 46 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class ResourcesMojoTest method testResourceSystemProperties_Filtering.

/**
 * @throws Exception
 */
public void testResourceSystemProperties_Filtering() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceSystemProperties_Filtering");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file4.txt", "current-working-directory = ${user.dir}");
    project.setResourceFiltering(0, true);
    project.setupBuildEnvironment();
    // setVariableValueToObject(mojo,"encoding","UTF-8");
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.TRUE);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setSystemProperties(System.getProperties());
    MavenSession mavenSession = new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null);
    setVariableValueToObject(mojo, "session", mavenSession);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    File userDir = new File(System.getProperty("user.dir"));
    assertTrue(userDir.exists());
    Properties props = new Properties();
    final FileInputStream inStream = new FileInputStream(new File(resourcesDir, "file4.txt"));
    try {
        props.load(inStream);
    } finally {
        inStream.close();
    }
    File fileFromFiltering = new File(props.getProperty("current-working-directory"));
    assertTrue(fileFromFiltering.getAbsolutePath() + " does not exist.", fileFromFiltering.exists());
    assertEquals(userDir.getAbsolutePath(), fileFromFiltering.getAbsolutePath());
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) Resource(org.apache.maven.model.Resource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 47 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AbstractWarMojoTest method configureMojo.

/**
 * initialize required parameters
 *
 * @param mojo The mojo to be tested.
 * @param filters The list of filters.
 * @param classesDir The classes directory.
 * @param webAppSource The webAppSource.
 * @param webAppDir The webAppDir folder.
 * @param project The Maven project.
 * @throws Exception in case of errors
 */
protected void configureMojo(AbstractWarMojo mojo, List<String> filters, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) throws Exception {
    setVariableValueToObject(mojo, "filters", filters);
    setVariableValueToObject(mojo, "useCache", Boolean.FALSE);
    setVariableValueToObject(mojo, "mavenFileFilter", lookup(MavenFileFilter.class.getName()));
    setVariableValueToObject(mojo, "useJvmChmod", Boolean.TRUE);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setSystemProperties(System.getProperties());
    MavenSession mavenSession = new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null);
    setVariableValueToObject(mojo, "session", mavenSession);
    mojo.setClassesDirectory(classesDir);
    mojo.setWarSourceDirectory(webAppSource);
    mojo.setWebappDirectory(webAppDir);
    mojo.setProject(project);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest)

Example 48 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AbstractSiteDeployWebDavTest method davDeployThruProxyWitAuthzInProxy.

@Test
public void davDeployThruProxyWitAuthzInProxy() throws Exception {
    FileUtils.cleanDirectory(siteTargetPath);
    // SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler( siteTargetPath );
    Map<String, String> authentications = new HashMap<String, String>();
    authentications.put("foo", "titi");
    AuthAsyncProxyServlet servlet = new AuthAsyncProxyServlet(authentications, siteTargetPath);
    SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(servlet);
    try {
        File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
        AbstractMojo mojo = getMojo(pluginXmlFile);
        assertNotNull(mojo);
        SiteMavenProjectStub siteMavenProjectStub = new SiteMavenProjectStub("deploy-dav");
        siteMavenProjectStub.getDistributionManagement().getSite().setUrl("dav:http://toto.com/site/");
        setVariableValueToObject(mojo, "project", siteMavenProjectStub);
        Settings settings = new Settings();
        Proxy proxy = new Proxy();
        // dummy proxy
        proxy.setActive(true);
        proxy.setHost("localhost");
        proxy.setPort(simpleDavServerHandler.getPort());
        proxy.setProtocol("dav");
        proxy.setUsername("foo");
        proxy.setPassword("titi");
        proxy.setNonProxyHosts("www.google.com|*.somewhere.com");
        settings.addProxy(proxy);
        setVariableValueToObject(mojo, "settings", settings);
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        request.setProxies(Arrays.asList(proxy));
        MavenSession mavenSession = new MavenSession(getContainer(), null, request, null);
        setVariableValueToObject(mojo, "mavenSession", mavenSession);
        File inputDirectory = new File("src/test/resources/unit/deploy-dav/target/site");
        // test which mojo we are using
        if (ReflectionUtils.getFieldByNameIncludingSuperclasses("inputDirectory", mojo.getClass()) != null) {
            setVariableValueToObject(mojo, "inputDirectory", inputDirectory);
        } else {
            ArtifactRepositoryFactory artifactRepositoryFactory = getContainer().lookup(ArtifactRepositoryFactory.class);
            setVariableValueToObject(mojo, "stagingDirectory", inputDirectory);
            setVariableValueToObject(mojo, "reactorProjects", Collections.emptyList());
            setVariableValueToObject(mojo, "localRepository", artifactRepositoryFactory.createArtifactRepository("local", "foo", "default", null, null));
            setVariableValueToObject(mojo, "siteTool", getContainer().lookup(SiteTool.class));
            setVariableValueToObject(mojo, "siteDirectory", new File("foo"));
            setVariableValueToObject(mojo, "repositories", Collections.emptyList());
        }
        mojo.execute();
        assertContentInFiles();
        assertTrue(requestsContainsProxyUse(servlet.httpRequests));
        assertAtLeastOneRequestContainsHeader(servlet.httpRequests, "Proxy-Authorization");
        for (HttpRequest rq : servlet.httpRequests) {
            log.info(rq.toString());
        }
    } finally {
        simpleDavServerHandler.stop();
    }
}
Also used : HttpRequest(org.apache.maven.plugins.site.deploy.SimpleDavServerHandler.HttpRequest) SiteMavenProjectStub(org.apache.maven.plugins.site.stubs.SiteMavenProjectStub) HashMap(java.util.HashMap) SiteTool(org.apache.maven.doxia.tools.SiteTool) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) AbstractMojo(org.apache.maven.plugin.AbstractMojo) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) MavenSession(org.apache.maven.execution.MavenSession) Proxy(org.apache.maven.settings.Proxy) File(java.io.File) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 49 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class TestIncludeExcludeUnpackMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("unpack", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
    mojo = (UnpackMojo) lookupMojo("unpack", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    // mojo.silent = true;
    // it needs to get the archivermanager
    // stubFactory.setUnpackableFile( mojo.getArchiverManager() );
    // i'm using one file repeatedly to archive so I can test the name
    // programmatically.
    stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
    Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
    ArtifactItem item = stubFactory.getArtifactItem(artifact);
    List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
    list.add(item);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
    mojo.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setArtifactItems(list);
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 50 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class TestClassifierTypeTranslator method setUp.

protected void setUp() throws Exception {
    super.setUp("classifiertype-translator", false);
    artifactHandlerManager = new DefaultArtifactHandlerManager();
    this.setVariableValueToObject(artifactHandlerManager, "artifactHandlers", new HashMap());
    artifactFactory = new DefaultArtifactFactory();
    this.setVariableValueToObject(artifactFactory, "artifactHandlerManager", artifactHandlerManager);
    artifactRepository = new StubArtifactRepository(null);
    DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory(null, false);
    artifacts = factory.getMixedArtifacts();
    repoManager = lookup(RepositoryManager.class);
    MavenSession session = newMavenSession(new MavenProjectStub());
    buildingRequest = session.getProjectBuildingRequest();
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) HashMap(java.util.HashMap) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)118 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)20 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 Properties (java.util.Properties)17 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)12 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6