42
42
class JNativeScanTask {
43
43
44
44
private final PrintWriter out ;
45
+ private final PrintWriter err ;
45
46
private final List <Path > classPaths ;
46
47
private final List <Path > modulePaths ;
47
48
private final List <String > cmdRootModules ;
48
49
private final Runtime .Version version ;
49
50
private final Action action ;
50
51
51
- public JNativeScanTask (PrintWriter out , List <Path > classPaths , List <Path > modulePaths ,
52
+ public JNativeScanTask (PrintWriter out , PrintWriter err , List <Path > classPaths , List <Path > modulePaths ,
52
53
List <String > cmdRootModules , Runtime .Version version , Action action ) {
53
54
this .out = out ;
55
+ this .err = err ;
54
56
this .classPaths = classPaths ;
55
57
this .modulePaths = modulePaths ;
56
58
this .version = version ;
@@ -71,18 +73,21 @@ public void run() throws JNativeScanFatalError {
71
73
toScan .add (new ClassFileSource .Module (m .reference ()));
72
74
}
73
75
76
+ Set <String > errors = new LinkedHashSet <>();
77
+ Diagnostics diagnostics = (context , error ) ->
78
+ errors .add ("Error while processing method: " + context + ": " + error .getMessage ());
74
79
SortedMap <ClassFileSource , SortedMap <ClassDesc , List <RestrictedUse >>> allRestrictedMethods ;
75
80
try (ClassResolver classesToScan = ClassResolver .forClassFileSources (toScan , version );
76
81
ClassResolver systemClassResolver = ClassResolver .forSystemModules (version )) {
77
- NativeMethodFinder finder = NativeMethodFinder .create (classesToScan , systemClassResolver );
82
+ NativeMethodFinder finder = NativeMethodFinder .create (diagnostics , classesToScan , systemClassResolver );
78
83
allRestrictedMethods = finder .findAll ();
79
84
} catch (IOException e ) {
80
85
throw new RuntimeException (e );
81
86
}
82
87
83
88
switch (action ) {
84
89
case PRINT -> printNativeAccess (allRestrictedMethods );
85
- case DUMP_ALL -> dumpAll (allRestrictedMethods );
90
+ case DUMP_ALL -> dumpAll (allRestrictedMethods , errors );
86
91
}
87
92
}
88
93
@@ -156,7 +161,7 @@ private void printNativeAccess(SortedMap<ClassFileSource, SortedMap<ClassDesc, L
156
161
out .println (nativeAccess );
157
162
}
158
163
159
- private void dumpAll (SortedMap <ClassFileSource , SortedMap <ClassDesc , List <RestrictedUse >>> allRestrictedMethods ) {
164
+ private void dumpAll (SortedMap <ClassFileSource , SortedMap <ClassDesc , List <RestrictedUse >>> allRestrictedMethods , Set < String > errors ) {
160
165
if (allRestrictedMethods .isEmpty ()) {
161
166
out .println (" <no restricted methods>" );
162
167
} else {
@@ -177,6 +182,10 @@ private void dumpAll(SortedMap<ClassFileSource, SortedMap<ClassDesc, List<Restri
177
182
});
178
183
});
179
184
}
185
+ if (!errors .isEmpty ()) {
186
+ err .println ("Error(s) while processing classes:" );
187
+ errors .forEach (error -> err .println (" " + error ));
188
+ }
180
189
}
181
190
182
191
private static boolean isJarFile (Path path ) throws JNativeScanFatalError {
@@ -192,4 +201,8 @@ public static String qualName(ClassDesc desc) {
192
201
String packagePrefix = desc .packageName ().isEmpty () ? "" : desc .packageName () + "." ;
193
202
return packagePrefix + desc .displayName ();
194
203
}
204
+
205
+ interface Diagnostics {
206
+ void error (MethodRef context , JNativeScanFatalError error );
207
+ }
195
208
}
0 commit comments