Search in sources :

Example 51 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project yeoman-maven-plugin by trecloux.

the class YeomanMojoTest method getMavenProject.

private MavenProject getMavenProject(String pomPath) throws Exception {
    File pom = new File(pomPath);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setPom(pom);
    ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    return lookup(ProjectBuilder.class).build(pom, configuration).getProject();
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) File(java.io.File)

Example 52 with MavenExecutionRequest

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

the class DefaultDependencyResolverTest method newMavenSession.

protected MavenSession newMavenSession(MavenProject project) {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
    repoSession.setLocalRepositoryManager(LegacyLocalRepositoryManager.wrap(new StubArtifactRepository("target/local-repo"), null));
    MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
    session.setCurrentProject(project);
    session.setProjects(Arrays.asList(project));
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession)

Example 53 with MavenExecutionRequest

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

the class AbstractDeployMojo method getProxy.

/**
 * Get proxy information for Maven 3.
 *
 * @param repository
 * @param settingsDecrypter
 * @return
 */
private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
    String protocol = repository.getProtocol();
    String url = repository.getUrl();
    getLog().debug("repository protocol " + protocol);
    String originalProtocol = protocol;
    // so we will check both
    if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) {
        url = url.substring(4);
        if (url.startsWith("http")) {
            try {
                URL urlSite = new URL(url);
                protocol = urlSite.getProtocol();
                getLog().debug("found dav protocol so transform to real transport protocol " + protocol);
            } catch (MalformedURLException e) {
                getLog().warn("fail to build URL with " + url);
            }
        }
    } else {
        getLog().debug("getProxy 'protocol': " + protocol);
    }
    if (mavenSession != null && protocol != null) {
        MavenExecutionRequest request = mavenSession.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol.equalsIgnoreCase(proxy.getProtocol()))) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        // so hackish for wagon the protocol is https for site dav:
                        // dav:https://dav.codehaus.org/mojo/
                        // proxy.getProtocol() );
                        proxyInfo.setType(protocol);
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        getLog().debug("found proxyInfo " + ("host:port " + proxyInfo.getHost() + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()));
                        return proxyInfo;
                    }
                }
            }
        }
    }
    getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found");
    return null;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MalformedURLException(java.net.MalformedURLException) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) URL(java.net.URL)

Example 54 with MavenExecutionRequest

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

the class AbstractSiteDeployWebDavTest method davDeployThruProxyWithoutAuthzInProxy.

@Test
public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {
    FileUtils.cleanDirectory(siteTargetPath);
    SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
    try {
        File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
        AbstractMojo mojo = getMojo(pluginXmlFile);
        assertNotNull(mojo);
        SiteMavenProjectStub siteMavenProjectStub = new SiteMavenProjectStub("deploy-dav");
        // olamy, Note : toto is something like foo or bar for french folks :-)
        String siteUrl = "dav:http://toto.com/site/";
        siteMavenProjectStub.getDistributionManagement().getSite().setUrl(siteUrl);
        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("http");
        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");
        setVariableValueToObject(mojo, "inputDirectory", inputDirectory);
        mojo.execute();
        assertContentInFiles();
        assertTrue(requestsContainsProxyUse(simpleDavServerHandler.httpRequests));
        for (HttpRequest rq : simpleDavServerHandler.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) MavenSession(org.apache.maven.execution.MavenSession) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) AbstractMojo(org.apache.maven.plugin.AbstractMojo) File(java.io.File) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 55 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getProxy.

private ProxyInfo getProxy(String protocol) {
    MavenSession session = legacySupport.getSession();
    if (session != null && protocol != null) {
        MavenExecutionRequest request = session.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        proxyInfo.setType(proxy.getProtocol());
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        return proxyInfo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult)

Aggregations

MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)56 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)40 File (java.io.File)24 MavenSession (org.apache.maven.execution.MavenSession)20 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)14 MavenProject (org.apache.maven.project.MavenProject)14 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)10 IOException (java.io.IOException)9 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)9 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)9 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)6 Path (java.nio.file.Path)6 Properties (java.util.Properties)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)6 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)5 ProjectBuilder (org.apache.maven.project.ProjectBuilder)5