Merge branch 'jetty-9.4.x'
This commit is contained in:
commit
9f66b552cd
|
@ -31,6 +31,18 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<execution>
|
||||||
|
<id>nolog-jar</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<classifier>nolog</classifier>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/services/org.apache.juli.logging.Log</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
|
@ -24,14 +24,20 @@ https://wiki.debian.org/LSBInitScripts[LSB tags].
|
||||||
|
|
||||||
You can safely replace Jetty 9.3's `jetty.sh` with 9.4's.
|
You can safely replace Jetty 9.3's `jetty.sh` with 9.4's.
|
||||||
|
|
||||||
==== Modules No Longer Available
|
==== Module Changes in Jetty 9.4
|
||||||
|
|
||||||
[cols="1,1", options="header"]
|
[cols="1,1", options="header"]
|
||||||
|===
|
|===
|
||||||
| 9.3 Module | 9.4 Module
|
| 9.3 Module | 9.4 Module
|
||||||
| logging | console-capture
|
| `logging` | `console-capture`
|
||||||
|
| `infinispan` | `session-store-infinispan-embedded` or `session-store-infinispan-remote`
|
||||||
|
| `jdbc-sessions` | `session-store-jdbc`
|
||||||
|
| `gcloud-memcached-sessions`, `gcloud-session-idmgr` and `gcloud-sessions` | `gcloud`, `gcloud-datastore` and `session-store-gcloud`
|
||||||
|
| `nosql` | `session-store-mongo`
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
===== Logging Modules
|
||||||
|
|
||||||
The module `logging` is no longer available in Jetty 9.4.
|
The module `logging` is no longer available in Jetty 9.4.
|
||||||
|
|
||||||
The logging module structure present in Jetty 9.3 has been replaced with
|
The logging module structure present in Jetty 9.3 has been replaced with
|
||||||
|
@ -45,7 +51,7 @@ If you have a Jetty 9.3 installation, and you have both
|
||||||
`$jetty.base/modules/logging.mod` and `$jetty.base/etc/jetty-logging.xml`,
|
`$jetty.base/modules/logging.mod` and `$jetty.base/etc/jetty-logging.xml`,
|
||||||
then this module is local to your `$jetty.base` setup and will be used
|
then this module is local to your `$jetty.base` setup and will be used
|
||||||
by Jetty 9.4 as before.
|
by Jetty 9.4 as before.
|
||||||
No changes required on your part.
|
No changes are required for your implementation.
|
||||||
|
|
||||||
If either `$jetty.base/modules/logging.mod` or `$jetty.base/etc/jetty-logging.xml`
|
If either `$jetty.base/modules/logging.mod` or `$jetty.base/etc/jetty-logging.xml`
|
||||||
are missing, then you were relying on those present in `$jetty.home`,
|
are missing, then you were relying on those present in `$jetty.home`,
|
||||||
|
@ -55,7 +61,7 @@ The Jetty 9.3 `logging` module has been renamed to `console-capture` in Jetty 9.
|
||||||
You need to open your Jetty 9.3 `start.ini` and replace the references to the
|
You need to open your Jetty 9.3 `start.ini` and replace the references to the
|
||||||
`logging` modules with `console-capture`.
|
`logging` modules with `console-capture`.
|
||||||
|
|
||||||
For example:
|
For example, in an existing 9.3 `start.ini` file the module declaration for logging would look like this:
|
||||||
|
|
||||||
.start.ini
|
.start.ini
|
||||||
----
|
----
|
||||||
|
@ -63,7 +69,7 @@ For example:
|
||||||
jetty.logging.retainDays=7
|
jetty.logging.retainDays=7
|
||||||
----
|
----
|
||||||
|
|
||||||
should be replaced by:
|
In 9.4, it should be replaced by:
|
||||||
|
|
||||||
.start.ini
|
.start.ini
|
||||||
----
|
----
|
||||||
|
@ -75,3 +81,15 @@ The properties that may be present in your Jetty 9.3's `start.ini`, such as
|
||||||
`jetty.logging.retainDays` will still be working in Jetty 9.4, but a warning
|
`jetty.logging.retainDays` will still be working in Jetty 9.4, but a warning
|
||||||
will be printed at Jetty 9.4 startup, saying to replace them with correspondent
|
will be printed at Jetty 9.4 startup, saying to replace them with correspondent
|
||||||
`jetty.console-capture.*` properties such as `jetty.console-capture.retainDays`.
|
`jetty.console-capture.*` properties such as `jetty.console-capture.retainDays`.
|
||||||
|
|
||||||
|
For information on logging modules in the Jetty 9.4 architecture please see the section on link:#configuring-logging-modules[configuring logging modules.]
|
||||||
|
|
||||||
|
===== Session Management
|
||||||
|
|
||||||
|
//TODO - More info.
|
||||||
|
|
||||||
|
Session management received a significant overhaul in Jetty 9.4. Whereas in prior versions of Jetty uses needed to implement individual instances of both `SessionIdManager` and `SessionManager`, now one instance of both handles sessions for the server.
|
||||||
|
|
||||||
|
As part of these changes, modules for individual technologies were re-named to make configuration more transparent.
|
||||||
|
|
||||||
|
For more information, please refer to the documentation on link:#jetty-sessions-architecture[Jetty Session Architecture.]
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.quickstart;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -58,6 +59,7 @@ public class AttributeNormalizer
|
||||||
{
|
{
|
||||||
public final Path path;
|
public final Path path;
|
||||||
public final String key;
|
public final String key;
|
||||||
|
private boolean isUriBased = false;
|
||||||
private int weight = -1;
|
private int weight = -1;
|
||||||
|
|
||||||
public PathAttribute(String key, Path path) throws IOException
|
public PathAttribute(String key, Path path) throws IOException
|
||||||
|
@ -94,6 +96,40 @@ public class AttributeNormalizer
|
||||||
return path.toAbsolutePath();
|
return path.toAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toUri()
|
||||||
|
{
|
||||||
|
if (isUriBased)
|
||||||
|
{
|
||||||
|
// Return "{KEY}" -> "<uri>" (including scheme)
|
||||||
|
return path.toUri().toASCIIString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Return "{KEY}" -> "<path>" (excluding scheme)
|
||||||
|
return path.toUri().getSchemeSpecificPart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNormalizedScheme()
|
||||||
|
{
|
||||||
|
if (isUriBased)
|
||||||
|
{
|
||||||
|
// If we are treating the {KEY} -> "<uri>" (scheme is expanded)
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If we are treating the {KEY} -> "<path>" (scheme is not part of KEY)
|
||||||
|
return "file:";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathAttribute treatAsUri()
|
||||||
|
{
|
||||||
|
this.isUriBased = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PathAttribute weight(int newweight)
|
public PathAttribute weight(int newweight)
|
||||||
{
|
{
|
||||||
this.weight = newweight;
|
this.weight = newweight;
|
||||||
|
@ -195,7 +231,7 @@ public class AttributeNormalizer
|
||||||
attributes.add(new PathAttribute("user.dir", "user.dir").weight(6));
|
attributes.add(new PathAttribute("user.dir", "user.dir").weight(6));
|
||||||
if(warURI != null && warURI.getScheme().equals("file"))
|
if(warURI != null && warURI.getScheme().equals("file"))
|
||||||
{
|
{
|
||||||
attributes.add(new PathAttribute("WAR", new File(warURI).toPath().toAbsolutePath()).weight(10));
|
attributes.add(new PathAttribute("WAR", new File(warURI).toPath().toAbsolutePath()).treatAsUri().weight(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(attributes, new PathAttributeComparator());
|
Collections.sort(attributes, new PathAttributeComparator());
|
||||||
|
@ -215,6 +251,12 @@ public class AttributeNormalizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a URI, URL, or File reference by replacing known attributes with ${key} attributes.
|
||||||
|
*
|
||||||
|
* @param o the object to normalize into a string
|
||||||
|
* @return the string representation of the object, with expansion keys.
|
||||||
|
*/
|
||||||
public String normalize(Object o)
|
public String normalize(Object o)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -230,10 +272,24 @@ public class AttributeNormalizer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String s = o.toString();
|
String s = o.toString();
|
||||||
|
try
|
||||||
|
{
|
||||||
uri = new URI(s);
|
uri = new URI(s);
|
||||||
if (uri.getScheme() == null)
|
if (uri.getScheme() == null)
|
||||||
|
{
|
||||||
|
// Unknown scheme? not relevant to normalize
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(URISyntaxException e)
|
||||||
|
{
|
||||||
|
// This path occurs for many reasons, but most common is when this
|
||||||
|
// is executed on MS Windows, on a string like "D:\jetty"
|
||||||
|
// and the new URI() fails for
|
||||||
|
// java.net.URISyntaxException: Illegal character in opaque part at index 2: D:\jetty
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ("jar".equalsIgnoreCase(uri.getScheme()))
|
if ("jar".equalsIgnoreCase(uri.getScheme()))
|
||||||
{
|
{
|
||||||
|
@ -245,7 +301,7 @@ public class AttributeNormalizer
|
||||||
}
|
}
|
||||||
else if ("file".equalsIgnoreCase(uri.getScheme()))
|
else if ("file".equalsIgnoreCase(uri.getScheme()))
|
||||||
{
|
{
|
||||||
return "file:" + normalizePath(new File(uri.getRawSchemeSpecificPart()).toPath());
|
return normalizePath(new File(uri.getRawSchemeSpecificPart()).toPath());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -275,6 +331,8 @@ public class AttributeNormalizer
|
||||||
|
|
||||||
public String normalizePath(Path path)
|
public String normalizePath(Path path)
|
||||||
{
|
{
|
||||||
|
String uriPath = path.toUri().getSchemeSpecificPart();
|
||||||
|
|
||||||
for (PathAttribute attr : attributes)
|
for (PathAttribute attr : attributes)
|
||||||
{
|
{
|
||||||
if (attr.path == null)
|
if (attr.path == null)
|
||||||
|
@ -284,7 +342,7 @@ public class AttributeNormalizer
|
||||||
{
|
{
|
||||||
if (path.startsWith(attr.path) || path.equals(attr.path) || Files.isSameFile(path,attr.path))
|
if (path.startsWith(attr.path) || path.equals(attr.path) || Files.isSameFile(path,attr.path))
|
||||||
{
|
{
|
||||||
return uriSeparators(URIUtil.addPaths("${" + attr.key + "}",attr.path.relativize(path).toString()));
|
return attr.getNormalizedScheme() + uriSeparators(URIUtil.addPaths("${" + attr.key + "}", attr.path.relativize(path).toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ignore)
|
catch (IOException ignore)
|
||||||
|
@ -380,18 +438,12 @@ public class AttributeNormalizer
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use war path (if known)
|
|
||||||
if("WAR".equalsIgnoreCase(property))
|
|
||||||
{
|
|
||||||
return warURI.toASCIIString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use known path attributes
|
// Use known path attributes
|
||||||
for (PathAttribute attr : attributes)
|
for (PathAttribute attr : attributes)
|
||||||
{
|
{
|
||||||
if (attr.key.equalsIgnoreCase(property))
|
if (attr.key.equalsIgnoreCase(property))
|
||||||
{
|
{
|
||||||
return uriSeparators(attr.path.toString());
|
return attr.toUri();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,21 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.quickstart;
|
package org.eclipse.jetty.quickstart;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.FileSystems;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.toolchain.test.FS;
|
||||||
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -37,9 +41,6 @@ import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class AttributeNormalizerPathTest
|
public class AttributeNormalizerPathTest
|
||||||
{
|
{
|
||||||
|
@ -47,56 +48,27 @@ public class AttributeNormalizerPathTest
|
||||||
public static List<String[]> data()
|
public static List<String[]> data()
|
||||||
{
|
{
|
||||||
String[][] tests = {
|
String[][] tests = {
|
||||||
// Can't test 'WAR' property, as its not a Path (which this testcase works with)
|
{ "jetty.home", EnvUtils.toSystemPath("/opt/jetty-distro") },
|
||||||
// { "WAR", toSystemPath("http://localhost/resources/webapps/root") },
|
{ "jetty.base", EnvUtils.toSystemPath("/opt/jetty-distro/demo.base") },
|
||||||
{ "jetty.home", toSystemPath("/opt/jetty-distro") },
|
{ "user.home", EnvUtils.toSystemPath("/home/user") },
|
||||||
{ "jetty.base", toSystemPath("/opt/jetty-distro/demo.base") },
|
{ "user.dir", EnvUtils.toSystemPath("/etc/init.d") },
|
||||||
{ "user.home", toSystemPath("/home/user") },
|
|
||||||
{ "user.dir", toSystemPath("/etc/init.d") },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Arrays.asList(tests);
|
return Arrays.asList(tests);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static Path testRoot;
|
||||||
* As the declared paths in this testcase might be actual paths on the system
|
|
||||||
* running these tests, the expected paths should be cleaned up to represent
|
|
||||||
* the actual system paths.
|
|
||||||
* <p>
|
|
||||||
* Eg: on fedora /etc/init.d is a symlink to /etc/rc.d/init.d
|
|
||||||
*/
|
|
||||||
public static String toSystemPath(String rawpath)
|
|
||||||
{
|
|
||||||
Path path = FileSystems.getDefault().getPath(rawpath);
|
|
||||||
if (Files.exists(path))
|
|
||||||
{
|
|
||||||
// It exists, resolve it to the real path
|
|
||||||
try
|
|
||||||
{
|
|
||||||
path = path.toRealPath();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
// something prevented us from resolving to real path, fallback to
|
|
||||||
// absolute path resolution (not as accurate)
|
|
||||||
path = path.toAbsolutePath();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// File doesn't exist, resolve to absolute path
|
|
||||||
// We can't rely on File.toCanonicalPath() here
|
|
||||||
path = path.toAbsolutePath();
|
|
||||||
}
|
|
||||||
return path.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String origJettyBase;
|
private static String origJettyBase;
|
||||||
private static String origJettyHome;
|
private static String origJettyHome;
|
||||||
private static String origUserHome;
|
private static String origUserHome;
|
||||||
private static String origUserDir;
|
private static String origUserDir;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
testRoot = MavenTestingUtils.getTargetTestingPath(AttributeNormalizerPathTest.class.getSimpleName());
|
||||||
|
FS.ensureEmpty(testRoot);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initProperties()
|
public static void initProperties()
|
||||||
{
|
{
|
||||||
|
@ -125,11 +97,16 @@ public class AttributeNormalizerPathTest
|
||||||
|
|
||||||
private AttributeNormalizer normalizer;
|
private AttributeNormalizer normalizer;
|
||||||
|
|
||||||
public AttributeNormalizerPathTest(String key, String path) throws MalformedURLException, IOException
|
public AttributeNormalizerPathTest(String key, String path) throws IOException
|
||||||
{
|
{
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.path = AttributeNormalizer.uriSeparators(path);
|
this.path = AttributeNormalizer.uriSeparators(path);
|
||||||
this.normalizer = new AttributeNormalizer(Resource.newResource("/opt/jetty-distro/demo.base/webapps/root"));
|
this.normalizer = new AttributeNormalizer(Resource.newResource(testRoot.toFile()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertExpand(String line, String expected)
|
||||||
|
{
|
||||||
|
assertThat("normalizer.expand(\"" + line + "\")", normalizer.expand(line), is(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -138,6 +115,13 @@ public class AttributeNormalizerPathTest
|
||||||
assertThat(normalizer.normalize("file:" + path), is("file:${" + key + "}"));
|
assertThat(normalizer.normalize("file:" + path), is("file:${" + key + "}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExpandEqual()
|
||||||
|
{
|
||||||
|
String expectedPath = new File(path).toPath().toUri().getRawSchemeSpecificPart();
|
||||||
|
assertExpand("file:${" + key + "}", "file:" + expectedPath);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsSlash()
|
public void testEqualsSlash()
|
||||||
{
|
{
|
||||||
|
@ -204,6 +188,13 @@ public class AttributeNormalizerPathTest
|
||||||
assertThat(normalizer.normalize("jar:file:" + path + "/file!/file"), is("jar:file:${" + key + "}/file!/file"));
|
assertThat(normalizer.normalize("jar:file:" + path + "/file!/file"), is("jar:file:${" + key + "}/file!/file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExpandJarFileEquals_FileBangFile()
|
||||||
|
{
|
||||||
|
String expectedPath = new File(path).toPath().toUri().getRawSchemeSpecificPart();
|
||||||
|
assertExpand("jar:file:${" + key + "}/file!/file", "jar:file:" + expectedPath + "/file!/file");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJarFileEquals_URIBangFile() throws URISyntaxException
|
public void testJarFileEquals_URIBangFile() throws URISyntaxException
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -42,9 +43,9 @@ public class AttributeNormalizerTest
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String testJettyHome = AttributeNormalizerPathTest.toSystemPath("/opt/jetty-distro");
|
String testJettyHome = EnvUtils.toSystemPath("/opt/jetty-distro");
|
||||||
String testJettyBase = AttributeNormalizerPathTest.toSystemPath("/opt/jetty-distro/demo.base");
|
String testJettyBase = EnvUtils.toSystemPath("/opt/jetty-distro/demo.base");
|
||||||
String testWar = AttributeNormalizerPathTest.toSystemPath("/opt/jetty-distro/demo.base/webapps/FOO");
|
String testWar = EnvUtils.toSystemPath("/opt/jetty-distro/demo.base/webapps/FOO");
|
||||||
|
|
||||||
System.setProperty("jetty.home", testJettyHome);
|
System.setProperty("jetty.home", testJettyHome);
|
||||||
System.setProperty("jetty.base", testJettyBase);
|
System.setProperty("jetty.base", testJettyBase);
|
||||||
|
@ -61,12 +62,12 @@ public class AttributeNormalizerTest
|
||||||
|
|
||||||
// Normalize as URI
|
// Normalize as URI
|
||||||
result = normalizer.normalize(testWarURI);
|
result = normalizer.normalize(testWarURI);
|
||||||
assertThat(result, is("file:${WAR}"));
|
assertThat(result, is("${WAR}"));
|
||||||
|
|
||||||
// Normalize deep path as File
|
// Normalize deep path as File
|
||||||
File testWarDeep = new File(new File(testWar), "deep/ref").getAbsoluteFile();
|
File testWarDeep = new File(new File(testWar), "deep/ref").getAbsoluteFile();
|
||||||
result = normalizer.normalize(testWarDeep);
|
result = normalizer.normalize(testWarDeep);
|
||||||
assertThat(result, is("file:${WAR}/deep/ref"));
|
assertThat(result, is("${WAR}/deep/ref"));
|
||||||
|
|
||||||
// Normalize deep path as String
|
// Normalize deep path as String
|
||||||
result = normalizer.normalize(testWarDeep.toString());
|
result = normalizer.normalize(testWarDeep.toString());
|
||||||
|
@ -74,40 +75,39 @@ public class AttributeNormalizerTest
|
||||||
|
|
||||||
// Normalize deep path as URI
|
// Normalize deep path as URI
|
||||||
result = normalizer.normalize(testWarDeep.toURI());
|
result = normalizer.normalize(testWarDeep.toURI());
|
||||||
assertThat(result, is("file:${WAR}/deep/ref"));
|
assertThat(result, is("${WAR}/deep/ref"));
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
restoreSystemProperty("jetty.home", oldJettyHome);
|
EnvUtils.restoreSystemProperty("jetty.home", oldJettyHome);
|
||||||
restoreSystemProperty("jetty.base", oldJettyBase);
|
EnvUtils.restoreSystemProperty("jetty.base", oldJettyBase);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restoreSystemProperty(String key, String value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
System.clearProperty(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.setProperty(key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalizeWAR() throws MalformedURLException, IOException
|
public void testNormalizeExpandWAR() throws IOException
|
||||||
{
|
{
|
||||||
String webref = "http://localhost/resource/webapps/root";
|
String webref = MavenTestingUtils.getTargetDir().getAbsolutePath() + "/bogus.war";
|
||||||
Resource webresource = Resource.newResource(webref);
|
Resource webresource = Resource.newResource(webref);
|
||||||
AttributeNormalizer normalizer = new AttributeNormalizer(webresource);
|
AttributeNormalizer normalizer = new AttributeNormalizer(webresource);
|
||||||
String result = null;
|
String result = null;
|
||||||
|
|
||||||
result = normalizer.normalize(URI.create(webref));
|
File webrefFile = new File(webref);
|
||||||
assertThat(result, is("${WAR}"));
|
URI uri = webrefFile.toURI();
|
||||||
|
// As normal URI ref
|
||||||
|
result = normalizer.normalize(uri);
|
||||||
|
assertThat("normalize(" + uri + ")", result, is("${WAR}"));
|
||||||
|
|
||||||
result = normalizer.normalize(URI.create(webref + "/deep/ref"));
|
// as jar internal resource reference
|
||||||
assertThat(result, is("${WAR}/deep/ref"));
|
uri = URI.create("jar:" + webrefFile.toURI().toASCIIString() + "!/deep/ref");
|
||||||
|
result = normalizer.normalize(uri);
|
||||||
|
assertThat("normalize(" + uri + ")", result, is("jar:${WAR}!/deep/ref"));
|
||||||
|
|
||||||
|
// as jar internal resource reference
|
||||||
|
String line = "jar:${WAR}!/other/file";
|
||||||
|
result = normalizer.expand(line);
|
||||||
|
uri = URI.create("jar:" + webrefFile.toPath().toUri().toASCIIString() + "!/other/file");
|
||||||
|
assertThat("expand(\"" + line + "\")", URI.create(result), is(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,7 +120,7 @@ public class AttributeNormalizerTest
|
||||||
|
|
||||||
// Setup example from windows
|
// Setup example from windows
|
||||||
String javaUserHome = System.getProperty("user.home");
|
String javaUserHome = System.getProperty("user.home");
|
||||||
String realUserHome = AttributeNormalizerPathTest.toSystemPath(javaUserHome);
|
String realUserHome = EnvUtils.toSystemPath(javaUserHome);
|
||||||
String userHome = AttributeNormalizer.uriSeparators(realUserHome);
|
String userHome = AttributeNormalizer.uriSeparators(realUserHome);
|
||||||
String path = "jar:file:" + userHome + "/.m2/repository/something/somejar.jar!/META-INF/some.tld";
|
String path = "jar:file:" + userHome + "/.m2/repository/something/somejar.jar!/META-INF/some.tld";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.quickstart;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common utility methods for quickstart tests
|
||||||
|
*/
|
||||||
|
public class EnvUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* As the declared paths in this testcase might be actual paths on the system
|
||||||
|
* running these tests, the expected paths should be cleaned up to represent
|
||||||
|
* the actual system paths.
|
||||||
|
* <p>
|
||||||
|
* Eg: on fedora /etc/init.d is a symlink to /etc/rc.d/init.d
|
||||||
|
*/
|
||||||
|
public static String toSystemPath(String rawpath)
|
||||||
|
{
|
||||||
|
Path path = FileSystems.getDefault().getPath(rawpath);
|
||||||
|
if (Files.exists(path))
|
||||||
|
{
|
||||||
|
// It exists, resolve it to the real path
|
||||||
|
try
|
||||||
|
{
|
||||||
|
path = path.toRealPath();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
// something prevented us from resolving to real path, fallback to
|
||||||
|
// absolute path resolution (not as accurate)
|
||||||
|
path = path.toAbsolutePath();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// File doesn't exist, resolve to absolute path
|
||||||
|
// We can't rely on File.toCanonicalPath() here
|
||||||
|
path = path.toAbsolutePath();
|
||||||
|
}
|
||||||
|
return path.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void restoreSystemProperty(String key, String value)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
System.clearProperty(key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.setProperty(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue