diff --git a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java index ebb12098cd3..7de48bc0efa 100644 --- a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java +++ b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java @@ -779,7 +779,7 @@ public class HTTPServerDocs ResourceHandler handler = new ResourceHandler(); // For multiple directories, use ResourceCollection. - Resource resource = Resource.combine( + Resource resource = ResourceFactory.combine( ResourceFactory.of(handler).newResource("/path/to/static/resources/"), ResourceFactory.of(handler).newResource("/another/path/to/static/resources/") ); diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java index ca8765ae462..62120669510 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java @@ -57,7 +57,6 @@ import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.resource.FileSystemPool; -import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; @@ -1805,7 +1804,7 @@ public class ResourceHandlerTest { copySimpleTestResource(docRoot); _rootResourceHandler.stop(); - _rootResourceHandler.setBaseResource(Resource.combine( + _rootResourceHandler.setBaseResource(ResourceFactory.combine( ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")), _rootResourceHandler.getBaseResource())); _rootResourceHandler.start(); @@ -1864,7 +1863,7 @@ public class ResourceHandlerTest { copySimpleTestResource(docRoot); _rootResourceHandler.stop(); - _rootResourceHandler.setBaseResource(Resource.combine( + _rootResourceHandler.setBaseResource(ResourceFactory.combine( ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")), ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer1/")), _rootResourceHandler.getBaseResource())); diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index 6a9afb96465..e042ea2cfbc 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -52,34 +52,6 @@ public abstract class Resource implements Iterable private static final LinkOption[] NO_FOLLOW_LINKS = new LinkOption[]{LinkOption.NOFOLLOW_LINKS}; private static final LinkOption[] FOLLOW_LINKS = new LinkOption[]{}; - /** - *

Make a Resource containing a collection of other resources

- * @param resources multiple resources to combine as a single resource. Typically, they are directories. - * @return A Resource of multiple resources. - * @see ResourceCollection - */ - // TODO this should be moved to ResourceFactory - public static ResourceCollection combine(List resources) - { - if (resources == null || resources.isEmpty()) - throw new IllegalArgumentException("No resources"); - return new ResourceCollection(resources); - } - - /** - *

Make a Resource containing a collection of other resources

- * @param resources multiple resources to combine as a single resource. Typically, they are directories. - * @return A Resource of multiple resources. - * @see ResourceCollection - */ - // TODO this should be moved to ResourceFactory - public static ResourceCollection combine(Resource... resources) - { - if (resources == null || resources.length == 0) - throw new IllegalArgumentException("No resources"); - return new ResourceCollection(List.of(resources)); - } - public static String dump(Resource resource) { if (resource == null) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java index f389125d4f3..4de67898aa6 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java @@ -32,6 +32,32 @@ import org.eclipse.jetty.util.component.Dumpable; */ public interface ResourceFactory { + /** + *

Make a Resource containing a collection of other resources

