Search in sources :

Example 11 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceDirectoryStructure.

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

Example 12 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testWindowsPathEscapingEnabled.

public void testWindowsPathEscapingEnabled() 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.TRUE);
    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 13 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceDirectoryStructure_RelativePath.

/**
     * @throws Exception
     */
public void testResourceDirectoryStructure_RelativePath() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceDirectoryStructure_RelativePath");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.setOutputDirectory("../relative_dir");
    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 + "/file4.txt"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/file3.nottest"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/package/test"));
    assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/test"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 14 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testResourceProjectProperties_Filtering.

/**
     * @throws Exception
     */
public void testResourceProjectProperties_Filtering() throws Exception {
    File testPom = new File(getBasedir(), defaultPomFilePath);
    ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
    MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceProjectProperties_Filtering");
    List<Resource> resources = project.getBuild().getResources();
    assertNotNull(mojo);
    project.addFile("file4.txt", "current working directory = ${user.dir}");
    project.setResourceFiltering(0, true);
    project.addProperty("user.dir", "FPJ kami!!!");
    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();
    String checkString = "current working directory = FPJ kami!!!";
    assertContent(resourcesDir + "/file4.txt", checkString);
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 15 with MavenProjectResourcesStub

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

the class ResourcesMojoTest method testPropertyFiles_MainAndExtra.

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