Skip to content

Commit

Permalink
Jetty 12.0.x 11377 fix jettyhome osgi path (#11418)
Browse files Browse the repository at this point in the history
* Issue #11377 fix jettyhome osgi path and  WebInfConfiguration.unpack for windows
  • Loading branch information
janbartel authored Feb 26, 2024
1 parent 1ca1c96 commit a1cb475
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -28,26 +30,31 @@

import org.eclipse.jetty.osgi.OSGiServerConstants;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Various useful functions utility methods for OSGi wide use.
*/
public class Util
{
private static final Logger LOG = LoggerFactory.getLogger(Util.class);

/**
* Resolve a path either absolutely or against the bundle install location, or
* against jetty home.
*
* @param path the path to resolve
* @param bundle the bundle
* @param jettyHome the path to jetty home
* @return the URI within the bundle as a usable URI
* @return the URI resolved either absolutely or against the bundle install location or jetty home.
*/
public static URI resolvePathAsLocalizedURI(String path, Bundle bundle, Path jettyHome)
throws Exception
Expand All @@ -56,7 +63,21 @@ public static URI resolvePathAsLocalizedURI(String path, Bundle bundle, Path jet
return null;

if (path.startsWith("/") || path.startsWith("file:/")) //absolute location
return Paths.get(path).toUri();
return URIUtil.toURI(path);
else
{
try
{
Path p = FileSystems.getDefault().getPath(path);
if (p.isAbsolute())
return p.toUri();
}
catch (InvalidPathException x)
{
//ignore and try via the jetty bundle instead
LOG.trace("IGNORED", x);
}
}

//relative location
//try inside the bundle first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.resource.URLResourceFactory;
Expand Down Expand Up @@ -357,7 +358,7 @@ public ContextHandler createContextHandler(AbstractContextProvider provider, App
{
OSGiApp osgiApp = OSGiApp.class.cast(app);
String jettyHome = (String)app.getDeploymentManager().getServer().getAttribute(OSGiServerConstants.JETTY_HOME);
Path jettyHomePath = (StringUtil.isBlank(jettyHome) ? null : Paths.get(jettyHome));
Path jettyHomePath = StringUtil.isBlank(jettyHome) ? null : Paths.get(URIUtil.toURI(jettyHome));

WebAppContext webApp = new WebAppContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public void unpack(WebAppContext context) throws IOException

if (war != null)
{
Path warPath = Path.of(war);
Path warPath = Path.of(URIUtil.toURI(war));

// look for a sibling like "foo/" to a "foo.war"
if (FileID.isWebArchive(warPath) && Files.exists(warPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.resource.URLResourceFactory;
Expand Down Expand Up @@ -356,7 +357,7 @@ public ContextHandler createContextHandler(AbstractContextProvider provider, App
{
OSGiApp osgiApp = OSGiApp.class.cast(app);
String jettyHome = (String)app.getDeploymentManager().getServer().getAttribute(OSGiServerConstants.JETTY_HOME);
Path jettyHomePath = (StringUtil.isBlank(jettyHome) ? null : Paths.get(jettyHome));
Path jettyHomePath = StringUtil.isBlank(jettyHome) ? null : Paths.get(URIUtil.toURI(jettyHome));

WebAppContext webApp = new WebAppContext();

Expand Down

0 comments on commit a1cb475

Please sign in to comment.