+ * @param resources multiple resources to combine as a single resource. Typically, they are directories. + * @return A Resource of multiple resources. + * @see ResourceCollection + */ + static ResourceCollection combine(List resources) + { + if (resources == null || resources.isEmpty()) + throw new IllegalArgumentException("No resources"); + return new ResourceCollection(resources); + } + + /** + *

Make a Resource containing a collection of other resources

+ * @param resources multiple resources to combine as a single resource. Typically, they are directories. + * @return A Resource of multiple resources. + * @see ResourceCollection + */ + static ResourceCollection combine(Resource... resources) + { + if (resources == null || resources.length == 0) + throw new IllegalArgumentException("No resources"); + return new ResourceCollection(List.of(resources)); + } + /** * Construct a resource from a uri. * @@ -187,7 +213,7 @@ public interface ResourceFactory if ((uris == null) || (uris.isEmpty())) throw new IllegalArgumentException("List of URIs is invalid"); - return Resource.combine(uris.stream().map(this::newResource).toList()); + return combine(uris.stream().map(this::newResource).toList()); } default Resource newResource(URL url) diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java index 056f2385673..5fac0fb43e8 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java @@ -77,7 +77,7 @@ public class ResourceCollectionTest Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two"); Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three"); - ResourceCollection rc = Resource.combine( + ResourceCollection rc = ResourceFactory.combine( resourceFactory.newResource(one), resourceFactory.newResource(two), resourceFactory.newResource(three) @@ -125,7 +125,7 @@ public class ResourceCollectionTest Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two"); Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three"); - ResourceCollection rc = Resource.combine( + ResourceCollection rc = ResourceFactory.combine( resourceFactory.newResource(one), resourceFactory.newResource(two), resourceFactory.newResource(three) @@ -147,7 +147,7 @@ public class ResourceCollectionTest Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two"); Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three"); - ResourceCollection rc = Resource.combine( + ResourceCollection rc = ResourceFactory.combine( resourceFactory.newResource(one), resourceFactory.newResource(two), resourceFactory.newResource(three) @@ -173,7 +173,7 @@ public class ResourceCollectionTest Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three"); Path twoDir = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two/dir"); - ResourceCollection rc1 = Resource.combine( + ResourceCollection rc1 = ResourceFactory.combine( List.of( resourceFactory.newResource(one), resourceFactory.newResource(two), @@ -181,7 +181,7 @@ public class ResourceCollectionTest ) ); - ResourceCollection rc2 = Resource.combine( + ResourceCollection rc2 = ResourceFactory.combine( List.of( // the original ResourceCollection rc1, @@ -215,7 +215,7 @@ public class ResourceCollectionTest Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three"); Path dirFoo = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two/dir"); - Resource compositeA = Resource.combine( + Resource compositeA = ResourceFactory.combine( List.of( resourceFactory.newResource(one), resourceFactory.newResource(two), @@ -223,7 +223,7 @@ public class ResourceCollectionTest ) ); - Resource compositeB = Resource.combine( + Resource compositeB = ResourceFactory.combine( List.of( // the original composite Resource compositeA, @@ -271,7 +271,7 @@ public class ResourceCollectionTest FS.ensureDirExists(dirC); Files.createFile(dirC.resolve("foo")); - Resource rc = Resource.combine( + Resource rc = ResourceFactory.combine( ResourceFactory.root().newResource(dirA), ResourceFactory.root().newResource(dirB), ResourceFactory.root().newResource(dirC) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java index bfe47a3ef26..96a754d8a2a 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java @@ -63,7 +63,7 @@ public class OverlayManager resourceBases.add(webApp.getBaseResource()); } - webApp.setBaseResource(Resource.combine(resourceBases)); + webApp.setBaseResource(ResourceFactory.combine(resourceBases)); } /** diff --git a/jetty-ee10/jetty-ee10-quickstart/src/main/java/org/eclipse/jetty/ee10/quickstart/QuickStartDescriptorProcessor.java b/jetty-ee10/jetty-ee10-quickstart/src/main/java/org/eclipse/jetty/ee10/quickstart/QuickStartDescriptorProcessor.java index 0459b00e162..d9b27a28b2c 100644 --- a/jetty-ee10/jetty-ee10-quickstart/src/main/java/org/eclipse/jetty/ee10/quickstart/QuickStartDescriptorProcessor.java +++ b/jetty-ee10/jetty-ee10-quickstart/src/main/java/org/eclipse/jetty/ee10/quickstart/QuickStartDescriptorProcessor.java @@ -242,6 +242,6 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor List collection = new ArrayList<>(); collection.add(context.getBaseResource()); collection.addAll(metaInfResources); - context.setBaseResource(Resource.combine(collection)); + context.setBaseResource(ResourceFactory.combine(collection)); } } diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java index c13ec516468..770d8676bcd 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/MetaInfConfiguration.java @@ -265,7 +265,7 @@ public class MetaInfConfiguration extends AbstractConfiguration List collection = new ArrayList<>(); collection.add(context.getBaseResource()); collection.addAll(resources); - context.setBaseResource(Resource.combine(collection)); + context.setBaseResource(ResourceFactory.combine(collection)); } } diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java index 5e0bfb28d08..50949d7fa30 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java @@ -448,7 +448,7 @@ public class WebInfConfiguration extends AbstractConfiguration webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath()); - Resource rc = Resource.combine(webInf, webApp); + Resource rc = ResourceFactory.combine(webInf, webApp); if (LOG.isDebugEnabled()) LOG.debug("context.baseResource={}", rc); diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppContextTest.java b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppContextTest.java index 8b96fbd2816..c938efd541c 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppContextTest.java +++ b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppContextTest.java @@ -49,7 +49,6 @@ import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.resource.FileSystemPool; -import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; @@ -513,7 +512,7 @@ public class WebAppContextTest WebAppContext context = new WebAppContext(); context.setContextPath("/"); - context.setBaseResource(Resource.combine( + context.setBaseResource(ResourceFactory.combine( ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")), ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/")))); server.setHandler(context); @@ -531,7 +530,7 @@ public class WebAppContextTest WebAppContext context = new WebAppContext(); context.setContextPath("/"); - context.setBaseResource(Resource.combine( + context.setBaseResource(ResourceFactory.combine( ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")), ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/")))); server.setHandler(context); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java index a549dfe47ab..b99c9b32f52 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java @@ -64,7 +64,7 @@ public class OverlayManager resourceBases.add(webApp.getBaseResource()); } - webApp.setBaseResource(Resource.combine(resourceBases)); + webApp.setBaseResource(ResourceFactory.combine(resourceBases)); } /** diff --git a/jetty-ee9/jetty-ee9-quickstart/src/main/java/org/eclipse/jetty/ee9/quickstart/QuickStartDescriptorProcessor.java b/jetty-ee9/jetty-ee9-quickstart/src/main/java/org/eclipse/jetty/ee9/quickstart/QuickStartDescriptorProcessor.java index 61a3d2be99e..a18dd1cd889 100644 --- a/jetty-ee9/jetty-ee9-quickstart/src/main/java/org/eclipse/jetty/ee9/quickstart/QuickStartDescriptorProcessor.java +++ b/jetty-ee9/jetty-ee9-quickstart/src/main/java/org/eclipse/jetty/ee9/quickstart/QuickStartDescriptorProcessor.java @@ -243,6 +243,6 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor List collection = new ArrayList<>(); collection.add(context.getBaseResource()); collection.addAll(metaInfResources); - context.setBaseResource(Resource.combine(collection)); + context.setBaseResource(ResourceFactory.combine(collection)); } } diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java index 7abab362d8e..010db64dbd4 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/MetaInfConfiguration.java @@ -265,7 +265,7 @@ public class MetaInfConfiguration extends AbstractConfiguration List collection = new ArrayList<>(); collection.add(context.getBaseResource()); collection.addAll(resources); - context.setBaseResource(Resource.combine(collection)); + context.setBaseResource(ResourceFactory.combine(collection)); } } diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java index 58e440abe80..7ac53a81bf7 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java @@ -446,7 +446,7 @@ public class WebInfConfiguration extends AbstractConfiguration webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath()); - Resource rc = Resource.combine(webInf, webApp); + Resource rc = ResourceFactory.combine(webInf, webApp); if (LOG.isDebugEnabled()) LOG.debug("context.baseResource={}", rc);