springCoreDartBuilder function

Builder springCoreDartBuilder(
  1. BuilderOptions options
)

Creates the main builder (SpringBuilder), which writes the *.spring.dart files; build.yaml names it in builder_factories.

Two options tune it, set in the build.yaml of the application's package. They only change how much code is generated: a bean without matching advice is never wrapped at runtime either way.

  • aop_proxies (see ProxyMode): all (the default) generates a proxy class for every bean that can be implemented, interfaces proxies only the abstract supertypes of a bean (a bean without one gets no proxy), none no proxies at all. Any other value throws an ArgumentError.
  • aop_prune (true by default; anything but a bool throws an ArgumentError): the @SpringBootApplication output leaves out the proxy classes of beans that no pointcut of the application can match. @ComponentScan modules are never pruned, because any other module may import them and bring aspects the build cannot see.
targets:
  $default:
    builders:
      spring_core_dart_generator:spring_core_dart:
        options:
          # Smaller output: only beans with an abstract supertype can
          # be advised, through that type.
          aop_proxies: interfaces

Spring (Java):

// The closest Spring switch decides between JDK interface proxies and
// CGLIB class proxies for AnnotationAwareAspectJAutoProxyCreator:
@EnableAspectJAutoProxy(proxyTargetClass = false) // interfaces only
@Configuration
class AopConfig {}

Implementation

Builder springCoreDartBuilder(BuilderOptions options) {
  final mode = options.config['aop_proxies'] as String? ?? 'all';
  final prune = options.config['aop_prune'] ?? true;
  if (prune is! bool) {
    throw ArgumentError.value(prune, 'aop_prune', 'Expected true or false');
  }
  return SpringBuilder(
    pruneProxies: prune,
    proxyMode: ProxyMode.values.firstWhere(
      (m) => m.name == mode,
      orElse: () => throw ArgumentError.value(
        mode,
        'aop_proxies',
        'Expected all, interfaces or none',
      ),
    ),
  );
}