Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Resource use in MetaInfConfiguration #10889

Merged

Conversation

janbartel
Copy link
Contributor

  • Reduce mounts of jar:file references in MetaInfConfiguration.
  • Only align META-INF/resources and META-INF/web-fragment.xml Resources with the lifecycle of the WebAppContext
  • Make scan of .tlds more efficient.

@janbartel janbartel requested review from gregw and joakime November 14, 2023 05:58
@janbartel janbartel self-assigned this Nov 14, 2023
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I will be away, feel free to dismiss this review once this is fixed

Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about 10% of what PR #10816 does.

This PR doesn't address the other issues with MetaInfConfiguration (that PR #10816 does address)

  • such as the NPEs present in some of the find methods
  • the continued use of File / Files / Path APIs
  • the bad scope of methods
  • the constant open/close/open/close/etc of Resources for no good reason
  • the lack of proper use of Resources (note the plural) utility methods
  • creating Resource objects of jar files themselves, not the contents (there is no reason to do that in this entire class, mount them, lots of code gets simpler! every Resource is a directory!)

if (!metaInf.isDirectory())
return tlds; //no tlds

try (Stream<Path> stream = Files.walk(metaInf.getPath()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Resource API, not Path + Walk. (like the other PR does).

In fact, I just checked, both this PR and my other one does this entire step (scan for TLDs) incorrectly per spec.

For webapps, its a recursive scan for anything *.tld from root.

  • ignore if found in /WEB-INF/classes/
  • ignore if found in /WEB-INF/lib/
  • ignore if ends in / (ie: it's a directory called foo.tld/)
  • ignore if found in /WEB-INF/tags/ (with exception for implicit.tld)
  • all other hits are valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be correct, as if you look at all previous versions of jetty that are looking for tlds we're using the JarFile class to enumerate all entries in the jar, then picking those that start with META_INF and end with .tld.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened Issue #10899 for this (with links to relevant parts of the spec)

* @return the collection of tlds as url references
* @throws IOException if unable to scan the jar file
*/
private Collection<URL> getTlds(WebAppContext context, URI uri) throws IOException
private Collection<URL> getTlds(WebAppContext context, Resource resource) throws IOException
{
HashSet<URL> tlds = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strongly discouraged by Java now. (using URL in a Set or any kind of comparison or hashcode/equals logic)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, as we're passing this on to the Apache Jasper implementation we need to support what they want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Apache Jasper Implementation uses a collection of org.apache.tomcat.util.descriptor.tld.TldResourcePath.
Internally, Apache Jasper uses String and URI, not URL.
The Set<URL> is entirely on us, not Apache Jasper.
See org.eclipse.jetty.ee10.apache.jsp.JettyTldPreScanned which also does not use Set<URL> too.

@janbartel janbartel requested review from gregw and joakime November 14, 2023 23:56
gregw
gregw previously approved these changes Nov 15, 2023
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, but I can see clearly what it is doing.

if (isEmptyFragment(webFrag))
return;

//convert webFragment Resource to one tied to the Context lifecycle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@joakime joakime changed the title Jetty 12.0.x reduce resources metainfconfiguration Improve Resource use in MetaInfConfiguration Nov 15, 2023
@janbartel
Copy link
Contributor Author

This is about 10% of what PR #10816 does.

This PR doesn't address the other issues with MetaInfConfiguration (that PR #10816 does address)

  • such as the NPEs present in some of the find methods
  • the continued use of File / Files / Path APIs
  • the bad scope of methods
  • the constant open/close/open/close/etc of Resources for no good reason
  • the lack of proper use of Resources (note the plural) utility methods
  • creating Resource objects of jar files themselves, not the contents (there is no reason to do that in this entire class, mount them, lots of code gets simpler! every Resource is a directory!)

I think this PR is a big improvement on what is there - particularly the rigorous lifecycle of the Resources that have mount points.

I would like to merge this, then you can build on top of it for your enhancements.

…e10/webapp/MetaInfConfiguration.java

Co-authored-by: Greg Wilkins <gregw@webtide.com>
@janbartel janbartel requested a review from gregw November 28, 2023 00:19
gregw
gregw previously approved these changes Nov 28, 2023
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good but one small niggle

Comment on lines 359 to 362
for (Resource r : jars)
{
Resource dir = r;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (Resource r : jars)
{
Resource dir = r;
for (Resource dir : jars)
{

@janbartel janbartel merged commit df42cb2 into jetty-12.0.x Nov 29, 2023
7 checks passed
@janbartel janbartel deleted the jetty-12.0.x-reduce-resources-metainfconfiguration branch November 29, 2023 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants