-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Improve Resource use in MetaInfConfiguration #10889
Conversation
There was a problem hiding this 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
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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!)
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
if (!metaInf.isDirectory()) | ||
return tlds; //no tlds | ||
|
||
try (Stream<Path> stream = Files.walk(metaInf.getPath())) |
There was a problem hiding this comment.
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 calledfoo.tld/
) - ignore if found in
/WEB-INF/tags/
(with exception forimplicit.tld
) - all other hits are valid.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
* @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<>(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Show resolved
Hide resolved
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
if (isEmptyFragment(webFrag)) | ||
return; | ||
|
||
//convert webFragment Resource to one tied to the Context lifecycle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
...ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java
Show resolved
Hide resolved
jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java
Outdated
Show resolved
Hide resolved
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>
There was a problem hiding this 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
for (Resource r : jars) | ||
{ | ||
Resource dir = r; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (Resource r : jars) | |
{ | |
Resource dir = r; | |
for (Resource dir : jars) | |
{ |
META-INF/resources
andMETA-INF/web-fragment.xml
Resources with the lifecycle of theWebAppContext