package org.apache.catalina.webresources;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import jakarta.servlet.ServletContext;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.WebResource;
import org.apache.catalina.startup.ExpandWar;
import org.apache.catalina.util.IOTools;
import org.apache.tomcat.util.res.StringManager;
public class extends StandardRoot {
private static final StringManager = StringManager.getManager(ExtractingRoot.class);
private static final String = "application-jars";
@Override
protected void () throws LifecycleException {
if (!super.isPackedWarFile()) {
super.processWebInfLib();
return;
}
File expansionTarget = getExpansionTarget();
if (!expansionTarget.isDirectory()) {
if (!expansionTarget.mkdirs()) {
throw new LifecycleException(
sm.getString("extractingRoot.targetFailed", expansionTarget));
}
}
WebResource[] possibleJars = listResources("/WEB-INF/lib", false);
for (WebResource possibleJar : possibleJars) {
if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
try {
File dest = new File(expansionTarget, possibleJar.getName());
dest = dest.getCanonicalFile();
try (InputStream sourceStream = possibleJar.getInputStream();
OutputStream destStream= new FileOutputStream(dest)) {
IOTools.flow(sourceStream, destStream);
}
createWebResourceSet(ResourceSetType.CLASSES_JAR,
"/WEB-INF/classes", dest.toURI().toURL(), "/");
} catch (IOException ioe) {
throw new LifecycleException(
sm.getString("extractingRoot.jarFailed", possibleJar.getName()), ioe);
}
}
}
}
private File () {
File tmpDir = (File) getContext().getServletContext().getAttribute(ServletContext.TEMPDIR);
File expansionTarget = new File(tmpDir, APPLICATION_JARS_DIR);
return expansionTarget;
}
@Override
protected boolean () {
return false;
}
@Override
protected void () throws LifecycleException {
super.stopInternal();
if (super.isPackedWarFile()) {
File expansionTarget = getExpansionTarget();
ExpandWar.delete(expansionTarget);
}
}
}