Fixed war file unpacking
This commit is contained in:
parent
62db79b791
commit
2badb454b3
|
@ -19,11 +19,11 @@ import java.net.URI;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.FileID;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
|
@ -297,7 +297,9 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} anti-aliased to {}", webApp, targetURI);
|
||||
webApp = context.newResource(targetURI);
|
||||
Resource targetWebApp = context.newResource(targetURI);
|
||||
if (targetWebApp != null && targetWebApp.exists())
|
||||
webApp = targetWebApp;
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -310,10 +312,12 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
Resource originalWarResource = webApp;
|
||||
|
||||
// Is the WAR usable directly?
|
||||
if (webApp.exists() && !webApp.isDirectory() && !webApp.toString().startsWith("jar:"))
|
||||
if (webApp != null && webApp.exists() && !webApp.isDirectory() && FileID.isJavaArchive(webApp.getURI()) && !webApp.getURI().getScheme().equalsIgnoreCase("jar"))
|
||||
{
|
||||
// No - then lets see if it can be turned into a jar URL.
|
||||
webApp = context.getResourceFactory().newJarFileResource(webApp.getURI());
|
||||
// Turned this into a jar URL.
|
||||
Resource jarWebApp = context.getResourceFactory().newJarFileResource(webApp.getURI());
|
||||
if (jarWebApp != null && jarWebApp.exists() && !jarWebApp.isDirectory())
|
||||
webApp = jarWebApp;
|
||||
}
|
||||
|
||||
// If we should extract or the URL is still not usable
|
||||
|
@ -329,11 +333,11 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
|
||||
if (war != null)
|
||||
{
|
||||
Path warPath = Path.of(war);
|
||||
// look for a sibling like "foo/" to a "foo.war"
|
||||
Path warfile = context.getResourceFactory().newResource(war).getPath();
|
||||
if (warfile != null && warfile.getFileName().toString().toLowerCase(Locale.ENGLISH).endsWith(".war"))
|
||||
if (FileID.isWebArchive(warPath) && Files.exists(warPath))
|
||||
{
|
||||
Path sibling = warfile.getParent().resolve(warfile.getFileName().toString().substring(0, warfile.getFileName().toString().length() - 4));
|
||||
Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath));
|
||||
if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling))
|
||||
extractedWebAppDir = sibling;
|
||||
}
|
||||
|
@ -368,7 +372,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
LOG.debug("Extract {} to {}", webApp, extractedWebAppDir);
|
||||
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
|
||||
{
|
||||
Resource jarWebApp = resourceFactory.newResource(webApp.getPath());
|
||||
Resource jarWebApp = resourceFactory.newJarFileResource(webApp.getURI());
|
||||
jarWebApp.copyTo(extractedWebAppDir);
|
||||
}
|
||||
extractionLock.delete();
|
||||
|
@ -386,7 +390,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
LOG.debug("Extract {} to {}", webApp, extractedWebAppDir);
|
||||
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
|
||||
{
|
||||
Resource jarWebApp = resourceFactory.newResource(webApp.getPath());
|
||||
Resource jarWebApp = resourceFactory.newJarFileResource(webApp.getURI());
|
||||
jarWebApp.copyTo(extractedWebAppDir);
|
||||
}
|
||||
extractionLock.delete();
|
||||
|
@ -414,40 +418,42 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
{
|
||||
Resource webInf = webApp.resolve("WEB-INF/");
|
||||
|
||||
File extractedWebInfDir = new File(context.getTempDirectory(), "webinf");
|
||||
if (extractedWebInfDir.exists())
|
||||
IO.delete(extractedWebInfDir);
|
||||
extractedWebInfDir.mkdir();
|
||||
Resource webInfLib = webInf.resolve("lib/");
|
||||
File webInfDir = new File(extractedWebInfDir, "WEB-INF");
|
||||
webInfDir.mkdir();
|
||||
|
||||
if (webInfLib.exists())
|
||||
if (webInf != null && webInf.exists() && webInf.isDirectory())
|
||||
{
|
||||
File webInfLibDir = new File(webInfDir, "lib");
|
||||
if (webInfLibDir.exists())
|
||||
IO.delete(webInfLibDir);
|
||||
webInfLibDir.mkdir();
|
||||
File extractedWebInfDir = new File(context.getTempDirectory(), "webinf");
|
||||
if (extractedWebInfDir.exists())
|
||||
IO.delete(extractedWebInfDir);
|
||||
extractedWebInfDir.mkdir();
|
||||
Resource webInfLib = webInf.resolve("lib/");
|
||||
File webInfDir = new File(extractedWebInfDir, "WEB-INF");
|
||||
webInfDir.mkdir();
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Copying WEB-INF/lib {} to {}", webInfLib, webInfLibDir);
|
||||
webInfLib.copyTo(webInfLibDir.toPath());
|
||||
if (webInfLib != null && webInfLib.exists() && webInfLib.isDirectory())
|
||||
{
|
||||
File webInfLibDir = new File(webInfDir, "lib");
|
||||
if (webInfLibDir.exists())
|
||||
IO.delete(webInfLibDir);
|
||||
webInfLibDir.mkdir();
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Copying WEB-INF/lib {} to {}", webInfLib, webInfLibDir);
|
||||
webInfLib.copyTo(webInfLibDir.toPath());
|
||||
}
|
||||
|
||||
Resource webInfClasses = webInf.resolve("classes/");
|
||||
if (webInfClasses != null && webInfClasses.exists() && !webInfClasses.isDirectory())
|
||||
{
|
||||
File webInfClassesDir = new File(webInfDir, "classes");
|
||||
if (webInfClassesDir.exists())
|
||||
IO.delete(webInfClassesDir);
|
||||
webInfClassesDir.mkdir();
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Copying WEB-INF/classes from {} to {}", webInfClasses, webInfClassesDir.getAbsolutePath());
|
||||
webInfClasses.copyTo(webInfClassesDir.toPath());
|
||||
}
|
||||
webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath());
|
||||
}
|
||||
|
||||
Resource webInfClasses = webInf.resolve("classes/");
|
||||
if (webInfClasses.exists())
|
||||
{
|
||||
File webInfClassesDir = new File(webInfDir, "classes");
|
||||
if (webInfClassesDir.exists())
|
||||
IO.delete(webInfClassesDir);
|
||||
webInfClassesDir.mkdir();
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Copying WEB-INF/classes from {} to {}", webInfClasses, webInfClassesDir.getAbsolutePath());
|
||||
webInfClasses.copyTo(webInfClassesDir.toPath());
|
||||
}
|
||||
|
||||
webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath());
|
||||
|
||||
Resource rc = ResourceFactory.combine(webInf, webApp);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
|
|
Loading…
Reference in New Issue