13
13
import javax .lang .model .element .TypeElement ;
14
14
import javax .lang .model .util .ElementFilter ;
15
15
import javax .lang .model .util .Elements ;
16
- import javax .tools .StandardLocation ;
16
+
17
+ import static java .util .stream .Collectors .joining ;
18
+ import static java .util .stream .Collectors .toSet ;
19
+
17
20
import java .io .IOException ;
18
- import java .net .URI ;
19
21
import java .nio .file .Files ;
20
- import java .nio .file .Paths ;
22
+ import java .nio .file .StandardOpenOption ;
21
23
import java .util .*;
22
24
import java .util .stream .Collectors ;
23
25
import java .util .stream .Stream ;
@@ -71,28 +73,42 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
71
73
this .defaultScope = allScopes .defaultScope ();
72
74
ExternalProvider .registerPluginProvidedTypes (defaultScope );
73
75
pluginFileProvided .forEach (defaultScope ::pluginProvided );
76
+
77
+ // write a note in target so that other apts can know inject is running
78
+ try {
79
+ var file = APContext .getBuildResource ("avaje-processors.txt" );
80
+ var addition = new StringBuilder ();
81
+ //if file exists, dedup and append current processor
82
+ if (file .toFile ().exists ()) {
83
+ var result = Stream .concat (Files .lines (file ), Stream .of ("avaje-inject-generator" ))
84
+ .distinct ()
85
+ .collect (joining ("\n " ));
86
+ addition .append (result );
87
+ } else {
88
+ addition .append ("avaje-inject-generator" );
89
+ }
90
+ Files .writeString (file , addition .toString (), StandardOpenOption .CREATE , StandardOpenOption .WRITE );
91
+ } catch (IOException e ) {
92
+ // not an issue worth failing over
93
+ }
74
94
}
75
95
76
96
/**
77
97
* Loads provider files generated by avaje-inject-maven-plugin
78
98
*/
79
99
void loadProvidedFiles () {
80
- this .performModuleValidation =
81
- lines ("target/avaje-plugin-exists.txt" ).isEmpty ()
82
- && lines ("build/avaje-plugin-exists.txt" ).isEmpty ();
83
- pluginFileProvided .addAll (lines ("target/avaje-plugin-provides.txt" ));
84
- moduleFileProvided .addAll (lines ("target/avaje-module-provides.txt" ));
85
- pluginFileProvided .addAll (lines ("build/avaje-plugin-provides.txt" ));
86
- moduleFileProvided .addAll (lines ("build/avaje-module-provides.txt" ));
100
+ performModuleValidation = lines ("avaje-plugin-exists.txt" ).isEmpty ();
101
+ pluginFileProvided .addAll (lines ("avaje-plugin-provides.txt" ));
102
+ moduleFileProvided .addAll (lines ("avaje-module-provides.txt" ));
87
103
}
88
104
89
105
/**
90
106
* Loads order files generated by avaje-inject-maven-plugin
91
107
*/
92
108
private void loadOrderFiles () {
93
109
Stream .concat (
94
- lines ("target/ avaje-module-dependencies.csv" ).stream ().skip (1 ),
95
- lines ("build/ avaje-module-dependencies.csv" ).stream ().skip (1 ))
110
+ lines ("avaje-module-dependencies.csv" ).stream ().skip (1 ),
111
+ lines ("avaje-module-dependencies.csv" ).stream ().skip (1 ))
96
112
.filter (s -> !s .startsWith ("External Module Type" ))
97
113
.distinct ()
98
114
.map (l -> l .split ("\\ |" ))
@@ -102,15 +118,7 @@ private void loadOrderFiles() {
102
118
103
119
private List <String > lines (String relativeName ) {
104
120
try {
105
- final String resource =
106
- processingEnv
107
- .getFiler ()
108
- .getResource (StandardLocation .CLASS_OUTPUT , "" , relativeName )
109
- .toUri ()
110
- .toString ()
111
- .replaceFirst ("/target/classes" , "" )
112
- .replaceFirst ("/build/classes/java/main" , "" );
113
- return Files .readAllLines (Paths .get (new URI (resource )));
121
+ return Files .readAllLines (APContext .getBuildResource (relativeName ));
114
122
} catch (final Exception e ) {
115
123
return Collections .emptyList ();
116
124
}
0 commit comments