You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2005/02/04 09:28:29 UTC
cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager FileSystemPAM.java WarInfusionPAM.java
rwatler 2005/02/04 00:28:29
Modified: portal/src/java/org/apache/jetspeed/tools/pamanager
FileSystemPAM.java WarInfusionPAM.java
Log:
isolate J2 class loaders from deployed webapps WEB-INF/lib/*.jar files - avoids windows locking
Revision Changes Path
1.49 +97 -10 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java
Index: FileSystemPAM.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- FileSystemPAM.java 2 Feb 2005 03:12:36 -0000 1.48
+++ FileSystemPAM.java 4 Feb 2005 08:28:29 -0000 1.49
@@ -16,7 +16,9 @@
package org.apache.jetspeed.tools.pamanager;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -86,6 +88,8 @@
protected SearchEngine searchEngine;
protected ApplicationServerManager appServerManager;
+
+ private File tempDirectory;
public FileSystemPAM( String webAppsDir,
PortletRegistry registry,
@@ -93,7 +97,7 @@
PortletWindowAccessor windowAccess,
PortletCache portletCache,
PortletFactory portletFactory,
- ApplicationServerManager appServerManager)
+ ApplicationServerManager appServerManager)
{
super();
ArgUtil.assertNotNull(PortletRegistry.class, registry, this);
@@ -106,6 +110,22 @@
this.portletFactory = portletFactory;
this.windowAccess = windowAccess;
this.appServerManager = appServerManager;
+
+ // configure temporary directory used in deployment
+ this.tempDirectory = new File(System.getProperty("java.io.tmpdir"), "jetspeed-FileSystemPAM");
+ if (!this.tempDirectory.isDirectory())
+ {
+ this.tempDirectory.mkdirs();
+ }
+ else
+ {
+ File [] purgeTempFiles = this.tempDirectory.listFiles();
+ for (int i = 0; (i < purgeTempFiles.length); i++)
+ {
+ deleteFile(purgeTempFiles[i], false);
+ }
+ }
+ this.tempDirectory.deleteOnExit();
}
/**
@@ -824,21 +844,53 @@
// deployed portlet app directories
if ((paWar == null) || !paWar.getFileSystem().getRootDirectory().getName().startsWith("jetspeed-"))
{
- // use expanded portlet app war file deployment directory
- File deploymentDirectory = new File(getDeploymentPath(paName));
- if (deploymentDirectory.isDirectory())
+ // copy jar files from expanded portlet app war
+ // file deployment directory into temp directory
+ // to avoid class loader jar/resource locking on
+ // windows platform
+ File paLib = new File(getDeploymentPath(paName), "WEB-INF/lib");
+ File paClasses = new File(getDeploymentPath(paName), "WEB-INF/classes");
+ if (paLib.isDirectory() || paClasses.isDirectory())
{
- FileSystemHelper paDirectory = new DirectoryHelper(deploymentDirectory);
- paWar = new PortletApplicationWar(paDirectory, paName, "/" + paName);
+ // create temporary lib directory
+ File classLoaderDir = new File(tempDirectory, paName + "-classpath-" + getUniqueId());
+ File classLoaderLib = new File(classLoaderDir, "WEB-INF/lib");
+ File classLoaderClasses = new File(classLoaderDir, "WEB-INF/classes");
+ if (!classLoaderLib.exists())
+ {
+ classLoaderLib.mkdirs();
+ }
+ if (!classLoaderClasses.exists())
+ {
+ classLoaderClasses.mkdirs();
+ }
+
+ // copy lib files into temporary directory
+ if (paLib.isDirectory())
+ {
+ (new DirectoryHelper(classLoaderLib)).copyFrom(paLib);
+ }
+ if (paClasses.isDirectory())
+ {
+ (new DirectoryHelper(classLoaderClasses)).copyFrom(paClasses);
+ }
+
+ // create psuedo portlet app war descriptor for
+ // temporary directory to use with class loader
+ FileSystemHelper classLoaderLibDirectory = new DirectoryHelper(classLoaderDir);
+ paWar = new PortletApplicationWar(classLoaderLibDirectory, paName, "/" + paName);
}
else
{
- throw new RuntimeException("Unable to configure class loader: missing portlet app deployment directory for " + paName);
+ log.warn("Unable to configure class loader: missing WEB-INF/lib and WEB-INF/classes portlet app deployment directory for " + paName);
}
}
// create and register class loader for portlet app
- portletFactory.addClassLoader(app.getId().toString(), paWar.createClassloader(getClass().getClassLoader()));
- log.info("Registered portlet app in the class loader registry... " + paName);
+ if (paWar != null)
+ {
+ portletFactory.addClassLoader(app.getId().toString(), paWar.createClassloader(getClass().getClassLoader()));
+ log.info("Registered portlet app in the class loader registry... " + paName);
+ }
// add to search engine result
if (searchEngine != null)
@@ -856,4 +908,39 @@
{
this.searchEngine = searchEngine;
}
+
+ /**
+ * getUniqueId - used for temporary file creation
+ *
+ * @return new unique id
+ */
+ private static long uniqueId = System.currentTimeMillis();
+ protected synchronized static long getUniqueId()
+ {
+ return uniqueId++;
+ }
+
+ /**
+ * deleteFile - move and deep file delete utility
+ *
+ * @param file
+ * @param useTemp
+ */
+ protected boolean deleteFile(File file, boolean useTemp)
+ {
+ // move directories to temp if possible and delete
+ if (file.isDirectory())
+ {
+ if (useTemp)
+ {
+ File delete = new File(tempDirectory, file.getName() + "-move-to-delete-" + getUniqueId());
+ if (file.renameTo(delete))
+ {
+ return (new DirectoryHelper(delete)).remove();
+ }
+ }
+ return (new DirectoryHelper(file)).remove();
+ }
+ return file.delete();
+ }
}
1.3 +17 -40 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/WarInfusionPAM.java
Index: WarInfusionPAM.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/WarInfusionPAM.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WarInfusionPAM.java 3 Feb 2005 01:47:15 -0000 1.2
+++ WarInfusionPAM.java 4 Feb 2005 08:28:29 -0000 1.3
@@ -89,6 +89,14 @@
{
this.tempDirectory.mkdirs();
}
+ else
+ {
+ File [] purgeTempFiles = this.tempDirectory.listFiles();
+ for (int i = 0; (i < purgeTempFiles.length); i++)
+ {
+ deleteFile(purgeTempFiles[i], false);
+ }
+ }
this.tempDirectory.deleteOnExit();
// determine if other context.xml files exist in
@@ -234,7 +242,7 @@
File deployPortletAppContextFile = new File(webAppsDir + "/" + paName + ".xml");
deployPortletAppWarFile.delete();
deployPortletAppContextFile.delete();
- deleteDirectory(deployPortletAppDirectory);
+ deleteFile(deployPortletAppDirectory, true);
if (!deployPortletAppContextFile.exists() && !deployPortletAppDirectory.exists() && !deployPortletAppWarFile.exists())
{
log.error("Portlet application undeployment of " + deployPortletAppWarFile.getAbsolutePath() + ", " + deployPortletAppContextFile.getAbsolutePath() + ", and/or " + deployPortletAppDirectory.getAbsolutePath() + " complete.");
@@ -335,7 +343,7 @@
if (sourcePortletAppWarFile.isDirectory())
{
// war file is expanded directory, create temporary war file
- tempSourcePortletAppWarFile = new File(tempDirectory, sourcePortletAppWarFile.getName() + ".jar-" + getUniqueId());
+ tempSourcePortletAppWarFile = new File(tempDirectory, sourcePortletAppWarFile.getName() + "-temp-repack-war-" + getUniqueId());
try
{
Map warFiles = new HashMap();
@@ -403,7 +411,7 @@
// portlet.tld, and context.xml into portlet app war file;
// note that name of source file must match name of
// destination war
- File tempDeployPortletAppWarFile = new File(tempDirectory, deployPortletAppWarFile.getName() + "-" + getUniqueId());
+ File tempDeployPortletAppWarFile = new File(tempDirectory, deployPortletAppWarFile.getName() + "-infused-war-" + getUniqueId());
Deploy warInfuser = deployFactory.getInstance(sourcePortletAppWar, tempDeployPortletAppWarFile.getAbsolutePath(), true);
if (tempSourcePortletAppWarFile != null)
{
@@ -417,7 +425,7 @@
if (deployExpandedWars)
{
// expand portlet app directory
- tempDeployPortletAppDirectory = new File(tempDirectory, deployPortletAppDirectory.getName() + "-" + getUniqueId());
+ tempDeployPortletAppDirectory = new File(tempDirectory, deployPortletAppDirectory.getName() + "-expanded-war-directory-" + getUniqueId());
byte[] buffer = new byte[1024];
int bytesRead;
JarInputStream tempWar = new JarInputStream(new FileInputStream(tempDeployPortletAppWarFile));
@@ -446,7 +454,7 @@
File contextXmlFile = new File(tempDeployPortletAppDirectory, "META-INF/context.xml");
if (contextXmlFile.exists())
{
- tempDeployPortletAppContextFile = new File(tempDirectory, deployPortletAppContextFile.getName() + "-" + getUniqueId());
+ tempDeployPortletAppContextFile = new File(tempDirectory, deployPortletAppContextFile.getName() + "-expanded-war-context-" + getUniqueId());
FileInputStream read = new FileInputStream(contextXmlFile);
FileOutputStream copy = new FileOutputStream(tempDeployPortletAppContextFile);
while ((bytesRead = read.read(buffer)) != -1)
@@ -490,7 +498,7 @@
{
// undeploy and deploy portlet app context.xml and expanded war file directory
deployPortletAppContextFile.delete();
- deleteDirectory(deployPortletAppDirectory);
+ deleteFile(deployPortletAppDirectory, true);
if (!deployPortletAppContextFile.exists() && !deployPortletAppDirectory.exists())
{
tempDeployPortletAppContextFile.renameTo(deployPortletAppContextFile);
@@ -502,7 +510,7 @@
else
{
deployPortletAppContextFile.delete();
- deleteDirectory(deployPortletAppDirectory);
+ deleteFile(deployPortletAppDirectory, true);
log.error("Expanded portlet application deployment of " + deployPortletAppContextFile.getAbsolutePath() + " and " + deployPortletAppDirectory.getAbsolutePath() + " failed, unable to deploy.");
}
}
@@ -514,7 +522,7 @@
else if (tempDeployPortletAppDirectory != null)
{
// undeploy and deploy portlet app expanded war file directory
- deleteDirectory(deployPortletAppDirectory);
+ deleteFile(deployPortletAppDirectory, true);
if (!deployPortletAppDirectory.exists())
{
tempDeployPortletAppDirectory.renameTo(deployPortletAppDirectory);
@@ -592,37 +600,6 @@
}
/**
- * deleteDirectory
- *
- * @param directory
- */
- private boolean deleteDirectory(File directory)
- {
- // move to tempDirectory if possible and delete
- if (directory.isDirectory())
- {
- File delete = new File(tempDirectory, directory.getName() + ".delete-" + getUniqueId());
- if (directory.renameTo(delete))
- {
- return (new DirectoryHelper(delete)).remove();
- }
- return (new DirectoryHelper(directory)).remove();
- }
- return directory.delete();
- }
-
- /**
- * getUniqueId - used for temporary file creation
- *
- * @return new unique id
- */
- private static long uniqueId = System.currentTimeMillis();
- private synchronized static long getUniqueId()
- {
- return uniqueId++;
- }
-
- /**
* addToWarFile - recursively add a file system directory
* of files to a list and map of File objects to be added
* to a war file archive
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org