From: <gla...@hy...> - 2010-03-09 17:51:27
|
Author: glaullon Date: 2010-03-09 09:51:18 -0800 (Tue, 09 Mar 2010) New Revision: 14360 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14360 Modified: trunk/src/org/hyperic/hq/product/ServerDetector.java Log: [HQ-2007] Embedded ActiveMQ server is not being Autodiscovered when embedded in spring app running on tcserver (6.0.20.C) [HPD-50] Modified: trunk/src/org/hyperic/hq/product/ServerDetector.java =================================================================== --- trunk/src/org/hyperic/hq/product/ServerDetector.java 2010-03-09 17:43:44 UTC (rev 14359) +++ trunk/src/org/hyperic/hq/product/ServerDetector.java 2010-03-09 17:51:18 UTC (rev 14360) @@ -26,7 +26,9 @@ package org.hyperic.hq.product; import java.io.File; +import java.io.FileFilter; import java.io.FileInputStream; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; @@ -40,6 +42,8 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -68,6 +72,7 @@ import org.hyperic.sigar.ptql.ProcessFinder; import org.w3c.dom.Document; import org.w3c.dom.Node; +import sun.security.krb5.internal.ccache.FileCCacheConstants; /** * Encapsulate the know-how to determine all kinds of @@ -447,6 +452,20 @@ } } + private File findVersionFile(File dir, String verFile) { + File res = null; + File[] files = dir.listFiles(new RegExprFilenameFilter(verFile)); + if (files.length == 0) { + File[] dirs = dir.listFiles(new DirFilter()); + for (int i = 0; ((i < dirs.length) && (res==null)); i++) { + res = findVersionFile(dirs[i], verFile); + } + } else { + res = files[0]; + } + return res; + } + /** * Test if server type version filters apply: * VERSION_FILE - Return true if given file exists within installpath @@ -460,23 +479,39 @@ String installPathMatch = getTypeProperty(INSTALLPATH_MATCH); String installPathNoMatch = getTypeProperty(INSTALLPATH_NOMATCH); - if (versionFile != null) { - File instPath = new File(installpath); - if (instPath.isFile() && !instPath.isDirectory()) { - instPath = instPath.getParentFile(); - } - File file = (instPath != null) ? new File(instPath, versionFile) : - new File(installpath, versionFile); - if (!file.exists()) { - String[] expanded = PluginLoader.expand(file); - if ((expanded == null) || (expanded.length == 0)) { - getLog().debug(file + " does not exist, skipping"); + if(versionFile.startsWith("**/")){ // recursive & regexpr + versionFile=versionFile.substring(3); + File f=findVersionFile(new File(installpath),versionFile); + if(f==null) + return false; + getLog().debug(VERSION_FILE + "=" + versionFile + " matches -> " + f); + Matcher m = Pattern.compile(versionFile).matcher(f.getAbsolutePath()); + m.find(); + if(m.groupCount()!=0){ // have version group + if(!getTypeInfo().getVersion().equals(m.group(1))){ + getLog().debug(installpath + " not a match for version " + getTypeInfo().getVersion() + ", skipping"); return false; } - else { - getLog().debug(VERSION_FILE + "=" + versionFile + - " matches -> " + expanded[0]); + } + }else{ + if (versionFile != null) { + File instPath = new File(installpath); + if (instPath.isFile() && !instPath.isDirectory()) { + instPath = instPath.getParentFile(); } + File file = (instPath != null) ? new File(instPath, versionFile) : + new File(installpath, versionFile); + if (!file.exists()) { + String[] expanded = PluginLoader.expand(file); + if ((expanded == null) || (expanded.length == 0)) { + getLog().debug(file + " does not exist, skipping"); + return false; + } + else { + getLog().debug(VERSION_FILE + "=" + versionFile + + " matches -> " + expanded[0]); + } + } } } @@ -1059,4 +1094,23 @@ return ((AutoinventoryPluginManager)getManager()). getServiceConfigs(type); } + + private class DirFilter implements FileFilter{ + public boolean accept(File file) { + return file.isDirectory(); + } + + } + + private class RegExprFilenameFilter implements FileFilter{ + Pattern pattern; + public RegExprFilenameFilter(String regexp){ + pattern=Pattern.compile(regexp); + } + + public boolean accept(File file) { + return pattern.matcher(file.getAbsolutePath()).find(); + } + + } } |