Skip to content

Commit

Permalink
Issue #12723 fix file:/ uris on windows for osgi (#12728)
Browse files Browse the repository at this point in the history
* Issue #12723 fix file:/ uris on windows for osgi
  • Loading branch information
janbartel authored Jan 29, 2025
1 parent 184ae29 commit 413a15d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.jetty.server.Deployable;
import org.eclipse.jetty.server.handler.ContextHandler;
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.osgi.framework.Bundle;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static Resource getBundleAsResource(Bundle bundle) throws Exception
File bundleLocation = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle);
File root = (bundleOverrideLocation == null ? bundleLocation : new File(bundleOverrideLocation));
//Fix some osgiPaths.get( locations which point to an archive, but that doesn't end in .jar
URL url = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(root.toURI().toURL());
URL url = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(URIUtil.correctURI(root.toURI()).toURL());

return ResourceFactory.root().newResource(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

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;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static URI resolvePathAsLocalizedURI(String path, Bundle bundle, Path jet
return null;

if (path.startsWith("file:/"))
return new URI(path);
return URIUtil.correctURI(new URI(path));

if (path.startsWith("/") && File.separatorChar != '/')
return new URI("file:" + path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,24 @@ public void unpack(WebAppContext context) throws IOException
!webApp.isDirectory()
)
{
// Look for sibling directory.
Path extractedWebAppDir = null;

// If this is a war file, we should look for a sibling
// directory of the same name where it has been already extracted
if (war != null)
{
Path warPath = context.getResourceFactory().newResource(war).getPath();

// look for a sibling like "foo/" to a "foo.war"
if (warPath != null && FileID.isWebArchive(warPath) && Files.exists(warPath))
// We have obtained the webApp from the war string, so it
// cannot be a CombinedResource, therefore safe to use it's Path
Path warPath = webApp.getPath();
if (warPath != null)
{
Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath));
if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling))
extractedWebAppDir = sibling;
// look for a sibling like "foo/" to a "foo.war"
if (FileID.isWebArchive(warPath) && Files.exists(warPath))
{
Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath));
if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling))
extractedWebAppDir = sibling;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,24 @@ public void unpack(WebAppContext context) throws IOException
!webApp.isDirectory())
)
{
// Look for sibling directory.
Path extractedWebAppDir = null;

// If this is a war file, we should look for a sibling
// directory of the same name
if (war != null)
{
Path warPath = Path.of(war);
// look for a sibling like "foo/" to a "foo.war"
if (FileID.isWebArchive(warPath) && Files.exists(warPath))
// We have obtained the webApp from the war string, so it
// cannot be a CombinedResource, therefore safe to use it's Path
Path warPath = webApp.getPath();
if (warPath != null)
{
Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath));
if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling))
extractedWebAppDir = sibling;
// look for a sibling like "foo/" to a "foo.war"
if (FileID.isWebArchive(warPath) && Files.exists(warPath))
{
Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath));
if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling))
extractedWebAppDir = sibling;
}
}
}

Expand Down

0 comments on commit 413a15d

Please sign in to comment.