[shrinkwrap-issues] [JBoss JIRA] (SHRINKRES-100) Allow Maven resource filtering to be applied for resources imported via MavenImporter

Yannick Majoros (JIRA) issues at jboss.org
Thu May 7 03:50:46 EDT 2015


    [ https://issues.jboss.org/browse/SHRINKRES-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13066089#comment-13066089 ] 

Yannick Majoros edited comment on SHRINKRES-100 at 5/7/15 3:49 AM:
-------------------------------------------------------------------

Better yet, it should be easy to add a method that just adds any test classpath resource to deployed archive. Here is a tested version, which I just call with this from @Deployment:

{code:java}
        addClassPathResourceToArchive(webArchive, "test.properties");

Here is the method code. I suggest adding a non-static version to ResourceContainer.

    private static <T extends Archive<T>> T addClassPathResourceToArchive(ResourceContainer<T> webArchive, String resourceName) throws IOException {
        File targetFile = writeClassPathResourceToTempFile(resourceName);
        return webArchive.addAsResource(targetFile, resourceName);
    }

    private static File writeClassPathResourceToTempFile(String resourceName) throws IOException {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        File targetFile = File.createTempFile("arquillian_test_", "." + resourceName);
        try (InputStream inputStream = contextClassLoader.getResourceAsStream(resourceName)) {
            Path targetPath = targetFile.toPath();
            Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
        }
        return targetFile;
    }
{code}


was (Author: ymajoros):
Better yet, it should be easy to add a method that just adds any test classpath resource to deployed archive. Here is a tested version, which I just call with this from @Deployment:

        addClassPathResourceToArchive(webArchive, "test.properties");

Here is the method code. I suggest adding a non-static version to ResourceContainer.

    private static <T extends Archive<T>> T addClassPathResourceToArchive(ResourceContainer<T> webArchive, String resourceName) throws IOException {
        File targetFile = writeClassPathResourceToTempFile(resourceName);
        return webArchive.addAsResource(targetFile, resourceName);
    }

    private static File writeClassPathResourceToTempFile(String resourceName) throws IOException {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        File targetFile = File.createTempFile("arquillian_test_", "." + resourceName);
        try (InputStream inputStream = contextClassLoader.getResourceAsStream(resourceName)) {
            Path targetPath = targetFile.toPath();
            Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
        }
        return targetFile;
    }

> Allow Maven resource filtering to be applied for resources imported via MavenImporter
> -------------------------------------------------------------------------------------
>
>                 Key: SHRINKRES-100
>                 URL: https://issues.jboss.org/browse/SHRINKRES-100
>             Project: ShrinkWrap Resolvers
>          Issue Type: Feature Request
>          Components: maven
>            Reporter: Karel Piwko
>              Labels: api-change
>
> When packaging resources to via MavenImporter, any filters defined on the path are ignored. Add support for applying filters.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the shrinkwrap-issues mailing list