Skip to content

Commit

Permalink
Graal: Report controller methods and generate file to build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Sep 5, 2018
1 parent 6de2481 commit 526ef41
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static void reportMissing(String type) {
}
}


/**
* Finish reporting classloading.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.micronaut.context.processor.ExecutableMethodProcessor;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.StringUtils;
Expand Down Expand Up @@ -162,6 +163,11 @@ public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> met
LOG.debug("Created Route to Function: {}", route);
}

ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}

String functionPath = resolveFunctionPath(methodName, declaringType, functionName);
availableFunctions.put(functionName, URI.create(functionPath));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,30 @@ public boolean isEnabled() {
return false;
} else {
String f = System.getProperty(REFLECTION_JSON_FILE);
File file = new File(StringUtils.isNotEmpty(f) ? f : "./reflect.json");
boolean enabled = !file.exists();
if (enabled) {
System.out.println("Graal Class Loading Analysis Enabled.");
if (StringUtils.isNotEmpty(f)) {
File file = new File(f);
boolean enabled = !file.exists();
if (enabled) {
System.out.println("Graal Class Loading Analysis Enabled.");
}
return enabled;
} else {
File parent = new File("build");
if (!parent.exists() || !parent.isDirectory()) {
parent = new File("target");
}

if (!parent.exists() || !parent.isDirectory()) {
return false;
} else {
File file = new File(parent, "reflect.json");
boolean enabled = !file.exists();
if (enabled) {
System.out.println("Graal Class Loading Analysis Enabled.");
}
return enabled;
}
}
return enabled;
}
}

Expand All @@ -92,7 +110,21 @@ public void onMissing(String name) {
@Override
public void close() {
String f = System.getProperty(REFLECTION_JSON_FILE);
File file = new File(StringUtils.isNotEmpty(f) ? f : "./reflect.json");
File file;
if (StringUtils.isNotEmpty(f)) {
file = new File(f);
} else {
File parent = new File("build");
if (!parent.exists() || !parent.isDirectory()) {
parent = new File("target");
}

if (!parent.exists() || !parent.isDirectory()) {
return;
} else {
file = new File(parent, "reflect.json");
}
}

if (!file.exists()) {
ClassLoader cls = GraalClassLoadingReporter.class.getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.micronaut.core.async.subscriber.Completable;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.type.Argument;
import io.micronaut.http.uri.UriTemplate;
import io.micronaut.inject.BeanDefinition;
Expand Down Expand Up @@ -98,7 +99,13 @@ public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> met
Class<?> declaringType = method.getDeclaringType();
if (method.hasStereotype(getSupportedAnnotation())) {
Optional<String> endPointId = resolveActiveEndPointId(declaringType);
endPointId.ifPresent(id -> registerRoute(method, id));
endPointId.ifPresent(id -> {
ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}
registerRoute(method, id);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.micronaut.context.processor.ExecutableMethodProcessor;
import io.micronaut.core.annotation.AnnotationValue;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.util.StringUtils;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
Expand Down Expand Up @@ -240,6 +241,10 @@ public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> met
actionAnn.ifPresent(annotationClass -> {
BiConsumer<BeanDefinition, ExecutableMethod> handler = httpMethodsHandlers.get(annotationClass);
if (handler != null) {
ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}
handler.accept(beanDefinition, method);
}
}
Expand Down

0 comments on commit 526ef41

Please sign in to comment.