2424
2525public class JmxScraper {
2626 private static final Logger logger = Logger .getLogger (JmxScraper .class .getName ());
27+ private static final String CONFIG_ARG = "-config" ;
2728
2829 private final JmxRemoteClient client ;
2930
@@ -40,11 +41,11 @@ public static void main(String[] args) {
4041 JmxScraperConfig config ;
4142 JmxScraper jmxScraper = null ;
4243 try {
43- JmxScraperConfigFactory factory = new JmxScraperConfigFactory ();
44- config = JmxScraper .createConfigFromArgs (Arrays .asList (args ), factory );
44+ config = JmxScraper .createConfigFromArgs (Arrays .asList (args ));
4545 jmxScraper = new JmxScraper (config );
4646
4747 } catch (ArgumentsParsingException e ) {
48+ System .err .println ("ERROR: " + e .getMessage ());
4849 System .err .println (
4950 "Usage: java -jar <path_to_jmxscraper.jar> "
5051 + "-config <path_to_config.properties or - for stdin>" );
@@ -67,23 +68,27 @@ public static void main(String[] args) {
6768 *
6869 * @param args application commandline arguments
6970 */
70- static JmxScraperConfig createConfigFromArgs (List <String > args , JmxScraperConfigFactory factory )
71+ static JmxScraperConfig createConfigFromArgs (List <String > args )
7172 throws ArgumentsParsingException , ConfigurationException {
72- if (!args .isEmpty () && (args .size () != 2 || !args .get (0 ).equalsIgnoreCase ("-config" ))) {
73- throw new ArgumentsParsingException ();
73+
74+ if (args .isEmpty ()) {
75+ throw new ArgumentsParsingException ("no argument provided" );
76+ }
77+ if (args .size () != 2 ) {
78+ throw new ArgumentsParsingException ("exactly two arguments expected, got " + args .size ());
79+ }
80+ if (!args .get (0 ).equalsIgnoreCase (CONFIG_ARG )) {
81+ throw new ArgumentsParsingException ("unexpected first argument must be '" + CONFIG_ARG + "'" );
7482 }
7583
7684 Properties loadedProperties = new Properties ();
77- if (args .size () == 2 ) {
78- String path = args .get (1 );
79- if (path .trim ().equals ("-" )) {
80- loadPropertiesFromStdin (loadedProperties );
81- } else {
82- loadPropertiesFromPath (loadedProperties , path );
83- }
85+ String path = args .get (1 );
86+ if (path .trim ().equals ("-" )) {
87+ loadPropertiesFromStdin (loadedProperties );
88+ } else {
89+ loadPropertiesFromPath (loadedProperties , path );
8490 }
85-
86- return factory .createConfig (loadedProperties );
91+ return new JmxScraperConfigFactory ().createConfig (loadedProperties );
8792 }
8893
8994 private static void loadPropertiesFromStdin (Properties props ) throws ConfigurationException {
0 commit comments