Search in sources :

Example 21 with Resource

use of org.apache.maven.model.Resource 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 22 with Resource

use of org.apache.maven.model.Resource 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 23 with Resource

use of org.apache.maven.model.Resource 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)

Example 24 with Resource

use of org.apache.maven.model.Resource 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 25 with Resource

use of org.apache.maven.model.Resource 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)

Aggregations

Resource (org.apache.maven.model.Resource)65 File (java.io.File)49 MavenProjectResourcesStub (org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub)17 ArrayList (java.util.ArrayList)16 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)11 Properties (java.util.Properties)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 FileInputStream (java.io.FileInputStream)7 List (java.util.List)6 InputStream (java.io.InputStream)5 OutputStream (java.io.OutputStream)5 URL (java.net.URL)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 URLClassLoader (java.net.URLClassLoader)3 Iterator (java.util.Iterator)3 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2