Skip to content

Instantly share code, notes, and snippets.

@PiotrNowicki
Created June 25, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrNowicki/2989390 to your computer and use it in GitHub Desktop.
Save PiotrNowicki/2989390 to your computer and use it in GitHub Desktop.
Shrinkwrap delete
WebArchive archive = ShrinkWrap.create(WebArchive.class).addPackages(true, "eu.awaketech.mymodule")
.addAsWebInfResource("beans.xml", "beans.xml")
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml");
// To remove some package, I need to do:
archive.delete("/WEB-INF/classes/eu/awaketech/mymodule/config");
// Wish I could do:
// - archive.delete(DataSource.class.getPackage());
// - archive.delete(DataSource.class);
@bartoszmajsak
Copy link

How about using filters instead of getting all into the archive and then removing? Sounds a bit more natural imho :)

@PiotrNowicki
Copy link
Author

Thanks Bartosz! you're right - it's more natural :-)

Now... perhaps Filters.exclude(Class) would be nice? ;-) Why the include has it and exclude doesn't?

@bartoszmajsak
Copy link

That's question to @ALRubinger
Note that javadoc I linked above is from some older version though

@PiotrNowicki
Copy link
Author

Aaaah, and there it is! http://docs.jboss.org/shrinkwrap/1.0.0-cr-3/org/jboss/shrinkwrap/api/Filters.html

Problem solved, thanks Bartosz!

@bartoszmajsak
Copy link

Anytime buddy :)

@ALRubinger
Copy link

Of course, excluding (applying a filter) before adding is the reason we haven't supported "delete" historically.

But now I think I've got a Use Case: The user might accept an Archive which was previously-created/populated from some source he/she does not control. And perhaps the user needs to modify that input archive to remove stuff. Currently we provide the ability to delete from String. This is API consistency; you can add a Class or Package but not remove it?

Piotr, would you like to open a JIRA? [1] And if so, any chance you'd like to work on this one?

S,
ALR

[1] https://issues.jboss.org/browse/SHRINKWRAP

@PiotrNowicki
Copy link
Author

And here's the JIRA: https://issues.jboss.org/browse/SHRINKWRAP-411

Sure! I would gladly work on this one. I'll be able to take a look at it in the following week (vacation, so more free time, yay!)
If that's ok than you can count me in ;-)

Cheers!

@ALRubinger
Copy link

Super - we'll save it for you!

Dev Instructions: https://community.jboss.org/docs/DOC-14304
And please apply here for the CLA? https://cla.jboss.org

@PiotrNowicki
Copy link
Author

@ALRubinger - wanted to get started with it and just to be sure about it - those delete Class (Classes) and Package (Packages) methods should be in the ClassContainer API, right?

Just asking because none of the containers (org.jboss.shrinkwrap.api.container.) have any delete methods - just additions are present. The only delete methods are on the Archive level, but this is too general as not every Archive must be capable of holding a Class/Package artifacts, right?

@ALRubinger
Copy link

Exactly. For everything that has an "add", we should have a corresponding "delete". Go for it!

@tommysdk
Copy link

Just stumbled across this one myself in my current use case, where I would like to remove a couple of classes in a jar built by a third party, to stub out that particular functionality. Nice to see that you've taken this issue Piotr, it'll be a nice enhancement to the API.

@PiotrNowicki
Copy link
Author

@tommysdk great that you also find it useful :-)

The pull request is here shrinkwrap/shrinkwrap#58

Don't know if it should be linked with the JIRA right away or after the review and acceptance?

@tommysdk
Copy link

I made a quick review and thought it looked good. I think you can link the pull request to the JIRA issue right away (that's what I usually do). If it needs further adjustments @ALRubinger will let you know :-)

@PiotrNowicki
Copy link
Author

Ok, JIRA updated, CLA signed.

Just waiting for @ALRubinger review :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment