From: <ju...@us...> - 2007-11-07 18:46:02
|
Revision: 5464 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=5464&view=rev Author: julgui Date: 2007-11-07 10:45:58 -0800 (Wed, 07 Nov 2007) Log Message: ----------- SFOS-538 New feature to warn about possibly duplicated jars in classpath or codebase. Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Diagnostics.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Logger.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/logger.sf Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Diagnostics.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Diagnostics.java 2007-11-07 17:19:07 UTC (rev 5463) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Diagnostics.java 2007-11-07 18:45:58 UTC (rev 5464) @@ -52,6 +52,8 @@ import java.io.PrintStream; import java.rmi.RemoteException; import java.util.*; +import java.util.regex.Pattern; +import java.util.regex.Matcher; import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.security.SFClassLoader; @@ -148,56 +150,87 @@ outPS.print(out); } - /** - * Print a report to the given StringBuffer. - * @param out the StringBuffer to print the report to. - * @param cd the SmartFrog component description where to extract info from. - * Derived from Ant Diagnostics class - */ - public static void doReport(StringBuffer out, ComponentDescription cd) { - out.append("\n------- SF CD diagnostics report -------"); - header(out, "Implementation Version"); - out.append(org.smartfrog.Version.versionString()); - out.append("\n"); - out.append(org.smartfrog.Version.copyright()); - out.append("\n"); - out.append("Build date: "); - out.append(org.smartfrog.Version.buildDate()); - out.append("\n"); + private static void doReportCommon(StringBuffer out) { + header(out, "Implementation Version"); + out.append(org.smartfrog.Version.versionString()); + out.append("\n"); + out.append(org.smartfrog.Version.copyright()); + out.append("\n"); + out.append("Build date: "); + out.append(org.smartfrog.Version.buildDate()); + out.append("\n"); - header(out, "System properties summary"); - doReportSummary(out); + header(out, "System properties summary"); + doReportSummary(out); - header(out, "Temp dir"); - doReportTempDir(out); + header(out, "Temp dir"); + doReportTempDir(out); - header(out, "Network"); - doReportLocalNetwork(out); - out.append("\n"); - doReportRemoteNetwork(out,Logger.testURI); - out.append("\n"); + header(out, "Network"); + doReportLocalNetwork(out); + out.append("\n"); + doReportRemoteNetwork(out, Logger.testURI); + out.append("\n"); - header(out, "ClassPath"); - doReportClassPath(out); + header(out, "ClassPath"); + doReportClassPath(out); - header(out, "CodeBase"); - doReportClassPath(out); + header(out, "ClassPath repeats"); + doReportClassPathRepeats(out); - header(out, "Locale information"); - doReportLocale(out); - doReportCD(out, cd); + header(out, "CodeBase"); + doReportCodeBase(out); + + header(out, "CodeBase repeats"); + doReportCodeBaseRepeats(out); - header(out, "System properties"); - doReportSystemProperties(out); + header(out, "Locale information"); + doReportLocale(out); + } - header(out, org.smartfrog.Version.versionString()); - out.append("\n"); + + /** + * Print a report to the given StringBuffer. + * @param out the StringBuffer to print the report to. + * @param object prim/componentdescription the SmartFrog component where to extract info from. + * Derived from Ant Diagnostics class + */ + public static void doReport(StringBuffer out, Object object) { + + if (object instanceof Prim) { + out.append("\n------- SF diagnostics report -------"); + } else if (object instanceof ComponentDescription) { + out.append("\n------- SF CD diagnostics report -------"); + } else { + out.append("\n------- SF (unknown) diagnostics report -------"); } + doReportCommon(out); + + if (object instanceof Prim) { + doReportPrim(out, (Prim) object); + } else if (object instanceof ComponentDescription) { + doReportCD(out, (ComponentDescription) object); + } else { + header (out, " WARNING: no SF object to report"); + } + + header(out, "System Thread Dump"); + doReportThreadDump(out); + + header(out, "System properties"); + doReportSystemProperties(out); + + header(out, org.smartfrog.Version.versionString() ); + out.append("\n"); + + } + + /** * Report specific Prim information. * @param out StringBuffer @@ -257,61 +290,8 @@ } } - /** - * Print a report to the given StringBuffer. - * @param out the StringBuffer to print the report to. - * @param prim the SmartFrog component where to extract info from. - * Derived from Ant Diagnostics class - */ - public static void doReport(StringBuffer out, Prim prim) { - out.append("\n------- SF diagnostics report -------"); - header(out, "Implementation Version"); - out.append(org.smartfrog.Version.versionString()); - out.append("\n"); - out.append(org.smartfrog.Version.copyright()); - out.append("\n"); - out.append("Build date: "); - out.append(org.smartfrog.Version.buildDate()); - out.append("\n"); - - header(out, "System properties summary"); - doReportSummary(out); - - header(out, "Temp dir"); - doReportTempDir(out); - - header(out, "Network"); - doReportLocalNetwork(out); - out.append("\n"); - doReportRemoteNetwork(out,Logger.testURI); - out.append("\n"); - - header(out, "ClassPath"); - doReportClassPath(out); - - header(out, "CodeBase"); - doReportCodeBase(out); - out.append("\n"); - - header(out, "Locale information"); - doReportLocale(out); - - doReportPrim(out, prim); - - header(out, "Thread Dump"); - doReportThreadDump(out); - - header(out, "System properties"); - doReportSystemProperties(out); - - header(out, org.smartfrog.Version.versionString() ); - out.append("\n"); - - } - - /** * Report specific Prim information. * @param out StringBuffer @@ -667,7 +647,7 @@ if (codebaseString!=null) { out.append(""+codebaseString.replace(System.getProperty("path.separator").charAt(0), '\n')); } else { - out.append(""+"Not defined, using default"); + out.append(""+"Not defined, using default\n"); } } @@ -787,4 +767,34 @@ + cal.get(Calendar.SECOND)) * 1000 + cal.get(Calendar.MILLISECOND)));out.append("\n"); } + + /** + * Report a listing of classpath used in the current vm. + * @param out the stream to print the properties report to. + */ + private static void doReportClassPathRepeats(StringBuffer out) { + String[] words = Logger.testJarRepeat; + String classpath[] = (System.getProperty("java.class.path")).split(System.getProperty("path.separator")); + StringBuffer message = Logger.getRepeatsMessage(words, classpath); + if (message !=null) out.append(message.toString()); + out.append("\n"); + } + + /** + * Report a listing of classpath used in the current vm. + * @param out the stream to print the properties report to. + */ + private static void doReportCodeBaseRepeats(StringBuffer out) { + String[] words = Logger.testJarRepeat; + StringBuffer message = null; + String codebaseproperty = System.getProperty(org.smartfrog.sfcore.security.SFClassLoader.SF_CODEBASE_PROPERTY); + if (codebaseproperty != null) { + String codebase[] = codebaseproperty.split(System.getProperty("path.separator")); + message = Logger.getRepeatsMessage(words, codebase); + if (message !=null) out.append(message.toString()); + } + out.append("\n"); + } + + } Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Logger.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Logger.java 2007-11-07 17:19:07 UTC (rev 5463) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Logger.java 2007-11-07 18:45:58 UTC (rev 5464) @@ -24,6 +24,9 @@ import org.smartfrog.sfcore.componentdescription.ComponentDescriptionImpl; import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + /** * Class used to store some flags used for log reporting. */ @@ -31,7 +34,11 @@ /** Used as default value in diagnostics for remote host {@value} */ public static final String SMARTFROG_URL = "http://www.smartfrog.org/"; + /** Used as default value in diagnostics for repeat jars {@value} */ + public static final String SMARTFROG_JAR = "smartfrog-"; + public static final String SFSERVICES_JAR = "sfServices"; + /** Property name for Logger class * Value {@value} * */ @@ -49,6 +56,9 @@ /** String name for optional attribute "{@value}". */ public final static String ATR_TEST_URI = "testURI"; + /** String name for optional attribute "{@value}". */ + public final static String ATR_TEST_JAR_REPEAT = "testJarRepeat"; + /** Property to enable stack trace. The default value is overridden by the * value specified in default.ini file. */ @@ -71,6 +81,11 @@ /** Property to define a list of remote hosts for remote network test . The default value can be overridden by the * value specified in default.ini file. */ + public static String[] testJarRepeat = {SMARTFROG_JAR, SFSERVICES_JAR}; + + /** Property to define a list of remote hosts for remote network test . The default value can be overridden by the + * value specified in default.ini file. + */ public static String[] testURI = {SMARTFROG_URL}; private static boolean initialized = false; @@ -96,6 +111,7 @@ processCompoundDiagReport = configuration.sfResolve(ATR_LOG_PC_DIAG_REPORT,processCompoundDiagReport,false); testNetwork = configuration.sfResolve(ATR_TEST_NETWORK,testNetwork,false); testURI = configuration.sfResolve(ATR_TEST_URI,testURI,false); + testJarRepeat = configuration.sfResolve(ATR_TEST_JAR_REPEAT,testJarRepeat,false); } } catch (Exception ex){ if (SFSystem.sfLog().isErrorEnabled()) { SFSystem.sfLog().error(ex); } @@ -112,9 +128,31 @@ if (logLiveness && (SFSystem.sfLog().isWarnEnabled())) { SFSystem.sfLog().warn(MessageUtil.formatMessage(MSG_WARNING_LIVENESS_ENABLED)); } + reportRepeatedJars(); + } /** + * Warn of repeated .jars + */ + private static void reportRepeatedJars() { + try { + // Check for repeated Jar files in classpath + String[] words = Logger.testJarRepeat; + String classpath[] = (System.getProperty("java.class.path")).split(System.getProperty("path.separator")); + StringBuffer message = Logger.getRepeatsMessage(words, classpath); + if (message !=null) SFSystem.sfLog().warn("Possible problem with classpath: \n"+message.toString()); + // Check for repeated Jar files in code base + String codebaseproperty = System.getProperty(org.smartfrog.sfcore.security.SFClassLoader.SF_CODEBASE_PROPERTY); + if (codebaseproperty != null) { + String codebase[] = codebaseproperty.split(System.getProperty("path.separator")); + message = Logger.getRepeatsMessage(words, codebase); + if (message !=null) SFSystem.sfLog().warn("Possible problem with codebase: "+message.toString()); + } + } catch (Throwable thr) { /*ignore*/ } + } + + /** * Return the intializaed status of Logger * @return boolean */ @@ -122,4 +160,45 @@ return initialized; } + public static StringBuffer getRepeatsMessage(String[] words, String[] codebase) { + String repeats; + StringBuffer message = null; + for (String word : words) { + repeats = checkRepeatedWords(word, codebase); + if (repeats !=null) { + if (message == null) message = new StringBuffer(); + message.append(repeats); + } + } + return message; + } + + + /** + * + * Method to search for repeted number of words in a String + * + * @param word Word to match + * @param content array of strings to search + * @return resultMessage list of lines where the word was found or NULL 1 or less found. + */ + public static String checkRepeatedWords (String word, String[] content) { + String regex = word; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(""); // Create Matcher + StringBuffer strb = new StringBuffer(); + int count = 0; + + for (String line : content) { + m.reset(line); + while (m.find()) { + strb.append("\n "+line); + count++; + } + } + if (count >1) { + return (count + " occurrences for "+word + strb.toString()+"\n"); + } else return null; + } + } Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/logger.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/logger.sf 2007-11-07 17:19:07 UTC (rev 5463) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/logger.sf 2007-11-07 18:45:58 UTC (rev 5464) @@ -24,4 +24,5 @@ // processCompoundDiagReport false; // testNetwork true; //testURI [|"http://www.smartfrog.org"|]; + testJarRepeat [|"smartfrog-","sfServices","sfExamples","sf-anubis"|] } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |