Search in sources :

Example 61 with Resource

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

Example 62 with Resource

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

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

Example 64 with Resource

use of org.apache.maven.model.Resource in project sling by apache.

the class GenerateAdapterMetadataMojo method addResource.

private void addResource() {
    final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
    boolean found = false;
    final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
    while (!found && rsrcIterator.hasNext()) {
        final Resource rsrc = rsrcIterator.next();
        found = rsrc.getDirectory().equals(ourRsrcPath);
    }
    if (!found) {
        final Resource resource = new Resource();
        resource.setDirectory(this.outputDirectory.getAbsolutePath());
        this.project.addResource(resource);
    }
}
Also used : Resource(org.apache.maven.model.Resource)

Example 65 with Resource

use of org.apache.maven.model.Resource in project sling by apache.

the class ValidationMojo method execute.

/**
     * @see org.apache.maven.plugin.AbstractMojo#execute()
     */
public void execute() throws MojoExecutionException {
    if (this.skip) {
        getLog().info("Validation is skipped.");
        return;
    }
    final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
    while (rsrcIterator.hasNext()) {
        final Resource rsrc = rsrcIterator.next();
        final File directory = new File(rsrc.getDirectory());
        if (directory.exists()) {
            getLog().debug("Scanning " + rsrc.getDirectory());
            final DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(directory);
            if (rsrc.getExcludes() != null && rsrc.getExcludes().size() > 0) {
                scanner.setExcludes((String[]) rsrc.getExcludes().toArray(new String[rsrc.getExcludes().size()]));
            }
            scanner.addDefaultExcludes();
            if (rsrc.getIncludes() != null && rsrc.getIncludes().size() > 0) {
                scanner.setIncludes((String[]) rsrc.getIncludes().toArray(new String[rsrc.getIncludes().size()]));
            }
            scanner.scan();
            final String[] files = scanner.getIncludedFiles();
            if (files != null) {
                for (int m = 0; m < files.length; m++) {
                    this.validate(directory, files[m]);
                }
            }
        }
    }
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) 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