modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java | 76 ++++++---- modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java | 4 modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java | 2 modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java | 4 modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java | 1 5 files changed, 54 insertions(+), 33 deletions(-)
New commits: commit f1365e541a2ba19357abfa063333dc9901f6d786 Author: Heiko W. Rupp hwr@redhat.com Date: Thu Aug 12 12:24:08 2010 +0200
12644 prevent NPE
diff --git a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java index 6830f5f..16d6c89 100644 --- a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java +++ b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java @@ -18,6 +18,7 @@ */ package org.rhq.plugins.perftest;
+import java.util.Collections; import java.util.Set; import org.rhq.core.domain.configuration.Configuration; import org.rhq.core.domain.resource.ResourceType; @@ -44,6 +45,9 @@ public class PerfTestDiscoveryComponent implements ResourceDiscoveryComponent { Set<DiscoveredResourceDetails> resourceDetails = null; if (manager.isEnabled()) { ResourceFactory resourceFactory = manager.getResourceFactory(resourceType.getName()); + if (resourceFactory==null) + return Collections.emptySet(); + resourceDetails = resourceFactory.discoverResources(context);
// If there is a plugin configuration factory defined, run it on each resource diff --git a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java index d9aabf9..1eb831d 100644 --- a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java +++ b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java @@ -310,6 +310,7 @@ public class ScenarioManager { return new SimpleResourceFactory((SimpleResourceGenerator) generator); }
+ log.warn("No factory for generator " + generator.toString() + " specified"); return null; }
commit 391f9be4637842049cc01e90d7bce1b4ce54e86f Author: Heiko W. Rupp hwr@redhat.com Date: Thu Aug 12 12:02:58 2010 +0200
Fix some potential NPE and resource leakage
diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java index 69587d0..17a6818 100644 --- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java +++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java @@ -61,37 +61,49 @@ public class PluginGen {
public void run() throws Exception {
+ Props props = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + try {
- Props props = askQuestions(br, new Props()); - if (props == null) { - // abort by user - return; - } + props = askQuestions(br, new Props()); + if (props == null) { + // abort by user + return; + } + + boolean done = false; + do {
- boolean done = false; - do { - - System.out.println(); - System.out.print("Do you want to add a child to " + props.getName() + "? (y/N) "); - String answer = br.readLine(); - answer = answer.toLowerCase(Locale.getDefault()); - if (answer.startsWith("n") || answer.length() == 0) - done = true; - else { - Props child = askQuestions(br, props); - if (child == null) { - // abort by user - return; + System.out.println(); + System.out.print("Do you want to add a child to " + props.getName() + "? (y/N) "); + String answer = br.readLine(); + if (answer==null) { + break; + } + answer = answer.toLowerCase(Locale.getDefault()); + if (answer.startsWith("n") || answer.length() == 0) + done = true; + else { + Props child = askQuestions(br, props); + if (child == null) { + // abort by user + return; + } + props.getChildren().add(child); } - props.getChildren().add(child); - }
- } while (!done); + } while (!done); + } catch (IOException ioe) { + System.err.println("Internal error happended: " + ioe.getMessage()); + } finally { + br.close(); + }
- log.info("\nYou have choosen:\n" + props.toString()); - postprocess(props); - generate(props); + if (props!=null) { + log.info("\nYou have chosen:\n" + props.toString()); + postprocess(props); + generate(props); + }
System.out.println("Don't forget to "); System.out.println(" - add your plugin to the parent pom.xml if needed"); @@ -345,11 +357,15 @@ public class PluginGen { Template templ = config.getTemplate(template + ".ftl");
Writer out = new BufferedWriter(new FileWriter(new File(directory, fileName))); - Map<String, Props> root = new HashMap<String, Props>(); - root.put("props", props); - templ.process(root, out); - out.flush(); - out.close(); + try { + Map<String, Props> root = new HashMap<String, Props>(); + root.put("props", props); + templ.process(root, out); + } + finally { + out.flush(); + out.close(); + } } catch (IOException ioe) { ioe.printStackTrace(); } catch (TemplateException te) { diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java index a657f42..4034184 100644 --- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java +++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java @@ -87,9 +87,9 @@ public class Props {
private Set<Template> templates = new HashSet<Template>();
- private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();; + private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();
- private Set<OperationProps> operations = new LinkedHashSet<OperationProps>();; + private Set<OperationProps> operations = new LinkedHashSet<OperationProps>();
private String pluginName; private String pluginDescription; diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java index 566af60..911ed41 100644 --- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java +++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java @@ -77,7 +77,7 @@ public enum ResourceCategory { public static ResourceCategory getByAbbrv(char abbrev) { EnumSet<ResourceCategory> set = EnumSet.allOf(ResourceCategory.class); for (ResourceCategory cat : set) { - if (cat.getAbbrev()==abbrev) + if (cat.abbrevLetter ==abbrev) return cat; } return null;
rhq-commits@lists.fedorahosted.org