]
Dan Allen commented on SHRINKWRAP-247:
--------------------------------------
I think we can use a Filter as a method argument to imply resources should be added
recursively.
Let's first consider the example in the workaround Aslak provided above (slight
revised):
{code:java}
war.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory("src/main/webapp").as(GenericArchive.class),
"/", Filters.includeAll());
{code}
We can introduce a native method on WebArchive to support this operation:
{code:java}
addAsWebResources(File sourceDirectory, String path, Filter<ArchivePath> filter)
{code}
If the File is a directory, it's walked recursively. Each file found becomes an
archive path relative to the second argument and passed through the filter before being
added to the archive.
If the File is a file, it's as though only one file is found.
Here's the example from above rewritten to use this method:
{code:java}
war.addAsWebResources(new File("src/main/webapp"), "/",
Filters.includeAll())
{code}
Of course, we can play around with the order of the parameters. This order is consistent
with the merge operation.
As Aslak mentioned, this operation should be available for all named archive locations
(e.g., web resource, WEB-INF resource, META-INF resource, etc)
If we want it to be more like the ClassContainer, we might have something like:
{code}
addAsWebResources(Filter<ArchivePath> filter, String path, File... sourceDirectory)
{code}
We could default the path to "/", allowing that argument to be dropped:
{code}
addAsWebResources(Filter<ArchivePath> filter, File... sourceDirectory)
{code}
I don't think developers are going to be too picky about the arguments or order as
long as the functionality is present.
Support recursive addition of web resources
--------------------------------------------
Key: SHRINKWRAP-247
URL:
https://issues.jboss.org/browse/SHRINKWRAP-247
Project: ShrinkWrap
Issue Type: Feature Request
Affects Versions: 1.0.0-alpha-11
Reporter: Karel Piwko
Labels: starter
There should be a similar way to include web resources recursively as for classes.
Imagine that you would like to build a complete WAR used for functional tests, than the
deployment method body will look like:
WebArchive war = ShrinkWrap.create(WebArchive.class,
"practice0x-testing.war")
.addLibraries(Dependencies.use(MavenDependencies.class).resolveFrom("pom.xml",
new ScopeFilter("", "compile")))
.addPackages(true, NO_TEST_CLASSES,
org.jboss.lectures.auction.AuctionManager.class.getPackage())
.addResource(new File("src/main/webapp/detail.xhtml"),
ArchivePaths.create("detail.xhtml"))
.addResource(new File("src/main/webapp/index.html"),
ArchivePaths.create("index.html"))
.addResource(new File("src/main/webapp/list.xhtml"),
ArchivePaths.create("list.xhtml"))
.addResource(new File("src/main/webapp/myAuctions.xhtml"),
ArchivePaths.create("myAuctions.xhtml"))
.addResource(new File("src/main/webapp/myOverview.xhtml"),
ArchivePaths.create("myOverview.xhtml"))
.addResource(new File("src/main/webapp/newAuction.xhtml"),
ArchivePaths.create("newAuction.xhtml"))
.addResource(new File("src/main/webapp/newAuctionDetails.xhtml"),
ArchivePaths.create("newAuctionDetails.xhtml"))
.addResource(new File("src/main/webapp/newAuctionSummary.xhtml"),
ArchivePaths.create("newAuctionSummary.xhtml"))
.addResource(new File("src/main/webapp/script.js"),
ArchivePaths.create("script.js"))
.addResource(new File("src/main/webapp/style.css"),
ArchivePaths.create("style.css"))
.addResource(new File("src/main/webapp/style.ie6.css"),
ArchivePaths.create("style.ie6.css"))
.addResource(new File("src/main/webapp/style.ie7.css"),
ArchivePaths.create("style.ie7.css"))
.addResource(new File("src/main/webapp/images/01.png"),
ArchivePaths.create("images/01.png"))
.addResource(new File("src/main/webapp/images/02.png"),
ArchivePaths.create("images/02.png"))
.addResource(new File("src/main/webapp/images/03.png"),
ArchivePaths.create("images/03.png"))
.addResource(new File("src/main/webapp/images/Block-h.png"),
ArchivePaths.create("images/Block-h.png"))
.addResource(new File("src/main/webapp/images/Block-s.png"),
ArchivePaths.create("images/Block-s.png"))
.addResource(new File("src/main/webapp/images/Block-v.png"),
ArchivePaths.create("images/Block-v.png"))
.addResource(new
File("src/main/webapp/images/BlockContentBullets.png"),
ArchivePaths.create("images/BlockContentBullets.png"))
.addResource(new File("src/main/webapp/images/BlockHeader.png"),
ArchivePaths.create("images/BlockHeader.png"))
.addResource(new
File("src/main/webapp/images/BlockHeaderIcon.png"),
ArchivePaths.create("images/BlockHeaderIcon.png"))
.addResource(new File("src/main/webapp/images/Button.png"),
ArchivePaths.create("images/Button.png"))
.addResource(new File("src/main/webapp/images/Footer.png"),
ArchivePaths.create("images/Footer.png"))
.addResource(new File("src/main/webapp/images/Header.jpg"),
ArchivePaths.create("images/Header.jpg"))
.addResource(new File("src/main/webapp/images/Header.png"),
ArchivePaths.create("images/Header.png"))
.addResource(new File("src/main/webapp/images/MenuItem.png"),
ArchivePaths.create("images/MenuItem.png"))
.addResource(new File("src/main/webapp/images/Page-BgGlare.png"),
ArchivePaths.create("images/Page-BgGlare.png"))
.addResource(new
File("src/main/webapp/images/Page-BgSimpleGradient.jpg"),
ArchivePaths.create("images/Page-BgSimpleGradient.jpg"))
.addResource(new File("src/main/webapp/images/PostQuote.png"),
ArchivePaths.create("images/PostQuote.png"))
.addResource(new File("src/main/webapp/images/Sheet-h.png"),
ArchivePaths.create("images/Sheet-h.png"))
.addResource(new File("src/main/webapp/images/Sheet-s.png"),
ArchivePaths.create("images/Sheet-s.png"))
.addResource(new File("src/main/webapp/images/Sheet-v.png"),
ArchivePaths.create("images/Sheet-v.png"))
.addResource(new File("src/main/webapp/images/contact.jpg"),
ArchivePaths.create("images/contact.jpg"))
.addResource(new File("src/main/webapp/images/link photo.txt"),
ArchivePaths.create("images/link photo.txt"))
.addResource(new File("src/main/webapp/images/nav.png"),
ArchivePaths.create("images/nav.png"))
.addResource(new File("src/main/webapp/images/rssIcon.png"),
ArchivePaths.create("images/rssIcon.png"))
.addResource(new File("src/main/webapp/images/spacer.gif"),
ArchivePaths.create("images/spacer.gif"))
.addResource(new File("src/main/webapp/images/spectacles.gif"),
ArchivePaths.create("images/spectacles.gif"))
.addResource(new File("src/main/webapp/images/subitem-bg.png"),
ArchivePaths.create("images/subitem-bg.png"))
.addResource(new
File("src/main/webapp/resources/auction/auctionList.xhtml"),
ArchivePaths.create("resources/auction/auctionList.xhtml"))
.addResource(new
File("src/main/webapp/resources/auction/menuItem.xhtml"),
ArchivePaths.create("resources/auction/menuItem.xhtml"))
.addResource(new File("src/main/webapp/templates/home.xhtml"),
ArchivePaths.create("templates/home.xhtml"))
.addResource(new File("src/main/webapp/templates/menu.xhtml"),
ArchivePaths.create("templates/menu.xhtml"))
.addResource(new File("src/main/webapp/templates/login.xhtml"),
ArchivePaths.create("templates/login.xhtml"))
.addWebResource(new File("src/main/webapp/WEB-INF/beans.xml"),
"beans.xml")
.addWebResource(new
File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml")
.addWebResource(new
File("src/main/webapp/WEB-INF/jboss-scanning.xml"),
"jboss-scanning.xml")
.addWebResource(new File("src/main/resources/import.sql"),
ArchivePaths.create("classes/import.sql"))
.addManifestResource(new
File("src/main/resources/META-INF/persistence.xml"))
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml"));
This could be massively reduced using a recursive addResources() call with a filter.
(ommiting incomming API changes in SHRINKWRAP-241)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: