Use MavenPaths where appropriate (ee9 -> ee8 conversion helper)

This commit is contained in:
Joakim Erdfelt 2022-10-17 15:23:24 -05:00
parent 28c34d402e
commit 00c06738f0
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
3 changed files with 20 additions and 9 deletions

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.WebDescriptor; import org.eclipse.jetty.ee10.webapp.WebDescriptor;
import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.JAR; import org.eclipse.jetty.toolchain.test.JAR;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.FileSystemPool;
@ -97,7 +98,7 @@ public class TestAnnotationConfiguration
testContainerSciJar.toUri().toURL() testContainerSciJar.toUri().toURL()
}, Thread.currentThread().getContextClassLoader()); }, Thread.currentThread().getContextClassLoader());
targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes"); targetClasses = ResourceFactory.root().newResource(MavenPaths.targetDir().resolve("test-classes"));
classes = List.of(webInfClasses, targetClasses); classes = List.of(webInfClasses, targetClasses);

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.ee9.webapp.WebDescriptor; import org.eclipse.jetty.ee9.webapp.WebDescriptor;
import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.JAR; import org.eclipse.jetty.toolchain.test.JAR;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.FileSystemPool;
@ -101,7 +102,7 @@ public class TestAnnotationConfiguration
testContainerSciJar.toUri().toURL() testContainerSciJar.toUri().toURL()
}, Thread.currentThread().getContextClassLoader()); }, Thread.currentThread().getContextClassLoader());
targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes"); targetClasses = ResourceFactory.root().newResource(MavenPaths.targetDir().resolve("test-classes"));
classes = List.of(webInfClasses, targetClasses); classes = List.of(webInfClasses, targetClasses);

View File

@ -42,6 +42,7 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
@ -49,6 +50,7 @@ import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.FileSystemPool;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.util.resource.ResourceFactory;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -406,8 +408,10 @@ public class WebAppContextTest
handlers.addHandler(contexts); handlers.addHandler(contexts);
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
Path testWebapp = MavenTestingUtils.getTargetPath("test-classes/webapp"); Path testWebapp = MavenPaths.findTestResourceDir("webapp");
context.setBaseResource(ResourceFactory.root().newResource(testWebapp)); Resource testWebappResource = context.getResourceFactory().newResource(testWebapp);
assertTrue(testWebappResource.isDirectory());
context.setBaseResource(testWebappResource);
context.setContextPath("/"); context.setContextPath("/");
contexts.addHandler(context); contexts.addHandler(context);
@ -417,7 +421,12 @@ public class WebAppContextTest
server.start(); server.start();
String rawResponse = connector.getResponse("GET http://localhost:8080 HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n"); String rawResponse = connector.getResponse("""
GET http://localhost:8080 HTTP/1.1\r
Host: localhost:8080\r
Connection: close\r
\r
""");
HttpTester.Response response = HttpTester.parseResponse(rawResponse); HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat("Response OK", response.getStatus(), is(HttpStatus.OK_200)); assertThat("Response OK", response.getStatus(), is(HttpStatus.OK_200));
} }
@ -560,7 +569,7 @@ public class WebAppContextTest
{ {
List<Arguments> references = new ArrayList<>(); List<Arguments> references = new ArrayList<>();
Path extLibs = MavenTestingUtils.getTargetPath("test-classes/ext"); Path extLibs = MavenPaths.findTestResourceDir("ext");
extLibs = extLibs.toAbsolutePath(); extLibs = extLibs.toAbsolutePath();
// Absolute reference with trailing slash // Absolute reference with trailing slash
@ -575,7 +584,7 @@ public class WebAppContextTest
// This will be in the String form similar to "src/test/resources/ext/" (with trailing slash) // This will be in the String form similar to "src/test/resources/ext/" (with trailing slash)
references.add(Arguments.of(relativeExtLibsDir + File.separator)); references.add(Arguments.of(relativeExtLibsDir + File.separator));
// This will be in the String form similar to "src/test/resources/ext/" (without trailing slash) // This will be in the String form similar to "src/test/resources/ext" (without trailing slash)
references.add(Arguments.of(relativeExtLibsDir)); references.add(Arguments.of(relativeExtLibsDir));
return references.stream(); return references.stream();
@ -592,7 +601,7 @@ public class WebAppContextTest
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
context.setContextPath("/"); context.setContextPath("/");
Path warPath = MavenTestingUtils.getTargetPath("test-classes/wars/dump.war"); Path warPath = MavenPaths.findTestResourceFile("wars/dump.war");
context.setBaseResource(context.getResourceFactory().newResource(warPath)); context.setBaseResource(context.getResourceFactory().newResource(warPath));
context.setExtraClasspath(extraClassPathReference); context.setExtraClasspath(extraClassPathReference);
@ -609,7 +618,7 @@ public class WebAppContextTest
WebAppClassLoader webAppClassLoader = (WebAppClassLoader)contextClassLoader; WebAppClassLoader webAppClassLoader = (WebAppClassLoader)contextClassLoader;
URL[] urls = webAppClassLoader.getURLs(); URL[] urls = webAppClassLoader.getURLs();
assertThat("URLs", urls.length, is(1)); assertThat("URLs", urls.length, is(1));
Path extLibs = MavenTestingUtils.getTargetPath("test-classes/ext"); Path extLibs = MavenPaths.findTestResourceDir("ext");
extLibs = extLibs.toAbsolutePath(); extLibs = extLibs.toAbsolutePath();
assertThat("URL[0]", urls[0].toURI(), is(extLibs.toUri())); assertThat("URL[0]", urls[0].toURI(), is(extLibs.toUri()));
} }