Search in sources :

Example 1 with MavenProjectResourcesStub

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

the class CopyResourcesMojoTest method testCopyWithoutFiltering.

public void testCopyWithoutFiltering() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    mojo.setOutputDirectory(outputDirectory);
    Resource resource = new Resource();
    resource.setDirectory(getBasedir() + "/src/test/unit-files/copy-resources-test/no-filter");
    resource.setFiltering(false);
    mojo.setResources(Collections.singletonList(resource));
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("CopyResourcesMojoTest");
    File targetFile = new File(getBasedir(), "/target/copyResourcesTests");
    project.setBaseDir(targetFile);
    setVariableValueToObject(mojo, "project", project);
    mojo.execute();
    assertTrue(new File(targetFile, "config.properties").exists());
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) ResourcesMojo(org.apache.maven.plugins.resources.ResourcesMojo) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 2 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceExclude.

/**
     * @throws Exception
     */
public void testResourceExclude() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceExclude");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file1.include");
    project.addFile("file2.exclude");
    project.addFile("file3.nottest");
    project.addFile("file4.txt");
    project.addFile("package/file1.include");
    project.addFile("package/file2.exclude");
    project.addFile("package/file3.nottest");
    project.addFile("package/file4.txt");
    project.addFile("notpackage/file1.include");
    project.addFile("notpackage/file2.exclude");
    project.addFile("notpackage/file3.nottest");
    project.addFile("notpackage/file4.txt");
    project.addFile("package/test/file1.txt");
    project.addFile("package/nottest/file2.txt");
    project.addFile("notpackage/test/file1.txt");
    project.addFile("notpackage/nottest/file.txt");
    project.setupBuildEnvironment();
    project.addExclude("**/*.exclude");
    project.addExclude("**/nottest*");
    project.addExclude("**/notest");
    project.addExclude("**/notpackage*");
    project.addExclude("**/notpackage*/**");
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/test"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/file1.include"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/file1.include"));
    assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include"));
    assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/nottest/file.txt"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 3 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceTargetPath.

/**
     * @throws Exception
     */
public void testResourceTargetPath() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceTargetPath");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.setTargetPath("org/apache/maven/plugin/test");
    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, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/file4.txt"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/package/file3.nottest"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/notpackage/file1.include"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/package/test"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/notpackage/test"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 4 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceInclude.

/**
     * @throws Exception
     */
public void testResourceInclude() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceInclude");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file1.include");
    project.addFile("file2.exclude");
    project.addFile("file3.nottest");
    project.addFile("file4.txt");
    project.addFile("package/file1.include");
    project.addFile("package/file2.exclude");
    project.addFile("package/file3.nottest");
    project.addFile("package/file4.txt");
    project.addFile("notpackage/file1.include");
    project.addFile("notpackage/file2.exclude");
    project.addFile("notpackage/file3.nottest");
    project.addFile("notpackage/file4.txt");
    project.addFile("package/test/file1.txt");
    project.addFile("package/nottest/file2.txt");
    project.addFile("notpackage/test/file1.txt");
    project.addFile("notpackage/nottest/file.txt");
    project.setupBuildEnvironment();
    project.addInclude("*.include");
    project.addInclude("**/test");
    project.addInclude("**/test/file*");
    project.addInclude("**/package/*.include");
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "resources", resources);
    setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/test"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/file1.include"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/file1.include"));
    assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include"));
    assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/nottest/file.txt"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 5 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testPropertyFiles_Filtering.

/**
     * @throws Exception
     */
public void testPropertyFiles_Filtering() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Filtering");
    List<Resource> resources = project.getBuild().getResources();
    LinkedList<String> filterList = new LinkedList<String>();
    assertNotNull(mojo);
    project.addFile("file4.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, "buildFilters", filterList);
    setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
    mojo.execute();
    String resourcesDir = project.getOutputDirectory();
    String checkString = "current working directory=testdir";
    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)

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