User: user57 Date: 02/02/07 17:06:19 Modified: src/main/org/jboss/deployment DeploymentException.java MainDeployer.java SARDeployer.java Log: o logging changes (mostly info -> debug), some fixes for showing exception traces o minor formatting changes (so that really long lines fit into 79 cols) Revision Changes Path 1.5 +6 -1 jboss/src/main/org/jboss/deployment/DeploymentException.java Index: DeploymentException.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/DeploymentException.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DeploymentException.java 3 Aug 2001 17:15:42 -0000 1.4 +++ DeploymentException.java 8 Feb 2002 01:06:19 -0000 1.5 @@ -12,7 +12,7 @@ * * @see DeployerMBean * @author <a href="mailto:[EMAIL PROTECTED]">Toby Allsopp</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class DeploymentException extends Exception @@ -36,6 +36,11 @@ super(message); this.cause = cause; + } + + public DeploymentException(Throwable cause) + { + this(cause.getMessage(), cause); } // Public -------------------------------------------------------- 1.10 +187 -165 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- MainDeployer.java 7 Feb 2002 06:00:15 -0000 1.9 +++ MainDeployer.java 8 Feb 2002 01:06:19 -0000 1.10 @@ -1,9 +1,10 @@ /* -* JBoss, the OpenSource J2EE webOS -* -* Distributable under LGPL license. -* See terms of license at gnu.org. -*/ + * JBoss, the OpenSource J2EE webOS + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + package org.jboss.deployment; import java.util.ArrayList; @@ -17,11 +18,12 @@ import java.util.jar.JarFile; import java.util.jar.Attributes; import java.util.jar.JarEntry; -import java.util.ConcurrentModificationException; -import java.net.JarURLConnection; import java.util.jar.Manifest; + +import java.net.JarURLConnection; import java.net.URL; import java.net.MalformedURLException; + import java.io.InputStream; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -29,33 +31,26 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; + import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.MalformedObjectNameException; -import org.jboss.system.ServiceMBeanSupport; - +import org.jboss.system.ServiceMBeanSupport; +import org.jboss.util.DirectoryBuilder; /** -* MainDeployer -* -* 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.9 $ -* -* -*/ - + * MainDeployer + * + * 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.10 $ + */ public class MainDeployer -extends ServiceMBeanSupport -implements MainDeployerMBean, Runnable + extends ServiceMBeanSupport + implements MainDeployerMBean, Runnable { - - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - /** JMX Server **/ MBeanServer server; @@ -81,21 +76,15 @@ /** Given a flat set of files, this is the order of deployment **/ String[] order = {"sar", "service.xml", "rar", "jar", "war", "ear", "zip"}; - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - - // Getters setters ---------------------------------------------- - /** Get on period **/ public void setPeriod(int period) { this.period = period; } public int getPeriod() {return period;} - /** Directory get set logic, these are "scanning" directories on the local filesystem **/ - - + /** + * Directory get set logic, these are "scanning" directories + * on the local filesystem + */ public void setDirectories(String urlList) { StringTokenizer urls = new StringTokenizer(urlList, ","); @@ -109,7 +98,6 @@ public void addDirectory(String url) { - // We are dealing with a relative path URL if (!( url.startsWith("file:") || url.startsWith("http:"))) { @@ -122,8 +110,10 @@ 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); } @@ -142,8 +132,10 @@ 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); } @@ -161,8 +153,6 @@ return urls; } - /** addDeployer **/ - public void addDeployer(DeployerMBean deployer) { deployers.add(deployer); } public void removeDeployer(DeployerMBean deployer) { deployers.remove(deployer); } @@ -171,37 +161,35 @@ // ServiceMBeanSupport overrides --------------------------------- /** - * Gets the Name attribute of the AutoDeployer object - * - * @return The Name value - */ + * Gets the Name attribute of the AutoDeployer object + * + * @return The Name value + */ public String getName() { return "Main Deployer"; } - // Public -------------------------------------------------------- /** - * Gets the ObjectName attribute of the AutoDeployer object - * - * @param server Description of Parameter - * @param name Description of Parameter - * @return The ObjectName value - * @exception MalformedObjectNameException Description of Exception - */ + * Gets the ObjectName attribute of the AutoDeployer object + * + * @param server Description of Parameter + * @param name Description of Parameter + * @return The ObjectName value + * @exception MalformedObjectNameException Description of Exception + */ protected ObjectName getObjectName(MBeanServer server, ObjectName name) - throws MalformedObjectNameException + throws MalformedObjectNameException { this.server = server; return name == null ? new ObjectName(OBJECT_NAME) : name; } - protected void startService() - throws Exception + throws Exception { - - // watch the deploy directory, it is a set so multiple adds (start/stop) only one entry is present + // watch the deploy directory, it is a set so multiple adds + // (start/stop) only one entry is present addDirectory("deploy"); // Do a first pass @@ -214,38 +202,35 @@ new Thread(this, "MainDeployer").start(); } - /** - * #Description of the Method - */ protected void stopService() { // Stop auto deploy thread running = false; } - public boolean getScan() { return running;} - public void setScan(boolean scan) { running = scan ;} + public boolean getScan() { return running; } + public void setScan(boolean scan) { running = scan; } /** - * Main processing method for the AutoDeployer object - */ + * Main processing method for the MainDeployer object + */ public void run() { do { - // Sleep - try {Thread.sleep(period);} - - catch (Exception ignoredAgain) {log.info("interrupted exception");} + try { + Thread.sleep(period); + } + catch (Exception e) { + log.debug("interrupted"); + } scan(); - - - } while (running); + } + while (running); } - public void scan() { try @@ -278,15 +263,18 @@ undeploy(di); deploy(di); } } - catch (Exception ignoreIt) {log.info("exception ", ignoreIt);} + catch (Exception e) { + log.warn("operation failed; ignoring", e); + } } } - catch (Exception ignored) {log.info ("exception ", ignored);} + catch (Exception e) { + log.warn("operation failed; ignoring", e); + } } public void undeploy(String url) { - try { DeploymentInfo sdi = (DeploymentInfo) deployments.get(new URL(url)); @@ -294,13 +282,16 @@ if (sdi!= null) undeploy(sdi); } - catch (Exception e) {log.error("Couldn't undeploy url "+url);} + catch (Exception e) { + log.error("Couldn't undeploy url " + url, e); + } } public void undeploy(DeploymentInfo di) { - log.info("Undeploy di "+di.url); + log.info("Undeploying "+di.url); + // First remove all sub-deployments Iterator subs = di.subDeployments.iterator(); while (subs.hasNext()) @@ -308,7 +299,9 @@ DeploymentInfo sub = (DeploymentInfo) subs.next(); // undeploy((DeploymentInfo) subs.next()); - log.info("DEPLOYMENT OF SUB "+sub.url); + if (log.isDebugEnabled()) { + log.debug("DEPLOYMENT OF SUB "+sub.url); + } undeploy(sub); } @@ -329,21 +322,27 @@ 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); + } } - public void deploy(String url) { // Just format it correctly 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) @@ -359,11 +358,13 @@ deploy(sdi); } - catch (DeploymentException de) {log.error("Couldn't deploy URL "+url, de);} + catch (DeploymentException e) { + log.error("Couldn't deploy URL "+url, e); + } } public void deploy(DeploymentInfo deployment) - throws DeploymentException + throws DeploymentException { boolean debug = log.isDebugEnabled(); @@ -371,7 +372,7 @@ // If we are already deployed return if (deployments.containsKey(deployment.url)) return; - log.info("Auto deploying: " + deployment.url.toString()); + log.info("Deploying: " + deployment.url.toString()); // Create a local copy of that File, the sdi keeps track of the copy directory makeLocalCopy(deployment); @@ -423,13 +424,15 @@ public void findDeployer(DeploymentInfo sdi) { + boolean debug = log.isDebugEnabled(); + // Defensive sdi.deployer = null; - /* - *To deploy directories of beans one should just name the directory - * mybean.ear/bla...bla, so that the directory gets picked up by the right deployer - */ + // + // To deploy directories of beans one should just name the directory + // mybean.ear/bla...bla, so that the directory gets picked up by the right deployer + // Iterator iterator = deployers.iterator(); while (iterator.hasNext()) { @@ -437,32 +440,32 @@ if (deployer.accepts(sdi)) { sdi.deployer = deployer; - log.info("using deployer "+deployer); + if (debug) { + log.debug("using deployer "+deployer); + } + return; } } - if (log.isDebugEnabled()) log.debug("NO DEPLOYER for url "+sdi.url); - // log.info("NO DEPLOYER for url "+sdi.url); + if (debug) { + log.debug("NO DEPLOYER for url "+sdi.url); + } } public void preDeregister() - throws Exception + throws Exception { running = false; } - // Protected ----------------------------------------------------- - /** - * ScanNew - * - * ScanNew scans the directories that are given to it and returns a Set with the new deployments - */ + * ScanNew scans the directories that are given to it and returns a + * Set with the new deployments + */ protected ArrayList scanNew() { - try { HashSet newDeployments = new HashSet(); @@ -471,12 +474,13 @@ Iterator iterator = directories.listIterator(); while (iterator.hasNext()) { - File dir = new File(((URL) iterator.next()).getFile()); - // if (log.isTraceEnabled()) log.trace("Scanning directory: " + dir); + // if (log.isTraceEnabled()) log.trace("Scanning directory: " + dir); File[] files = dir.listFiles(); - if (files == null) log.info("%%%%%%%%%%%%%%%%%%%%%%%%%%we have a problem null files in directory"); - + if (files == null) { + log.error("we have a problem null files in directory; should not happen"); + } + for (int i = 0; i < files.length; i++) { // It is a new file @@ -487,14 +491,16 @@ return sortURLs(newDeployments); } - catch (Exception ignored) { ignored.printStackTrace();log.error(ignored); return null;} + catch (Exception e) { + log.error("operation failed", e); + return null; + } } /** - * scanModified - * - * scanModified scans the existing deployments and return a Set with the modified deployments - */ + * scanModified scans the existing deployments and return a + * Set with the modified deployments + */ protected ArrayList scanModified() { try @@ -531,20 +537,22 @@ return sortDeployments(modified); } - catch (ConcurrentModificationException cme) {cme.printStackTrace(); return null;} - - catch (Throwable ignored) {ignored.printStackTrace();log.error(ignored); return null;} + catch (Throwable t) { + log.error("operation failed", t); + return null; + } } /** - * extractPackages - * - * TODO marcf: support directories as well right now depends on the jar format - * - * In case of identifiable sub-deployment we recursively call the deploy method on the deployer - */ + * extractPackages + * + * TODO marcf: support directories as well right now depends on the jar format + * + * In case of identifiable sub-deployment we recursively call the deploy method + * on the deployer + */ protected void deploySubPackages(DeploymentInfo di) - throws DeploymentException + throws DeploymentException { // If XML only no subdeployment to speak of // FIXME do the sub deploy for directory and the move to @@ -562,10 +570,14 @@ // 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();} - catch (Exception ignored) {throw new DeploymentException(ignored.getMessage());} + try { + jarFile = ((JarURLConnection)new URL("jar:"+di.localUrl.toString()+"!/").openConnection()).getJarFile(); + } + catch (Exception e) { + throw new DeploymentException(e); + } - for (Enumeration e = jarFile.entries(); e.hasMoreElements(); ) + for (Enumeration e = jarFile.entries(); e.hasMoreElements();) { JarEntry entry = (JarEntry)e.nextElement(); String name = entry.getName(); @@ -581,41 +593,45 @@ || name.endsWith(".war") || name.endsWith(".zip")) { - // 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 + // example war's WEBINF/lib/myjar.jar appears as myjar.jar in + // the tmp directory if (name.lastIndexOf("/") != -1) name = name.substring(name.lastIndexOf("/")+1); try { - File localCopyDir = new File(System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy"); - + 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 = new File(localCopyDir, getNextID ()+"."+name); + File outFile = builder.cd(getNextID () + "." + name).get(); // Copy in and out 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 = new URL("file:" + outFile.toString()); + URL subURL = outFile.toURL(); DeploymentInfo sub = new DeploymentInfo(subURL, di); // And deploy it, this call is recursive subDeployments.add(sub); - } - catch (Exception e2) + catch (Exception ex) { - log.error("Error in subDeployment with name "+name, e2); + log.error("Error in subDeployment with name "+name, ex); - throw new DeploymentException("Could not deploy sub deployment "+name+" of deployment "+di.url); + throw new DeploymentException + ("Could not deploy sub deployment "+name+" of deployment "+di.url); } } @@ -637,15 +653,19 @@ // Deploy them all while (lt.hasNext()) { - - try{ deploy((DeploymentInfo) lt.next());} - - catch (DeploymentException de) { di.subDeployments.remove(di);} + try { + deploy((DeploymentInfo) lt.next()); + } + catch (DeploymentException e) { + di.subDeployments.remove(di); + } } } public void parseManifestLibraries(DeploymentInfo sdi) throws DeploymentException { + boolean debug = log.isDebugEnabled(); + String classPath = null; Manifest mf = sdi.getManifest(); @@ -661,7 +681,10 @@ { ArrayList tmp = new ArrayList(); StringTokenizer st = new StringTokenizer(classPath); - log.debug("resolveLibraries: "+classPath); + if (debug) { + log.debug("resolveLibraries: "+classPath); + } + while (st.hasMoreTokens()) { URL lib = null; @@ -669,8 +692,10 @@ String tk = st.nextToken(); DeploymentInfo sub = null; - - log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is "+tk); + + if (debug) { + log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is "+tk); + } try { @@ -678,7 +703,6 @@ if (!deployments.containsKey(lib)) { - // Try having it as a full subdeployment sub = new DeploymentInfo(lib, sdi); @@ -686,23 +710,22 @@ } } catch (Exception ignore) { - log.error("The manifest entry in "+sdi.url+" references URL "+lib+ + 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. - * @return a File object representing the downloaded module - * @throws IOException - */ + /** + * Downloads the jar file or directory the src URL points to. + * In case of directory it becomes packed to a jar file. + * + * @return a File object representing the downloaded module + * @throws IOException + */ public void makeLocalCopy(DeploymentInfo sdi) - throws DeploymentException + throws DeploymentException { URL dest = null; File localCopyDir = null; @@ -735,15 +758,14 @@ 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); + } } - - protected void copy(InputStream in, OutputStream out) - throws IOException + throws IOException { - byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) > 0) @@ -755,7 +777,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: protocoll is allowed as destination!"); InputStream in; OutputStream out; @@ -836,7 +858,7 @@ } public boolean isDeployed(String url) - throws MalformedURLException + throws MalformedURLException { return ( getDeployment(new URL(url)) != null ); } 1.4 +4 -3 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SARDeployer.java 30 Jan 2002 01:50:16 -0000 1.3 +++ SARDeployer.java 8 Feb 2002 01:06:19 -0000 1.4 @@ -58,7 +58,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.3 $ <p> +* @version $Revision: 1.4 $ <p> * * <b>20010830 marc fleury:</b> * <ul>initial import @@ -433,8 +433,9 @@ new Object[] {sub}, new String[] {"org.jboss.deployment.DeploymentInfo"}); } - - catch (Exception e) {log.error(e);} + catch (Exception e) { + log.error("operation failed", e); + } log.debug("deployed classes for " + neededUrl);
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development