Search in sources :

Example 16 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testPropertyFiles_Extra.

/**
     * @throws Exception
     */
public void testPropertyFiles_Extra() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Extra");
    List<Resource> resources = project.getBuild().getResources();
    LinkedList<String> filterList = new LinkedList<String>();
    assertNotNull(mojo);
    project.addFile("extra.properties", "current working directory=${dir}");
    project.addFile("filter.properties", "dir:testdir");
    project.setResourceFiltering(0, true);
    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, "filters", filterList);
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    String checkString = "current working directory=testdir";
    assertContent(resourcesDir + "/extra.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 17 with MavenProjectResourcesStub

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

the class TestResourcesTest method testTestResourceDirectoryCreation.

/**
     * @throws Exception
     */
public void testTestResourceDirectoryCreation() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo("testResources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("testResourceDirectoryStructure");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file4.txt");
    project.addFile("package/file3.nottest");
    project.addFile("notpackage/file1.include");
    project.addFile("package/test/file1.txt");
    project.addFile("notpackage/test/file2.txt");
    project.setupBuildEnvironment();
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getTestOutputDirectory()));
    setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resorucesDir = project.getTestOutputDirectory();
    assertTrue(FileUtils.fileExists(resorucesDir + "/file4.txt"));
    assertTrue(FileUtils.fileExists(resorucesDir + "/package/file3.nottest"));
    assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/file1.include"));
    assertTrue(FileUtils.fileExists(resorucesDir + "/package/test"));
    assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/test"));
}
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