User: starksm
Date: 02/02/10 09:44:33
Modified: src/main/org/jboss/deployment MainDeployer.java
SARDeployer.java
Log:
Fix problems with handling of file urls on win32 platforms.
Revision Changes Path
1.12 +172 -148 jboss/src/main/org/jboss/deployment/MainDeployer.java
Index: MainDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/MainDeployer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MainDeployer.java 9 Feb 2002 16:09:17 -0000 1.11
+++ MainDeployer.java 10 Feb 2002 17:44:32 -0000 1.12
@@ -45,7 +45,7 @@
* Takes a series of URL to watch, detects changes and calls the appropriate
Deployers
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class MainDeployer
extends ServiceMBeanSupport
@@ -110,17 +110,18 @@
if (!directories.contains(dir)) directories.add(dir);
}
- catch (MalformedURLException bad) {
- log.warn("Failed to add directory scan "+url);
- return;
+ catch (MalformedURLException bad)
+ {
+ log.warn("Failed to add directory scan "+url);
+ return;
}
- if (log.isDebugEnabled()) log.debug("Added directory scan "+url);
+ if (log.isDebugEnabled())
+ log.debug("Added directory scan "+url);
}
public void removeDirectory(String url)
{
-
// We are dealing with a relative path URL
if (!( url.startsWith("file:") || url.startsWith("http:")))
{
@@ -132,14 +133,16 @@
int index = directories.lastIndexOf(new URL(url));
if (index != -1) directories.remove(index);
}
- catch (MalformedURLException bad) {
- log.warn("Failed to remove directory scan "+url);
- return;
+ catch (MalformedURLException bad)
+ {
+ log.warn("Failed to remove directory scan "+url);
+ return;
}
- if (log.isDebugEnabled()) log.debug("Removed directory scan "+url);
+ if (log.isDebugEnabled())
+ log.debug("Removed directory scan "+url);
}
-
+
public String[] getDeployed()
{
String[] urls = new String[deployments.size()];
@@ -219,13 +222,14 @@
do
{
// Sleep
- try {
- Thread.sleep(period);
- }
- catch (Exception e) {
- log.debug("interrupted");
- }
-
+ try
+ {
+ Thread.sleep(period);
+ }
+ catch (Exception e)
+ {
+ log.debug("interrupted");
+ }
scan();
}
while (running);
@@ -237,20 +241,19 @@
{
// Scan diretories for new deployments
Iterator newDeployments = scanNew().listIterator();
-
while (newDeployments.hasNext())
{
deploy((URL) newDeployments.next());
}
-
+
// Undeploy and redeployto the modified ones
Iterator modified = scanModified().listIterator();
while (modified.hasNext())
{
DeploymentInfo di = (DeploymentInfo) modified.next();
-
- try {
+ try
+ {
// if the url is a file that doesn't exist, it was removed ->
undeploy
// TODO: check connection on http protocol and see if it is removed.
if (di.url.getProtocol().startsWith("file") && !new
File(di.url.getFile()).exists())
@@ -263,27 +266,30 @@
undeploy(di); deploy(di);
}
}
- catch (Exception e) {
- log.warn("operation failed; ignoring", e);
- }
+ catch (Exception e)
+ {
+ log.warn("operation failed; ignoring", e);
+ }
}
}
- catch (Exception e) {
- log.warn("operation failed; ignoring", e);
+ catch (Exception e)
+ {
+ log.warn("operation failed; ignoring", e);
}
- }
-
+ }
+
public void undeploy(String url)
{
try
{
DeploymentInfo sdi = (DeploymentInfo) deployments.get(new URL(url));
- if (sdi!= null) undeploy(sdi);
-
+ if (sdi!= null)
+ undeploy(sdi);
}
- catch (Exception e) {
- log.error("Couldn't undeploy url " + url, e);
+ catch (Exception e)
+ {
+ log.error("Couldn't undeploy url " + url, e);
}
}
@@ -301,22 +307,22 @@
DeploymentInfo sub = (DeploymentInfo) subs.next();
// undeploy((DeploymentInfo) subs.next());
- if (log.isDebugEnabled()) {
- log.debug("DEPLOYMENT OF SUB "+sub.url);
- }
- undeploy(sub);
-
+ if (log.isDebugEnabled())
+ log.debug("DEPLOYMENT OF SUB "+sub.url);
+ undeploy(sub);
}
-
+
// Them remove the deployment itself
try
{
// Tell the respective deployer to undeploy this one
- if (di.deployer != null) di.deployer.undeploy(di);
-
+ if (di.deployer != null)
+ di.deployer.undeploy(di);
+
// remove from local maps
deployments.remove(di.url);
- if (deploymentsList.lastIndexOf(di) != -1)
deploymentsList.remove(deploymentsList.lastIndexOf(di));
+ if (deploymentsList.lastIndexOf(di) != -1)
+ deploymentsList.remove(deploymentsList.lastIndexOf(di));
// Nuke my stuff, this includes the class loader
di.cleanup(log);
@@ -325,8 +331,9 @@
log.info("Undeployed "+di.url);
}
- catch (Exception e) {
- log.error("Undeployment failed: " + di.url, e);
+ catch (Exception e)
+ {
+ log.error("Undeployment failed: " + di.url, e);
}
}
@@ -336,48 +343,53 @@
try
{
// if no protocol, assume file based and prepend protocol
- if (! url.startsWith("http") && ! url.startsWith("file")) {
- deploy(new URL("file:"+url));
- }
- else {
- deploy(new URL(url));
- }
+ if (! url.startsWith("http") && ! url.startsWith("file"))
+ {
+ deploy(new URL("file:"+url));
+ }
+ else
+ {
+ deploy(new URL(url));
+ }
}
- catch (Exception e) {
- log.error("Problem with URL "+url, e);
+ catch (Exception e)
+ {
+ log.error("Problem with URL "+url, e);
}
}
-
+
public void deploy(URL url)
{
DeploymentInfo sdi = (DeploymentInfo) deployments.get(url);
try
{
- // if it exists, return
- if (sdi != null) return;
-
- // A new deployment
- else sdi = new DeploymentInfo(url, null);
-
- deploy(sdi);
+ // if it does not exist create a new deployment
+ if (sdi == null)
+ {
+ sdi = new DeploymentInfo(url, null);
+ deploy(sdi);
+ }
}
- catch (DeploymentException e) {
- log.error("Couldn't deploy URL "+url, e);
+ catch (DeploymentException e)
+ {
+ log.error("Couldn't deploy URL "+url, e);
}
}
-
+
public void deploy(DeploymentInfo deployment)
throws DeploymentException
{
boolean debug = log.isDebugEnabled();
- try {
+ try
+ {
// If we are already deployed return
- if (deployments.containsKey(deployment.url)) return;
-
+ if (deployments.containsKey(deployment.url))
+ return;
+
if (log.isInfoEnabled());
log.info("Deploying: " + deployment.url.toString());
-
+
// Create a local copy of that File, the sdi keeps track of the copy
directory
makeLocalCopy(deployment);
@@ -387,24 +399,24 @@
// What deployer is able to deploy this file
findDeployer(deployment);
- if(deployment.deployer != null) deployment.deployer.init(deployment);
-
+ if(deployment.deployer != null)
+ deployment.deployer.init(deployment);
+
// create subdeployments as needed
deploySubPackages(deployment);
// Deploy this SDI, if it is a deployable type
- if (deployment.deployer != null) deployment.deployer.deploy(deployment);
-
+ if (deployment.deployer != null)
+ deployment.deployer.deploy(deployment);
+
deployment.status="Deployed";
- if (debug) {
- log.debug("Done deploying " + deployment.shortName);
- }
+ if (debug)
+ log.debug("Done deploying " + deployment.shortName);
}
catch (DeploymentException e)
{
- deployment.status="Deployment FAILED reason: "+e.getMessage();
-
+ deployment.status="Deployment FAILED reason: "+e.getMessage();
throw e;
}
finally
@@ -419,9 +431,8 @@
if
(!deployment.url.toString().startsWith("file:"+System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy"))
{
deploymentsList.add(deployment);
- if (debug) {
- log.debug("Watching new file: " + deployment.url);
- }
+ if (debug)
+ log.debug("Watching new file: " + deployment.url);
}
}
}
@@ -444,19 +455,16 @@
if (deployer.accepts(sdi))
{
sdi.deployer = deployer;
- if (debug) {
- log.debug("using deployer "+deployer);
- }
-
+ if (debug)
+ log.debug("using deployer "+deployer);
return;
- }
- }
-
- if (debug) {
- log.debug("NO DEPLOYER for url "+sdi.url);
+ }
}
+
+ if (debug)
+ log.debug("NO DEPLOYER for url "+sdi.url);
}
-
+
public void preDeregister()
throws Exception
{
@@ -473,20 +481,24 @@
try
{
HashSet newDeployments = new HashSet();
-
+ boolean trace = log.isTraceEnabled();
// Scan directories
Iterator iterator = directories.listIterator();
while (iterator.hasNext())
{
File dir = new File(((URL) iterator.next()).getFile());
- // if (log.isTraceEnabled()) log.trace("Scanning directory: " + dir);
+ if (trace)
+ log.trace("Scanning directory: " + dir);
File[] files = dir.listFiles();
- if (files == null) {
- log.error("we have a problem null files in directory; should not
happen");
- }
+ if (files == null)
+ {
+ log.error("we have a problem null files in directory; should not
happen");
+ }
for (int i = 0; i < files.length; i++)
{
+ if( trace )
+ log.trace("Checking deployment file: "+files[i]);
// It is a new file
if (!deployments.containsKey(files[i].toURL()))
newDeployments.add(files[i].toURL());
@@ -495,9 +507,10 @@
return sortURLs(newDeployments);
}
- catch (Exception e) {
- log.error("operation failed", e);
- return null;
+ catch (Exception e)
+ {
+ log.error("operation failed", e);
+ return null;
}
}
@@ -511,8 +524,9 @@
{
HashSet modified = new HashSet();
- if (log.isTraceEnabled()) log.trace("Scanning installed deployments");
-
+ if (log.isTraceEnabled())
+ log.trace("Scanning installed deployments");
+
// People already deployed, scan for modifications
Iterator it = deploymentsList.listIterator();
@@ -541,9 +555,10 @@
return sortDeployments(modified);
}
- catch (Throwable t) {
- log.error("operation failed", t);
- return null;
+ catch (Throwable t)
+ {
+ log.error("operation failed", t);
+ return null;
}
}
@@ -561,8 +576,9 @@
// If XML only no subdeployment to speak of
// FIXME do the sub deploy for directory and the move to
// if (di.isXML) return;
- if (di.isXML || di.isDirectory) return ;
-
+ if (di.isXML || di.isDirectory)
+ return ;
+
// J2EE legacy goo in manifest
parseManifestLibraries(di);
@@ -574,13 +590,17 @@
// marcf FIXME FIXME FIXME add support for directories not just jar files
// Do we have a jar file jar:<theURL>!/..
- try {
- jarFile = ((JarURLConnection)new
URL("jar:"+di.localUrl.toString()+"!/").openConnection()).getJarFile();
+ try
+ {
+ URL jarURL = new URL("jar:"+di.localUrl.toString()+"!/");
+ JarURLConnection jarConn = (JarURLConnection) jarURL.openConnection();
+ jarFile = jarConn.getJarFile();
}
- catch (Exception e) {
- throw new DeploymentException(e);
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
}
-
+
for (Enumeration e = jarFile.entries(); e.hasMoreElements();)
{
JarEntry entry = (JarEntry)e.nextElement();
@@ -599,15 +619,15 @@
{
// Make sure the name is flat no directory structure in subs name
// example war's WEBINF/lib/myjar.jar appears as myjar.jar in
- // the tmp directory
+ // the tmp directory
if (name.lastIndexOf("/") != -1)
name = name.substring(name.lastIndexOf("/")+1);
try
{
- DirectoryBuilder builder =
- new DirectoryBuilder(System.getProperty("jboss.system.home"));
- File localCopyDir = builder.cd("tmp").cd("deploy").get();
+ DirectoryBuilder builder =
+ new DirectoryBuilder(System.getProperty("jboss.system.home"));
+ File localCopyDir = builder.cd("tmp").cd("deploy").get();
// We use the name of the entry as the name of the file under deploy
File outFile = builder.cd(getNextID () + "." + name).get();
@@ -616,13 +636,15 @@
OutputStream out = new FileOutputStream(outFile);
InputStream in = jarFile.getInputStream(entry);
- try {
- copy(in, out);
- }
- finally {
- out.close();
- }
-
+ try
+ {
+ copy(in, out);
+ }
+ finally
+ {
+ out.close();
+ }
+
// It is a sub-deployment
URL subURL = outFile.toURL();
DeploymentInfo sub = new DeploymentInfo(subURL, di);
@@ -633,9 +655,8 @@
catch (Exception ex)
{
log.error("Error in subDeployment with name "+name, ex);
-
throw new DeploymentException
- ("Could not deploy sub deployment "+name+" of deployment "+di.url);
+ ("Could not deploy sub deployment "+name+" of deployment "+di.url);
}
}
@@ -657,12 +678,14 @@
// Deploy them all
while (lt.hasNext())
{
- try {
- deploy((DeploymentInfo) lt.next());
- }
- catch (DeploymentException e) {
- di.subDeployments.remove(di);
- }
+ try
+ {
+ deploy((DeploymentInfo) lt.next());
+ }
+ catch (DeploymentException e)
+ {
+ di.subDeployments.remove(di);
+ }
}
}
@@ -685,9 +708,8 @@
{
ArrayList tmp = new ArrayList();
StringTokenizer st = new StringTokenizer(classPath);
- if (debug) {
- log.debug("resolveLibraries: "+classPath);
- }
+ if (debug)
+ log.debug("resolveLibraries: "+classPath);
while (st.hasMoreTokens())
{
@@ -697,12 +719,11 @@
DeploymentInfo sub = null;
- if (debug) {
- log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is
"+tk);
- }
-
- try {
-
+ if (debug)
+ log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is
"+tk);
+
+ try
+ {
lib = new URL(sdi.url, tk);
if (!deployments.containsKey(lib))
@@ -713,14 +734,15 @@
deploy(sub);
}
}
- catch (Exception ignore) {
+ catch (Exception ignore)
+ {
log.warn("The manifest entry in "+sdi.url+" references URL "+lib+
" which could not be opened, entry ignored");
}
}
}
- }
-
+ }
+
/**
* Downloads the jar file or directory the src URL points to.
* In case of directory it becomes packed to a jar file.
@@ -762,8 +784,9 @@
copy(sdi.url, sdi.localUrl);
}
}
- catch (Exception e) {
- log.error("Could not make local copy for "+sdi.url.toString(), e);
+ catch (Exception e)
+ {
+ log.error("Could not make local copy for "+sdi.url.toString(), e);
}
}
@@ -781,7 +804,7 @@
protected void copy (URL _src, URL _dest) throws IOException
{
if (!_dest.getProtocol ().equals ("file"))
- throw new IOException ("only file: protocoll is allowed as destination!");
+ throw new IOException ("only file: protocol is allowed as destination!");
InputStream in;
OutputStream out;
@@ -801,7 +824,7 @@
{
read = in.read(buffer);
if (read == -1)
- break;
+ break;
out.write(buffer, 0, read);
}
@@ -825,8 +848,7 @@
if (url.toString().endsWith(order[i]))
{
- list.add(url); it.remove();
-
+ list.add(url); it.remove();
}
}
}
@@ -864,9 +886,11 @@
public boolean isDeployed(String url)
throws MalformedURLException
{
- return ( getDeployment(new URL(url)) != null );
+ URL deployURL = new URL(url);
+ DeploymentInfo di = getDeployment(deployURL);
+ return ( di != null );
}
-
+
public DeploymentInfo getDeployment(URL url)
{
return (DeploymentInfo) deployments.get(url);
1.7 +9 -7 jboss/src/main/org/jboss/deployment/SARDeployer.java
Index: SARDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/SARDeployer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SARDeployer.java 9 Feb 2002 23:36:52 -0000 1.6
+++ SARDeployer.java 10 Feb 2002 17:44:32 -0000 1.7
@@ -57,7 +57,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Maplesden</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
-* @version $Revision: 1.6 $ <p>
+* @version $Revision: 1.7 $ <p>
*
* <b>20010830 marc fleury:</b>
* <ul>initial import
@@ -262,7 +262,7 @@
for (int i = 0; i < classpaths.getLength(); i++)
{
Element classpathElement = (Element)classpaths.item(i);
- log.debug("found classpath " + classpath);
+ log.debug("Found classpath element: " + classpathElement);
//String codebase = System.getProperty("jboss.system.libraryDirectory");
String codebase = "";
@@ -271,9 +271,9 @@
//Does it specify a codebase?
if (classpathElement != null)
{
- log.debug("setting up classpath " + classpath);
// Load the codebase
codebase = classpathElement.getAttribute("codebase").trim();
+ log.debug("Setting up classpath from raw codebase: " + codebase);
if ("".equals(codebase) || ".".equals(codebase))
{
@@ -289,9 +289,9 @@
}
// Let's make sure the formatting of the codebase ends with the /
- if (codebase.startsWith("file:") && !codebase.endsWith(File.separator))
+ if (codebase.startsWith("file:") && !codebase.endsWith("/"))
{
- codebase += File.separator;
+ codebase += "/";
}
else if (codebase.startsWith("http:") && !codebase.endsWith("/"))
{
@@ -307,7 +307,8 @@
{
try
{
- File dir = new File(codebase.substring(5));
+ URL fileURL = new URL(codebase);
+ File dir = new File(fileURL.getFile());
// The patchDir can only be a File one, local
File[] jars = dir.listFiles(
new java.io.FileFilter()
@@ -354,7 +355,8 @@
try
{
- File dir = new File(codebase.substring(5));
+ URL fileURL = new URL(codebase);
+ File dir = new File(fileURL.getFile());
// The patchDir can only be a File one, local
File[] jars = dir.listFiles(
new java.io.FileFilter()
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development