Jetty 12 : `Descriptor` cleanup (#8611)
+ Sanity check Resource being provided + Descriptor toString changed to include full URI to descriptor so that it can be used consistently in Logging and Exception messages. + New Descriptor.toURI() for use in Servlet Source and other logging messages + Servlet Source value is now the URI of the Descriptor + More cleanup around `Source` location/name .getResource() must be a Resource as it's used in the AnnotationIntrospector all others use new .getName() Not all location/name usages can be loaded as a Resource.
This commit is contained in:
parent
1a51e07a9f
commit
597a6af31d
|
@ -649,7 +649,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
if (annotation != null)
|
||||
classes = annotation.value();
|
||||
|
||||
DiscoveredServletContainerInitializerHolder holder = new DiscoveredServletContainerInitializerHolder(new Source(Origin.ANNOTATION, sci.getClass().getName()), sci);
|
||||
DiscoveredServletContainerInitializerHolder holder = new DiscoveredServletContainerInitializerHolder(new Source(Origin.ANNOTATION, sci.getClass()), sci);
|
||||
_sciHolders.add(holder);
|
||||
|
||||
if (classes.length > 0)
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jetty.ee10.servlet.BaseHolder;
|
|||
import org.eclipse.jetty.ee10.servlet.Source.Origin;
|
||||
import org.eclipse.jetty.ee10.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee10.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.thread.AutoLock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -165,10 +166,10 @@ public class AnnotationIntrospector
|
|||
if (_context.getMetaData().isMetaDataComplete())
|
||||
return false;
|
||||
|
||||
String descriptorLocation = holder.getSource().getResource();
|
||||
Resource descriptorLocation = holder.getSource().getResource();
|
||||
if (descriptorLocation == null)
|
||||
return true; //no descriptor, can't be metadata-complete
|
||||
return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(_context.getResourceFactory().newResource(descriptorLocation)));
|
||||
return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(descriptorLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class WebFilterAnnotation extends DiscoveredAnnotation
|
|||
if (holder == null)
|
||||
{
|
||||
//Filter with this name does not already exist, so add it
|
||||
holder = _context.getServletHandler().newFilterHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
holder = _context.getServletHandler().newFilterHolder(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
holder.setName(name);
|
||||
|
||||
holder.setHeldClass(clazz);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class WebListenerAnnotation extends DiscoveredAnnotation
|
|||
MetaData metaData = _context.getMetaData();
|
||||
if (metaData.getOrigin(clazz.getName() + ".listener") == Origin.NotSet)
|
||||
{
|
||||
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
h.setHeldClass(clazz);
|
||||
_context.getServletHandler().addListener(h);
|
||||
metaData.setOrigin(clazz.getName() + ".listener", clazz.getAnnotation(WebListener.class), clazz);
|
||||
|
|
|
@ -122,7 +122,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
{
|
||||
//No servlet of this name has already been defined, either by a descriptor
|
||||
//or another annotation (which would be impossible).
|
||||
Source source = new Source(Source.Origin.ANNOTATION, clazz.getName());
|
||||
Source source = new Source(Source.Origin.ANNOTATION, clazz);
|
||||
|
||||
holder = _context.getServletHandler().newServletHolder(source);
|
||||
holder.setHeldClass(clazz);
|
||||
|
@ -183,7 +183,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
//about processing these url mappings
|
||||
if (existingMappings.isEmpty() || !containsNonDefaultMappings(existingMappings))
|
||||
{
|
||||
mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setPathSpecs(LazyList.toStringArray(urlPatternList));
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), annotation, clazz);
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
|
||||
package org.eclipse.jetty.ee10.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.ServletContainerInitializer;
|
||||
|
@ -26,6 +26,7 @@ import org.eclipse.jetty.ee10.webapp.WebDescriptor;
|
|||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.JAR;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
|
@ -38,12 +39,13 @@ import static org.hamcrest.Matchers.containsString;
|
|||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestAnnotationConfiguration
|
||||
{
|
||||
public class TestableAnnotationConfiguration extends AnnotationConfiguration
|
||||
public static class TestableAnnotationConfiguration extends AnnotationConfiguration
|
||||
{
|
||||
public void assertAnnotationDiscovery(boolean b)
|
||||
{
|
||||
|
@ -52,67 +54,55 @@ public class TestAnnotationConfiguration
|
|||
else
|
||||
assertFalse(_discoverableAnnotationHandlers.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
public File web25;
|
||||
|
||||
public File web31false;
|
||||
|
||||
public File web31true;
|
||||
|
||||
public File jarDir;
|
||||
|
||||
public File testSciJar;
|
||||
|
||||
public File testContainerSciJar;
|
||||
|
||||
public File testWebInfClassesJar;
|
||||
|
||||
public File unpacked;
|
||||
}
|
||||
|
||||
public WorkDir workDir;
|
||||
public Path web25;
|
||||
public Path web31false;
|
||||
public Path web31true;
|
||||
public Path jarDir;
|
||||
public Path testSciJar;
|
||||
public Path testContainerSciJar;
|
||||
public Path testWebInfClassesJar;
|
||||
public Path unpacked;
|
||||
public URLClassLoader containerLoader;
|
||||
|
||||
public URLClassLoader webAppLoader;
|
||||
|
||||
public List<Resource> classes;
|
||||
|
||||
public Resource targetClasses;
|
||||
|
||||
public Resource webInfClasses;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
|
||||
web25 = MavenTestingUtils.getTestResourceFile("web25.xml");
|
||||
web31false = MavenTestingUtils.getTestResourceFile("web31false.xml");
|
||||
web31true = MavenTestingUtils.getTestResourceFile("web31true.xml");
|
||||
web25 = MavenTestingUtils.getTestResourcePathFile("web25.xml");
|
||||
web31false = MavenTestingUtils.getTestResourcePathFile("web31false.xml");
|
||||
web31true = MavenTestingUtils.getTestResourcePathFile("web31true.xml");
|
||||
|
||||
// prepare an sci that will be on the webapp's classpath
|
||||
jarDir = new File(MavenTestingUtils.getTestResourcesDir().getParentFile(), "jar");
|
||||
testSciJar = new File(jarDir, "test-sci.jar");
|
||||
assertTrue(testSciJar.exists());
|
||||
jarDir = MavenTestingUtils.getProjectDirPath("src/test/jar");
|
||||
testSciJar = jarDir.resolve("test-sci.jar");
|
||||
assertTrue(Files.exists(testSciJar));
|
||||
|
||||
testContainerSciJar = new File(jarDir, "test-sci-for-container-path.jar");
|
||||
testWebInfClassesJar = new File(jarDir, "test-sci-for-webinf.jar");
|
||||
testContainerSciJar = jarDir.resolve("test-sci-for-container-path.jar");
|
||||
testWebInfClassesJar = jarDir.resolve("test-sci-for-webinf.jar");
|
||||
|
||||
// unpack some classes to pretend that are in WEB-INF/classes
|
||||
unpacked = new File(MavenTestingUtils.getTargetTestingDir(), "test-sci-for-webinf");
|
||||
unpacked.mkdirs();
|
||||
unpacked = workDir.getEmptyPathDir();
|
||||
FS.cleanDirectory(unpacked);
|
||||
JAR.unpack(testWebInfClassesJar, unpacked);
|
||||
webInfClasses = ResourceFactory.root().newResource(unpacked.toPath());
|
||||
JAR.unpack(testWebInfClassesJar.toFile(), unpacked.toFile());
|
||||
webInfClasses = ResourceFactory.root().newResource(unpacked);
|
||||
|
||||
containerLoader = new URLClassLoader(new URL[]{
|
||||
testContainerSciJar.toURI().toURL()
|
||||
testContainerSciJar.toUri().toURL()
|
||||
}, Thread.currentThread().getContextClassLoader());
|
||||
|
||||
targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes");
|
||||
|
||||
classes = Arrays.asList(new Resource[]{webInfClasses, targetClasses});
|
||||
classes = List.of(webInfClasses, targetClasses);
|
||||
|
||||
webAppLoader = new URLClassLoader(new URL[]{
|
||||
testSciJar.toURI().toURL(), targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
testSciJar.toUri().toURL(), targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
},
|
||||
containerLoader);
|
||||
}
|
||||
|
@ -133,7 +123,7 @@ public class TestAnnotationConfiguration
|
|||
context25.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context25.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context25.setConfigurationDiscovered(false);
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(context25.getResourceFactory().newResource(web25)));
|
||||
context25.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context25.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
config25.configure(context25);
|
||||
|
@ -145,7 +135,7 @@ public class TestAnnotationConfiguration
|
|||
context25b.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context25b.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context25b.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(context25b.getResourceFactory().newResource(web25)));
|
||||
context25b.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context25b.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
config25b.configure(context25b);
|
||||
|
@ -157,7 +147,7 @@ public class TestAnnotationConfiguration
|
|||
context31.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context31.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context31.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(context31.getResourceFactory().newResource(web31true)));
|
||||
context31.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context31.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
config31.configure(context31);
|
||||
|
@ -169,7 +159,7 @@ public class TestAnnotationConfiguration
|
|||
context31b.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context31b.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context31b.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context31b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context31b.getMetaData().setWebDescriptor(new WebDescriptor(context31b.getResourceFactory().newResource(web31false)));
|
||||
context31b.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context31b.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
config31b.configure(context31b);
|
||||
|
@ -191,8 +181,8 @@ public class TestAnnotationConfiguration
|
|||
|
||||
//test 3.1 webapp loads both server and app scis
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
|
@ -208,7 +198,7 @@ public class TestAnnotationConfiguration
|
|||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClassScanHandlersForSCIs() throws Exception
|
||||
{
|
||||
|
@ -236,24 +226,24 @@ public class TestAnnotationConfiguration
|
|||
assertEquals("com.acme.initializer.Foo", handler._annotation.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MyAnnotationConfiguration config = new MyAnnotationConfiguration();
|
||||
|
||||
|
||||
WebAppContext context = new WebAppContext();
|
||||
config.preConfigure(context);
|
||||
List<ServletContainerInitializer> scis;
|
||||
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
assertNotNull(scis);
|
||||
assertEquals(3, scis.size());
|
||||
|
||||
config.createServletContainerInitializerAnnotationHandlers(context, scis);
|
||||
|
||||
config.createServletContainerInitializerAnnotationHandlers(context, scis);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -276,9 +266,9 @@ public class TestAnnotationConfiguration
|
|||
// test a 3.1 webapp with metadata-complete=false loads both server
|
||||
// and webapp scis
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31false)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
|
@ -306,10 +296,10 @@ public class TestAnnotationConfiguration
|
|||
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
File orderedFragmentJar = new File(jarDir, "test-sci-with-ordering.jar");
|
||||
assertTrue(orderedFragmentJar.exists());
|
||||
Path orderedFragmentJar = jarDir.resolve("test-sci-with-ordering.jar");
|
||||
assertTrue(Files.exists(orderedFragmentJar));
|
||||
URLClassLoader orderedLoader = new URLClassLoader(new URL[]{
|
||||
orderedFragmentJar.toURI().toURL(), testSciJar.toURI().toURL(),
|
||||
orderedFragmentJar.toUri().toURL(), testSciJar.toUri().toURL(),
|
||||
targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
},
|
||||
containerLoader);
|
||||
|
@ -322,11 +312,11 @@ public class TestAnnotationConfiguration
|
|||
config.preConfigure(context);
|
||||
List<ServletContainerInitializer> scis;
|
||||
context.setClassLoader(orderedLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
RelativeOrdering ordering = new RelativeOrdering(context.getMetaData());
|
||||
context.getMetaData().setOrdering(ordering);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(orderedFragmentJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(orderedFragmentJar));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().orderFragments();
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
|
@ -359,9 +349,9 @@ public class TestAnnotationConfiguration
|
|||
List<ServletContainerInitializer> scis;
|
||||
context.setConfigurationDiscovered(false);
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web25)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
|
@ -369,8 +359,8 @@ public class TestAnnotationConfiguration
|
|||
for (ServletContainerInitializer s : scis)
|
||||
{
|
||||
//should not have any of the web-inf lib scis in here
|
||||
assertFalse(s.getClass().getName().equals("com.acme.ordering.AcmeServletContainerInitializer"));
|
||||
assertFalse(s.getClass().getName().equals("com.acme.initializer.FooInitializer"));
|
||||
assertNotEquals("com.acme.ordering.AcmeServletContainerInitializer", s.getClass().getName());
|
||||
assertNotEquals("com.acme.initializer.FooInitializer", s.getClass().getName());
|
||||
//NOTE: should also not have the web-inf classes scis in here either, but due to the
|
||||
//way the test is set up, the sci we're pretending is in web-inf classes will actually
|
||||
//NOT be loaded by the webapp's classloader, but rather by the junit classloader, so
|
||||
|
@ -397,14 +387,14 @@ public class TestAnnotationConfiguration
|
|||
List<ServletContainerInitializer> scis;
|
||||
context.setConfigurationDiscovered(true);
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web25)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
assertNotNull(scis);
|
||||
assertEquals(3, scis.size(), () -> scis.toString());
|
||||
assertEquals(3, scis.size(), scis::toString);
|
||||
assertEquals("com.acme.ServerServletContainerInitializer", scis.get(0).getClass().getName()); //container path
|
||||
assertEquals("com.acme.webinf.WebInfClassServletContainerInitializer", scis.get(1).getClass().getName()); // web-inf
|
||||
assertEquals("com.acme.initializer.FooInitializer", scis.get(2).getClass().getName()); //web-inf jar no web-fragment
|
||||
|
|
|
@ -23,13 +23,11 @@ import org.eclipse.jetty.ee10.webapp.MetaData;
|
|||
import org.eclipse.jetty.ee10.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee10.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.xml.XmlParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -37,16 +35,15 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class TestAnnotationDecorator
|
||||
{
|
||||
public WorkDir workDir;
|
||||
|
||||
public class TestWebDescriptor extends WebDescriptor
|
||||
{
|
||||
public TestWebDescriptor(Resource resource, MetaData.Complete metadata)
|
||||
public TestWebDescriptor(Resource xml, MetaData.Complete metadata)
|
||||
{
|
||||
super(resource);
|
||||
super(xml);
|
||||
_metaDataComplete = metadata;
|
||||
}
|
||||
|
||||
|
@ -86,9 +83,10 @@ public class TestAnnotationDecorator
|
|||
@Test
|
||||
public void testAnnotationDecorator() throws Exception
|
||||
{
|
||||
Path dummyXml = workDir.getEmptyPathDir().resolve("dummy.xml");
|
||||
Files.createFile(dummyXml);
|
||||
Resource dummyXmlResource = ResourceFactory.root().newResource(dummyXml);
|
||||
Path docroot = workDir.getEmptyPathDir();
|
||||
Path dummyDescriptor = docroot.resolve("dummy.xml");
|
||||
Files.createFile(dummyDescriptor);
|
||||
Resource dummyResource = ResourceFactory.root().newResource(dummyDescriptor);
|
||||
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
{
|
||||
|
@ -108,9 +106,9 @@ public class TestAnnotationDecorator
|
|||
context.removeAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
|
||||
|
||||
//test with BaseHolder metadata, should not introspect with metdata-complete==true
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyXmlResource, MetaData.Complete.True));
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyResource, MetaData.Complete.True));
|
||||
assertTrue(context.getMetaData().isMetaDataComplete());
|
||||
ServletHolder holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, ""));
|
||||
ServletHolder holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR));
|
||||
holder.setHeldClass(ServletE.class);
|
||||
context.getServletHandler().addServlet(holder);
|
||||
DecoratedObjectFactory.associateInfo(holder);
|
||||
|
@ -124,7 +122,7 @@ public class TestAnnotationDecorator
|
|||
context.removeAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
|
||||
|
||||
//test with BaseHolder metadata, should introspect with metadata-complete==false
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyXmlResource, MetaData.Complete.False));
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyResource, MetaData.Complete.False));
|
||||
DecoratedObjectFactory.associateInfo(holder);
|
||||
decorator = new AnnotationDecorator(context);
|
||||
decorator.decorate(servlet);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.ee10.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.ee10.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.ee10.servlet.Source;
|
||||
|
@ -23,7 +23,6 @@ import org.eclipse.jetty.ee10.webapp.WebDescriptor;
|
|||
import org.eclipse.jetty.logging.StacklessLogging;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -58,36 +57,38 @@ public class TestAnnotationIntrospector
|
|||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//an ANNOTATION sourced servlet can be introspected
|
||||
holder = new ServletHolder(new Source(Source.Origin.ANNOTATION, ServletE.class.getName()));
|
||||
holder = new ServletHolder(new Source(Source.Origin.ANNOTATION, ServletE.class));
|
||||
holder.setHeldClass(ServletE.class);
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet can be introspected if web.xml metdata-complete==false
|
||||
File file = MavenTestingUtils.getTestResourceFile("web31false.xml");
|
||||
Resource resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
Path xml = MavenTestingUtils.getTestResourcePathFile("web31false.xml");
|
||||
Resource xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet can be introspected if web-fragment.xml medata-complete==false && web.xml metadata-complete==false
|
||||
file = MavenTestingUtils.getTestResourceFile("web-fragment4false.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().addFragmentDescriptor(ResourceFactory.root().newResource(file.getParentFile().toPath()), new FragmentDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTestResourcePathFile("web-fragment4false.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
Resource parent = wac.getResourceFactory().newResource(xml.getParent());
|
||||
wac.getMetaData().addFragmentDescriptor(parent, new FragmentDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet cannot be introspected if web-fragment.xml medata-complete==true (&& web.xml metadata-complete==false)
|
||||
file = MavenTestingUtils.getTestResourceFile("web-fragment4true.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().addFragmentDescriptor(ResourceFactory.root().newResource(file.getParentFile().toPath()), new FragmentDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTestResourcePathFile("web-fragment4true.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
parent = wac.getResourceFactory().newResource(xml.getParent());
|
||||
wac.getMetaData().addFragmentDescriptor(parent, new FragmentDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertFalse(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet cannot be introspected if web.xml medata-complete==true
|
||||
file = MavenTestingUtils.getTestResourceFile("web31true.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTestResourcePathFile("web31true.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertFalse(introspector.isIntrospectable(new ServletE(), holder));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class TestDiscoveredServletContainerInitializerHolder
|
|||
SampleServletContainerInitializer sci = new SampleServletContainerInitializer();
|
||||
|
||||
AnnotationConfiguration.DiscoveredServletContainerInitializerHolder holder =
|
||||
new AnnotationConfiguration.DiscoveredServletContainerInitializerHolder(new Source(Source.Origin.ANNOTATION, sci.getClass().getName()),
|
||||
new AnnotationConfiguration.DiscoveredServletContainerInitializerHolder(new Source(Source.Origin.ANNOTATION, sci.getClass()),
|
||||
sci);
|
||||
|
||||
//add the @HandlesTypes to the holder
|
||||
|
|
|
@ -20,15 +20,11 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder;
|
|||
import org.eclipse.jetty.ee10.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee10.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class TestRunAsAnnotation
|
||||
{
|
||||
public WorkDir workDir;
|
||||
|
@ -36,10 +32,6 @@ public class TestRunAsAnnotation
|
|||
@Test
|
||||
public void testRunAsAnnotation() throws Exception
|
||||
{
|
||||
Path dummyXml = workDir.getEmptyPathDir().resolve("dummy.xml");
|
||||
Files.createFile(dummyXml);
|
||||
Resource dummyXmlResource = ResourceFactory.root().newResource(dummyXml);
|
||||
|
||||
WebAppContext wac = new WebAppContext();
|
||||
|
||||
//pre-add a servlet but not by descriptor
|
||||
|
@ -55,7 +47,9 @@ public class TestRunAsAnnotation
|
|||
holder2.setHeldClass(ServletC.class);
|
||||
holder2.setInitOrder(1);
|
||||
wac.getServletHandler().addServletWithMapping(holder2, "/foo2/*");
|
||||
wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(dummyXmlResource));
|
||||
Path fakeXml = workDir.getEmptyPathDir().resolve("fake.xml");
|
||||
Files.createFile(fakeXml);
|
||||
wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(wac.getResourceFactory().newResource(fakeXml)));
|
||||
|
||||
AnnotationIntrospector parser = new AnnotationIntrospector(wac);
|
||||
RunAsAnnotationHandler handler = new RunAsAnnotationHandler(wac);
|
||||
|
@ -63,6 +57,6 @@ public class TestRunAsAnnotation
|
|||
parser.introspect(new ServletC(), null);
|
||||
|
||||
assertEquals("admin", holder.getRunAsRole());
|
||||
assertEquals(null, holder2.getRunAsRole());
|
||||
assertNull(holder2.getRunAsRole());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
case WebFragment:
|
||||
{
|
||||
//ServletSpec p.75. No declaration in web.xml, but in multiple web-fragments. Error.
|
||||
throw new IllegalStateException("Conflicting env-entry " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting env-entry " + name + " in " + descriptor.getURI());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -293,7 +293,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
//ServletSpec p.75. No declaration of resource-ref in web xml, but different in multiple web-fragments. Error.
|
||||
if (!type.equals(otherType) || !auth.equals(otherAuth) || !shared.equals(otherShared))
|
||||
throw new IllegalStateException("Conflicting resource-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting resource-ref " + jndiName + " in " + descriptor.getURI());
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
//ServletSpec p.75. No declaration of resource-ref in web xml, but different in multiple web-fragments. Error.
|
||||
if (!type.equals(otherType))
|
||||
throw new IllegalStateException("Conflicting resource-env-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting resource-env-ref " + jndiName + " in " + descriptor.getURI());
|
||||
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
|
@ -503,7 +503,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
type = (type == null ? "" : type);
|
||||
usage = (usage == null ? "" : usage);
|
||||
if (!type.equals(otherType) || !usage.equalsIgnoreCase(otherUsage))
|
||||
throw new IllegalStateException("Conflicting message-destination-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting message-destination-ref " + jndiName + " in " + descriptor.getURI());
|
||||
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.jetty.ee10.servlet;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
* Source
|
||||
*
|
||||
|
@ -20,8 +22,8 @@ package org.eclipse.jetty.ee10.servlet;
|
|||
*/
|
||||
public class Source
|
||||
{
|
||||
public static final Source EMBEDDED = new Source(Origin.EMBEDDED, null);
|
||||
public static final Source JAVAX_API = new Source(Origin.JAKARTA_API, null);
|
||||
public static final Source EMBEDDED = new Source(Origin.EMBEDDED);
|
||||
public static final Source JAVAX_API = new Source(Origin.JAKARTA_API);
|
||||
|
||||
public enum Origin
|
||||
{
|
||||
|
@ -29,19 +31,49 @@ public class Source
|
|||
JAKARTA_API, DESCRIPTOR, ANNOTATION
|
||||
}
|
||||
|
||||
public Origin _origin;
|
||||
public String _resource;
|
||||
public final Origin _origin;
|
||||
public final String _name;
|
||||
public Resource _resource;
|
||||
|
||||
/**
|
||||
* A Source without a name/location.
|
||||
*
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
*/
|
||||
public Source(Origin o)
|
||||
{
|
||||
this(o, (String)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param clazz the class where the artifact was declared
|
||||
*/
|
||||
public Source(Origin o, Class<?> clazz)
|
||||
{
|
||||
this(o, clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param resource the location where the artifact was declared
|
||||
*/
|
||||
public Source(Origin o, String resource)
|
||||
public Source(Origin o, Resource resource)
|
||||
{
|
||||
this(o, resource.getURI().toASCIIString());
|
||||
_resource = resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param name the name of the location where the artifact was declared (not a {@link Resource})
|
||||
*/
|
||||
public Source(Origin o, String name)
|
||||
{
|
||||
if (o == null)
|
||||
throw new IllegalArgumentException("Origin is null");
|
||||
_origin = o;
|
||||
_resource = resource;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,15 +87,22 @@ public class Source
|
|||
/**
|
||||
* @return the resource
|
||||
*/
|
||||
public String getResource()
|
||||
public Resource getResource()
|
||||
{
|
||||
return _resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
||||
return _origin + ":" + _resource;
|
||||
return _origin + ":" + (_name == null ? "<null>" : _name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class ServletContainerInitializerHolderTest
|
|||
@Test
|
||||
public void testInstanceWithStartupClassesAndSource() throws Exception
|
||||
{
|
||||
ServletContainerInitializerHolder holder = new ServletContainerInitializerHolder(new Source(Origin.ANNOTATION, null), new SimpleSCI(), Integer.class);
|
||||
ServletContainerInitializerHolder holder = new ServletContainerInitializerHolder(new Source(Origin.ANNOTATION), new SimpleSCI(), Integer.class);
|
||||
assertEquals(Origin.ANNOTATION, holder.getSource().getOrigin());
|
||||
assertEquals(SimpleSCI.class, holder.getHeldClass());
|
||||
assertEquals("ContainerInitializer{org.eclipse.jetty.ee10.servlet.ServletContainerInitializerHolderTest$SimpleSCI,interested=[java.lang.Integer],applicable=[],annotated=[]}", holder.toString());
|
||||
|
|
|
@ -15,8 +15,6 @@ package org.eclipse.jetty.ee10.webapp;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -33,13 +31,11 @@ public abstract class Descriptor
|
|||
protected XmlParser.Node _root;
|
||||
protected String _dtd;
|
||||
|
||||
public Descriptor(Resource xml)
|
||||
public Descriptor(Resource resource)
|
||||
{
|
||||
_xml = Objects.requireNonNull(xml);
|
||||
if (!_xml.exists())
|
||||
throw new IllegalArgumentException("Descriptor does not exist: " + xml);
|
||||
_xml = Objects.requireNonNull(resource, "Resource must not be null");
|
||||
if (_xml.isDirectory())
|
||||
throw new IllegalArgumentException("Descriptor is not a file: " + xml);
|
||||
throw new IllegalArgumentException("Descriptor cannot be a directory");
|
||||
}
|
||||
|
||||
public void parse(XmlParser parser)
|
||||
|
@ -48,7 +44,7 @@ public abstract class Descriptor
|
|||
if (_root == null)
|
||||
{
|
||||
Objects.requireNonNull(parser);
|
||||
try (InputStream is = Files.newInputStream(_xml.getPath(), StandardOpenOption.READ))
|
||||
try (InputStream is = _xml.newInputStream())
|
||||
{
|
||||
_root = parser.parse(is);
|
||||
_dtd = parser.getDTD();
|
||||
|
@ -61,9 +57,9 @@ public abstract class Descriptor
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isParsed()
|
||||
public String getURI()
|
||||
{
|
||||
return _root != null;
|
||||
return _xml.getURI().toASCIIString();
|
||||
}
|
||||
|
||||
public Resource getResource()
|
||||
|
@ -79,6 +75,6 @@ public abstract class Descriptor
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass().getSimpleName() + "(" + _xml + ")";
|
||||
return this.getClass().getSimpleName() + "(" + getURI() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class FragmentConfiguration extends AbstractConfiguration
|
||||
{
|
||||
public static final String FRAGMENT_RESOURCES = "org.eclipse.jetty.webFragments";
|
||||
// Holds a Map<Resource, Resource> .
|
||||
// key: Resource to the Jar
|
||||
// value: Resource to the web fragment xml
|
||||
public static final String FRAGMENT_RESOURCES = FragmentConfiguration.class.getPackageName() + ".webFragments";
|
||||
|
||||
public FragmentConfiguration()
|
||||
{
|
||||
|
|
|
@ -36,7 +36,6 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
None, Before, After
|
||||
}
|
||||
|
||||
;
|
||||
protected OtherType _otherType = OtherType.None;
|
||||
|
||||
protected List<String> _befores = new ArrayList<String>();
|
||||
|
@ -44,7 +43,6 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
protected String _name;
|
||||
|
||||
public FragmentDescriptor(Resource xml)
|
||||
throws Exception
|
||||
{
|
||||
super(xml);
|
||||
}
|
||||
|
@ -109,7 +107,7 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
if (node.getTag().equalsIgnoreCase("others"))
|
||||
{
|
||||
if (_otherType != OtherType.None)
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml.getURI());
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml);
|
||||
|
||||
_otherType = OtherType.Before;
|
||||
}
|
||||
|
@ -136,7 +134,7 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
if (node.getTag().equalsIgnoreCase("others"))
|
||||
{
|
||||
if (_otherType != OtherType.None)
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml.getURI());
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml);
|
||||
|
||||
_otherType = OtherType.After;
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ public class MetaData
|
|||
Descriptor existing = _webFragmentNameMap.get(descriptor.getName());
|
||||
if (existing != null && !isAllowDuplicateFragmentNames())
|
||||
{
|
||||
throw new IllegalStateException("Duplicate fragment name: " + descriptor.getName() + " for " + existing.getResource() + " and " + descriptor.getResource());
|
||||
throw new IllegalStateException("Duplicate fragment name: " + descriptor.getName() + " for " + existing.getURI() + " and " + descriptor.getURI());
|
||||
}
|
||||
else
|
||||
_webFragmentNameMap.put(descriptor.getName(), descriptor);
|
||||
|
|
|
@ -376,10 +376,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
* @param context the context for the scan
|
||||
* @param target the target resource to scan for
|
||||
* @param cache the resource cache
|
||||
* @throws Exception if unable to scan for resources
|
||||
*/
|
||||
public void scanForResources(WebAppContext context, Resource target, ConcurrentHashMap<Resource, Resource> cache)
|
||||
throws Exception
|
||||
{
|
||||
Resource resourcesDir = null;
|
||||
if (cache != null && cache.containsKey(target))
|
||||
|
@ -450,10 +448,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
* @param context the context for the scan
|
||||
* @param jar the jar resource to scan for fragements in
|
||||
* @param cache the resource cache
|
||||
* @throws Exception if unable to scan for fragments
|
||||
*/
|
||||
public void scanForFragment(WebAppContext context, Resource jar, ConcurrentHashMap<Resource, Resource> cache)
|
||||
throws Exception
|
||||
{
|
||||
Resource webFrag = null;
|
||||
if (cache != null && cache.containsKey(jar))
|
||||
|
@ -485,7 +481,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
|
||||
if (cache != null)
|
||||
{
|
||||
//web-fragment.xml doesn't exist: put token in cache to signal we've seen the jar
|
||||
//web-fragment.xml doesn't exist: put token in cache to signal we've seen the jar
|
||||
Resource old = cache.putIfAbsent(jar, webFrag);
|
||||
if (old != null)
|
||||
webFrag = old;
|
||||
|
@ -569,7 +565,6 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO do we want to keep a collection of URLs or should that be changed to a collection of URIs?
|
||||
Collection<URL> metaInfTlds = (Collection<URL>)context.getAttribute(METAINF_TLDS);
|
||||
if (metaInfTlds == null)
|
||||
{
|
||||
|
@ -671,10 +666,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
protected List<Resource> findJars(WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> jarResources = new ArrayList<Resource>();
|
||||
List<Resource> webInfLibJars = findWebInfLibJars(context);
|
||||
if (webInfLibJars != null)
|
||||
jarResources.addAll(webInfLibJars);
|
||||
List<Resource> jarResources = new ArrayList<>();
|
||||
jarResources.addAll(findWebInfLibJars(context));
|
||||
List<Resource> extraClasspathJars = findExtraClasspathJars(context);
|
||||
if (extraClasspathJars != null)
|
||||
jarResources.addAll(extraClasspathJars);
|
||||
|
@ -691,9 +684,12 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
protected List<Resource> findWebInfLibJars(WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
if (context == null)
|
||||
return List.of();
|
||||
|
||||
Resource webInf = context.getWebInf();
|
||||
if (webInf == null)
|
||||
return null;
|
||||
if (webInf == null || !webInf.exists() || !webInf.isDirectory())
|
||||
return List.of();
|
||||
|
||||
Resource webInfLib = webInf.resolve("/lib");
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
if (descriptor instanceof FragmentDescriptor)
|
||||
{
|
||||
if (!((String)context.getInitParams().get(name)).equals(value))
|
||||
throw new IllegalStateException("Conflicting context-param " + name + "=" + value + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting context-param " + name + "=" + value + " in " + descriptor.getURI());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
//If servlet of that name does not already exist, create it.
|
||||
if (holder == null)
|
||||
{
|
||||
holder = context.getServletHandler().newServletHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
holder = context.getServletHandler().newServletHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
holder.setName(name);
|
||||
_servletHolderMap.put(name, holder);
|
||||
_servletHolders.add(holder);
|
||||
|
@ -250,7 +250,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
|
||||
if ((descriptor != originDescriptor) && !holder.getInitParameter(pname).equals(pvalue))
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -306,7 +306,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//the class was set by another fragment, ensure this fragment's value is the same
|
||||
if (!servletClass.equals(holder.getClassName()))
|
||||
throw new IllegalStateException("Conflicting servlet-class " + servletClass + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting servlet-class " + servletClass + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -370,7 +370,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//it was already set by another fragment, if we're parsing a fragment, the values must match
|
||||
if (order != holder.getInitOrder())
|
||||
throw new IllegalStateException("Conflicting load-on-startup value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting load-on-startup value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -413,7 +413,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
case WebFragment:
|
||||
{
|
||||
if (!holder.getUserRoleLink(roleName).equals(roleLink))
|
||||
throw new IllegalStateException("Conflicting role-link for role-name " + roleName + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting role-link for role-name " + roleName + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -459,7 +459,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//run-as was set by another fragment, this fragment must show the same value
|
||||
if (!holder.getRunAsRole().equals(roleName))
|
||||
throw new IllegalStateException("Conflicting run-as role " + roleName + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting run-as role " + roleName + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -498,7 +498,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//async-supported set by another fragment, this fragment's value must match
|
||||
if (holder.isAsyncSupported() != val)
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -536,7 +536,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//was set by another fragment, this fragment's value must match
|
||||
if (holder.isEnabled() != isEnabled)
|
||||
throw new IllegalStateException("Conflicting value of servlet enabled for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting value of servlet enabled for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -589,14 +589,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
MultipartConfigElement cfg = ((ServletHolder.Registration)holder.getRegistration()).getMultipartConfig();
|
||||
|
||||
if (cfg.getMaxFileSize() != element.getMaxFileSize())
|
||||
throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet " + name + " in " + descriptor.getURI());
|
||||
if (cfg.getMaxRequestSize() != element.getMaxRequestSize())
|
||||
throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet " + name + " in " + descriptor.getURI());
|
||||
if (cfg.getFileSizeThreshold() != element.getFileSizeThreshold())
|
||||
throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet " + name + " in " + descriptor.getURI());
|
||||
if ((cfg.getLocation() != null && (element.getLocation() == null || element.getLocation().length() == 0)) ||
|
||||
(cfg.getLocation() == null && (element.getLocation() != null || element.getLocation().length() > 0)))
|
||||
throw new IllegalStateException("Conflicting multipart-config location for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config location for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -805,7 +805,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set an attribute of the same name, all web-fragments must have the same value
|
||||
if (!StringUtil.nonNull(value).equals(StringUtil.nonNull(context.getSessionHandler().getSessionCookieConfig().getAttribute(name))))
|
||||
throw new IllegalStateException("Conflicting attribute " + name + "=" + value + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting attribute " + name + "=" + value + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -847,7 +847,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!context.getMimeTypes().getMimeByExtension("." + extension).equals(mimeType))
|
||||
throw new IllegalStateException("Conflicting mime-type " + mimeType + " for extension " + extension + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting mime-type " + mimeType + " for extension " + extension + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -938,7 +938,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a value was set by a web-fragment, all fragments must have the same value
|
||||
if (!encoding.equals(context.getLocaleEncoding(locale)))
|
||||
throw new IllegalStateException("Conflicting loacle-encoding mapping for locale " + locale + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting locale-encoding mapping for locale " + locale + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1004,7 +1004,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//another web fragment set the same error code or exception, if its different its an error
|
||||
if (!handler.getErrorPages().get(error).equals(location))
|
||||
throw new IllegalStateException("Conflicting error-code or exception-type " + error + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting error-code or exception-type " + error + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1028,7 +1028,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
public ServletMapping addServletMapping(String servletName, XmlParser.Node node, WebAppContext context, Descriptor descriptor)
|
||||
{
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setFromDefaultDescriptor(descriptor instanceof DefaultsDescriptor);
|
||||
context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), descriptor);
|
||||
|
@ -1271,7 +1271,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
else
|
||||
{
|
||||
//no mapping for jsp yet, make one
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
mapping.setServletName("jsp");
|
||||
mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
|
||||
_servletMappings.add(mapping);
|
||||
|
@ -1429,7 +1429,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//it was already set by another fragment, if we're parsing a fragment, the values must match
|
||||
if (!context.getSecurityHandler().getAuthMethod().equals(method.toString(false, true)))
|
||||
throw new IllegalStateException("Conflicting auth-method value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting auth-method value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1465,7 +1465,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a fragment set it, and we must be parsing another fragment, so the values must match
|
||||
if (!context.getSecurityHandler().getRealmName().equals(nameStr))
|
||||
throw new IllegalStateException("Conflicting realm-name value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting realm-name value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1513,7 +1513,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
|
||||
if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE).equals(loginPageName))
|
||||
throw new IllegalStateException("Conflicting form-login-page value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting form-login-page value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1547,7 +1547,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
|
||||
if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_ERROR_PAGE).equals(errorPageName))
|
||||
throw new IllegalStateException("Conflicting form-error-page value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting form-error-page value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1582,7 +1582,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
FilterHolder holder = _filterHolderMap.get(name);
|
||||
if (holder == null)
|
||||
{
|
||||
holder = context.getServletHandler().newFilterHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
holder = context.getServletHandler().newFilterHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
holder.setName(name);
|
||||
_filterHolderMap.put(name, holder);
|
||||
_filterHolders.add(holder);
|
||||
|
@ -1619,7 +1619,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//the filter class was set up by a web fragment, all fragments must be the same
|
||||
if (!holder.getClassName().equals(filterClass))
|
||||
throw new IllegalStateException("Conflicting filter-class for filter " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting filter-class for filter " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1661,7 +1661,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
|
||||
if (!holder.getInitParameter(pname).equals(pvalue))
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1701,7 +1701,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//async-supported set by another fragment, this fragment's value must match
|
||||
if (holder.isAsyncSupported() != val)
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for filter " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for filter " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1766,7 +1766,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
((WebDescriptor)descriptor).addClassName(className);
|
||||
|
||||
ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
h.setClassName(className);
|
||||
context.getServletHandler().addListener(h);
|
||||
context.getMetaData().setOrigin(className + ".listener", descriptor);
|
||||
|
@ -1775,7 +1775,6 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Could not instantiate listener {}", className, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ public class WebXmlConfiguration extends AbstractConfiguration
|
|||
{
|
||||
context.setWelcomeFiles(null);
|
||||
|
||||
//TODO: ErrorPageErorrHandler is not an ErrorProcessor
|
||||
//TODO: ErrorPageErrorHandler is not an ErrorProcessor
|
||||
if (context.getErrorProcessor() instanceof ErrorPageErrorHandler errorPageErrorHandler)
|
||||
errorPageErrorHandler.setErrorPages(null);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.ee10.webapp;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -22,7 +22,6 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -94,16 +93,16 @@ public class MetaInfConfigurationTest
|
|||
@Test
|
||||
public void testScanTypes() throws Exception
|
||||
{
|
||||
File web25 = MavenTestingUtils.getTestResourceFile("web25.xml");
|
||||
File web31 = MavenTestingUtils.getTestResourceFile("web31.xml");
|
||||
File web31false = MavenTestingUtils.getTestResourceFile("web31false.xml");
|
||||
Path web25 = MavenTestingUtils.getTestResourcePathFile("web25.xml");
|
||||
Path web31 = MavenTestingUtils.getTestResourcePathFile("web31.xml");
|
||||
Path web31false = MavenTestingUtils.getTestResourcePathFile("web31false.xml");
|
||||
|
||||
//test a 2.5 webapp will not look for fragments as manually configured
|
||||
MetaInfConfiguration meta25 = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
Arrays.asList(MetaInfConfiguration.METAINF_TLDS, MetaInfConfiguration.METAINF_RESOURCES));
|
||||
WebAppContext context25 = new WebAppContext();
|
||||
context25.setConfigurationDiscovered(false);
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(context25.getResourceFactory().newResource(web25)));
|
||||
context25.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context25.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
meta25.preConfigure(context25);
|
||||
|
@ -112,7 +111,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration meta25b = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
MetaInfConfiguration.__allScanTypes);
|
||||
WebAppContext context25b = new WebAppContext();
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(context25b.getResourceFactory().newResource(web25)));
|
||||
context25b.getContext().getServletContext().setEffectiveMajorVersion(2);
|
||||
context25b.getContext().getServletContext().setEffectiveMinorVersion(5);
|
||||
meta25b.preConfigure(context25b);
|
||||
|
@ -121,7 +120,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration meta31 = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
Arrays.asList(MetaInfConfiguration.METAINF_TLDS, MetaInfConfiguration.METAINF_RESOURCES));
|
||||
WebAppContext context31 = new WebAppContext();
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31.toPath())));
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(context31.getResourceFactory().newResource(web31)));
|
||||
context31.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context31.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
meta31.preConfigure(context31);
|
||||
|
@ -131,7 +130,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration.__allScanTypes);
|
||||
WebAppContext context31false = new WebAppContext();
|
||||
context31false.setConfigurationDiscovered(true);
|
||||
context31false.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context31false.getMetaData().setWebDescriptor(new WebDescriptor(context31false.getResourceFactory().newResource(web31false)));
|
||||
context31false.getContext().getServletContext().setEffectiveMajorVersion(3);
|
||||
context31false.getContext().getServletContext().setEffectiveMinorVersion(1);
|
||||
meta31false.preConfigure(context31false);
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
package org.eclipse.jetty.ee10.webapp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -39,85 +39,29 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
public class OrderingTest
|
||||
{
|
||||
public class TestResource extends Resource
|
||||
WorkDir workDir;
|
||||
|
||||
private Resource newTestableDirResource(String name) throws IOException
|
||||
{
|
||||
public String _name;
|
||||
Path dir = workDir.getPath().resolve(name);
|
||||
if (!Files.exists(dir))
|
||||
Files.createDirectories(dir);
|
||||
return ResourceFactory.root().newResource(dir);
|
||||
}
|
||||
|
||||
public TestResource(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource resolve(String subUriPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream newInputStream() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableByteChannel newReadableByteChannel() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContainedIn(Resource r)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long length()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private Resource newTestableFileResource(String name) throws IOException
|
||||
{
|
||||
Path file = workDir.getPath().resolve(name);
|
||||
if (!Files.exists(file))
|
||||
Files.createFile(file);
|
||||
return ResourceFactory.root().newResource(file);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach()
|
||||
{
|
||||
// ensure work dir exists, and is empty
|
||||
workDir.getEmptyPathDir();
|
||||
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
|
||||
}
|
||||
|
||||
|
@ -133,13 +77,13 @@ public class OrderingTest
|
|||
{
|
||||
//Example from ServletSpec p.70
|
||||
MetaData metaData = new MetaData();
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, after C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -149,9 +93,9 @@ public class OrderingTest
|
|||
f1._afters.add("C");
|
||||
|
||||
//B: before others
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -160,9 +104,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addBeforeOthers(r2);
|
||||
|
||||
//C: after others
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -171,9 +115,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addAfterOthers(r3);
|
||||
|
||||
//D: no ordering
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -182,9 +126,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addNoOthers(r4);
|
||||
|
||||
//E: no ordering
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
|
@ -193,9 +137,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addNoOthers(r5);
|
||||
|
||||
//F: before others, before B
|
||||
TestResource jar6 = new TestResource("F");
|
||||
Resource jar6 = newTestableDirResource("F");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("F/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("F/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = "F";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -210,13 +154,13 @@ public class OrderingTest
|
|||
String[] outcomes = {"FBDECA"};
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -224,15 +168,15 @@ public class OrderingTest
|
|||
public void testRelativeOrdering1()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//Example from ServletSpec p.70-71
|
||||
//No name: after others, before C
|
||||
TestResource jar1 = new TestResource("plain");
|
||||
Resource jar1 = newTestableDirResource("plain");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -242,9 +186,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -253,9 +197,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addBeforeOthers(f2);
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -264,9 +208,9 @@ public class OrderingTest
|
|||
f3._otherType = FragmentDescriptor.OtherType.None;
|
||||
|
||||
//D: after others
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -275,9 +219,9 @@ public class OrderingTest
|
|||
f4._otherType = FragmentDescriptor.OtherType.After;
|
||||
|
||||
//E: before others
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
|
@ -286,9 +230,9 @@ public class OrderingTest
|
|||
f5._otherType = FragmentDescriptor.OtherType.Before;
|
||||
|
||||
//F: no ordering
|
||||
TestResource jar6 = new TestResource("F");
|
||||
Resource jar6 = newTestableDirResource("F");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("F/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("F/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = "F";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -313,13 +257,13 @@ public class OrderingTest
|
|||
"EBFDplainC"
|
||||
};
|
||||
|
||||
String orderedNames = "";
|
||||
StringBuilder orderedNames = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
orderedNames += (((TestResource)r)._name);
|
||||
orderedNames.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(orderedNames, outcomes))
|
||||
if (!checkResult(orderedNames.toString(), outcomes))
|
||||
fail("No outcome matched " + orderedNames);
|
||||
}
|
||||
|
||||
|
@ -327,16 +271,16 @@ public class OrderingTest
|
|||
public void testRelativeOrdering2()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//Example from Spec p. 71-72
|
||||
|
||||
//A: after B
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -346,9 +290,9 @@ public class OrderingTest
|
|||
f1._afters.add("B");
|
||||
|
||||
//B: no order
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -357,9 +301,9 @@ public class OrderingTest
|
|||
f2._otherType = FragmentDescriptor.OtherType.None;
|
||||
|
||||
//C: before others
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -368,9 +312,9 @@ public class OrderingTest
|
|||
f3._otherType = FragmentDescriptor.OtherType.Before;
|
||||
|
||||
//D: no order
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -390,13 +334,13 @@ public class OrderingTest
|
|||
};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -404,14 +348,14 @@ public class OrderingTest
|
|||
public void testRelativeOrdering3()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -421,9 +365,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, before C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -433,9 +377,9 @@ public class OrderingTest
|
|||
f2._befores.add("C");
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -447,13 +391,13 @@ public class OrderingTest
|
|||
String[] outcomes = {"BAC"};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -461,7 +405,7 @@ public class OrderingTest
|
|||
public void testOrderFragments() throws Exception
|
||||
{
|
||||
final MetaData metadata = new MetaData();
|
||||
final Resource jarResource = new TestResource("A");
|
||||
final Resource jarResource = newTestableDirResource("A");
|
||||
|
||||
metadata.setOrdering(new RelativeOrdering(metadata));
|
||||
metadata.addWebInfResource(jarResource);
|
||||
|
@ -478,14 +422,14 @@ public class OrderingTest
|
|||
|
||||
//A: after B
|
||||
//B: after A
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after B
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -495,9 +439,9 @@ public class OrderingTest
|
|||
f1._afters.add("B");
|
||||
|
||||
//B: after A
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -517,14 +461,14 @@ public class OrderingTest
|
|||
public void testInvalid1()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -534,9 +478,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, after C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -546,9 +490,9 @@ public class OrderingTest
|
|||
f2._afters.add("C");
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -559,10 +503,10 @@ public class OrderingTest
|
|||
assertThrows(IllegalStateException.class, () ->
|
||||
{
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
System.err.println("Invalid Result = " + result);
|
||||
fail("A and B have an impossible relationship to C");
|
||||
|
@ -576,7 +520,7 @@ public class OrderingTest
|
|||
//
|
||||
// A,B,C,others
|
||||
//
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
@ -584,49 +528,49 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("C");
|
||||
((AbsoluteOrdering)metaData._ordering).addOthers();
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -635,13 +579,13 @@ public class OrderingTest
|
|||
List<Resource> list = metaData._ordering.order(resources);
|
||||
|
||||
String[] outcomes = {"ABCDEplain"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -650,7 +594,7 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
// C,B,A
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
|
@ -658,49 +602,49 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("B");
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -708,13 +652,13 @@ public class OrderingTest
|
|||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
String[] outcomes = {"CBA"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -726,10 +670,10 @@ public class OrderingTest
|
|||
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
|
||||
resources.add(new TestResource("A"));
|
||||
resources.add(new TestResource("B"));
|
||||
resources.add(newTestableDirResource("A"));
|
||||
resources.add(newTestableDirResource("B"));
|
||||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
assertThat(list, is(empty()));
|
||||
|
@ -740,14 +684,14 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
//B,A,C other jars with no fragments
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -757,9 +701,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, before C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -769,9 +713,9 @@ public class OrderingTest
|
|||
f2._befores.add("C");
|
||||
|
||||
//C: after A
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -781,24 +725,24 @@ public class OrderingTest
|
|||
f3._afters.add("A");
|
||||
|
||||
//No fragment jar 1
|
||||
TestResource r4 = new TestResource("plain1");
|
||||
Resource r4 = newTestableFileResource("plain1");
|
||||
resources.add(r4);
|
||||
|
||||
//No fragment jar 2
|
||||
TestResource r5 = new TestResource("plain2");
|
||||
Resource r5 = newTestableFileResource("plain2");
|
||||
resources.add(r5);
|
||||
|
||||
//result: BAC
|
||||
String[] outcomes = {"Bplain1plain2AC"};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -807,14 +751,14 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
//web.xml has no ordering, jar A has fragment after others, jar B is plain, jar C is plain
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A has after others
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -822,22 +766,22 @@ public class OrderingTest
|
|||
f1._otherType = FragmentDescriptor.OtherType.After;
|
||||
|
||||
//No fragment jar B
|
||||
TestResource r4 = new TestResource("plainB");
|
||||
Resource r4 = newTestableFileResource("plainB");
|
||||
resources.add(r4);
|
||||
|
||||
//No fragment jar C
|
||||
TestResource r5 = new TestResource("plainC");
|
||||
Resource r5 = newTestableFileResource("plainC");
|
||||
resources.add(r5);
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String[] outcomes = {"plainBplainCA"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -848,7 +792,7 @@ public class OrderingTest
|
|||
//
|
||||
// A,B,C,others
|
||||
//
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
@ -856,82 +800,81 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("C");
|
||||
((AbsoluteOrdering)metaData._ordering).addOthers();
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
metaData._webFragmentResourceMap.put(jar6, f6);
|
||||
|
||||
//plain jar
|
||||
TestResource r7 = new TestResource("plain1");
|
||||
Resource r7 = newTestableFileResource("plain1");
|
||||
resources.add(r7);
|
||||
|
||||
TestResource r8 = new TestResource("plain2");
|
||||
Resource r8 = newTestableFileResource("plain2");
|
||||
resources.add(r8);
|
||||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
|
||||
String[] outcomes = {"ABCDEplainplain1plain2"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
public boolean checkResult(String result, String[] outcomes)
|
||||
{
|
||||
boolean matched = false;
|
||||
for (String s : outcomes)
|
||||
{
|
||||
if (s.equals(result))
|
||||
matched = true;
|
||||
return true;
|
||||
}
|
||||
return matched;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.nio.file.Path;
|
|||
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.xml.XmlParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -48,8 +47,7 @@ public class WebDescriptorTest
|
|||
</web-app>
|
||||
""", StandardCharsets.UTF_8);
|
||||
|
||||
Resource xmlRes = ResourceFactory.root().newResource(xml);
|
||||
WebDescriptor webDescriptor = new WebDescriptor(xmlRes);
|
||||
WebDescriptor webDescriptor = new WebDescriptor(ResourceFactory.root().newResource(xml));
|
||||
XmlParser xmlParser = WebDescriptor.newParser(true);
|
||||
// This should not throw an exception, if it does then you have a bad state.
|
||||
// Such as missing required XML resource entities.
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jetty.ee9.servlet.BaseHolder;
|
|||
import org.eclipse.jetty.ee9.servlet.Source.Origin;
|
||||
import org.eclipse.jetty.ee9.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee9.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.thread.AutoLock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -165,10 +166,10 @@ public class AnnotationIntrospector
|
|||
if (_context.getMetaData().isMetaDataComplete())
|
||||
return false;
|
||||
|
||||
String descriptorLocation = holder.getSource().getResource();
|
||||
Resource descriptorLocation = holder.getSource().getResource();
|
||||
if (descriptorLocation == null)
|
||||
return true; //no descriptor, can't be metadata-complete
|
||||
return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(_context.getResourceFactory().newResource(descriptorLocation)));
|
||||
return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(descriptorLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class WebFilterAnnotation extends DiscoveredAnnotation
|
|||
if (holder == null)
|
||||
{
|
||||
//Filter with this name does not already exist, so add it
|
||||
holder = _context.getServletHandler().newFilterHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
holder = _context.getServletHandler().newFilterHolder(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
holder.setName(name);
|
||||
|
||||
holder.setHeldClass(clazz);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class WebListenerAnnotation extends DiscoveredAnnotation
|
|||
MetaData metaData = _context.getMetaData();
|
||||
if (metaData.getOrigin(clazz.getName() + ".listener") == Origin.NotSet)
|
||||
{
|
||||
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
h.setHeldClass(clazz);
|
||||
_context.getServletHandler().addListener(h);
|
||||
metaData.setOrigin(clazz.getName() + ".listener", clazz.getAnnotation(WebListener.class), clazz);
|
||||
|
|
|
@ -122,7 +122,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
{
|
||||
//No servlet of this name has already been defined, either by a descriptor
|
||||
//or another annotation (which would be impossible).
|
||||
Source source = new Source(Source.Origin.ANNOTATION, clazz.getName());
|
||||
Source source = new Source(Source.Origin.ANNOTATION, clazz);
|
||||
|
||||
holder = _context.getServletHandler().newServletHolder(source);
|
||||
holder.setHeldClass(clazz);
|
||||
|
@ -183,7 +183,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
//about processing these url mappings
|
||||
if (existingMappings.isEmpty() || !containsNonDefaultMappings(existingMappings))
|
||||
{
|
||||
mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setPathSpecs(LazyList.toStringArray(urlPatternList));
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), annotation, clazz);
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.ServletContainerInitializer;
|
||||
|
@ -26,6 +26,7 @@ import org.eclipse.jetty.ee9.webapp.WebDescriptor;
|
|||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.JAR;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
|
@ -38,12 +39,13 @@ import static org.hamcrest.Matchers.containsString;
|
|||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestAnnotationConfiguration
|
||||
{
|
||||
public class TestableAnnotationConfiguration extends AnnotationConfiguration
|
||||
public static class TestableAnnotationConfiguration extends AnnotationConfiguration
|
||||
{
|
||||
public void assertAnnotationDiscovery(boolean b)
|
||||
{
|
||||
|
@ -52,67 +54,59 @@ public class TestAnnotationConfiguration
|
|||
else
|
||||
assertFalse(_discoverableAnnotationHandlers.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
public File web25;
|
||||
|
||||
public File web31false;
|
||||
|
||||
public File web31true;
|
||||
|
||||
public File jarDir;
|
||||
|
||||
public File testSciJar;
|
||||
|
||||
public File testContainerSciJar;
|
||||
|
||||
public File testWebInfClassesJar;
|
||||
|
||||
public File unpacked;
|
||||
}
|
||||
|
||||
public WorkDir workDir;
|
||||
public Path web25;
|
||||
public Path web31false;
|
||||
public Path web31true;
|
||||
public Path jarDir;
|
||||
public Path testSciJar;
|
||||
public Path testContainerSciJar;
|
||||
public Path testWebInfClassesJar;
|
||||
public Path unpacked;
|
||||
public URLClassLoader containerLoader;
|
||||
|
||||
public URLClassLoader webAppLoader;
|
||||
|
||||
public List<Resource> classes;
|
||||
|
||||
public Resource targetClasses;
|
||||
|
||||
public Resource webInfClasses;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception
|
||||
{
|
||||
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
|
||||
web25 = MavenTestingUtils.getTargetFile("test-classes/web25.xml");
|
||||
web31false = MavenTestingUtils.getTargetFile("test-classes/web31false.xml");
|
||||
web31true = MavenTestingUtils.getTargetFile("test-classes/web31true.xml");
|
||||
web25 = MavenTestingUtils.getTargetPath().resolve("test-classes/web25.xml");
|
||||
web31false = MavenTestingUtils.getTargetPath().resolve("test-classes/web31false.xml");
|
||||
web31true = MavenTestingUtils.getTargetPath().resolve("test-classes/web31true.xml");
|
||||
|
||||
assertTrue(Files.exists(web25), web25 + " should exist");
|
||||
assertTrue(Files.exists(web31false), web31false + " should exist");
|
||||
assertTrue(Files.exists(web31true), web31true + " should exist");
|
||||
|
||||
// prepare an sci that will be on the webapp's classpath
|
||||
jarDir = new File(MavenTestingUtils.getTargetPath("test-classes").toFile(), "jar");
|
||||
testSciJar = new File(jarDir, "test-sci.jar");
|
||||
assertTrue(testSciJar.exists());
|
||||
jarDir = MavenTestingUtils.getProjectDirPath("src/test/jar");
|
||||
testSciJar = jarDir.resolve("test-sci.jar");
|
||||
assertTrue(Files.exists(testSciJar));
|
||||
|
||||
testContainerSciJar = new File(jarDir, "test-sci-for-container-path.jar");
|
||||
testWebInfClassesJar = new File(jarDir, "test-sci-for-webinf.jar");
|
||||
testContainerSciJar = jarDir.resolve("test-sci-for-container-path.jar");
|
||||
testWebInfClassesJar = jarDir.resolve("test-sci-for-webinf.jar");
|
||||
|
||||
// unpack some classes to pretend that are in WEB-INF/classes
|
||||
unpacked = new File(MavenTestingUtils.getTargetTestingDir(), "test-sci-for-webinf");
|
||||
unpacked.mkdirs();
|
||||
unpacked = workDir.getEmptyPathDir();
|
||||
FS.cleanDirectory(unpacked);
|
||||
JAR.unpack(testWebInfClassesJar, unpacked);
|
||||
webInfClasses = ResourceFactory.root().newResource(unpacked.toPath());
|
||||
JAR.unpack(testWebInfClassesJar.toFile(), unpacked.toFile());
|
||||
webInfClasses = ResourceFactory.root().newResource(unpacked);
|
||||
|
||||
containerLoader = new URLClassLoader(new URL[]{
|
||||
testContainerSciJar.toURI().toURL()
|
||||
testContainerSciJar.toUri().toURL()
|
||||
}, Thread.currentThread().getContextClassLoader());
|
||||
|
||||
targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes");
|
||||
|
||||
classes = Arrays.asList(new Resource[]{webInfClasses, targetClasses});
|
||||
classes = List.of(webInfClasses, targetClasses);
|
||||
|
||||
webAppLoader = new URLClassLoader(new URL[]{
|
||||
testSciJar.toURI().toURL(), targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
testSciJar.toUri().toURL(), targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
},
|
||||
containerLoader);
|
||||
}
|
||||
|
@ -133,7 +127,7 @@ public class TestAnnotationConfiguration
|
|||
context25.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context25.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context25.setConfigurationDiscovered(false);
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(context25.getResourceFactory().newResource(web25)));
|
||||
context25.getServletContext().setEffectiveMajorVersion(2);
|
||||
context25.getServletContext().setEffectiveMinorVersion(5);
|
||||
config25.configure(context25);
|
||||
|
@ -145,7 +139,7 @@ public class TestAnnotationConfiguration
|
|||
context25b.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context25b.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context25b.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(context25b.getResourceFactory().newResource(web25)));
|
||||
context25b.getServletContext().setEffectiveMajorVersion(2);
|
||||
context25b.getServletContext().setEffectiveMinorVersion(5);
|
||||
config25b.configure(context25b);
|
||||
|
@ -157,7 +151,7 @@ public class TestAnnotationConfiguration
|
|||
context31.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context31.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context31.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(context31.getResourceFactory().newResource(web31true)));
|
||||
context31.getServletContext().setEffectiveMajorVersion(3);
|
||||
context31.getServletContext().setEffectiveMinorVersion(1);
|
||||
config31.configure(context31);
|
||||
|
@ -169,7 +163,7 @@ public class TestAnnotationConfiguration
|
|||
context31b.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
context31b.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE);
|
||||
context31b.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0);
|
||||
context31b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context31b.getMetaData().setWebDescriptor(new WebDescriptor(context31b.getResourceFactory().newResource(web31false)));
|
||||
context31b.getServletContext().setEffectiveMajorVersion(3);
|
||||
context31b.getServletContext().setEffectiveMinorVersion(1);
|
||||
config31b.configure(context31b);
|
||||
|
@ -191,8 +185,8 @@ public class TestAnnotationConfiguration
|
|||
|
||||
//test 3.1 webapp loads both server and app scis
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getServletContext().setEffectiveMinorVersion(1);
|
||||
|
@ -208,7 +202,7 @@ public class TestAnnotationConfiguration
|
|||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClassScanHandlersForSCIs() throws Exception
|
||||
{
|
||||
|
@ -236,24 +230,24 @@ public class TestAnnotationConfiguration
|
|||
assertEquals("com.acme.initializer.Foo", handler._annotation.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MyAnnotationConfiguration config = new MyAnnotationConfiguration();
|
||||
|
||||
|
||||
WebAppContext context = new WebAppContext();
|
||||
config.preConfigure(context);
|
||||
List<ServletContainerInitializer> scis;
|
||||
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getServletContext().setEffectiveMinorVersion(1);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
assertNotNull(scis);
|
||||
assertEquals(3, scis.size());
|
||||
|
||||
config.createServletContainerInitializerAnnotationHandlers(context, scis);
|
||||
|
||||
config.createServletContainerInitializerAnnotationHandlers(context, scis);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -276,9 +270,9 @@ public class TestAnnotationConfiguration
|
|||
// test a 3.1 webapp with metadata-complete=false loads both server
|
||||
// and webapp scis
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31false)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getServletContext().setEffectiveMajorVersion(3);
|
||||
context.getServletContext().setEffectiveMinorVersion(1);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
|
@ -306,10 +300,10 @@ public class TestAnnotationConfiguration
|
|||
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
File orderedFragmentJar = new File(jarDir, "test-sci-with-ordering.jar");
|
||||
assertTrue(orderedFragmentJar.exists());
|
||||
Path orderedFragmentJar = jarDir.resolve("test-sci-with-ordering.jar");
|
||||
assertTrue(Files.exists(orderedFragmentJar));
|
||||
URLClassLoader orderedLoader = new URLClassLoader(new URL[]{
|
||||
orderedFragmentJar.toURI().toURL(), testSciJar.toURI().toURL(),
|
||||
orderedFragmentJar.toUri().toURL(), testSciJar.toUri().toURL(),
|
||||
targetClasses.getURI().toURL(), webInfClasses.getURI().toURL()
|
||||
},
|
||||
containerLoader);
|
||||
|
@ -322,11 +316,11 @@ public class TestAnnotationConfiguration
|
|||
config.preConfigure(context);
|
||||
List<ServletContainerInitializer> scis;
|
||||
context.setClassLoader(orderedLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31true.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web31true)));
|
||||
RelativeOrdering ordering = new RelativeOrdering(context.getMetaData());
|
||||
context.getMetaData().setOrdering(ordering);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(orderedFragmentJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(orderedFragmentJar));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().orderFragments();
|
||||
context.getServletContext().setEffectiveMajorVersion(3);
|
||||
|
@ -359,9 +353,9 @@ public class TestAnnotationConfiguration
|
|||
List<ServletContainerInitializer> scis;
|
||||
context.setConfigurationDiscovered(false);
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web25)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getServletContext().setEffectiveMajorVersion(2);
|
||||
context.getServletContext().setEffectiveMinorVersion(5);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
|
@ -369,8 +363,8 @@ public class TestAnnotationConfiguration
|
|||
for (ServletContainerInitializer s : scis)
|
||||
{
|
||||
//should not have any of the web-inf lib scis in here
|
||||
assertFalse(s.getClass().getName().equals("com.acme.ordering.AcmeServletContainerInitializer"));
|
||||
assertFalse(s.getClass().getName().equals("com.acme.initializer.FooInitializer"));
|
||||
assertNotEquals("com.acme.ordering.AcmeServletContainerInitializer", s.getClass().getName());
|
||||
assertNotEquals("com.acme.initializer.FooInitializer", s.getClass().getName());
|
||||
//NOTE: should also not have the web-inf classes scis in here either, but due to the
|
||||
//way the test is set up, the sci we're pretending is in web-inf classes will actually
|
||||
//NOT be loaded by the webapp's classloader, but rather by the junit classloader, so
|
||||
|
@ -397,14 +391,14 @@ public class TestAnnotationConfiguration
|
|||
List<ServletContainerInitializer> scis;
|
||||
context.setConfigurationDiscovered(true);
|
||||
context.setClassLoader(webAppLoader);
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context.getMetaData().setWebDescriptor(new WebDescriptor(context.getResourceFactory().newResource(web25)));
|
||||
context.getMetaData().setWebInfClassesResources(classes);
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar.toURI().toURL()));
|
||||
context.getMetaData().addWebInfResource(ResourceFactory.root().newResource(testSciJar));
|
||||
context.getServletContext().setEffectiveMajorVersion(2);
|
||||
context.getServletContext().setEffectiveMinorVersion(5);
|
||||
scis = config.getNonExcludedInitializers(context);
|
||||
assertNotNull(scis);
|
||||
assertEquals(3, scis.size(), () -> scis.toString());
|
||||
assertEquals(3, scis.size(), scis::toString);
|
||||
assertEquals("com.acme.ServerServletContainerInitializer", scis.get(0).getClass().getName()); //container path
|
||||
assertEquals("com.acme.webinf.WebInfClassServletContainerInitializer", scis.get(1).getClass().getName()); // web-inf
|
||||
assertEquals("com.acme.initializer.FooInitializer", scis.get(2).getClass().getName()); //web-inf jar no web-fragment
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.annotations;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.ee9.plus.annotation.LifeCycleCallbackCollection;
|
||||
|
@ -21,7 +22,9 @@ import org.eclipse.jetty.ee9.servlet.Source;
|
|||
import org.eclipse.jetty.ee9.webapp.MetaData;
|
||||
import org.eclipse.jetty.ee9.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee9.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.xml.XmlParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -34,11 +37,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
public class TestAnnotationDecorator
|
||||
{
|
||||
public WorkDir workDir;
|
||||
|
||||
public class TestWebDescriptor extends WebDescriptor
|
||||
{
|
||||
public TestWebDescriptor(MetaData.Complete metadata)
|
||||
public TestWebDescriptor(Resource xml, MetaData.Complete metadata)
|
||||
{
|
||||
super(ResourceFactory.root().newResource(Path.of(".")));
|
||||
super(xml);
|
||||
_metaDataComplete = metadata;
|
||||
}
|
||||
|
||||
|
@ -78,6 +83,11 @@ public class TestAnnotationDecorator
|
|||
@Test
|
||||
public void testAnnotationDecorator() throws Exception
|
||||
{
|
||||
Path docroot = workDir.getEmptyPathDir();
|
||||
Path dummyDescriptor = docroot.resolve("dummy.xml");
|
||||
Files.createFile(dummyDescriptor);
|
||||
Resource dummyResource = ResourceFactory.root().newResource(dummyDescriptor);
|
||||
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
{
|
||||
new AnnotationDecorator(null);
|
||||
|
@ -96,9 +106,9 @@ public class TestAnnotationDecorator
|
|||
context.removeAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
|
||||
|
||||
//test with BaseHolder metadata, should not introspect with metdata-complete==true
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(MetaData.Complete.True));
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyResource, MetaData.Complete.True));
|
||||
assertTrue(context.getMetaData().isMetaDataComplete());
|
||||
ServletHolder holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, ""));
|
||||
ServletHolder holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR));
|
||||
holder.setHeldClass(ServletE.class);
|
||||
context.getServletHandler().addServlet(holder);
|
||||
DecoratedObjectFactory.associateInfo(holder);
|
||||
|
@ -112,7 +122,7 @@ public class TestAnnotationDecorator
|
|||
context.removeAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
|
||||
|
||||
//test with BaseHolder metadata, should introspect with metadata-complete==false
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(MetaData.Complete.False));
|
||||
context.getMetaData().setWebDescriptor(new TestWebDescriptor(dummyResource, MetaData.Complete.False));
|
||||
DecoratedObjectFactory.associateInfo(holder);
|
||||
decorator = new AnnotationDecorator(context);
|
||||
decorator.decorate(servlet);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.ee9.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.ee9.servlet.Source;
|
||||
|
@ -23,7 +23,6 @@ import org.eclipse.jetty.ee9.webapp.WebDescriptor;
|
|||
import org.eclipse.jetty.logging.StacklessLogging;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -58,36 +57,38 @@ public class TestAnnotationIntrospector
|
|||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//an ANNOTATION sourced servlet can be introspected
|
||||
holder = new ServletHolder(new Source(Source.Origin.ANNOTATION, ServletE.class.getName()));
|
||||
holder = new ServletHolder(new Source(Source.Origin.ANNOTATION, ServletE.class));
|
||||
holder.setHeldClass(ServletE.class);
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet can be introspected if web.xml metdata-complete==false
|
||||
File file = MavenTestingUtils.getTargetFile("test-classes/web31false.xml");
|
||||
Resource resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
Path xml = MavenTestingUtils.getTargetPath().resolve("test-classes/web31false.xml");
|
||||
Resource xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet can be introspected if web-fragment.xml medata-complete==false && web.xml metadata-complete==false
|
||||
file = MavenTestingUtils.getTargetFile("test-classes/web-fragment4false.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().addFragmentDescriptor(ResourceFactory.root().newResource(file.getParentFile().toPath()), new FragmentDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTargetPath().resolve("test-classes/web-fragment4false.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
Resource parent = wac.getResourceFactory().newResource(xml.getParent());
|
||||
wac.getMetaData().addFragmentDescriptor(parent, new FragmentDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertTrue(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet cannot be introspected if web-fragment.xml medata-complete==true (&& web.xml metadata-complete==false)
|
||||
file = MavenTestingUtils.getTargetFile("test-classes/web-fragment4true.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().addFragmentDescriptor(ResourceFactory.root().newResource(file.getParentFile().toPath()), new FragmentDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTargetPath().resolve("test-classes/web-fragment4true.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
parent = wac.getResourceFactory().newResource(xml.getParent());
|
||||
wac.getMetaData().addFragmentDescriptor(parent, new FragmentDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertFalse(introspector.isIntrospectable(new ServletE(), holder));
|
||||
|
||||
//a DESCRIPTOR sourced servlet cannot be introspected if web.xml medata-complete==true
|
||||
file = MavenTestingUtils.getTargetFile("test-classes/web31true.xml");
|
||||
resource = ResourceFactory.root().newResource(file.toPath());
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(resource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, resource.toString()));
|
||||
xml = MavenTestingUtils.getTargetPath().resolve("test-classes/web31true.xml");
|
||||
xmlResource = wac.getResourceFactory().newResource(xml);
|
||||
wac.getMetaData().setWebDescriptor(new WebDescriptor(xmlResource));
|
||||
holder = new ServletHolder(new Source(Source.Origin.DESCRIPTOR, xmlResource));
|
||||
assertFalse(introspector.isIntrospectable(new ServletE(), holder));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class TestDiscoveredServletContainerInitializerHolder
|
|||
SampleServletContainerInitializer sci = new SampleServletContainerInitializer();
|
||||
|
||||
AnnotationConfiguration.DiscoveredServletContainerInitializerHolder holder =
|
||||
new AnnotationConfiguration.DiscoveredServletContainerInitializerHolder(new Source(Source.Origin.ANNOTATION, sci.getClass().getName()),
|
||||
new AnnotationConfiguration.DiscoveredServletContainerInitializerHolder(new Source(Source.Origin.ANNOTATION, sci.getClass()),
|
||||
sci);
|
||||
|
||||
//add the @HandlesTypes to the holder
|
||||
|
|
|
@ -13,20 +13,22 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.ee9.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.ee9.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee9.webapp.WebDescriptor;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestRunAsAnnotation
|
||||
{
|
||||
public WorkDir workDir;
|
||||
|
||||
@Test
|
||||
public void testRunAsAnnotation() throws Exception
|
||||
{
|
||||
|
@ -45,8 +47,9 @@ public class TestRunAsAnnotation
|
|||
holder2.setHeldClass(ServletC.class);
|
||||
holder2.setInitOrder(1);
|
||||
wac.getServletHandler().addServletWithMapping(holder2, "/foo2/*");
|
||||
Resource fakeXml = ResourceFactory.root().newResource(new File(MavenTestingUtils.getTargetTestingDir("run-as"), "fake.xml").toPath());
|
||||
wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(fakeXml));
|
||||
Path fakeXml = workDir.getEmptyPathDir().resolve("fake.xml");
|
||||
Files.createFile(fakeXml);
|
||||
wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(wac.getResourceFactory().newResource(fakeXml)));
|
||||
|
||||
AnnotationIntrospector parser = new AnnotationIntrospector(wac);
|
||||
RunAsAnnotationHandler handler = new RunAsAnnotationHandler(wac);
|
||||
|
@ -54,6 +57,6 @@ public class TestRunAsAnnotation
|
|||
parser.introspect(new ServletC(), null);
|
||||
|
||||
assertEquals("admin", holder.getRunAsRole());
|
||||
assertEquals(null, holder2.getRunAsRole());
|
||||
assertNull(holder2.getRunAsRole());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
case WebFragment:
|
||||
{
|
||||
//ServletSpec p.75. No declaration in web.xml, but in multiple web-fragments. Error.
|
||||
throw new IllegalStateException("Conflicting env-entry " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting env-entry " + name + " in " + descriptor.getURI());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -293,7 +293,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
//ServletSpec p.75. No declaration of resource-ref in web xml, but different in multiple web-fragments. Error.
|
||||
if (!type.equals(otherType) || !auth.equals(otherAuth) || !shared.equals(otherShared))
|
||||
throw new IllegalStateException("Conflicting resource-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting resource-ref " + jndiName + " in " + descriptor.getURI());
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
//ServletSpec p.75. No declaration of resource-ref in web xml, but different in multiple web-fragments. Error.
|
||||
if (!type.equals(otherType))
|
||||
throw new IllegalStateException("Conflicting resource-env-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting resource-env-ref " + jndiName + " in " + descriptor.getURI());
|
||||
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
|
@ -503,7 +503,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
type = (type == null ? "" : type);
|
||||
usage = (usage == null ? "" : usage);
|
||||
if (!type.equals(otherType) || !usage.equalsIgnoreCase(otherUsage))
|
||||
throw new IllegalStateException("Conflicting message-destination-ref " + jndiName + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting message-destination-ref " + jndiName + " in " + descriptor.getURI());
|
||||
|
||||
//same in multiple web-fragments, merge the injections
|
||||
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ExtraXmlDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
public void start(WebAppContext context, Descriptor descriptor)
|
||||
{
|
||||
LOG.debug("process {}", descriptor);
|
||||
_origin = (StringUtil.isBlank(_originAttribute) ? null : " <!-- " + descriptor + " -->\n");
|
||||
_origin = (StringUtil.isBlank(_originAttribute) ? null : " <!-- " + descriptor.getURI() + " -->\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.servlet;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
* Source
|
||||
*
|
||||
|
@ -20,8 +24,8 @@ package org.eclipse.jetty.ee9.servlet;
|
|||
*/
|
||||
public class Source
|
||||
{
|
||||
public static final Source EMBEDDED = new Source(Origin.EMBEDDED, null);
|
||||
public static final Source JAVAX_API = new Source(Origin.JAKARTA_API, null);
|
||||
public static final Source EMBEDDED = new Source(Origin.EMBEDDED);
|
||||
public static final Source JAVAX_API = new Source(Origin.JAKARTA_API);
|
||||
|
||||
public enum Origin
|
||||
{
|
||||
|
@ -29,19 +33,49 @@ public class Source
|
|||
JAKARTA_API, DESCRIPTOR, ANNOTATION
|
||||
}
|
||||
|
||||
public Origin _origin;
|
||||
public String _resource;
|
||||
public final Origin _origin;
|
||||
public final String _name;
|
||||
public Resource _resource;
|
||||
|
||||
/**
|
||||
* A Source without a name/location.
|
||||
*
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
*/
|
||||
public Source(Origin o)
|
||||
{
|
||||
this(o, (String)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param clazz the class where the artifact was declared
|
||||
*/
|
||||
public Source(Origin o, Class<?> clazz)
|
||||
{
|
||||
this(o, clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param resource the location where the artifact was declared
|
||||
*/
|
||||
public Source(Origin o, String resource)
|
||||
public Source(Origin o, Resource resource)
|
||||
{
|
||||
this(o, Objects.requireNonNull(resource).getURI().toASCIIString());
|
||||
_resource = resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o the Origin of the artifact (servlet, filter, mapping etc)
|
||||
* @param name the name of the location where the artifact was declared (not a {@link Resource})
|
||||
*/
|
||||
public Source(Origin o, String name)
|
||||
{
|
||||
if (o == null)
|
||||
throw new IllegalArgumentException("Origin is null");
|
||||
_origin = o;
|
||||
_resource = resource;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,15 +89,22 @@ public class Source
|
|||
/**
|
||||
* @return the resource
|
||||
*/
|
||||
public String getResource()
|
||||
public Resource getResource()
|
||||
{
|
||||
return _resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
||||
return _origin + ":" + _resource;
|
||||
return _origin + ":" + (_name == null ? "<null>" : _name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class ServletContainerInitializerHolderTest
|
|||
@Test
|
||||
public void testInstanceWithStartupClassesAndSource() throws Exception
|
||||
{
|
||||
ServletContainerInitializerHolder holder = new ServletContainerInitializerHolder(new Source(Origin.ANNOTATION, null), new SimpleSCI(), Integer.class);
|
||||
ServletContainerInitializerHolder holder = new ServletContainerInitializerHolder(new Source(Origin.ANNOTATION), new SimpleSCI(), Integer.class);
|
||||
assertEquals(Origin.ANNOTATION, holder.getSource().getOrigin());
|
||||
assertEquals(SimpleSCI.class, holder.getHeldClass());
|
||||
assertEquals("ContainerInitializer{org.eclipse.jetty.ee9.servlet.ServletContainerInitializerHolderTest$SimpleSCI,interested=[java.lang.Integer],applicable=[],annotated=[]}", holder.toString());
|
||||
|
|
|
@ -15,8 +15,6 @@ package org.eclipse.jetty.ee9.webapp;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -33,19 +31,20 @@ public abstract class Descriptor
|
|||
protected XmlParser.Node _root;
|
||||
protected String _dtd;
|
||||
|
||||
public Descriptor(Resource xml)
|
||||
public Descriptor(Resource resource)
|
||||
{
|
||||
_xml = Objects.requireNonNull(xml);
|
||||
_xml = Objects.requireNonNull(resource, "Resource must not be null");
|
||||
if (_xml.isDirectory())
|
||||
throw new IllegalArgumentException("Descriptor cannot be a directory");
|
||||
}
|
||||
|
||||
public void parse(XmlParser parser)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
if (_root == null)
|
||||
{
|
||||
Objects.requireNonNull(parser);
|
||||
try (InputStream is = Files.newInputStream(_xml.getPath(), StandardOpenOption.READ))
|
||||
try (InputStream is = _xml.newInputStream())
|
||||
{
|
||||
_root = parser.parse(is);
|
||||
_dtd = parser.getDTD();
|
||||
|
@ -58,9 +57,9 @@ public abstract class Descriptor
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isParsed()
|
||||
public String getURI()
|
||||
{
|
||||
return _root != null;
|
||||
return _xml.getURI().toASCIIString();
|
||||
}
|
||||
|
||||
public Resource getResource()
|
||||
|
@ -76,6 +75,6 @@ public abstract class Descriptor
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass().getSimpleName() + "(" + _xml + ")";
|
||||
return this.getClass().getSimpleName() + "(" + getURI() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class FragmentConfiguration extends AbstractConfiguration
|
||||
{
|
||||
public static final String FRAGMENT_RESOURCES = "org.eclipse.jetty.webFragments";
|
||||
// Holds a Map<Resource, Resource> .
|
||||
// key: Resource to the Jar
|
||||
// value: Resource to the web fragment xml
|
||||
public static final String FRAGMENT_RESOURCES = FragmentConfiguration.class.getPackageName() + ".webFragments";
|
||||
|
||||
public FragmentConfiguration()
|
||||
{
|
||||
|
|
|
@ -36,7 +36,6 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
None, Before, After
|
||||
}
|
||||
|
||||
;
|
||||
protected OtherType _otherType = OtherType.None;
|
||||
|
||||
protected List<String> _befores = new ArrayList<String>();
|
||||
|
@ -44,7 +43,6 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
protected String _name;
|
||||
|
||||
public FragmentDescriptor(Resource xml)
|
||||
throws Exception
|
||||
{
|
||||
super(xml);
|
||||
}
|
||||
|
@ -109,7 +107,7 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
if (node.getTag().equalsIgnoreCase("others"))
|
||||
{
|
||||
if (_otherType != OtherType.None)
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml.getURI());
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml);
|
||||
|
||||
_otherType = OtherType.Before;
|
||||
}
|
||||
|
@ -136,7 +134,7 @@ public class FragmentDescriptor extends WebDescriptor
|
|||
if (node.getTag().equalsIgnoreCase("others"))
|
||||
{
|
||||
if (_otherType != OtherType.None)
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml.getURI());
|
||||
throw new IllegalStateException("Duplicate <other> clause detected in " + _xml);
|
||||
|
||||
_otherType = OtherType.After;
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ public class MetaData
|
|||
Descriptor existing = _webFragmentNameMap.get(descriptor.getName());
|
||||
if (existing != null && !isAllowDuplicateFragmentNames())
|
||||
{
|
||||
throw new IllegalStateException("Duplicate fragment name: " + descriptor.getName() + " for " + existing.getResource() + " and " + descriptor.getResource());
|
||||
throw new IllegalStateException("Duplicate fragment name: " + descriptor.getName() + " for " + existing.getURI() + " and " + descriptor.getURI());
|
||||
}
|
||||
else
|
||||
_webFragmentNameMap.put(descriptor.getName(), descriptor);
|
||||
|
@ -448,7 +448,7 @@ public class MetaData
|
|||
{
|
||||
LOG.debug("metadata resolve {}", context);
|
||||
|
||||
// Ensure origins is fresh
|
||||
//Ensure origins is fresh
|
||||
_origins.clear();
|
||||
|
||||
// Set the ordered lib attribute
|
||||
|
|
|
@ -250,6 +250,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
}
|
||||
loader = loader.getParent();
|
||||
}
|
||||
|
||||
return uris;
|
||||
}
|
||||
|
||||
|
@ -325,6 +326,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
* @param scanTypes the type of things to look for in the jars
|
||||
* @throws Exception if unable to scan the jars
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void scanJars(final WebAppContext context, Collection<Resource> jars, boolean useCaches, List<String> scanTypes)
|
||||
throws Exception
|
||||
{
|
||||
|
@ -374,10 +376,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
* @param context the context for the scan
|
||||
* @param target the target resource to scan for
|
||||
* @param cache the resource cache
|
||||
* @throws Exception if unable to scan for resources
|
||||
*/
|
||||
public void scanForResources(WebAppContext context, Resource target, ConcurrentHashMap<Resource, Resource> cache)
|
||||
throws Exception
|
||||
{
|
||||
Resource resourcesDir = null;
|
||||
if (cache != null && cache.containsKey(target))
|
||||
|
@ -404,7 +404,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
}
|
||||
else
|
||||
{
|
||||
//Resource represents a packed jar
|
||||
// Resource represents a packed jar
|
||||
URI uri = target.getURI();
|
||||
resourcesDir = _resourceFactory.newResource(URIUtil.uriJarPrefix(uri, "!/META-INF/resources"));
|
||||
}
|
||||
|
@ -448,10 +448,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
* @param context the context for the scan
|
||||
* @param jar the jar resource to scan for fragements in
|
||||
* @param cache the resource cache
|
||||
* @throws Exception if unable to scan for fragments
|
||||
*/
|
||||
public void scanForFragment(WebAppContext context, Resource jar, ConcurrentHashMap<Resource, Resource> cache)
|
||||
throws Exception
|
||||
{
|
||||
Resource webFrag = null;
|
||||
if (cache != null && cache.containsKey(jar))
|
||||
|
@ -543,7 +541,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
else
|
||||
{
|
||||
//not using caches or not in the cache so find all tlds
|
||||
tlds = new HashSet<URL>();
|
||||
tlds = new HashSet<>();
|
||||
if (jar.isDirectory())
|
||||
{
|
||||
tlds.addAll(getTlds(jar.getPath()));
|
||||
|
@ -613,7 +611,6 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
tlds.add(entry.toUri().toURL());
|
||||
}
|
||||
}
|
||||
|
||||
return tlds;
|
||||
}
|
||||
|
||||
|
@ -654,9 +651,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
Resource webInfClasses = findWebInfClassesDir(context);
|
||||
if (webInfClasses != null)
|
||||
classDirs.add(webInfClasses);
|
||||
List<Resource> extraClassDirs = findExtraClasspathDirs(context);
|
||||
if (extraClassDirs != null)
|
||||
classDirs.addAll(extraClassDirs);
|
||||
classDirs.addAll(findExtraClasspathDirs(context));
|
||||
|
||||
return classDirs;
|
||||
}
|
||||
|
@ -671,10 +666,8 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
protected List<Resource> findJars(WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> jarResources = new ArrayList<Resource>();
|
||||
List<Resource> webInfLibJars = findWebInfLibJars(context);
|
||||
if (webInfLibJars != null)
|
||||
jarResources.addAll(webInfLibJars);
|
||||
List<Resource> jarResources = new ArrayList<>();
|
||||
jarResources.addAll(findWebInfLibJars(context));
|
||||
List<Resource> extraClasspathJars = findExtraClasspathJars(context);
|
||||
if (extraClasspathJars != null)
|
||||
jarResources.addAll(extraClasspathJars);
|
||||
|
@ -691,9 +684,12 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
protected List<Resource> findWebInfLibJars(WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
if (context == null)
|
||||
return List.of();
|
||||
|
||||
Resource webInf = context.getWebInf();
|
||||
if (webInf == null || !webInf.exists())
|
||||
return null;
|
||||
if (webInf == null || !webInf.exists() || !webInf.isDirectory())
|
||||
return List.of();
|
||||
|
||||
Resource webInfLib = webInf.resolve("/lib");
|
||||
|
||||
|
@ -754,15 +750,14 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
*
|
||||
* @param context the context to look for extra classpaths in
|
||||
* @return the list of Resources to the extra classpath
|
||||
* @throws Exception if unable to resolve the extra classpath resources
|
||||
*/
|
||||
protected List<Resource> findExtraClasspathDirs(WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
if (context == null || context.getExtraClasspath() == null)
|
||||
return null;
|
||||
return List.of();
|
||||
|
||||
return context.getExtraClasspath().getResources()
|
||||
return context.getExtraClasspath()
|
||||
.getResources()
|
||||
.stream()
|
||||
.filter(Resource::isDirectory)
|
||||
.collect(Collectors.toList());
|
||||
|
|
|
@ -175,7 +175,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
if (descriptor instanceof FragmentDescriptor)
|
||||
{
|
||||
if (!((String)context.getInitParams().get(name)).equals(value))
|
||||
throw new IllegalStateException("Conflicting context-param " + name + "=" + value + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting context-param " + name + "=" + value + " in " + descriptor.getURI());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
//If servlet of that name does not already exist, create it.
|
||||
if (holder == null)
|
||||
{
|
||||
holder = context.getServletHandler().newServletHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
holder = context.getServletHandler().newServletHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
holder.setName(name);
|
||||
_servletHolderMap.put(name, holder);
|
||||
_servletHolders.add(holder);
|
||||
|
@ -249,7 +249,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
|
||||
if ((descriptor != originDescriptor) && !holder.getInitParameter(pname).equals(pvalue))
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -305,7 +305,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//the class was set by another fragment, ensure this fragment's value is the same
|
||||
if (!servletClass.equals(holder.getClassName()))
|
||||
throw new IllegalStateException("Conflicting servlet-class " + servletClass + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting servlet-class " + servletClass + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -369,7 +369,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//it was already set by another fragment, if we're parsing a fragment, the values must match
|
||||
if (order != holder.getInitOrder())
|
||||
throw new IllegalStateException("Conflicting load-on-startup value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting load-on-startup value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -412,7 +412,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
case WebFragment:
|
||||
{
|
||||
if (!holder.getUserRoleLink(roleName).equals(roleLink))
|
||||
throw new IllegalStateException("Conflicting role-link for role-name " + roleName + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting role-link for role-name " + roleName + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -458,7 +458,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//run-as was set by another fragment, this fragment must show the same value
|
||||
if (!holder.getRunAsRole().equals(roleName))
|
||||
throw new IllegalStateException("Conflicting run-as role " + roleName + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting run-as role " + roleName + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -497,7 +497,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//async-supported set by another fragment, this fragment's value must match
|
||||
if (holder.isAsyncSupported() != val)
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -535,7 +535,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//was set by another fragment, this fragment's value must match
|
||||
if (holder.isEnabled() != isEnabled)
|
||||
throw new IllegalStateException("Conflicting value of servlet enabled for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting value of servlet enabled for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -588,14 +588,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
MultipartConfigElement cfg = ((ServletHolder.Registration)holder.getRegistration()).getMultipartConfig();
|
||||
|
||||
if (cfg.getMaxFileSize() != element.getMaxFileSize())
|
||||
throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet " + name + " in " + descriptor.getURI());
|
||||
if (cfg.getMaxRequestSize() != element.getMaxRequestSize())
|
||||
throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet " + name + " in " + descriptor.getURI());
|
||||
if (cfg.getFileSizeThreshold() != element.getFileSizeThreshold())
|
||||
throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet " + name + " in " + descriptor.getURI());
|
||||
if ((cfg.getLocation() != null && (element.getLocation() == null || element.getLocation().length() == 0)) ||
|
||||
(cfg.getLocation() == null && (element.getLocation() != null || element.getLocation().length() > 0)))
|
||||
throw new IllegalStateException("Conflicting multipart-config location for servlet " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting multipart-config location for servlet " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -741,7 +741,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!name.equals(context.getSessionHandler().getSessionCookieConfig().getName()))
|
||||
throw new IllegalStateException("Conflicting cookie-config name " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config name " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -779,7 +779,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!context.getSessionHandler().getSessionCookieConfig().getDomain().equals(domain))
|
||||
throw new IllegalStateException("Conflicting cookie-config domain " + domain + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config domain " + domain + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -817,7 +817,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!path.equals(context.getSessionHandler().getSessionCookieConfig().getPath()))
|
||||
throw new IllegalStateException("Conflicting cookie-config path " + path + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config path " + path + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -855,7 +855,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!context.getSessionHandler().getSessionCookieConfig().getComment().equals(comment))
|
||||
throw new IllegalStateException("Conflicting cookie-config comment " + comment + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config comment " + comment + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -894,7 +894,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (context.getSessionHandler().getSessionCookieConfig().isHttpOnly() != httpOnly)
|
||||
throw new IllegalStateException("Conflicting cookie-config http-only " + httpOnly + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config http-only " + httpOnly + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -933,7 +933,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (context.getSessionHandler().getSessionCookieConfig().isSecure() != secure)
|
||||
throw new IllegalStateException("Conflicting cookie-config secure " + secure + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config secure " + secure + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -972,7 +972,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (context.getSessionHandler().getSessionCookieConfig().getMaxAge() != maxAge)
|
||||
throw new IllegalStateException("Conflicting cookie-config max-age " + maxAge + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting cookie-config max-age " + maxAge + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1016,7 +1016,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment set the value, all web-fragments must have the same value
|
||||
if (!context.getMimeTypes().getMimeByExtension("." + extension).equals(mimeType))
|
||||
throw new IllegalStateException("Conflicting mime-type " + mimeType + " for extension " + extension + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting mime-type " + mimeType + " for extension " + extension + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1107,7 +1107,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a value was set by a web-fragment, all fragments must have the same value
|
||||
if (!encoding.equals(context.getLocaleEncoding(locale)))
|
||||
throw new IllegalStateException("Conflicting loacle-encoding mapping for locale " + locale + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting locale-encoding mapping for locale " + locale + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1172,7 +1172,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//another web fragment set the same error code or exception, if its different its an error
|
||||
if (!handler.getErrorPages().get(error).equals(location))
|
||||
throw new IllegalStateException("Conflicting error-code or exception-type " + error + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting error-code or exception-type " + error + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1196,7 +1196,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
public ServletMapping addServletMapping(String servletName, XmlParser.Node node, WebAppContext context, Descriptor descriptor)
|
||||
{
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setFromDefaultDescriptor(descriptor instanceof DefaultsDescriptor);
|
||||
context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), descriptor);
|
||||
|
@ -1439,7 +1439,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
else
|
||||
{
|
||||
//no mapping for jsp yet, make one
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
mapping.setServletName("jsp");
|
||||
mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
|
||||
_servletMappings.add(mapping);
|
||||
|
@ -1597,7 +1597,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//it was already set by another fragment, if we're parsing a fragment, the values must match
|
||||
if (!context.getSecurityHandler().getAuthMethod().equals(method.toString(false, true)))
|
||||
throw new IllegalStateException("Conflicting auth-method value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting auth-method value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1633,7 +1633,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a fragment set it, and we must be parsing another fragment, so the values must match
|
||||
if (!context.getSecurityHandler().getRealmName().equals(nameStr))
|
||||
throw new IllegalStateException("Conflicting realm-name value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting realm-name value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1681,7 +1681,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
|
||||
if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE).equals(loginPageName))
|
||||
throw new IllegalStateException("Conflicting form-login-page value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting form-login-page value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1715,7 +1715,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
|
||||
if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_ERROR_PAGE).equals(errorPageName))
|
||||
throw new IllegalStateException("Conflicting form-error-page value in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting form-error-page value in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1750,7 +1750,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
FilterHolder holder = _filterHolderMap.get(name);
|
||||
if (holder == null)
|
||||
{
|
||||
holder = context.getServletHandler().newFilterHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
holder = context.getServletHandler().newFilterHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource()));
|
||||
holder.setName(name);
|
||||
_filterHolderMap.put(name, holder);
|
||||
_filterHolders.add(holder);
|
||||
|
@ -1787,7 +1787,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//the filter class was set up by a web fragment, all fragments must be the same
|
||||
if (!holder.getClassName().equals(filterClass))
|
||||
throw new IllegalStateException("Conflicting filter-class for filter " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting filter-class for filter " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1829,7 +1829,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
|
||||
if (!holder.getInitParameter(pname).equals(pvalue))
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1869,7 +1869,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
//async-supported set by another fragment, this fragment's value must match
|
||||
if (holder.isAsyncSupported() != val)
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for filter " + name + " in " + descriptor.getResource());
|
||||
throw new IllegalStateException("Conflicting async-supported=" + async + " for filter " + name + " in " + descriptor.getURI());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1934,7 +1934,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
((WebDescriptor)descriptor).addClassName(className);
|
||||
|
||||
ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getURI()));
|
||||
h.setClassName(className);
|
||||
context.getServletHandler().addListener(h);
|
||||
context.getMetaData().setOrigin(className + ".listener", descriptor);
|
||||
|
@ -1943,7 +1943,6 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Could not instantiate listener {}", className, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.ee9.webapp;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -22,7 +22,6 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -94,16 +93,16 @@ public class MetaInfConfigurationTest
|
|||
@Test
|
||||
public void testScanTypes() throws Exception
|
||||
{
|
||||
File web25 = MavenTestingUtils.getTargetFile("test-classes/web25.xml");
|
||||
File web31 = MavenTestingUtils.getTargetFile("test-classes/web31.xml");
|
||||
File web31false = MavenTestingUtils.getTargetFile("test-classes/web31false.xml");
|
||||
Path web25 = MavenTestingUtils.getTargetPath().resolve("test-classes/web25.xml");
|
||||
Path web31 = MavenTestingUtils.getTargetPath().resolve("test-classes/web31.xml");
|
||||
Path web31false = MavenTestingUtils.getTargetPath().resolve("test-classes/web31false.xml");
|
||||
|
||||
//test a 2.5 webapp will not look for fragments as manually configured
|
||||
MetaInfConfiguration meta25 = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
Arrays.asList(MetaInfConfiguration.METAINF_TLDS, MetaInfConfiguration.METAINF_RESOURCES));
|
||||
WebAppContext context25 = new WebAppContext();
|
||||
context25.setConfigurationDiscovered(false);
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25.getMetaData().setWebDescriptor(new WebDescriptor(context25.getResourceFactory().newResource(web25)));
|
||||
context25.getServletContext().setEffectiveMajorVersion(2);
|
||||
context25.getServletContext().setEffectiveMinorVersion(5);
|
||||
meta25.preConfigure(context25);
|
||||
|
@ -112,7 +111,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration meta25b = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
MetaInfConfiguration.__allScanTypes);
|
||||
WebAppContext context25b = new WebAppContext();
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web25.toPath())));
|
||||
context25b.getMetaData().setWebDescriptor(new WebDescriptor(context25b.getResourceFactory().newResource(web25)));
|
||||
context25b.getServletContext().setEffectiveMajorVersion(2);
|
||||
context25b.getServletContext().setEffectiveMinorVersion(5);
|
||||
meta25b.preConfigure(context25b);
|
||||
|
@ -121,7 +120,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration meta31 = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes,
|
||||
Arrays.asList(MetaInfConfiguration.METAINF_TLDS, MetaInfConfiguration.METAINF_RESOURCES));
|
||||
WebAppContext context31 = new WebAppContext();
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31.toPath())));
|
||||
context31.getMetaData().setWebDescriptor(new WebDescriptor(context31.getResourceFactory().newResource(web31)));
|
||||
context31.getServletContext().setEffectiveMajorVersion(3);
|
||||
context31.getServletContext().setEffectiveMinorVersion(1);
|
||||
meta31.preConfigure(context31);
|
||||
|
@ -131,7 +130,7 @@ public class MetaInfConfigurationTest
|
|||
MetaInfConfiguration.__allScanTypes);
|
||||
WebAppContext context31false = new WebAppContext();
|
||||
context31false.setConfigurationDiscovered(true);
|
||||
context31false.getMetaData().setWebDescriptor(new WebDescriptor(ResourceFactory.root().newResource(web31false.toPath())));
|
||||
context31false.getMetaData().setWebDescriptor(new WebDescriptor(context31false.getResourceFactory().newResource(web31false)));
|
||||
context31false.getServletContext().setEffectiveMajorVersion(3);
|
||||
context31false.getServletContext().setEffectiveMinorVersion(1);
|
||||
meta31false.preConfigure(context31false);
|
||||
|
@ -162,6 +161,7 @@ public class MetaInfConfigurationTest
|
|||
context.setClassLoader(loader);
|
||||
config.findAndFilterContainerPaths(context);
|
||||
List<Resource> containerResources = context.getMetaData().getContainerResources();
|
||||
|
||||
assertEquals(2, containerResources.size());
|
||||
for (Resource r : containerResources)
|
||||
{
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
package org.eclipse.jetty.ee9.webapp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -39,85 +39,29 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
public class OrderingTest
|
||||
{
|
||||
public class TestResource extends Resource
|
||||
WorkDir workDir;
|
||||
|
||||
private Resource newTestableDirResource(String name) throws IOException
|
||||
{
|
||||
public String _name;
|
||||
Path dir = workDir.getPath().resolve(name);
|
||||
if (!Files.exists(dir))
|
||||
Files.createDirectories(dir);
|
||||
return ResourceFactory.root().newResource(dir);
|
||||
}
|
||||
|
||||
public TestResource(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource resolve(String subUriPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream newInputStream() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableByteChannel newReadableByteChannel() throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContainedIn(Resource r)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long length()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private Resource newTestableFileResource(String name) throws IOException
|
||||
{
|
||||
Path file = workDir.getPath().resolve(name);
|
||||
if (!Files.exists(file))
|
||||
Files.createFile(file);
|
||||
return ResourceFactory.root().newResource(file);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach()
|
||||
{
|
||||
// ensure work dir exists, and is empty
|
||||
workDir.getEmptyPathDir();
|
||||
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
|
||||
}
|
||||
|
||||
|
@ -133,13 +77,13 @@ public class OrderingTest
|
|||
{
|
||||
//Example from ServletSpec p.70
|
||||
MetaData metaData = new MetaData();
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, after C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -149,9 +93,9 @@ public class OrderingTest
|
|||
f1._afters.add("C");
|
||||
|
||||
//B: before others
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -160,9 +104,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addBeforeOthers(r2);
|
||||
|
||||
//C: after others
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -171,9 +115,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addAfterOthers(r3);
|
||||
|
||||
//D: no ordering
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -182,9 +126,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addNoOthers(r4);
|
||||
|
||||
//E: no ordering
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
|
@ -193,9 +137,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addNoOthers(r5);
|
||||
|
||||
//F: before others, before B
|
||||
TestResource jar6 = new TestResource("F");
|
||||
Resource jar6 = newTestableDirResource("F");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("F/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("F/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = "F";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -210,13 +154,13 @@ public class OrderingTest
|
|||
String[] outcomes = {"FBDECA"};
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -224,15 +168,15 @@ public class OrderingTest
|
|||
public void testRelativeOrdering1()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//Example from ServletSpec p.70-71
|
||||
//No name: after others, before C
|
||||
TestResource jar1 = new TestResource("plain");
|
||||
Resource jar1 = newTestableDirResource("plain");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -242,9 +186,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -253,9 +197,9 @@ public class OrderingTest
|
|||
//((RelativeOrdering)metaData._ordering).addBeforeOthers(f2);
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -264,9 +208,9 @@ public class OrderingTest
|
|||
f3._otherType = FragmentDescriptor.OtherType.None;
|
||||
|
||||
//D: after others
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -275,9 +219,9 @@ public class OrderingTest
|
|||
f4._otherType = FragmentDescriptor.OtherType.After;
|
||||
|
||||
//E: before others
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
|
@ -286,9 +230,9 @@ public class OrderingTest
|
|||
f5._otherType = FragmentDescriptor.OtherType.Before;
|
||||
|
||||
//F: no ordering
|
||||
TestResource jar6 = new TestResource("F");
|
||||
Resource jar6 = newTestableDirResource("F");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("F/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("F/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = "F";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -313,13 +257,13 @@ public class OrderingTest
|
|||
"EBFDplainC"
|
||||
};
|
||||
|
||||
String orderedNames = "";
|
||||
StringBuilder orderedNames = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
orderedNames += (((TestResource)r)._name);
|
||||
orderedNames.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(orderedNames, outcomes))
|
||||
if (!checkResult(orderedNames.toString(), outcomes))
|
||||
fail("No outcome matched " + orderedNames);
|
||||
}
|
||||
|
||||
|
@ -327,16 +271,16 @@ public class OrderingTest
|
|||
public void testRelativeOrdering2()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//Example from Spec p. 71-72
|
||||
|
||||
//A: after B
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -346,9 +290,9 @@ public class OrderingTest
|
|||
f1._afters.add("B");
|
||||
|
||||
//B: no order
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -357,9 +301,9 @@ public class OrderingTest
|
|||
f2._otherType = FragmentDescriptor.OtherType.None;
|
||||
|
||||
//C: before others
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -368,9 +312,9 @@ public class OrderingTest
|
|||
f3._otherType = FragmentDescriptor.OtherType.Before;
|
||||
|
||||
//D: no order
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
|
@ -390,13 +334,13 @@ public class OrderingTest
|
|||
};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -404,14 +348,14 @@ public class OrderingTest
|
|||
public void testRelativeOrdering3()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -421,9 +365,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, before C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -433,9 +377,9 @@ public class OrderingTest
|
|||
f2._befores.add("C");
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -447,13 +391,13 @@ public class OrderingTest
|
|||
String[] outcomes = {"BAC"};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -461,7 +405,7 @@ public class OrderingTest
|
|||
public void testOrderFragments() throws Exception
|
||||
{
|
||||
final MetaData metadata = new MetaData();
|
||||
final Resource jarResource = new TestResource("A");
|
||||
final Resource jarResource = newTestableDirResource("A");
|
||||
|
||||
metadata.setOrdering(new RelativeOrdering(metadata));
|
||||
metadata.addWebInfResource(jarResource);
|
||||
|
@ -478,14 +422,14 @@ public class OrderingTest
|
|||
|
||||
//A: after B
|
||||
//B: after A
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after B
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -495,9 +439,9 @@ public class OrderingTest
|
|||
f1._afters.add("B");
|
||||
|
||||
//B: after A
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -517,14 +461,14 @@ public class OrderingTest
|
|||
public void testInvalid1()
|
||||
throws Exception
|
||||
{
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -534,9 +478,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, after C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -546,9 +490,9 @@ public class OrderingTest
|
|||
f2._afters.add("C");
|
||||
|
||||
//C: no ordering
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -559,10 +503,10 @@ public class OrderingTest
|
|||
assertThrows(IllegalStateException.class, () ->
|
||||
{
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
System.err.println("Invalid Result = " + result);
|
||||
fail("A and B have an impossible relationship to C");
|
||||
|
@ -576,7 +520,7 @@ public class OrderingTest
|
|||
//
|
||||
// A,B,C,others
|
||||
//
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
@ -584,49 +528,49 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("C");
|
||||
((AbsoluteOrdering)metaData._ordering).addOthers();
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -635,13 +579,13 @@ public class OrderingTest
|
|||
List<Resource> list = metaData._ordering.order(resources);
|
||||
|
||||
String[] outcomes = {"ABCDEplain"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -650,7 +594,7 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
// C,B,A
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
|
@ -658,49 +602,49 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("B");
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
|
@ -708,13 +652,13 @@ public class OrderingTest
|
|||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
String[] outcomes = {"CBA"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -726,10 +670,10 @@ public class OrderingTest
|
|||
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
|
||||
resources.add(new TestResource("A"));
|
||||
resources.add(new TestResource("B"));
|
||||
resources.add(newTestableDirResource("A"));
|
||||
resources.add(newTestableDirResource("B"));
|
||||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
assertThat(list, is(empty()));
|
||||
|
@ -740,14 +684,14 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
//B,A,C other jars with no fragments
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A: after others, before C
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -757,9 +701,9 @@ public class OrderingTest
|
|||
f1._befores.add("C");
|
||||
|
||||
//B: before others, before C
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
|
@ -769,9 +713,9 @@ public class OrderingTest
|
|||
f2._befores.add("C");
|
||||
|
||||
//C: after A
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
|
@ -781,24 +725,24 @@ public class OrderingTest
|
|||
f3._afters.add("A");
|
||||
|
||||
//No fragment jar 1
|
||||
TestResource r4 = new TestResource("plain1");
|
||||
Resource r4 = newTestableFileResource("plain1");
|
||||
resources.add(r4);
|
||||
|
||||
//No fragment jar 2
|
||||
TestResource r5 = new TestResource("plain2");
|
||||
Resource r5 = newTestableFileResource("plain2");
|
||||
resources.add(r5);
|
||||
|
||||
//result: BAC
|
||||
String[] outcomes = {"Bplain1plain2AC"};
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -807,14 +751,14 @@ public class OrderingTest
|
|||
throws Exception
|
||||
{
|
||||
//web.xml has no ordering, jar A has fragment after others, jar B is plain, jar C is plain
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new RelativeOrdering(metaData);
|
||||
|
||||
//A has after others
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
|
@ -822,22 +766,22 @@ public class OrderingTest
|
|||
f1._otherType = FragmentDescriptor.OtherType.After;
|
||||
|
||||
//No fragment jar B
|
||||
TestResource r4 = new TestResource("plainB");
|
||||
Resource r4 = newTestableFileResource("plainB");
|
||||
resources.add(r4);
|
||||
|
||||
//No fragment jar C
|
||||
TestResource r5 = new TestResource("plainC");
|
||||
Resource r5 = newTestableFileResource("plainC");
|
||||
resources.add(r5);
|
||||
|
||||
List<Resource> orderedList = metaData._ordering.order(resources);
|
||||
String[] outcomes = {"plainBplainCA"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : orderedList)
|
||||
{
|
||||
result += (((TestResource)r)._name);
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
|
@ -848,7 +792,7 @@ public class OrderingTest
|
|||
//
|
||||
// A,B,C,others
|
||||
//
|
||||
List<Resource> resources = new ArrayList<Resource>();
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
MetaData metaData = new MetaData();
|
||||
metaData._ordering = new AbsoluteOrdering(metaData);
|
||||
((AbsoluteOrdering)metaData._ordering).add("A");
|
||||
|
@ -856,82 +800,81 @@ public class OrderingTest
|
|||
((AbsoluteOrdering)metaData._ordering).add("C");
|
||||
((AbsoluteOrdering)metaData._ordering).addOthers();
|
||||
|
||||
TestResource jar1 = new TestResource("A");
|
||||
Resource jar1 = newTestableDirResource("A");
|
||||
resources.add(jar1);
|
||||
TestResource r1 = new TestResource("A/web-fragment.xml");
|
||||
Resource r1 = newTestableFileResource("A/web-fragment.xml");
|
||||
FragmentDescriptor f1 = new FragmentDescriptor(r1);
|
||||
f1._name = "A";
|
||||
metaData._webFragmentNameMap.put(f1._name, f1);
|
||||
metaData._webFragmentResourceMap.put(jar1, f1);
|
||||
|
||||
TestResource jar2 = new TestResource("B");
|
||||
Resource jar2 = newTestableDirResource("B");
|
||||
resources.add(jar2);
|
||||
TestResource r2 = new TestResource("B/web-fragment.xml");
|
||||
Resource r2 = newTestableFileResource("B/web-fragment.xml");
|
||||
FragmentDescriptor f2 = new FragmentDescriptor(r2);
|
||||
f2._name = "B";
|
||||
metaData._webFragmentNameMap.put(f2._name, f2);
|
||||
metaData._webFragmentResourceMap.put(jar2, f2);
|
||||
|
||||
TestResource jar3 = new TestResource("C");
|
||||
Resource jar3 = newTestableDirResource("C");
|
||||
resources.add(jar3);
|
||||
TestResource r3 = new TestResource("C/web-fragment.xml");
|
||||
Resource r3 = newTestableFileResource("C/web-fragment.xml");
|
||||
FragmentDescriptor f3 = new FragmentDescriptor(r3);
|
||||
f3._name = "C";
|
||||
metaData._webFragmentNameMap.put(f3._name, f3);
|
||||
metaData._webFragmentResourceMap.put(jar3, f3);
|
||||
|
||||
TestResource jar4 = new TestResource("D");
|
||||
Resource jar4 = newTestableDirResource("D");
|
||||
resources.add(jar4);
|
||||
TestResource r4 = new TestResource("D/web-fragment.xml");
|
||||
Resource r4 = newTestableFileResource("D/web-fragment.xml");
|
||||
FragmentDescriptor f4 = new FragmentDescriptor(r4);
|
||||
f4._name = "D";
|
||||
metaData._webFragmentNameMap.put(f4._name, f4);
|
||||
metaData._webFragmentResourceMap.put(jar4, f4);
|
||||
|
||||
TestResource jar5 = new TestResource("E");
|
||||
Resource jar5 = newTestableDirResource("E");
|
||||
resources.add(jar5);
|
||||
TestResource r5 = new TestResource("E/web-fragment.xml");
|
||||
Resource r5 = newTestableFileResource("E/web-fragment.xml");
|
||||
FragmentDescriptor f5 = new FragmentDescriptor(r5);
|
||||
f5._name = "E";
|
||||
metaData._webFragmentNameMap.put(f5._name, f5);
|
||||
metaData._webFragmentResourceMap.put(jar5, f5);
|
||||
|
||||
TestResource jar6 = new TestResource("plain");
|
||||
Resource jar6 = newTestableDirResource("plain");
|
||||
resources.add(jar6);
|
||||
TestResource r6 = new TestResource("plain/web-fragment.xml");
|
||||
Resource r6 = newTestableFileResource("plain/web-fragment.xml");
|
||||
FragmentDescriptor f6 = new FragmentDescriptor(r6);
|
||||
f6._name = FragmentDescriptor.NAMELESS + "1";
|
||||
metaData._webFragmentNameMap.put(f6._name, f6);
|
||||
metaData._webFragmentResourceMap.put(jar6, f6);
|
||||
|
||||
//plain jar
|
||||
TestResource r7 = new TestResource("plain1");
|
||||
Resource r7 = newTestableFileResource("plain1");
|
||||
resources.add(r7);
|
||||
|
||||
TestResource r8 = new TestResource("plain2");
|
||||
Resource r8 = newTestableFileResource("plain2");
|
||||
resources.add(r8);
|
||||
|
||||
List<Resource> list = metaData._ordering.order(resources);
|
||||
|
||||
String[] outcomes = {"ABCDEplainplain1plain2"};
|
||||
String result = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Resource r : list)
|
||||
{
|
||||
result += ((TestResource)r)._name;
|
||||
result.append(r.getFileName());
|
||||
}
|
||||
|
||||
if (!checkResult(result, outcomes))
|
||||
if (!checkResult(result.toString(), outcomes))
|
||||
fail("No outcome matched " + result);
|
||||
}
|
||||
|
||||
public boolean checkResult(String result, String[] outcomes)
|
||||
{
|
||||
boolean matched = false;
|
||||
for (String s : outcomes)
|
||||
{
|
||||
if (s.equals(result))
|
||||
matched = true;
|
||||
return true;
|
||||
}
|
||||
return matched;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,14 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.ee9.nested.ContextHandler;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.component.Environment;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.xml.XmlParser;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
|
@ -36,17 +39,13 @@ public class WebDescriptorTest
|
|||
@Test
|
||||
public void testXmlWithXsd() throws Exception
|
||||
{
|
||||
// TODO: need to address ee8 issues with missing jsp-configType from the <xsd:include schemaLocation="jsp_2_3.xsd"/> that seems to be a missing resource
|
||||
// org.xml.sax.SAXParseException; systemId: jar:file:///path/to/jetty-servlet-api-4.0.6.jar!/javax/servlet/resources/web-common_4_0.xsd; lineNumber: 142; columnNumber: 50;
|
||||
// src-resolve: Cannot resolve the name 'javaee:jsp-configType' to a(n) 'type definition' component.
|
||||
Assumptions.assumeTrue(ContextHandler.ENVIRONMENT.getName().endsWith("9"));
|
||||
|
||||
Path xml = workDir.getEmptyPathDir().resolve("test.xml");
|
||||
Files.writeString(xml, """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
metadata-complete="false"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
|
||||
version="5.0">
|
||||
<display-name>Empty WebApp Descriptor</display-name>
|
||||
</web-app>
|
||||
""", StandardCharsets.UTF_8);
|
||||
Files.writeString(xml, getWebAppXml(ContextHandler.ENVIRONMENT), StandardCharsets.UTF_8);
|
||||
|
||||
Resource xmlRes = ResourceFactory.root().newResource(xml);
|
||||
WebDescriptor webDescriptor = new WebDescriptor(xmlRes);
|
||||
|
@ -55,4 +54,29 @@ public class WebDescriptorTest
|
|||
// Such as missing required XML resource entities.
|
||||
webDescriptor.parse(xmlParser);
|
||||
}
|
||||
|
||||
private String getWebAppXml(Environment env)
|
||||
{
|
||||
String namespace = "https://jakarta.ee/xml/ns/jakartaee";
|
||||
String schemaLocation = "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd";
|
||||
String version = "5.0";
|
||||
|
||||
if (env.getName().equals("ee8"))
|
||||
{
|
||||
namespace = "http://xmlns.jcp.org/xml/ns/javaee";
|
||||
schemaLocation = "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd";
|
||||
version = "4.0";
|
||||
}
|
||||
|
||||
return """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="%s"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
metadata-complete="false"
|
||||
xsi:schemaLocation="%s"
|
||||
version="%s">
|
||||
<display-name>Empty WebApp Descriptor</display-name>
|
||||
</web-app>
|
||||
""".formatted(namespace, schemaLocation, version);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue