@@ -20,8 +20,7 @@ protected CordaCaplet(Capsule pred) {
20
20
}
21
21
22
22
private Config parseConfigFile (List <String > args ) {
23
- String baseDirOption = getOption (args , "--base-directory" );
24
- this .baseDir = Paths .get ((baseDirOption == null ) ? "." : baseDirOption ).toAbsolutePath ().normalize ().toString ();
23
+ this .baseDir = getBaseDirectory (args );
25
24
String config = getOption (args , "--config-file" );
26
25
File configFile = (config == null ) ? new File (baseDir , "node.conf" ) : new File (config );
27
26
try {
@@ -36,17 +35,44 @@ private Config parseConfigFile(List<String> args) {
36
35
}
37
36
}
38
37
38
+ File getConfigFile (List <String > args , String baseDir ) {
39
+ String config = getOptionMultiple (args , Arrays .asList ("--config-file" , "-f" ));
40
+ return (config == null || config .equals ("" )) ? new File (baseDir , "node.conf" ) : new File (config );
41
+ }
42
+
43
+ String getBaseDirectory (List <String > args ) {
44
+ String baseDir = getOptionMultiple (args , Arrays .asList ("--base-directory" , "-b" ));
45
+ return Paths .get ((baseDir == null ) ? "." : baseDir ).toAbsolutePath ().normalize ().toString ();
46
+ }
47
+
48
+ private String getOptionMultiple (List <String > args , List <String > possibleOptions ) {
49
+ String result = null ;
50
+ for (String option : possibleOptions ) {
51
+ result = getOption (args , option );
52
+ if (result != null ) break ;
53
+ }
54
+ return result ;
55
+ }
56
+
39
57
private String getOption (List <String > args , String option ) {
40
58
final String lowerCaseOption = option .toLowerCase ();
41
59
int index = 0 ;
42
60
for (String arg : args ) {
43
61
if (arg .toLowerCase ().equals (lowerCaseOption )) {
44
- if (index < args .size () - 1 ) {
62
+ if (index < args .size () - 1 && ! args . get ( index + 1 ). startsWith ( "-" ) ) {
45
63
return args .get (index + 1 );
46
64
} else {
47
65
return null ;
48
66
}
49
67
}
68
+
69
+ if (arg .toLowerCase ().startsWith (lowerCaseOption )) {
70
+ if (arg .length () > option .length () && arg .substring (option .length (), option .length () + 1 ).equals ("=" )) {
71
+ return arg .substring (option .length () + 1 );
72
+ } else {
73
+ return null ;
74
+ }
75
+ }
50
76
index ++;
51
77
}
52
78
return null ;
@@ -82,7 +108,10 @@ protected <T> T attribute(Map.Entry<String, T> attr) {
82
108
83
109
File cordappsDir = new File (baseDir , "cordapps" );
84
110
// Create cordapps directory if it doesn't exist.
85
- requireCordappsDirExists (cordappsDir );
111
+ if (!checkIfCordappDirExists (cordappsDir )) {
112
+ // If it fails, just return the existing class path. The main Corda jar will detect the error and fail gracefully.
113
+ return cp ;
114
+ }
86
115
// Add additional directories of JARs to the classpath (at the end), e.g., for JDBC drivers.
87
116
augmentClasspath ((List <Path >) cp , cordappsDir );
88
117
try {
@@ -152,17 +181,18 @@ private static void checkJavaVersion() {
152
181
}
153
182
}
154
183
155
- private void requireCordappsDirExists (File dir ) {
184
+ private Boolean checkIfCordappDirExists (File dir ) {
156
185
try {
157
186
if (!dir .mkdir () && !dir .exists ()) { // It is unlikely to enter this if-branch, but just in case.
158
187
logOnFailedCordappDir ();
159
- throw new RuntimeException ( "Cordapps dir could not be created" ); // Let Capsule handle the error (log error, clean up, die).
188
+ return false ;
160
189
}
161
190
}
162
191
catch (SecurityException | NullPointerException e ) {
163
192
logOnFailedCordappDir ();
164
- throw e ; // Let Capsule handle the error (log error, clean up, die).
193
+ return false ;
165
194
}
195
+ return true ;
166
196
}
167
197
168
198
private void logOnFailedCordappDir () {
0 commit comments