Search in sources :

Example 16 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 17 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 18 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 19 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project cayenne by apache.

the class DbImporterMojoTest 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 20 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project drools by kiegroup.

the class MavenEmbedder method buildMavenExecutionRequest.

protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException {
    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
    if (mavenRequest.getGlobalSettingsFile() != null) {
        mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile()));
    }
    SettingsSource userSettings = mavenRequest.getUserSettingsSource();
    if (userSettings != null) {
        if (userSettings instanceof FileSettingsSource) {
            mavenExecutionRequest.setUserSettingsFile(((FileSettingsSource) userSettings).getSettingsFile());
        } else {
            try {
                mavenExecutionRequest.setUserSettingsFile(copyInTempFile(userSettings.getInputStream(), "xml"));
            } catch (IOException ioe) {
                log.warn("Unable to use maven settings defined in " + userSettings, ioe);
            }
        }
    }
    try {
        componentProvider.lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings());
        componentProvider.lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest);
    } catch (MavenExecutionRequestPopulationException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    }
    ArtifactRepository localRepository = getLocalRepository();
    mavenExecutionRequest.setLocalRepository(localRepository);
    mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir());
    mavenExecutionRequest.setOffline(mavenRequest.isOffline());
    mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots());
    // TODO check null and create a console one ?
    mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener());
    mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound());
    mavenExecutionRequest.setCacheTransferError(true);
    mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties());
    mavenExecutionRequest.getSystemProperties().putAll(System.getProperties());
    if (mavenRequest.getSystemProperties() != null) {
        mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties());
    }
    mavenExecutionRequest.getSystemProperties().putAll(getEnvVars());
    if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) {
        for (String id : mavenRequest.getProfiles()) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            mavenExecutionRequest.addProfile(p);
            mavenExecutionRequest.addActiveProfile(id);
        }
    }
    MavenRepositoryConfiguration mavenRepoConf = getMavenRepositoryConfiguration();
    // DROOLS-899: Copy repositories defined in settings to execution request
    for (ArtifactRepository artifactRepository : mavenRepoConf.getArtifactRepositoriesForRequest()) {
        mavenExecutionRequest.addRemoteRepository(artifactRepository);
    }
    mavenExecutionRequest.setProxies(mavenRepoConf.getProxies());
    mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel());
    componentProvider.lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel());
    mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()).setInteractiveMode(mavenRequest.isInteractive()).setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals());
    if (mavenRequest.getPom() != null) {
        mavenExecutionRequest.setPom(new File(mavenRequest.getPom()));
    }
    if (mavenRequest.getWorkspaceReader() != null) {
        mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader());
    }
    if (mavenRequest.getBaseDirectory() != null) {
        mavenExecutionRequest.setBaseDirectory(new File(mavenRequest.getBaseDirectory()));
    }
    return mavenExecutionRequest;
}
Also used : FileSettingsSource(org.apache.maven.settings.building.FileSettingsSource) SettingsSource(org.apache.maven.settings.building.SettingsSource) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) MavenRepositoryConfiguration(org.kie.maven.integration.MavenRepositoryConfiguration) Logger(org.codehaus.plexus.logging.Logger) Profile(org.apache.maven.model.Profile) FileSettingsSource(org.apache.maven.settings.building.FileSettingsSource) File(java.io.File) IoUtils.copyInTempFile(org.kie.maven.integration.IoUtils.copyInTempFile) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

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