From: <do...@hy...> - 2009-11-11 19:16:30
|
Author: dougm Date: 2009-11-11 11:16:17 -0800 (Wed, 11 Nov 2009) New Revision: 13936 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13936 Modified: trunk/src/org/hyperic/hq/common/shared/ProductProperties.java Log: (HHQ-3528) make sure ProductProperties.getProperties() finds the right files Modified: trunk/src/org/hyperic/hq/common/shared/ProductProperties.java =================================================================== --- trunk/src/org/hyperic/hq/common/shared/ProductProperties.java 2009-11-11 19:13:43 UTC (rev 13935) +++ trunk/src/org/hyperic/hq/common/shared/ProductProperties.java 2009-11-11 19:16:17 UTC (rev 13936) @@ -27,7 +27,9 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; import java.util.Properties; import org.apache.commons.logging.Log; @@ -74,11 +76,39 @@ } private static void load(String name, boolean required) { - InputStream in = - ProductProperties.class.getClassLoader(). - getResourceAsStream(name); + //XXX unhardcode these filenames here and elsewhere + final String[] jars = { //we should find one or the other + "hq-product.jar", //agent side (including command-line) + "hq.jar" //server side + }; + ClassLoader loader = ProductProperties.class.getClassLoader(); + InputStream in = null; + try { //XXX must be better way other than renaming these files w/ an hq- prefix? + //HHQ-3528 make sure we find {version,product}.properties in the right place(s) + //also note AgentCommandsService.upgrade has its own way but only works for the agent + for (Enumeration urls = loader.getResources(name); urls.hasMoreElements(); ) { + URL url = (URL)urls.nextElement(); + for (int i=0; i<jars.length; i++) { + //example: url == file:/.../pdk/lib/hq-product.jar!/version.properties + if (url.getFile().endsWith(jars[i] + "!/" + name)) { + in = url.openStream(); + _log.debug("Found " + name + " via " + url); + break; + } + } + } + } catch (IOException e) { + //fallthru + } if (in == null) { + //fallback to the old fashioned way + if ((in = loader.getResourceAsStream(name)) != null) { + _log.debug("Found " + name + " via getResourceAsStream"); + } + } + + if (in == null) { if (required) { throw new IllegalStateException("Package not packed " + "correctly, missing: " + name); |