Skip to content

Commit

Permalink
commandLine: flyway.consoleWidth property should be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
panchenko committed Mar 7, 2013
1 parent 19ded0e commit 3163d63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -81,7 +81,7 @@ public static void main(String[] args) {
Flyway flyway = new Flyway(); Flyway flyway = new Flyway();
flyway.configure(properties); flyway.configure(properties);


int consoleWidth = Integer.parseInt(properties.getProperty("flyway.consoleWidth")); int consoleWidth = PropertiesUtils.getIntProperty(properties, "flyway.consoleWidth", 80, true);


executeOperation(flyway, operation, consoleWidth); executeOperation(flyway, operation, consoleWidth);
} catch (Exception e) { } catch (Exception e) {
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/ */
package com.googlecode.flyway.core.util; package com.googlecode.flyway.core.util;


import com.googlecode.flyway.core.util.logging.LogFactory;

import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
Expand Down Expand Up @@ -104,4 +106,20 @@ private static String unescape(String str) {
} }
return outBuffer.toString(); return outBuffer.toString();
} }

public static int getIntProperty(Properties properties, String key, int defaultValue, boolean useDefaultOnError) {
final String value = properties.getProperty(key);
if (value != null) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
if (useDefaultOnError) {
LogFactory.getLog(PropertiesUtils.class).debug(e.toString());
} else {
throw e;
}
}
}
return defaultValue;
}
} }

0 comments on commit 3163d63

Please sign in to comment.