ate 2005/03/02 05:51:41
Modified: portal/src/java/org/apache/jetspeed/deployment/impl Tag:
deployment-refactoring
DeployDecoratorEventListener.java
StandardDeploymentManager.java
StandardDeploymentObject.java JarExpander.java
DeployPortletAppEventListener.java
Log:
(Re)implementation of decorators deployment
Furthermore, code cleanup and reformat (I made a mess out of it)
Revision Changes Path
No revision
No revision
1.7.2.2 +156 -164
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployDecoratorEventListener.java
Index: DeployDecoratorEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployDecoratorEventListener.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -r1.7.2.1 -r1.7.2.2
--- DeployDecoratorEventListener.java 2 Mar 2005 02:48:58 -0000 1.7.2.1
+++ DeployDecoratorEventListener.java 2 Mar 2005 13:51:41 -0000 1.7.2.2
@@ -1,8 +1,17 @@
-/**
- * Created on Jan 13, 2004
- *
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * @author
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.jetspeed.deployment.impl;
@@ -12,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.configuration.PropertiesConfiguration;
@@ -20,6 +30,7 @@
import org.apache.jetspeed.deployment.DeploymentEvent;
import org.apache.jetspeed.deployment.DeploymentEventListener;
import org.apache.jetspeed.deployment.DeploymentException;
+import org.apache.jetspeed.util.DirectoryHelper;
/**
* <p>
@@ -27,33 +38,34 @@
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
- * @version $Id: DeployDecoratorEventListener.java,v 1.3 2004/03/25 21:39:22
- * jford Exp $
- *
+ * @version $Id$
*/
public class DeployDecoratorEventListener implements DeploymentEventListener
{
protected static final Log log = LogFactory.getLog("deployment");
+ protected String deployToDir;
- protected String deployToDir;
-
- public DeployDecoratorEventListener(String deployToDir) throws
IOException
+ public DeployDecoratorEventListener(String deployToDir) throws
FileNotFoundException
{
File checkFile = new File(deployToDir);
if (checkFile.exists())
{
- this.deployToDir = deployToDir;
+ try
+ {
+ this.deployToDir = checkFile.getCanonicalPath();
+ }
+ catch (IOException e) {}
}
else
{
throw new FileNotFoundException("The deployment directory, " +
checkFile.getAbsolutePath()
- + ", does not exist");
+ + ", does not exist");
}
}
public void initialize()
{
- // nothing to do
+ // nothing to do
}
/**
@@ -67,7 +79,12 @@
*/
public void invokeDeploy(DeploymentEvent event) throws
DeploymentException
{
-/*
+ String fileName = event.getName();
+ if (!fileName.endsWith(".jar") && !fileName.endsWith(".zip"))
+ {
+ return;
+ }
+
// get decorator configuration if available
PropertiesConfiguration conf = getDecoratorConfiguration(event);
// silently return if configuration not available, (assumes
@@ -79,113 +96,92 @@
// process decorator by id
String id = conf.getString("id");
- if (id != null)
+ if (id == null)
{
- log.info("Found decorator deployment archive " + id);
+ throw new DeploymentException("Unable to deploy decorator,
\"id\" attribute not defined in configuration");
+ }
+
+ log.info("Found decorator deployment archive " + id);
- FileSystemHelper sourceObject = null;
- FileSystemHelper deployObject = null;
- try
+ try
+ {
+ // construct decorator deploy path
+ String baseDeployPath = getBaseDeployPath(conf);
+ String deployPath = baseDeployPath + File.separator + id;
+ File deployPathFile = new File(deployPath);
+
+ // undeploy decorator if it already exists and is a redeploy or
+ // skip deployment if initial deployment
+ if (deployPathFile.exists())
{
- // construct decorator deploy path
- String baseDeployPath = getBaseDeployPath(conf);
- String deployPath = baseDeployPath + File.separator + id;
- File deployPathFile = new File(deployPath);
-
- // undeploy decorator if it already exists and is a redeploy
or
- // skip deployment if initial deployment
- if (deployPathFile.exists())
- {
- invokeUndeploy(baseDeployPath, id);
- }
-
- // redeploy/deploy decorator w/o META_INF jar metadata
- log.info("Deploying decorator " + id + " to " + deployPath);
- deployPathFile.mkdirs();
- deployObject = new DirectoryHelper(deployPathFile);
- sourceObject = event.getDeploymentObject().getFileObject();
- deployObject.copyFrom(sourceObject.getRootDirectory());
- File metaInf = new File(deployPathFile, "META-INF");
- if (metaInf.exists())
- {
- DirectoryHelper cleanup = new DirectoryHelper(metaInf);
- cleanup.remove();
- cleanup.close();
- }
-
- // detect language/country localized decorator components
- final List localeSpecificDeployPathsList =
getLocaleSpecificDeployPaths(deployPathFile);
-
- // deploy individual locale specific decorator components
- Iterator deployPathsIter =
localeSpecificDeployPathsList.iterator();
- while (deployPathsIter.hasNext())
+ invokeUndeploy(deployPathFile);
+ }
+
+ // redeploy/deploy decorator w/o META_INF jar metadata
+ log.info("Deploying decorator " + id + " to " + deployPath);
+ JarExpander.expand(event.getDeploymentObject().getFile(),
deployPathFile);
+ File metaInf = new File(deployPathFile, "META-INF");
+ if (metaInf.exists())
+ {
+ DirectoryHelper cleanup = new DirectoryHelper(metaInf);
+ cleanup.remove();
+ cleanup.close();
+ }
+
+ // detect language/country localized decorator components
+ final List localeSpecificDeployPathsList =
getLocaleSpecificDeployPaths(deployPathFile);
+
+ // deploy individual locale specific decorator components
+ Iterator deployPathsIter =
localeSpecificDeployPathsList.iterator();
+ while (deployPathsIter.hasNext())
+ {
+ File localeDeployPathFile = (File) deployPathsIter.next();
+
+ // deploy to locale specific location
+ File deployToPathFile = new File(baseDeployPath
+ +
localeDeployPathFile.getPath().substring(deployPath.length())
+ + File.separator + id);
+ log.info("Deploying locale specific decorator component to "
+ deployToPathFile.getPath());
+ deployToPathFile.mkdirs();
+
+ // deploy decorator components by moving from deployed
decorator
+ File[] filesToDeploy = localeDeployPathFile.listFiles(new
FileFilter()
{
- File localeDeployPathFile = (File)
deployPathsIter.next();
-
- // deploy to locale specific location
- File deployToPathFile = new File(baseDeployPath +
localeDeployPathFile.getPath().substring(deployPath.length()) + File.separator
+ id);
- log.info("Deploying decorator " + id + " to " +
deployToPathFile.getPath());
- deployToPathFile.mkdirs();
-
- // deploy decorator components by moving from deployed
decorator
- File [] filesToDeploy =
localeDeployPathFile.listFiles(new FileFilter()
- {
- public boolean accept(File pathname)
- {
- return
!localeSpecificDeployPathsList.contains(pathname);
- }
- });
- for (int i = 0; (i < filesToDeploy.length); i++)
+ public boolean accept(File pathname)
{
- filesToDeploy[i].renameTo(new File(deployToPathFile,
filesToDeploy[i].getName()));
+ return
!localeSpecificDeployPathsList.contains(pathname);
}
- }
-
- // cleanup locale specific deployment directories
- Iterator cleanupDeployPathsIter =
localeSpecificDeployPathsList.iterator();
- while (cleanupDeployPathsIter.hasNext())
+ });
+ for (int i = 0; (i < filesToDeploy.length); i++)
{
- File cleanupLocaleDeployPathFile = (File)
cleanupDeployPathsIter.next();
- if (cleanupLocaleDeployPathFile.exists())
- {
- DirectoryHelper cleanup = new
DirectoryHelper(cleanupLocaleDeployPathFile);
- cleanup.remove();
- cleanup.close();
- }
+ filesToDeploy[i].renameTo(new File(deployToPathFile,
filesToDeploy[i].getName()));
}
-
- log.info("Decorator " + id + " deployed successfuly.");
- event.setStatus(DeploymentEvent.STATUS_OKAY);
}
- catch (Exception e)
- {
- log.error("Error deploying decorator " + id + ": " +
e.toString(), e);
- event.setStatus(DeploymentEvent.STATUS_FAILED);
- }
- finally
+
+ // cleanup locale specific deployment directories
+ Iterator cleanupDeployPathsIter =
localeSpecificDeployPathsList.iterator();
+ while (cleanupDeployPathsIter.hasNext())
{
- try
- {
- if (sourceObject != null)
- {
- sourceObject.close();
- }
- if (deployObject != null)
- {
- deployObject.close();
- }
- }
- catch (IOException e2)
+ File cleanupLocaleDeployPathFile = (File)
cleanupDeployPathsIter.next();
+ if (cleanupLocaleDeployPathFile.exists())
{
+ DirectoryHelper cleanup = new
DirectoryHelper(cleanupLocaleDeployPathFile);
+ cleanup.remove();
+ cleanup.close();
}
}
+
+ log.info("Decorator " + id + " deployed successfuly.");
+ event.setStatus(DeploymentEvent.STATUS_OKAY);
}
- else
+ catch (DeploymentException de)
{
- log.error("Unable to deploy decorator, \"id\" attribute not
defined in configuration");
- event.setStatus(DeploymentEvent.STATUS_FAILED);
+ throw de;
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Error deploying decorator " + id,
e);
}
-*/
}
/**
@@ -193,56 +189,53 @@
* invokeUndeploy
* </p>
*
- * @see
org.apache.jetspeed.deployment.DeploymentEventListener#invokeUndeploy(org.apache.jetspeed.deployment.DeploymentEvent)
- * @param event
* @throws DeploymentException
*/
- public void invokeUndeploy(String baseDeployPath, String id) throws
DeploymentException
+ public void invokeUndeploy(File deployPathFile) throws
DeploymentException
{
-/*
- if (baseDeployPath != null && id != null)
- {
- try
+
+ if (deployPathFile == null || !deployPathFile.exists() ||
!deployPathFile.isDirectory()
+ || deployPathFile.getParentFile() == null ||
deployPathFile.getParentFile().getParentFile() == null
+ ||
!deployToDir.equals(deployPathFile.getParentFile().getParentFile().getParent()))
+ {
+ throw new DeploymentException("Cannot undeploy decorator at " +
deployPathFile + ": invalid decorator path");
+ }
+
+ String id = deployPathFile.getName();
+
+ try
+ {
+ // undeploy decorator
+ log.info("Undeploying decorator " + id + " at " +
deployPathFile.getAbsolutePath());
+
+ // detect language/country localized decorator components
+ final List localeSpecificDeployPathsList =
getLocaleSpecificDeployPaths(deployPathFile.getParentFile());
+
+ // undeploy individual locale specific decorator components
depth first
+ for (int i = localeSpecificDeployPathsList.size() - 1; i > -1;
i--)
{
- // find and construct decorator deploy path
- String deployPath = baseDeployPath + File.separator + id;
-
- // undeploy decorator
- File deployPathFile = new File(deployPath);
- if (deployPathFile.exists())
+ File localeDeployPathFile = new File((File)
localeSpecificDeployPathsList.get(i), id);
+ if (localeDeployPathFile.exists())
{
- log.info("Undeploying decorator " + id + " at " +
deployPath);
- DirectoryHelper cleanup = new
DirectoryHelper(deployPathFile);
+ log.info("Undeploying locale specific decorator
component at " + localeDeployPathFile.getPath());
+ DirectoryHelper cleanup = new
DirectoryHelper(localeDeployPathFile);
cleanup.remove();
cleanup.close();
+ localeDeployPathFile.getParentFile().delete();
}
-
- // detect language/country localized decorator components
- final List localeSpecificDeployPathsList =
getLocaleSpecificDeployPaths(new File(baseDeployPath));
-
- // undeploy individual locale specific decorator components
- Iterator deployPathsIter =
localeSpecificDeployPathsList.iterator();
- while (deployPathsIter.hasNext())
- {
- File localeDeployPathFile = new File((File)
deployPathsIter.next(), id);
- if (localeDeployPathFile.exists())
- {
- log.info("Undeploying decorator " + id + " at " +
localeDeployPathFile.getPath());
- DirectoryHelper cleanup = new
DirectoryHelper(localeDeployPathFile);
- cleanup.remove();
- cleanup.close();
- localeDeployPathFile.getParentFile().delete();
- }
- }
-
- log.info("Decorator " + id + " undeployed and deregistered
successfuly.");
- }
- catch (Exception e)
- {
- log.error("Error undeploying or deregistering decorator " +
id + ": " + e.toString(), e);
}
+
+ // now undeploy the decorator root itself
+ DirectoryHelper cleanup = new DirectoryHelper(deployPathFile);
+ cleanup.remove();
+ cleanup.close();
+
+ log.info("Decorator " + id + " undeployed successfuly.");
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Error undeploying decorator " +
id, e);
}
- */
}
/**
@@ -250,8 +243,8 @@
* getDecorationConfiguration
* </p>
*
- * @param event
- @ @return configuration
+ * @param event @
+ * @return configuration
* @throws DeploymentException
*/
private PropertiesConfiguration
getDecoratorConfiguration(DeploymentEvent event) throws DeploymentException
@@ -277,7 +270,7 @@
}
catch (Exception e1)
{
- throw new DeploymentException("Error reading configuration from
jar: " + e1.toString(), e1);
+ throw new DeploymentException("Error reading
decorator.properties from " + event.getPath(), e1);
}
finally
{
@@ -306,8 +299,7 @@
private String getBaseDeployPath(PropertiesConfiguration configuration)
{
// construct decorator deploy base path
- String decorates = configuration.getString("decorates", "generic");
- String layoutType = decorates;
+ String layoutType = configuration.getString("decorates", "generic");
if (layoutType.equalsIgnoreCase("any"))
{
layoutType = "generic";
@@ -328,25 +320,25 @@
{
// detect language/country localized deploy paths
List localeSpecificDeployPathsList = new ArrayList();
- File [] localeLanguageSpecificRoots = rootPath.listFiles(new
FileFilter()
+ File[] localeLanguageSpecificRoots = rootPath.listFiles(new
FileFilter()
+ {
+ public boolean accept(File pathname)
+ {
+ // filter language code dirs, (assume length test is
accurate enough)
+ return (pathname.isDirectory() &&
(pathname.getName().length() == 2));
+ }
+ });
+ for (int i = 0; (i < localeLanguageSpecificRoots.length); i++)
+ {
+
localeSpecificDeployPathsList.add(localeLanguageSpecificRoots[i]);
+ File[] localeCountrySpecificPaths =
localeLanguageSpecificRoots[i].listFiles(new FileFilter()
{
public boolean accept(File pathname)
{
- // filter language code dirs, (assume length test is
accurate enough)
+ // filter country code dirs, (assume length test is
accurate enough)
return (pathname.isDirectory() &&
(pathname.getName().length() == 2));
}
});
- for (int i = 0; (i < localeLanguageSpecificRoots.length); i++)
- {
-
localeSpecificDeployPathsList.add(localeLanguageSpecificRoots[i]);
- File [] localeCountrySpecificPaths =
localeLanguageSpecificRoots[i].listFiles(new FileFilter()
- {
- public boolean accept(File pathname)
- {
- // filter country code dirs, (assume length test is
accurate enough)
- return (pathname.isDirectory() &&
(pathname.getName().length() == 2));
- }
- });
for (int j = 0; (j < localeCountrySpecificPaths.length); j++)
{
localeSpecificDeployPathsList.add(localeCountrySpecificPaths[j]);
@@ -354,4 +346,4 @@
}
return localeSpecificDeployPathsList;
}
-}
+}
\ No newline at end of file
1.5.2.2 +92 -111
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/StandardDeploymentManager.java
Index: StandardDeploymentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/StandardDeploymentManager.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- StandardDeploymentManager.java 2 Mar 2005 02:48:58 -0000 1.5.2.1
+++ StandardDeploymentManager.java 2 Mar 2005 13:51:41 -0000 1.5.2.2
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation.
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,40 +36,30 @@
/**
* <p>
- * AutoDeploymentManager
+ * StandardDeploymentManager
* </p>
* Implementation of [EMAIL PROTECTED]
org.apache.jetspeed.deployment.DeploymentManager}
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
- * @version $Id: StandardDeploymentManager.java,v 1.2 2004/07/21 00:46:21
taylor
- * Exp $
- *
+ * @version $Id$
*/
public class StandardDeploymentManager implements DeploymentManager
{
- protected Log log = LogFactory.getLog("deployment");
-
+ protected Log log = LogFactory.getLog("deployment");
protected FileSystemScanner scanner;
-
- protected PortletRegistry registry;
-
- protected Collection deploymentListeners;
-
- protected long scanningDelay;
-
- protected String stagingDirectories;
-
- protected File[] stagingDirectoriesAsFiles;
-
- protected HashMap ignoredFiles;
+ protected PortletRegistry registry;
+ protected Collection deploymentListeners;
+ protected long scanningDelay;
+ protected String stagingDirectories;
+ protected File[] stagingDirectoriesAsFiles;
+ protected HashMap ignoredFiles;
/**
- *
* @param stagingDirectories
* @param scanningDelay
* @param deploymentListeners
*/
- public StandardDeploymentManager( String stagingDirectories, long
scanningDelay, Collection deploymentListeners )
+ public StandardDeploymentManager(String stagingDirectories, long
scanningDelay, Collection deploymentListeners)
{
this.scanningDelay = scanningDelay;
this.stagingDirectories = stagingDirectories;
@@ -87,13 +77,11 @@
}
/**
- *
* <p>
* start
* </p>
*
* @see org.picocontainer.Startable#start()
- *
*/
public void start()
{
@@ -109,8 +97,8 @@
if (!stagingDirectoriesAsFiles[i].exists())
{
log
- .error(stagingDirectoriesAsFiles[i].getAbsolutePath()
- + " does not exist, auto deployment
disabled.");
+
.error(stagingDirectoriesAsFiles[i].getAbsolutePath()
+ + " does not exist, auto deployment
disabled.");
stop();
return;
}
@@ -120,7 +108,7 @@
Iterator itr = deploymentListeners.iterator();
while (itr.hasNext())
{
- ((DeploymentEventListener)itr.next()).initialize();
+ ((DeploymentEventListener) itr.next()).initialize();
}
if (scanningDelay > -1)
@@ -128,7 +116,7 @@
try
{
scanner = new
FileSystemScanner(Thread.currentThread().getThreadGroup(),
- "Autodeployment File Scanner Thread");
+ "Autodeployment File Scanner
Thread");
scanner.setDaemon(true);
//
scanner.setContextClassLoader(Thread.currentThread().getContextClassLoader());
@@ -139,8 +127,8 @@
catch (Exception e)
{
log.warn(
- "Unable to intialize Catalina Portlet Application
Manager. Auto deployment will be disabled: "
- + e.toString(), e);
+ "Unable to intialize Catalina Portlet Application
Manager. Auto deployment will be disabled: "
+
+ e.toString(), e);
stop();
return;
@@ -149,19 +137,17 @@
else
{
log.info("Scanning delay set to " + scanningDelay
- + " has disabled automatic scanning of staging
directory.");
+ + " has disabled automatic scanning of staging
directory.");
}
}
/**
- *
* <p>
* stop
* </p>
*
* @see org.picocontainer.Startable#stop()
- *
*/
public void stop()
{
@@ -182,7 +168,7 @@
{
boolean failed = false;
boolean unknown = false;
-
+
DeploymentObject deploymentObject = null;
try
{
@@ -192,45 +178,46 @@
}
catch (FileNotDeployableException e)
{
- unknown = true;
+ unknown = true;
}
- if ( deploymentObject != null )
- {
- DeploymentEvent event = new
DeploymentEventImpl(deploymentObject);
- dispatch(event);
- if (event.getStatus() == DeploymentEvent.STATUS_OKAY)
+ if (deploymentObject != null)
{
- if ( aFile.exists() )
+ DeploymentEvent event = new
DeploymentEventImpl(deploymentObject);
+ dispatch(event);
+ deploymentObject.close();
+ if (event.getStatus() == DeploymentEvent.STATUS_OKAY)
{
- System.err.println("File:
"+aFile.getAbsolutePath()+" deployed");
- boolean result = aFile.delete();
- if ( !result )
- {
- System.err.println("Failed to remove aFile:
"+aFile);
- }
- }
- }
- else if ( event.getStatus() ==
DeploymentEvent.STATUS_EVAL )
- {
- unknown = true;
- }
- else
- {
- failed = true;
- }
+ if (aFile.exists())
+ {
+ System.err.println("File: " +
aFile.getAbsolutePath() + " deployed");
+ boolean result = aFile.delete();
+ if (!result)
+ {
+ System.err.println("Failed to remove: "
+ aFile);
+ }
+ }
+ }
+ else if (event.getStatus() ==
DeploymentEvent.STATUS_EVAL)
+ {
+ unknown = true;
+ }
+ else
+ {
+ failed = true;
+ }
}
if (failed || unknown)
{
- if ( unknown )
+ if (unknown)
{
- log.warn("Unrecognized file " +
aFile.getAbsolutePath());
+ log.warn("Unrecognized file " +
aFile.getAbsolutePath());
}
- else
+ else
{
- log.error("Failure deploying " +
aFile.getAbsolutePath());
+ log.error("Failure deploying " +
aFile.getAbsolutePath());
}
- ignoredFiles.put(aFile.getAbsolutePath(), new
Long(aFile.lastModified()));
+ ignoredFiles.put(aFile.getAbsolutePath(), new
Long(aFile.lastModified()));
}
}
@@ -238,28 +225,27 @@
{
log.error("Failure deploying " +
aFile.getAbsolutePath(), e1);
ignoredFiles.put(aFile.getAbsolutePath(), new
Long(aFile.lastModified()));
- }
+ }
finally
- {
+ {
if (deploymentObject != null)
- {
+ {
try
- {
+ {
deploymentObject.close();
- }
+ }
catch (IOException e)
- {
+ {
- }
- }
+ }
+ }
- }
+ }
}
}
}
/**
- *
* <p>
* dispatch
* </p>
@@ -267,30 +253,29 @@
* @see
org.apache.jetspeed.deployment.DeploymentManager#dispatch(org.apache.jetspeed.deployment.DeploymentEvent)
* @param event
*/
- public void dispatch( DeploymentEvent event )
+ public void dispatch(DeploymentEvent event)
{
- try
- {
- Iterator itr = deploymentListeners.iterator();
- while (itr.hasNext())
+ try
{
- DeploymentEventListener listener = (DeploymentEventListener)
itr.next();
- listener.invokeDeploy(event);
- if ( event.getStatus() != DeploymentEvent.STATUS_EVAL )
+ Iterator itr = deploymentListeners.iterator();
+ while (itr.hasNext())
+ {
+ DeploymentEventListener listener = (DeploymentEventListener)
itr.next();
+ listener.invokeDeploy(event);
+ if (event.getStatus() != DeploymentEvent.STATUS_EVAL)
{
- break;
+ break;
}
- }
- }
- catch (DeploymentException e)
- {
- log.error(e.toString(), e);
- event.setStatus(DeploymentEvent.STATUS_FAILED);
}
}
+ catch (DeploymentException e)
+ {
+ log.error(e.getMessage(), e);
+ event.setStatus(DeploymentEvent.STATUS_FAILED);
+ }
+ }
/**
- *
* <p>
* ignoreFile
* </p>
@@ -298,29 +283,28 @@
* @param fileName
* @return
*/
- protected boolean ignoreFile( File aFile )
+ protected boolean ignoreFile(File aFile)
{
- Long previousModified =
(Long)ignoredFiles.get(aFile.getAbsolutePath());
- if ( previousModified != null )
+ Long previousModified = (Long)
ignoredFiles.get(aFile.getAbsolutePath());
+ if (previousModified != null)
{
- if ( previousModified.longValue() != aFile.lastModified() )
- {
- ignoredFiles.remove(aFile.getAbsolutePath());
- }
- else
- {
- return true;
- }
- }
- return false;
+ if (previousModified.longValue() != aFile.lastModified())
+ {
+ ignoredFiles.remove(aFile.getAbsolutePath());
+ }
+ else
+ {
+ return true;
+ }
+ }
+ return false;
}
-
+
/**
- *
* <p>
* getAllStagedFiles
* </p>
- *
+ *
* @return
*/
protected File[] getAllStagedFiles()
@@ -328,9 +312,9 @@
ArrayList fileList = new ArrayList();
for (int i = 0; i < stagingDirectoriesAsFiles.length; i++)
{
-
fileList.addAll(Arrays.asList(stagingDirectoriesAsFiles[i].listFiles()));
+
fileList.addAll(Arrays.asList(stagingDirectoriesAsFiles[i].listFiles()));
}
-
+
return (File[]) fileList.toArray(new File[fileList.size()]);
}
@@ -339,7 +323,7 @@
private boolean started = true;
- public FileSystemScanner( ThreadGroup threadGroup, String name )
throws FileNotFoundException, IOException
+ public FileSystemScanner(ThreadGroup threadGroup, String name)
throws FileNotFoundException, IOException
{
super(threadGroup, name);
setPriority(MIN_PRIORITY);
@@ -366,9 +350,7 @@
}
/**
- * notifies a switch variable that exits the watcher's montior loop
- * started in the <code>run()</code> method.
- *
+ * notifies a switch variable that exits the watcher's montior loop
started in the <code>run()</code> method.
*/
public void safeStop()
{
@@ -376,6 +358,5 @@
}
}
-
-}
+}
\ No newline at end of file
1.1.2.2 +39 -35
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/StandardDeploymentObject.java
Index: StandardDeploymentObject.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/StandardDeploymentObject.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- StandardDeploymentObject.java 2 Mar 2005 02:48:58 -0000 1.1.2.1
+++ StandardDeploymentObject.java 2 Mar 2005 13:51:41 -0000 1.1.2.2
@@ -24,79 +24,83 @@
import org.apache.jetspeed.deployment.DeploymentObject;
/**
- * @author scott
- *
+ * <p>
+ * DeploymentObject
+ * </p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
+ * @version $Id$
*/
public class StandardDeploymentObject implements DeploymentObject
{
protected File deploymentObject;
protected ZipFile zipFile;
-
+
/**
* @throws IOException
- *
*/
public StandardDeploymentObject(File deploymentObject) throws
IOException, FileNotDeployableException
{
- if(verifyExtension(deploymentObject))
+ if (verifyExtension(deploymentObject))
{
- this.deploymentObject = deploymentObject;
+ this.deploymentObject = deploymentObject;
}
else
{
- throw new FileNotDeployableException("File type for
"+deploymentObject.getName()+" is not supported by StandardDeploymentObject.");
+ throw new FileNotDeployableException("File type for " +
deploymentObject.getName()
+ + " is not supported by
StandardDeploymentObject.");
}
-
+
}
/**
* <p>
* close
* </p>
- *
+ *
* @see org.apache.jetspeed.deployment.DeploymentObject#close()
* @throws IOException
*/
public void close() throws IOException
{
- if ( zipFile != null )
- {
- zipFile.close();
- zipFile = null;
- }
+ if (zipFile != null)
+ {
+ zipFile.close();
+ zipFile = null;
+ }
}
/**
* <p>
* getConfiguration
* </p>
- *
+ *
* @see
org.apache.jetspeed.deployment.DeploymentObject#getConfiguration(java.lang.String)
* @param configPath
* @return
* @throws IOException
*/
- public InputStream getConfiguration( String configPath ) throws
IOException
- {
- ZipFile zipFile = getZipFile();
- ZipEntry entry = zipFile.getEntry(configPath);
- if ( entry != null )
+ public InputStream getConfiguration(String configPath) throws IOException
+ {
+ ZipFile zipFile = getZipFile();
+ ZipEntry entry = zipFile.getEntry(configPath);
+ if (entry != null)
{
- return zipFile.getInputStream(entry);
- }
- return null;
+ return zipFile.getInputStream(entry);
}
+ return null;
+ }
/**
* <p>
* getName
* </p>
- *
+ *
* @see org.apache.jetspeed.deployment.DeploymentObject#getName()
* @return
*/
public String getName()
- {
+ {
return deploymentObject.getName();
}
@@ -104,7 +108,7 @@
* <p>
* getPath
* </p>
- *
+ *
* @see org.apache.jetspeed.deployment.DeploymentObject#getPath()
* @return
*/
@@ -115,23 +119,23 @@
public ZipFile getZipFile() throws IOException
{
- if ( zipFile == null )
- {
- zipFile = new ZipFile(deploymentObject);
- }
- return zipFile;
+ if (zipFile == null)
+ {
+ zipFile = new ZipFile(deploymentObject);
+ }
+ return zipFile;
}
public File getFile()
{
- return deploymentObject;
+ return deploymentObject;
}
-
+
protected boolean verifyExtension(File file)
{
String fileName = file.getName();
int dot = fileName.lastIndexOf('.');
- if(dot != -1)
+ if (dot != -1)
{
String ext = fileName.substring(dot);
return ext.equals(".war") || ext.equals(".jar") ||
ext.equals(".zip");
@@ -142,4 +146,4 @@
}
}
-}
+}
\ No newline at end of file
1.1.2.2 +66 -67
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/Attic/JarExpander.java
Index: JarExpander.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/Attic/JarExpander.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- JarExpander.java 2 Mar 2005 02:48:58 -0000 1.1.2.1
+++ JarExpander.java 2 Mar 2005 13:51:41 -0000 1.1.2.2
@@ -30,84 +30,83 @@
/**
* JarExpander
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id$
- *
*/
public class JarExpander
{
- public static void expand(File srcFile, File targetDir)
- throws IOException
- {
- if (targetDir.exists())
- {
- DirectoryHelper cleanup = new
DirectoryHelper(targetDir);
- cleanup.remove();
- cleanup.close();
- }
-
- targetDir.mkdirs();
- JarFile jarFile = new JarFile(srcFile);
- try
+ public static void expand(File srcFile, File targetDir) throws
IOException
{
- Enumeration entries = jarFile.entries();
-
- InputStream is = null;
- OutputStream os = null;
-
- byte[] buf = new byte[1024];
- int len;
-
- while (entries.hasMoreElements())
- {
- JarEntry jarEntry = (JarEntry) entries.nextElement();
- String name = jarEntry.getName();
- File entryFile = new File(targetDir, name);
-
- if (jarEntry.isDirectory())
+ if (targetDir.exists())
{
- entryFile.mkdir();
+ DirectoryHelper cleanup = new DirectoryHelper(targetDir);
+ cleanup.remove();
+ cleanup.close();
}
- else
+
+ targetDir.mkdirs();
+ JarFile jarFile = new JarFile(srcFile);
+
+ try
{
- if (!entryFile.getParentFile().exists())
- {
- entryFile.getParentFile().mkdirs();
- }
-
- entryFile.createNewFile();
-
- try
- {
- is = jarFile.getInputStream(jarEntry);
- os = new FileOutputStream(entryFile);
+ Enumeration entries = jarFile.entries();
- while ((len = is.read(buf)) > 0)
- {
- os.write(buf, 0, len);
- }
- }
- finally
- {
- if (is != null)
+ InputStream is = null;
+ OutputStream os = null;
+
+ byte[] buf = new byte[1024];
+ int len;
+
+ while (entries.hasMoreElements())
{
- is.close();
+ JarEntry jarEntry = (JarEntry) entries.nextElement();
+ String name = jarEntry.getName();
+ File entryFile = new File(targetDir, name);
+
+ if (jarEntry.isDirectory())
+ {
+ entryFile.mkdir();
+ }
+ else
+ {
+ if (!entryFile.getParentFile().exists())
+ {
+ entryFile.getParentFile().mkdirs();
+ }
+
+ entryFile.createNewFile();
+
+ try
+ {
+ is = jarFile.getInputStream(jarEntry);
+ os = new FileOutputStream(entryFile);
+
+ while ((len = is.read(buf)) > 0)
+ {
+ os.write(buf, 0, len);
+ }
+ }
+ finally
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+
+ if (os != null)
+ {
+ os.close();
+ }
+ }
+ }
}
-
- if (os != null)
+ }
+ finally
+ {
+ if (jarFile != null)
{
- os.close();
+ jarFile.close();
}
- }
}
- }
- }
- finally
- {
- if ( jarFile != null )
- {
- jarFile.close();
- }
}
- }
-}
+}
\ No newline at end of file
1.22.2.2 +88 -72
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java
Index: DeployPortletAppEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java,v
retrieving revision 1.22.2.1
retrieving revision 1.22.2.2
diff -u -r1.22.2.1 -r1.22.2.2
--- DeployPortletAppEventListener.java 2 Mar 2005 02:48:58 -0000
1.22.2.1
+++ DeployPortletAppEventListener.java 2 Mar 2005 13:51:41 -0000
1.22.2.2
@@ -1,8 +1,17 @@
-/**
- * Created on Jan 14, 2004
- *
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * @author
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.jetspeed.deployment.impl;
@@ -30,27 +39,26 @@
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
- * @version $Id: DeployPortletAppEventListener.java,v 1.13 2004/06/23
18:41:26
- * weaver Exp $
- *
+ * @version $Id$
*/
public class DeployPortletAppEventListener implements DeploymentEventListener
{
- protected static final Log log = LogFactory.getLog("deployment");
- private String webAppDir;
- private String localAppDir;
+ protected static final Log log =
LogFactory.getLog("deployment");
+ private String webAppDir;
+ private String localAppDir;
private PortletApplicationManagement pam;
- private PortletRegistry registry;
+ private PortletRegistry registry;
/**
* @param pam
* @param webAppDir
* @param localAppDir
- * @throws FileNotFoundException
- * the <code>webAppDir</code> or <code>localAppDir</code>
directory does not exist.
+ * @throws FileNotFoundException the <code>webAppDir</code> or
<code>localAppDir</code> directory does not
+ * exist.
*/
- public DeployPortletAppEventListener(PortletApplicationManagement pam,
PortletRegistry registry, String webAppDir, String localAppDir) throws
FileNotFoundException
+ public DeployPortletAppEventListener(PortletApplicationManagement pam,
PortletRegistry registry, String webAppDir,
+ String localAppDir) throws
FileNotFoundException
{
this.pam = pam;
this.registry = registry;
@@ -59,7 +67,11 @@
if (webAppDirFile.exists())
{
- this.webAppDir = webAppDir;
+ try
+ {
+ this.webAppDir = webAppDirFile.getCanonicalPath();
+ }
+ catch (IOException e) {}
}
else
{
@@ -77,30 +89,34 @@
throw new FileNotFoundException("Invalid depoyment directory for
local portlet applications: \""
+
localAppDirFile.getAbsolutePath());
}
- this.localAppDir = localAppDir;
+ try
+ {
+ this.localAppDir = localAppDirFile.getCanonicalPath();
+ }
+ catch (IOException e) {}
}
-
+
public void initialize()
- {
+ {
// start deployed local pa
- File[] localApps = new File(localAppDir).listFiles(
- new FileFilter()
- {
- public boolean accept(File pathname)
+ File[] localApps = new File(localAppDir).listFiles(new FileFilter()
+ {
+ public boolean accept(File pathname)
{
- return pathname.isDirectory() &&
registry.getPortletApplication(pathname.getName()) != null;
+ return pathname.isDirectory() &&
registry.getPortletApplication(pathname.getName()) != null;
}
- });
- for ( int i = 0; i < localApps.length; i++ )
+ });
+ for (int i = 0; i < localApps.length; i++)
{
DirectoryHelper paDirHelper = new DirectoryHelper(localApps[i]);
try
{
- pam.startLocalPortletApplication(localApps[i].getName(),
paDirHelper, createLocalPAClassLoader(localApps[i]));
+ pam.startLocalPortletApplication(localApps[i].getName(),
paDirHelper,
+
createLocalPAClassLoader(localApps[i]));
}
catch (Exception e)
{
- log.error("Failed to start Local Portlet Application
"+localApps[i],e);
+ log.error("Failed to start Local Portlet Application " +
localApps[i], e);
}
}
}
@@ -113,56 +129,56 @@
* @param event
* @throws DeploymentException
*/
- public void invokeDeploy( DeploymentEvent event ) throws
DeploymentException
- {
- String fileName = event.getName();
- if (fileName.endsWith(".war"))
+ public void invokeDeploy(DeploymentEvent event) throws
DeploymentException
{
- int prefixLength =
PortletApplicationManagement.LOCAL_PA_PREFIX.length();
- if (fileName.length() > prefixLength &&
-
fileName.substring(0,prefixLength).equalsIgnoreCase(PortletApplicationManagement.LOCAL_PA_PREFIX))
+ String fileName = event.getName();
+ if (fileName.endsWith(".war"))
{
- deployLocalPortletApplication(event);
- }
- else
+ int prefixLength =
PortletApplicationManagement.LOCAL_PA_PREFIX.length();
+ if (fileName.length() > prefixLength
+ && fileName.substring(0,
prefixLength).equalsIgnoreCase(PortletApplicationManagement.LOCAL_PA_PREFIX))
{
- deployPortletApplication(event);
- }
+ deployLocalPortletApplication(event);
}
+ else
+ {
+ deployPortletApplication(event);
}
+ }
+ }
protected void deployPortletApplication(DeploymentEvent event) throws
DeploymentException
- {
- try
- {
- File toFile = new File(webAppDir, event.getName());
- new JetspeedDeploy(event.getPath(),toFile.getAbsolutePath());
- event.setStatus(DeploymentEvent.STATUS_OKAY);
- }
- catch (Exception e)
- {
- throw new DeploymentException(e);
- }
- }
+ {
+ try
+ {
+ File toFile = new File(webAppDir, event.getName());
+ new JetspeedDeploy(event.getPath(), toFile.getAbsolutePath());
+ event.setStatus(DeploymentEvent.STATUS_OKAY);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
protected void deployLocalPortletApplication(DeploymentEvent event)
throws DeploymentException
- {
- try
- {
- String fileName = event.getName();
- String appName = fileName.substring(0,fileName.length()-4);
- pam.stopLocalPortletApplication(appName);
- File targetDir = new File(localAppDir, appName);
- JarExpander.expand(event.getDeploymentObject().getFile(), targetDir);
- DirectoryHelper paDirHelper = new DirectoryHelper(targetDir);
- pam.startLocalPortletApplication(appName, paDirHelper,
createLocalPAClassLoader(targetDir));
- event.setStatus(DeploymentEvent.STATUS_OKAY);
- }
- catch (Exception e)
- {
- throw new DeploymentException(e);
- }
- }
+ {
+ try
+ {
+ String fileName = event.getName();
+ String appName = fileName.substring(0, fileName.length() - 4);
+ pam.stopLocalPortletApplication(appName);
+ File targetDir = new File(localAppDir, appName);
+ JarExpander.expand(event.getDeploymentObject().getFile(),
targetDir);
+ DirectoryHelper paDirHelper = new DirectoryHelper(targetDir);
+ pam.startLocalPortletApplication(appName, paDirHelper,
createLocalPAClassLoader(targetDir));
+ event.setStatus(DeploymentEvent.STATUS_OKAY);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
protected ClassLoader createLocalPAClassLoader(File paDir) throws
IOException
{
@@ -172,7 +188,7 @@
webInfClasses = new File(paDir, ("WEB-INF/classes/"));
if (webInfClasses.exists())
{
- log.info("Adding " + webInfClasses.toURL() + " to class path for
Local PA "+paDir.getName());
+ log.info("Adding " + webInfClasses.toURL() + " to class path for
Local PA " + paDir.getName());
urls.add(webInfClasses.toURL());
}
@@ -183,13 +199,13 @@
File[] jars = webInfLib.listFiles();
for (int i = 0; i < jars.length; i++)
- {
+ {
File jar = jars[i];
- log.info("Adding " + jar.toURL() + " to class path for Local
PA "+paDir.getName());
+ log.info("Adding " + jar.toURL() + " to class path for Local
PA " + paDir.getName());
urls.add(jar.toURL());
}
}
return new URLClassLoader((URL[]) urls.toArray(new
URL[urls.size()]), getClass().getClassLoader());
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]