22
22
23
23
import java .io .File ;
24
24
import java .io .FileInputStream ;
25
+ import java .util .Enumeration ;
25
26
import java .util .Properties ;
26
27
27
28
/**
@@ -68,6 +69,18 @@ public static String getArgString( String argName ) {
68
69
* @return the arguments parsed
69
70
*/
70
71
public static Properties getArgs ( String [] args , boolean checkParamFile ) {
72
+ return getArgs ( args , checkParamFile , true );
73
+ }
74
+
75
+ /**
76
+ * <p>Parse an argument list as a property object.</p>
77
+ *
78
+ * @param args command line arguments
79
+ * @param checkParamFile true if param-file should be checked if the argument is set.
80
+ * @param priorityToParamFile true if param-file arguments should override command line arguments
81
+ * @return the arguments parsed
82
+ */
83
+ public static Properties getArgs ( String [] args , boolean checkParamFile , boolean priorityToParamFile ) {
71
84
Properties props = new Properties ();
72
85
if ( args != null ) {
73
86
String currentkey = null ;
@@ -94,7 +107,19 @@ public static Properties getArgs( String[] args, boolean checkParamFile ) {
94
107
File f = new File ( paramFile );
95
108
try {
96
109
FileInputStream fis = new FileInputStream ( f );
97
- props .load ( fis );
110
+ if ( priorityToParamFile ) {
111
+ props .load ( fis );
112
+ } else {
113
+ Properties toLoad = new Properties ();
114
+ toLoad .load ( fis );
115
+ Enumeration <Object > keys = toLoad .keys ();
116
+ while ( keys .hasMoreElements () ) {
117
+ String currentKey = keys .nextElement ().toString ();
118
+ if ( !props .contains ( currentKey ) ) {
119
+ props .setProperty ( currentKey , toLoad .getProperty ( currentKey ) );
120
+ }
121
+ }
122
+ }
98
123
fis .close ();
99
124
} catch (Exception e ) {
100
125
throw new RuntimeException ( e );
0 commit comments