Search in sources :

Example 6 with MavenProjectResourcesStub

use of org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub in project maven-plugins by apache.

the class ResourcesMojoTest method testWindowsPathEscapingDisabled.

public void testWindowsPathEscapingDisabled() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("windows-paths");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.getProperties().setProperty("basePath", "C:\\Users\\Administrator");
    project.getProperties().setProperty("docsPath", "${basePath}\\Documents");
    project.addFile("path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}");
    project.setResourceFiltering(0, true);
    project.cleanBuildEnvironment();
    project.setupBuildEnvironment();
    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.FALSE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    assertTrue(FileUtils.fileExists(new File(resourcesDir, "path-listing.txt").getAbsolutePath()));
    assertEquals("base path is C:\\Users\\Administrator\ndocuments path is C:\\Users\\Administrator\\Documents", FileUtils.fileRead(new File(resourcesDir, "path-listing.txt")));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 7 with MavenProjectResourcesStub

use of org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub in project maven-plugins by apache.

the class ResourcesMojoTest method testPropertyFiles_Filtering_TokensInFilters.

/**
     * Validates that a Filter token containing a project property will be resolved before the Filter is applied to the
     * resources.
     *
     * @throws Exception
     */
public void testPropertyFiles_Filtering_TokensInFilters() throws Exception {
    final File testPom = new File(getBasedir(), defaultPomFilePath);
    final ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    final MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Filtering_TokensInFilters");
    final List<Resource> resources = project.getBuild().getResources();
    final LinkedList<String> filterList = new LinkedList<String>();
    assertNotNull(mojo);
    project.addFile("file4.properties", "current working directory=${filter.token}");
    project.addFile("filter.properties", "filter.token=${pom-property}");
    project.setResourceFiltering(0, true);
    project.addProperty("pom-property", "foobar");
    project.setupBuildEnvironment();
    filterList.add(project.getResourcesDirectory() + "filter.properties");
    // setVariableValueToObject(mojo,"encoding","UTF-8");
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "buildFilters", filterList);
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    final String resourcesDir = project.getOutputDirectory();
    final String checkString = "current working directory=foobar";
    assertContent(resourcesDir + "/file4.properties", checkString);
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File) LinkedList(java.util.LinkedList)

Example 8 with MavenProjectResourcesStub

use of org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub in project maven-plugins by apache.

the class ResourcesMojoTest method testResourceEncoding.

/**
     * @throws Exception
     */
public void testResourceEncoding() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("encoding");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file4.txt");
    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);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    assertTrue(FileUtils.fileExists(resourcesDir + "/file4.txt"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 9 with MavenProjectResourcesStub

use of org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub 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 10 with MavenProjectResourcesStub

use of org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub in project maven-plugins by apache.

the class ResourcesMojoTest method testProjectProperty_Filtering_PropertyDestination.

/**
     * @throws Exception
     */
public void testProjectProperty_Filtering_PropertyDestination() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePojectProperty_Filtering_PropertyDestination");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file4.properties", "current working directory=${description}");
    project.setResourceFiltering(0, true);
    project.setupBuildEnvironment();
    // setup dummy property
    project.setDescription("c:\\\\org\\apache\\test");
    // 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);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    String checkString = "current working directory=c:\\\\org\\\\apache\\\\test";
    assertContent(resourcesDir + "/file4.properties", checkString);
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Aggregations

File (java.io.File)17 Resource (org.apache.maven.model.Resource)17 MavenProjectResourcesStub (org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub)17 LinkedList (java.util.LinkedList)4 FileInputStream (java.io.FileInputStream)1 Properties (java.util.Properties)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenSession (org.apache.maven.execution.MavenSession)1 ResourcesMojo (org.apache.maven.plugins.resources.ResourcesMojo)1