13
13
import javax .lang .model .util .ElementFilter ;
14
14
import javax .lang .model .util .Elements ;
15
15
import javax .tools .StandardLocation ;
16
- import java .io .BufferedReader ;
17
16
import java .io .IOException ;
18
- import java .io .InputStreamReader ;
19
17
import java .net .URI ;
18
+ import java .nio .file .Files ;
19
+ import java .nio .file .Paths ;
20
20
import java .util .*;
21
21
import java .util .stream .Collectors ;
22
22
@@ -47,6 +47,7 @@ public final class Processor extends AbstractProcessor {
47
47
private boolean readModuleInfo ;
48
48
private final Set <String > pluginFileProvided = new HashSet <>();
49
49
private final Set <String > moduleFileProvided = new HashSet <>();
50
+ private boolean performModuleValidation ;
50
51
51
52
@ Override
52
53
public SourceVersion getSupportedSourceVersion () {
@@ -56,45 +57,43 @@ public SourceVersion getSupportedSourceVersion() {
56
57
@ Override
57
58
public synchronized void init (ProcessingEnvironment processingEnv ) {
58
59
super .init (processingEnv );
59
- loadProvidedFiles (processingEnv .getFiler ());
60
- ProcessingContext .init (processingEnv , moduleFileProvided );
60
+ APContext .init (processingEnv );
61
+ loadProvidedFiles ();
62
+ ProcessingContext .init (moduleFileProvided , performModuleValidation );
61
63
this .elementUtils = processingEnv .getElementUtils ();
62
64
this .allScopes = new AllScopes ();
63
65
this .defaultScope = allScopes .defaultScope ();
64
66
ExternalProvider .registerPluginProvidedTypes (defaultScope );
65
67
pluginFileProvided .forEach (defaultScope ::pluginProvided );
66
68
}
67
69
68
- /**
69
- * Loads provider files generated by avaje-inject-maven-plugin
70
- */
71
- void loadProvidedFiles (Filer filer ) {
72
- pluginFileProvided .addAll (lines (filer , "target/avaje-plugin-provides.txt" , "/target/classes" ));
73
- moduleFileProvided .addAll (lines (filer , "target/avaje-module-provides.txt" , "/target/classes" ));
74
- pluginFileProvided .addAll (lines (filer , "build/avaje-plugin-provides.txt" , "/build/classes/java/main" ));
75
- moduleFileProvided .addAll (lines (filer , "build/avaje-module-provides.txt" , "/build/classes/java/main" ));
70
+ /** Loads provider files generated by avaje-inject-maven-plugin */
71
+ void loadProvidedFiles () {
72
+ this .performModuleValidation =
73
+ lines ("target/avaje-plugin-exists.txt" ).isEmpty ()
74
+ && lines ("build/avaje-plugin-exists.txt" ).isEmpty ();
75
+ pluginFileProvided .addAll (lines ("target/avaje-plugin-provides.txt" ));
76
+ moduleFileProvided .addAll (lines ("target/avaje-module-provides.txt" ));
77
+ pluginFileProvided .addAll (lines ("build/avaje-plugin-provides.txt" ));
78
+ moduleFileProvided .addAll (lines ("build/avaje-module-provides.txt" ));
76
79
}
77
80
78
- private static List <String > lines (Filer filer , String relativeName , String replace ) {
81
+ private List <String > lines (String relativeName ) {
79
82
try {
80
- final String resource = resource (filer , relativeName , replace );
81
- try (var inputStream = new URI (resource ).toURL ().openStream ();
82
- var reader = new BufferedReader (new InputStreamReader (inputStream ))) {
83
- return reader .lines ().collect (Collectors .toList ());
84
- }
83
+ final String resource =
84
+ processingEnv
85
+ .getFiler ()
86
+ .getResource (StandardLocation .CLASS_OUTPUT , "" , relativeName )
87
+ .toUri ()
88
+ .toString ()
89
+ .replaceFirst ("/target/classes" , "" )
90
+ .replaceFirst ("/build/classes/java/main" , "" );
91
+ return Files .readAllLines (Paths .get (new URI (resource )));
85
92
} catch (final Exception e ) {
86
93
return Collections .emptyList ();
87
94
}
88
95
}
89
96
90
- private static String resource (Filer filer , String relativeName , String replace ) throws IOException {
91
- return filer
92
- .getResource (StandardLocation .CLASS_OUTPUT , "" , relativeName )
93
- .toUri ()
94
- .toString ()
95
- .replace (replace , "" );
96
- }
97
-
98
97
@ Override
99
98
public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
100
99
APContext .setProjectModuleElement (annotations , roundEnv );
0 commit comments