Search in sources :

Example 16 with Resource

use of org.apache.maven.model.Resource in project maven-plugins by apache.

the class DefaultCheckstyleExecutor method addResourceFilesToProcess.

private void addResourceFilesToProcess(CheckstyleExecutorRequest request, List<Resource> resources, Collection<File> files) throws IOException {
    for (Resource resource : resources) {
        if (resource.getDirectory() != null) {
            File resourcesDirectory = new File(resource.getDirectory());
            if (resourcesDirectory.isDirectory()) {
                String includes = request.getResourceIncludes();
                String excludes = request.getResourceExcludes();
                // MCHECKSTYLE-214: Only with project-root respect in/excludes, otherwise you'll get every file
                if (resourcesDirectory.equals(request.getProject().getBasedir())) {
                    String resourceIncludes = StringUtils.join(resource.getIncludes().iterator(), ",");
                    if (StringUtils.isEmpty(includes)) {
                        includes = resourceIncludes;
                    } else {
                        includes += "," + resourceIncludes;
                    }
                    String resourceExcludes = StringUtils.join(resource.getExcludes().iterator(), ",");
                    if (StringUtils.isEmpty(excludes)) {
                        excludes = resourceExcludes;
                    } else {
                        excludes += "," + resourceExcludes;
                    }
                }
                List<File> resourceFiles = FileUtils.getFiles(resourcesDirectory, includes, excludes);
                files.addAll(resourceFiles);
                getLogger().debug("Added " + resourceFiles.size() + " resource files found in '" + resourcesDirectory.getAbsolutePath() + "'.");
            } else {
                getLogger().debug("The resources directory '" + resourcesDirectory.getAbsolutePath() + "' does not exist or is not a directory.");
            }
        }
    }
}
Also used : Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 17 with Resource

use of org.apache.maven.model.Resource in project maven-plugins by apache.

the class MavenProjectResourcesStub method setupResources.

private void setupResources() {
    Resource resource = new Resource();
    // see MavenProjectBasicStub for details
    // of getBasedir
    // setup default resources
    resource.setDirectory(getBasedir().getPath() + "/src/main/resources");
    resource.setFiltering(false);
    resource.setTargetPath(null);
    build.addResource(resource);
}
Also used : Resource(org.apache.maven.model.Resource)

Example 18 with Resource

use of org.apache.maven.model.Resource in project maven-plugins by apache.

the class MavenProjectResourcesStub method setupTestResources.

private void setupTestResources() {
    Resource resource = new Resource();
    // see MavenProjectBasicStub for details
    // of getBasedir
    // setup default test resources
    resource.setDirectory(getBasedir().getPath() + "/src/test/resources");
    resource.setFiltering(false);
    resource.setTargetPath(null);
    build.addTestResource(resource);
}
Also used : Resource(org.apache.maven.model.Resource)

Example 19 with Resource

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

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

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