Skip to content

Commit 71e6d5d

Browse files
committed
use txt files to store info
1 parent 016faa9 commit 71e6d5d

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ build/
1313
*.Module
1414
dependency-reduced-pom.xml
1515
.DS_Store
16-
tests/test-sigma/avaje-processors.txt
16+
*avaje-processors.txt
17+
*controllers.txt
1718
tests/test-sigma/io.avaje.jsonb.spi.JsonbExtension
19+
tests/test-javalin-jsonb/*.txt

http-generator-core/src/main/java/io/avaje/http/generator/core/AnnotationCopier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ static void copyAnnotations(Append writer, Element element, String indent, boole
3333
|| type.contains("Consumes")
3434
|| type.contains("InstrumentServerContext")
3535
|| type.contains("Default")
36-
|| type.contains("OpenAPI")) {
36+
|| type.contains("OpenAPI")
37+
|| type.contains("Valid")) {
3738
continue;
3839
}
3940

http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@
3939
})
4040
public abstract class BaseProcessor extends AbstractProcessor {
4141

42-
private static final String HTTP_CONTROLLERS_TXT = "controllers.txt";
43-
42+
private static final String HTTP_CONTROLLERS_TXT = "testAPI/controllers.txt";
4443
protected String contextPathString;
4544

4645
protected Map<String, String> packagePaths = new HashMap<>();
4746

48-
private final Set<String> controllerFQNs = new HashSet<>();
47+
private final Set<String> clientFQNs = new HashSet<>();
4948

5049
@Override
5150
public SourceVersion getSupportedSourceVersion() {
@@ -68,10 +67,12 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
6867
var txtFilePath = APContext.getBuildResource(HTTP_CONTROLLERS_TXT);
6968

7069
if (txtFilePath.toFile().exists()) {
71-
Files.lines(txtFilePath).forEach(controllerFQNs::add);
70+
Files.lines(txtFilePath).forEach(clientFQNs::add);
7271
}
7372
if (APContext.isTestCompilation()) {
74-
controllerFQNs.stream().map(APContext::typeElement).forEach(this::writeClientAdapter);
73+
for (var path : clientFQNs) {
74+
TestClientWriter.writeActual(path);
75+
}
7576
}
7677
} catch (IOException e) {
7778
e.printStackTrace();
@@ -124,7 +125,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
124125
try {
125126
Files.write(
126127
APContext.getBuildResource(HTTP_CONTROLLERS_TXT),
127-
controllerFQNs,
128+
clientFQNs,
128129
StandardOpenOption.CREATE,
129130
StandardOpenOption.WRITE);
130131
} catch (IOException e) {
@@ -175,26 +176,22 @@ private void writeAdapter(TypeElement controller) {
175176
try {
176177

177178
writeControllerAdapter(reader);
178-
controllerFQNs.add(controller.getQualifiedName().toString());
179+
writeClientAdapter(reader);
179180

180181
} catch (final Throwable e) {
181182
logError(reader.beanType(), "Failed to write $Route class " + e);
182183
}
183184
}
184185

185-
private void writeClientAdapter(TypeElement controller) {
186-
final var packageFQN = elements().getPackageOf(controller).getQualifiedName().toString();
187-
final var contextPath = Util.combinePath(contextPathString, packagePath(packageFQN));
188-
final var reader = new ControllerReader(controller, contextPath);
189-
reader.read(true);
186+
private void writeClientAdapter(ControllerReader reader) {
187+
190188
try {
191-
if (controller.getInterfaces().isEmpty()
192-
&& "java.lang.Object".equals(controller.getSuperclass().toString())) {
189+
if (reader.beanType().getInterfaces().isEmpty()
190+
&& "java.lang.Object".equals(reader.beanType().getSuperclass().toString())) {
193191
new TestClientWriter(reader).write();
192+
clientFQNs.add(reader.beanType().getQualifiedName().toString() + "$TestAPI");
194193
}
195-
writeControllerAdapter(reader);
196-
197-
} catch (final Throwable e) {
194+
} catch (final IOException e) {
198195
logError(reader.beanType(), "Failed to write $Route class " + e);
199196
}
200197
}

http-generator-core/src/main/java/io/avaje/http/generator/core/TestClientWriter.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import static java.util.stream.Collectors.toList;
44

5+
import java.io.FileWriter;
56
import java.io.IOException;
7+
import java.nio.file.Files;
68
import java.util.List;
79
import java.util.Set;
810
import java.util.TreeSet;
@@ -19,7 +21,6 @@ public class TestClientWriter {
1921
private String originName;
2022
private String shortName;
2123
private String packageName;
22-
private String fullName;
2324
private Append writer;
2425
private List<MethodReader> methods;
2526

@@ -30,7 +31,6 @@ public class TestClientWriter {
3031
this.originName = origin.getQualifiedName().toString();
3132
this.shortName = origin.getSimpleName().toString();
3233
this.packageName = initPackageName(originName);
33-
this.fullName = packageName + "." + shortName + "$TestAPI";
3434
this.methods =
3535
reader.methods().stream()
3636
.filter(MethodReader::isWebMethod)
@@ -42,7 +42,11 @@ public class TestClientWriter {
4242
&& m.webMethod() != CoreWebMethod.OTHER)
4343
.collect(toList());
4444
if (methods.isEmpty()) return;
45-
writer = new Append(APContext.createSourceFile(fullName, reader.beanType()).openWriter());
45+
46+
writer =
47+
new Append(
48+
new FileWriter(
49+
APContext.getBuildResource("testAPI/" + originName + "$TestAPI.txt").toFile()));
4650
}
4751

4852
protected String initPackageName(String originName) {
@@ -144,4 +148,14 @@ private void writeRoute(MethodReader method) {
144148
writer.eol();
145149
writer.eol();
146150
}
151+
152+
static void writeActual(String controller) throws IOException {
153+
154+
try (var out = APContext.createSourceFile(controller).openOutputStream();
155+
var in =
156+
Files.newInputStream(APContext.getBuildResource("testAPI/" + controller + ".txt")); ) {
157+
158+
in.transferTo(out);
159+
}
160+
}
147161
}

0 commit comments

Comments
 (0)