-
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
ResourceCollection should not have a path #8711
Conversation
Nor name, nor filename unless all resources agree on it.
Nor name, nor filename unless all resources agree on it.
If we go this path, then I think
The changes you are doing here also apply to |
The code overall would be so much easier with a |
lastModified has a sensible and meaningful interpretation for composite directories: the most recently modified time of all the composites
Agreed.
Yep, should return null... I think this PR already does.
I'm on the fence about this one.... if for example you have a composite base resource and resolve "WEB-INF", then you may get back a composite that contains Flip side, is that if it always returned null, I don't think it would be a big problem... except perhaps for debugging.... maybe when we are naming contexts etc. So I think on balance going with the impl in this PR is OK.
Yep.
Oh I thought we got rid of that class? Is it still used? If not, let's kill it. If we are still using it, then I'll also review. |
Absolutely not! We have a bunch of methods that can apply to a composite collection of resources that we have to think carefully about how to interpret them against a collection: is it the first; is it a combination; is it null; is it allowed at all? With a If we pass around a
Note that there are valid usages for |
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
Show resolved
Hide resolved
I'm not sure that's a valid use case, where do you see this being used like this?
Interesting, I'll have to see if we use this from a Directory based Resource.
Most debugging should be using either
The original proposal was in (the now closed, un-merged) PR #8470 Now, the work Lachlan is doing for HttpContent.Factory can easily get rid of MemoryResource, as it can serve a static HttpContent for |
…resourceCollect-no-path
fix javadoc
revert combine and related methods to return Resource and not explicitly a ResourceCollection, as if there is only 1, then a collection is not needed
@@ -112,7 +113,7 @@ public interface Context extends ClassVisibilityChecker | |||
*/ | |||
boolean isParentLoaderPriority(); | |||
|
|||
ResourceCollection getExtraClasspath(); | |||
Resource getExtraClasspath(); |
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.
@lorban @joakime @sbordet I believe it was a miss-use of ResourceCollection
when this was changed from a List<Resource>
. We should very VERY rarely ever explicitly use a ResourceCollection
, because the whole point of that class is to look like a singe resource. If anything needs to iterate over the contained resources, then it probably should be using a List<Resources>
rather than a ResourceCollection
.
However, for not, I have only partially reverted to try how it looks if extra classpath is just a Resource
, which may or may not be a collection. This requires the addClassPath
method below to be somewhat ResourceCollection
away, as it needs to extract URLs. I've done this for now with a static stream method.... but not sure I like. Reverting all the way back to List<Resource>
may be the best thing to do here.
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.
maybe ResourceCollection
should be renamed to MultiResource
to emphasise that it is-a Resource
and should not be thought of as a Collection
(which is an implementation detail).
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.
Better name options include:
MultiResource
CompositeDirectoryResource
CombinedResource
CombinedDirectoryResource
{ | ||
for (Resource resource: resources) | ||
ResourceCollection.stream(resource).forEach(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.
Since any Resource
might be a collection, if we need URLs, URIs or Paths from a resource, then we should use this stream abstraction to get back the one or more values. The stream can then be used to pick the first, collect into a list or do forEach handling like I am below:
* @see ResourceCollection | ||
*/ | ||
static ResourceCollection combine(List<Resource> resources) | ||
static Resource combine(List<Resource> resources) |
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.
combine
should return a Resource
and not a ResourceCollection
, since if the passed list has only a single entry, then a collection is not needed. The caller should not need to know if it is a collection or not.
Fixed QuickStart handling to handle collections
cleanup ResourceCollection creation. Avoid sanity checks on resolved resources.
fixed typo
…resourceCollect-no-path
…resourceCollect-no-path
update after merge to head
@joakime nudge |
…resourceCollect-no-path
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.
My not-yet-fully-reviewed review
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorProcessor.java
Outdated
Show resolved
Hide resolved
...re/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ReHandlingErrorProcessor.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/AttributeNormalizer.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/CombinedResource.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/CombinedResource.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/CombinedResource.java
Show resolved
Hide resolved
return null; | ||
} | ||
|
||
@Override | ||
public String getFileName() | ||
{ | ||
String filename = null; | ||
// return a non-null filename only if all resources agree on the same name. |
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.
Perhaps we should make getFileName()
not be the last segment name in case of Directory? Is there a use case were in we care about, and use getFileName()
in a directory case?
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.
We can use the fileName to generate a context name. I'm not 100% sure we still use this method for that, but it is a reasonable use-case to ask a directory for the name of it's last segment.
This method exists and I think this is a reasonable interpretation of it for a combined resource.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
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.
Looks good to me but there are some test failures.
*/ | ||
ResourceCollection(List<Resource> resources) | ||
static Resource combine(List<Resource> resources) |
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.
Should this also have a Resource combine(Resource... resources)
same as the ResourceFactory
?
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.
It's not a public API. It is just there to move the implementation into the correct file. So if the ... is not needed, no need to add it.
...en-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestWebAppPropertyConverter.java
Outdated
Show resolved
Hide resolved
updates from review
…resourceCollect-no-path
Reintroduced List<Resources> for extra classpath
fixed null bug
…resourceCollect-no-path
A
ResourceCollection
should have a null path and URI. It is by definition a collection of different paths and URIs, so it cannot just pick one of them and return it. This is hiding lots of bugs in the code whereresource.getPath()
is called and assumes it will always get a non-null value that holds all the required resources. However, when scanning for descriptors, annotations, TLDs etc. the underlying resource is often a collection, thus code that uses getPath is currently only scanning the first resource in the collection.This PR fixes
ResourceCollection
, but will almost certainly break some other tests. I think we want to use other PRs to fix those uses ofgetPath
first before considering completing this PR.