modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java | 48 +++++----- 1 file changed, 26 insertions(+), 22 deletions(-)
New commits: commit dfa063dcb426f7ba05cfd3923c603b9d33e4dbf4 Author: Lukas Krejci lkrejci@redhat.com Date: Tue Aug 10 17:46:45 2010 +0200
Trivial - code formatting.
diff --git a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java index 49172bd..91490c0 100644 --- a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java +++ b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java @@ -37,27 +37,28 @@ import java.util.regex.Pattern;
public class PostfixServerDiscoveryComponent extends AugeasConfigurationDiscoveryComponent {
- private static final Pattern hostNamePattern = Pattern.compile("[\s]*myhostname[\s]*=[\s]*([^$].*)[\s]*"); - - public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext) throws InvalidPluginConfigurationException, Exception { + private static final Pattern HOSTNAME_PATTERN = Pattern.compile("[\s]*myhostname[\s]*=[\s]*([^$].*)[\s]*"); + + public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext) + throws InvalidPluginConfigurationException, Exception { Set<DiscoveredResourceDetails> resources = super.discoverResources(resourceDiscoveryContext); - for (DiscoveredResourceDetails detail : resources){ + for (DiscoveredResourceDetails detail : resources) { Configuration config = detail.getPluginConfiguration(); PropertySimple property = (PropertySimple) config.get(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP); String configFilePath = property.getStringValue(); String resourceName; - + try { - resourceName = findHostName(configFilePath); - }catch(Exception e){ - resourceName = resourceDiscoveryContext.getSystemInformation().getHostname(); + resourceName = findHostName(configFilePath); + } catch (Exception e) { + resourceName = resourceDiscoveryContext.getSystemInformation().getHostname(); } detail.setResourceName(resourceName); } return resources; } - - private String findHostName(String includeFile) throws Exception{ + + private String findHostName(String includeFile) throws Exception { try { File file = new File(includeFile); if (file.exists()) { @@ -66,21 +67,20 @@ public class PostfixServerDiscoveryComponent extends AugeasConfigurationDiscover try { String strLine; while ((strLine = br.readLine()) != null) { - Matcher m = hostNamePattern.matcher(strLine); + Matcher m = HOSTNAME_PATTERN.matcher(strLine); if (m.matches()) { String glob = m.group(1); - - return glob; - } + + return glob; + } } } finally { StreamUtil.safeClose(br); } } - } - catch (Exception e) { - throw new Exception("NetBios name was not found in configuration file "+ includeFile + " cause:",e); + } catch (Exception e) { + throw new Exception("NetBios name was not found in configuration file " + includeFile + " cause:", e); } - throw new Exception("NetBios name was not found in configuration file "+ includeFile); + throw new Exception("NetBios name was not found in configuration file " + includeFile); } }
commit e13bce0c0d7a0d84a6afbfc5c7c04586f306329a Author: Lukas Krejci lkrejci@redhat.com Date: Tue Aug 10 17:37:40 2010 +0200
Close the stream.
diff --git a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java index 8f26ee0..49172bd 100644 --- a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java +++ b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java @@ -23,6 +23,7 @@ import org.rhq.core.domain.configuration.PropertySimple; import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails; import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException; import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext; +import org.rhq.core.util.stream.StreamUtil; import org.rhq.plugins.augeas.AugeasConfigurationComponent; import org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent;
@@ -62,16 +63,19 @@ public class PostfixServerDiscoveryComponent extends AugeasConfigurationDiscover if (file.exists()) { FileInputStream fstream = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine; - while ((strLine = br.readLine()) != null) { - Matcher m = hostNamePattern.matcher(strLine); - if (m.matches()) { - String glob = m.group(1); - - return glob; - } + try { + String strLine; + while ((strLine = br.readLine()) != null) { + Matcher m = hostNamePattern.matcher(strLine); + if (m.matches()) { + String glob = m.group(1); + + return glob; + } + } + } finally { + StreamUtil.safeClose(br); } - br.close(); } } catch (Exception e) {
rhq-commits@lists.fedorahosted.org