modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java | 49 +++++----- 1 file changed, 27 insertions(+), 22 deletions(-)
New commits: commit ac90dbd66d849db6dc7d4d82e595cf44cf58b5c0 Author: Lukas Krejci lkrejci@redhat.com Date: Tue Aug 10 18:02:45 2010 +0200
Trivial - code formatting.
diff --git a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java index 1821eed..b805ea9 100644 --- a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java +++ b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java @@ -37,27 +37,29 @@ import org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent;
public class SambaServerDiscoveryComponent extends AugeasConfigurationDiscoveryComponent {
- private static final Pattern netBiosNamePattern = Pattern.compile("[\s]*netbios[\s]*name[\s]*=[\s]*(.*)[\s]*"); - - public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext) throws InvalidPluginConfigurationException, Exception { + private static final Pattern NET_BIOS_NAME_PATTERN = Pattern + .compile("[\s]*netbios[\s]*name[\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 = findNetBiosName(configFilePath); - }catch(Exception e){ - resourceName = resourceDiscoveryContext.getSystemInformation().getHostname(); + resourceName = findNetBiosName(configFilePath); + } catch (Exception e) { + resourceName = resourceDiscoveryContext.getSystemInformation().getHostname(); } detail.setResourceName(resourceName); } return resources; } - - private String findNetBiosName(String includeFile) throws Exception{ + + private String findNetBiosName(String includeFile) throws Exception { try { File file = new File(includeFile); if (file.exists()) { @@ -66,21 +68,20 @@ public class SambaServerDiscoveryComponent extends AugeasConfigurationDiscoveryC try { String strLine; while ((strLine = br.readLine()) != null) { - Matcher m = netBiosNamePattern.matcher(strLine); + Matcher m = NET_BIOS_NAME_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 892927807a251621668c91bbf18e07e05c8037bd Author: Lukas Krejci lkrejci@redhat.com Date: Tue Aug 10 18:00:39 2010 +0200
Close the stream.
diff --git a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java index b53c006..1821eed 100644 --- a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java +++ b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java @@ -31,6 +31,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 SambaServerDiscoveryComponent extends AugeasConfigurationDiscoveryC if (file.exists()) { FileInputStream fstream = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine; - while ((strLine = br.readLine()) != null) { - Matcher m = netBiosNamePattern.matcher(strLine); - if (m.matches()) { - String glob = m.group(1); - - return glob; - } + try { + String strLine; + while ((strLine = br.readLine()) != null) { + Matcher m = netBiosNamePattern.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