Search in sources :

Example 1 with AbstractMojo

use of org.apache.maven.plugin.AbstractMojo 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 2 with AbstractMojo

use of org.apache.maven.plugin.AbstractMojo in project m2e-nar by maven-nar.

the class MavenUtils method readSettings.

public static <T extends AbstractCompileMojo> NarExecution readSettings(final ConfiguratorContext context, final IMavenProjectFacade facade, final MojoExecution compileExecution, final Class<T> mojoType, final String buildType, final IProgressMonitor monitor) throws CoreException {
    final IMaven maven = context.getMaven();
    final MavenProject mavenProject = facade.getMavenProject();
    NarExecution settings = null;
    if (compileExecution != null) {
        // Load plugin with Maven in order to check config
        // and to get at aol.properties resource inside the plugin
        AbstractMojo narMojo = loadMojo(maven, mavenProject, compileExecution, AbstractMojo.class, monitor);
        try {
            // ClassRealm pluginRealm =
            // compileExecution.getMojoDescriptor().getPluginDescriptor().getClassRealm();
            // NarClassloader classloader = new NarClassloader(pluginRealm);
            // INarExecutionBuilder builder =
            // classloader.createNarExecutionBuilder(mavenProject,
            // compileMojo);
            // settings = builder.build(NarExecution.MAIN);
            T compileMojo = getConfiguredMojo(maven, mavenProject, compileExecution, mojoType, narMojo.getLog(), monitor);
            compileMojo.setNarProperties(new NarProperties(mavenProject, narMojo.getClass()));
            // Need to call validate to set up defaults
            compileMojo.validate();
            // Resolve the NAR artifacts, possibly from workspace
            compileMojo.prepareNarArtifacts(context, facade, monitor);
            NarExecutionBuilder builder = new NarExecutionBuilder(compileMojo, compileExecution);
            settings = builder.build(buildType);
        } catch (MojoFailureException e) {
            throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo"));
        } catch (MojoExecutionException e) {
            throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo"));
        } finally {
            releaseMojo(maven, mavenProject, narMojo, compileExecution, monitor);
        }
    } else {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't find default-nar-compile execution"));
    }
    return settings;
}
Also used : NarProperties(com.github.maven_nar.NarProperties) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractMojo(org.apache.maven.plugin.AbstractMojo) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IMaven(org.eclipse.m2e.core.embedder.IMaven) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Example 3 with AbstractMojo

use of org.apache.maven.plugin.AbstractMojo 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 4 with AbstractMojo

use of org.apache.maven.plugin.AbstractMojo in project maven-plugins by apache.

the class AbstractSiteDeployWebDavTest method noAuthzDavDeploy.

@Test
public void noAuthzDavDeploy() throws Exception {
    FileUtils.cleanDirectory(siteTargetPath);
    SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
    try {
        File pomFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
        AbstractMojo mojo = getMojo(pomFile);
        assertNotNull(mojo);
        SiteMavenProjectStub siteMavenProjectStub = new SiteMavenProjectStub("deploy-dav");
        assertTrue("dav server port not available: " + simpleDavServerHandler.getPort(), simpleDavServerHandler.getPort() > 0);
        siteMavenProjectStub.getDistributionManagement().getSite().setUrl("dav:http://localhost:" + simpleDavServerHandler.getPort() + "/site/");
        setVariableValueToObject(mojo, "project", siteMavenProjectStub);
        Settings settings = new Settings();
        setVariableValueToObject(mojo, "settings", settings);
        File inputDirectory = new File("src/test/resources/unit/deploy-dav/target/site");
        setVariableValueToObject(mojo, "inputDirectory", inputDirectory);
        mojo.execute();
        assertContentInFiles();
        assertFalse(requestsContainsProxyUse(simpleDavServerHandler.httpRequests));
    } finally {
        simpleDavServerHandler.stop();
    }
}
Also used : SiteMavenProjectStub(org.apache.maven.plugins.site.stubs.SiteMavenProjectStub) AbstractMojo(org.apache.maven.plugin.AbstractMojo) File(java.io.File) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Aggregations

AbstractMojo (org.apache.maven.plugin.AbstractMojo)4 File (java.io.File)3 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)3 Settings (org.apache.maven.settings.Settings)3 Test (org.junit.Test)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 MavenSession (org.apache.maven.execution.MavenSession)2 HttpRequest (org.apache.maven.plugins.site.deploy.SimpleDavServerHandler.HttpRequest)2 Proxy (org.apache.maven.settings.Proxy)2 NarProperties (com.github.maven_nar.NarProperties)1 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)1 HashMap (java.util.HashMap)1 ArtifactRepositoryFactory (org.apache.maven.artifact.repository.ArtifactRepositoryFactory)1 SiteTool (org.apache.maven.doxia.tools.SiteTool)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MavenProject (org.apache.maven.project.MavenProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1