Search in sources :

Example 1 with BuildContext

use of io.quarkus.builder.BuildContext in project quarkus by quarkusio.

the class QuarkusDeployableContainer method deploy.

@SuppressWarnings("rawtypes")
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    old = Thread.currentThread().getContextClassLoader();
    if (testClass.get() == null) {
        throw new IllegalStateException("Test class not available");
    }
    Class testJavaClass = testClass.get().getJavaClass();
    // some TCK tests embed random libraries such as old versions of Jackson databind
    // this breaks quarkus, so we just skip them
    boolean skipLibraries = Boolean.getBoolean("io.quarkus.arquillian.skip-libraries");
    try {
        // Export the test archive
        Path tmpLocation = Files.createTempDirectory("quarkus-arquillian-test");
        deploymentLocation.set(tmpLocation);
        archive.as(ExplodedExporter.class).exportExplodedInto(tmpLocation.toFile());
        Path appLocation;
        Set<Path> libraries = new HashSet<>();
        if (archive instanceof WebArchive) {
            // Quarkus does not support the WAR layout and so adapt the layout (similarly to quarkus-war-launcher)
            appLocation = tmpLocation.resolve("app").toAbsolutePath();
            // WEB-INF/lib -> lib/
            if (!skipLibraries) {
                if (Files.exists(tmpLocation.resolve("WEB-INF/lib"))) {
                    Files.move(tmpLocation.resolve("WEB-INF/lib"), tmpLocation.resolve("lib"));
                }
            }
            // WEB-INF/classes -> archive/
            if (Files.exists(tmpLocation.resolve("WEB-INF/classes"))) {
                Files.move(tmpLocation.resolve("WEB-INF/classes"), appLocation);
            } else {
                Files.createDirectory(appLocation);
            }
            // META-INF -> archive/META-INF/
            if (Files.exists(tmpLocation.resolve("META-INF"))) {
                if (Files.exists(appLocation.resolve("META-INF"))) {
                    // Target directory not empty.
                    try (Stream<Path> fileTreeElements = Files.walk(tmpLocation.resolve("META-INF"), 2)) {
                        fileTreeElements.forEach(p -> {
                            try {
                                Files.createFile(p);
                            } catch (FileAlreadyExistsException faee) {
                            // Do Nothing
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        });
                    }
                } else {
                    Files.move(tmpLocation.resolve("META-INF"), appLocation.resolve("META-INF"));
                }
            }
            // WEB-INF -> archive/WEB-INF
            if (Files.exists(tmpLocation.resolve("WEB-INF"))) {
                Files.move(tmpLocation.resolve("WEB-INF"), appLocation.resolve("WEB-INF"));
            }
            // Collect all libraries
            if (Files.exists(tmpLocation.resolve("lib"))) {
                try (Stream<Path> libs = Files.walk(tmpLocation.resolve("lib"), 1)) {
                    libs.forEach((i) -> {
                        if (i.getFileName().toString().endsWith(".jar")) {
                            libraries.add(i);
                        }
                    });
                }
            }
        } else {
            appLocation = tmpLocation;
        }
        List<Consumer<BuildChainBuilder>> customizers = new ArrayList<>();
        // Test class is a bean
        customizers.add(new Consumer<BuildChainBuilder>() {

            @Override
            public void accept(BuildChainBuilder buildChainBuilder) {
                buildChainBuilder.addBuildStep(new BuildStep() {

                    @Override
                    public void execute(BuildContext context) {
                        context.produce(AdditionalBeanBuildItem.unremovableOf(testJavaClass));
                    }
                }).produces(AdditionalBeanBuildItem.class).build();
            }
        });
        QuarkusBootstrap.Builder bootstrapBuilder = QuarkusBootstrap.builder().setApplicationRoot(appLocation).setProjectRoot(appLocation).setIsolateDeployment(false).setFlatClassPath(true).setMode(QuarkusBootstrap.Mode.TEST);
        for (Path i : libraries) {
            bootstrapBuilder.addAdditionalApplicationArchive(new AdditionalDependency(i, false, true));
        }
        // Path testLocation = PathTestHelper.getTestClassesLocation(testJavaClass);
        // bootstrapBuilder.setProjectRoot(PathTestHelper.getTestClassesLocation(testJavaClass));
        CuratedApplication curatedApplication = bootstrapBuilder.build().bootstrap();
        AugmentAction augmentAction = new AugmentActionImpl(curatedApplication, customizers);
        StartupAction app = augmentAction.createInitialRuntimeApplication();
        RunningQuarkusApplication runningQuarkusApplication = app.run();
        appClassloader.set(runningQuarkusApplication.getClassLoader());
        runningApp.set(runningQuarkusApplication);
        Thread.currentThread().setContextClassLoader(runningQuarkusApplication.getClassLoader());
        // Instantiate the real test instance
        testInstance = TestInstantiator.instantiateTest(testJavaClass, runningQuarkusApplication.getClassLoader());
        // its pretty bogus
        if (Boolean.getBoolean("io.quarkus.arquillian.copy-fields")) {
            Class<?> dest = testInstance.getClass();
            Class<?> source = testClass.get().getJavaClass();
            while (source != Object.class) {
                for (Field f : source.getDeclaredFields()) {
                    try {
                        if (Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers())) {
                            Field df = dest.getDeclaredField(f.getName());
                            df.setAccessible(true);
                            f.setAccessible(true);
                            df.set(null, f.get(null));
                        }
                    } catch (Exception e) {
                        LOGGER.error("Failed to copy static field", e);
                    }
                }
                source = source.getSuperclass();
                dest = dest.getSuperclass();
            }
        }
    } catch (Throwable t) {
        // clone the exception into the correct class loader
        Throwable nt;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ObjectOutputStream a = new ObjectOutputStream(out)) {
            a.writeObject(t);
            a.close();
            nt = (Throwable) new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
        } catch (Exception e) {
            throw new DeploymentException("Unable to start the runtime runner", t);
        }
        throw new DeploymentException("Unable to start the runtime runner", nt);
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
    ProtocolMetaData metadata = new ProtocolMetaData();
    // TODO: fix this
    String testUri = TestHTTPResourceManager.getUri(runningApp.get());
    System.setProperty("test.url", testUri);
    URI uri = URI.create(testUri);
    HTTPContext httpContext = new HTTPContext(uri.getHost(), uri.getPort());
    // This is to work around https://github.com/arquillian/arquillian-core/issues/216
    httpContext.add(new Servlet("dummy", "/"));
    metadata.addContext(httpContext);
    return metadata;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.builder.BuildStep) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) Field(java.lang.reflect.Field) Consumer(java.util.function.Consumer) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) ExplodedExporter(org.jboss.shrinkwrap.api.exporter.ExplodedExporter) HashSet(java.util.HashSet) AugmentActionImpl(io.quarkus.runner.bootstrap.AugmentActionImpl) Path(java.nio.file.Path) AugmentAction(io.quarkus.bootstrap.app.AugmentAction) StartupAction(io.quarkus.bootstrap.app.StartupAction) RunningQuarkusApplication(io.quarkus.bootstrap.app.RunningQuarkusApplication) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) TestClass(org.jboss.arquillian.test.spi.TestClass) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with BuildContext

use of io.quarkus.builder.BuildContext in project quarkus by quarkusio.

the class IsolatedDevModeMain method accept.

// the main entry point, but loaded inside the augmentation class loader
@Override
public void accept(CuratedApplication o, Map<String, Object> params) {
    // setup the dev mode thread pool for NIO
    System.setProperty("java.nio.channels.DefaultThreadPool.threadFactory", "io.quarkus.dev.io.NioThreadPoolThreadFactory");
    Timing.staticInitStarted(o.getBaseRuntimeClassLoader(), false);
    // https://github.com/quarkusio/quarkus/issues/9748
    // if you have an app with all daemon threads then the app thread
    // may be the only thread keeping the JVM alive
    // during the restart process when this thread is stopped then
    // the JVM will die
    // we start this thread to keep the JVM alive until the shutdown hook is run
    // even for command mode we still want the JVM to live until it receives
    // a signal to make the 'press enter to restart' function to work
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                shutdownLatch.await();
            } catch (InterruptedException ignore) {
            }
        }
    }, "Quarkus Devmode keep alive thread").start();
    try {
        curatedApplication = o;
        Object potentialContext = params.get(DevModeContext.class.getName());
        if (potentialContext instanceof DevModeContext) {
            context = (DevModeContext) potentialContext;
        } else {
            // this was from the external class loader
            // we need to copy it into this one
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ObjectOutputStream oo = new ObjectOutputStream(out);
            oo.writeObject(potentialContext);
            context = (DevModeContext) new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
        }
        augmentAction = new AugmentActionImpl(curatedApplication, Collections.singletonList(new Consumer<BuildChainBuilder>() {

            @Override
            public void accept(BuildChainBuilder buildChainBuilder) {
                buildChainBuilder.addBuildStep(new BuildStep() {

                    @Override
                    public void execute(BuildContext context) {
                        // we need to make sure all hot reloadable classes are application classes
                        context.produce(new ApplicationClassPredicateBuildItem(new Predicate<String>() {

                            @Override
                            public boolean test(String s) {
                                QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
                                // if the class file is present in this (and not the parent) CL then it is an application class
                                List<ClassPathElement> res = cl.getElementsWithResource(s.replace('.', '/') + ".class", true);
                                return !res.isEmpty();
                            }
                        }));
                    }
                }).produces(ApplicationClassPredicateBuildItem.class).build();
            }
        }), Collections.emptyList());
        List<CodeGenData> codeGens = new ArrayList<>();
        QuarkusClassLoader deploymentClassLoader = curatedApplication.createDeploymentClassLoader();
        for (DevModeContext.ModuleInfo module : context.getAllModules()) {
            if (!module.getSourceParents().isEmpty() && module.getPreBuildOutputDir() != null) {
                // it's null for remote dev
                codeGens.addAll(CodeGenerator.init(deploymentClassLoader, module.getSourceParents(), Paths.get(module.getPreBuildOutputDir()), Paths.get(module.getTargetDir()), sourcePath -> module.addSourcePathFirst(sourcePath.toAbsolutePath().toString())));
            }
        }
        RuntimeUpdatesProcessor.INSTANCE = setupRuntimeCompilation(context, (Path) params.get(APP_ROOT), (DevModeType) params.get(DevModeType.class.getName()));
        if (RuntimeUpdatesProcessor.INSTANCE != null) {
            RuntimeUpdatesProcessor.INSTANCE.checkForFileChange();
            RuntimeUpdatesProcessor.INSTANCE.checkForChangedClasses(true);
        }
        firstStart(deploymentClassLoader, codeGens);
        // doStart(false, Collections.emptySet());
        if (deploymentProblem != null || RuntimeUpdatesProcessor.INSTANCE.getCompileProblem() != null) {
            if (context.isAbortOnFailedStart()) {
                throw new RuntimeException(deploymentProblem == null ? RuntimeUpdatesProcessor.INSTANCE.getCompileProblem() : deploymentProblem);
            }
        }
        shutdownThread = new Thread(new Runnable() {

            @Override
            public void run() {
                shutdownLatch.countDown();
                synchronized (DevModeMain.class) {
                    if (runner != null) {
                        try {
                            close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }, "Quarkus Shutdown Thread");
        Runtime.getRuntime().addShutdownHook(shutdownThread);
    } catch (Exception e) {
        close();
        throw new RuntimeException(e);
    }
}
Also used : BiFunction(java.util.function.BiFunction) ObjectInputStream(java.io.ObjectInputStream) ClassTransformingBuildStep(io.quarkus.deployment.steps.ClassTransformingBuildStep) CommandLineUtils(org.apache.maven.shared.utils.cli.CommandLineUtils) ConfigProviderResolver(org.eclipse.microprofile.config.spi.ConfigProviderResolver) ApplicationLifecycleManager(io.quarkus.runtime.ApplicationLifecycleManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) AugmentAction(io.quarkus.bootstrap.app.AugmentAction) ConsoleStateManager(io.quarkus.deployment.console.ConsoleStateManager) DevConsoleManager(io.quarkus.dev.console.DevConsoleManager) InitialConfigurator(io.quarkus.bootstrap.logging.InitialConfigurator) Path(java.nio.file.Path) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) LoggingSetupRecorder(io.quarkus.runtime.logging.LoggingSetupRecorder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AugmentActionImpl(io.quarkus.runner.bootstrap.AugmentActionImpl) Set(java.util.Set) BLUE(io.quarkus.deployment.dev.testing.MessageFormat.BLUE) ServiceLoader(java.util.ServiceLoader) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) StartupAction(io.quarkus.bootstrap.app.StartupAction) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) MessageFormat(io.quarkus.deployment.dev.testing.MessageFormat) BuildStep(io.quarkus.builder.BuildStep) ColorPatternFormatter(org.jboss.logmanager.formatters.ColorPatternFormatter) BuildContext(io.quarkus.builder.BuildContext) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunningQuarkusApplication(io.quarkus.bootstrap.app.RunningQuarkusApplication) DevModeType(io.quarkus.dev.spi.DevModeType) Logger(org.jboss.logging.Logger) DeploymentFailedStartHandler(io.quarkus.dev.spi.DeploymentFailedStartHandler) LaunchMode(io.quarkus.runtime.LaunchMode) ClassChangeInformation(io.quarkus.bootstrap.app.ClassChangeInformation) Timing(io.quarkus.bootstrap.runner.Timing) BindException(java.net.BindException) TestSupport(io.quarkus.deployment.dev.testing.TestSupport) CodeGenData(io.quarkus.deployment.codegen.CodeGenData) ArrayList(java.util.ArrayList) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) ApplicationClassPredicateBuildItem(io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem) BiConsumer(java.util.function.BiConsumer) ObjectOutputStream(java.io.ObjectOutputStream) ApplicationStartException(io.quarkus.dev.appstate.ApplicationStartException) QuarkusConfigFactory(io.quarkus.runtime.configuration.QuarkusConfigFactory) HotReplacementSetup(io.quarkus.dev.spi.HotReplacementSetup) Properties(java.util.Properties) ClassPathElement(io.quarkus.bootstrap.classloading.ClassPathElement) CommandLineException(org.apache.maven.shared.utils.cli.CommandLineException) IOException(java.io.IOException) ConsoleCommand(io.quarkus.deployment.console.ConsoleCommand) Consumer(java.util.function.Consumer) Paths(java.nio.file.Paths) Closeable(java.io.Closeable) CodeGenerator(io.quarkus.deployment.CodeGenerator) Comparator(java.util.Comparator) FSWatchUtil(io.quarkus.deployment.util.FSWatchUtil) Collections(java.util.Collections) ArrayList(java.util.ArrayList) ClassTransformingBuildStep(io.quarkus.deployment.steps.ClassTransformingBuildStep) BuildStep(io.quarkus.builder.BuildStep) ApplicationClassPredicateBuildItem(io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem) ClassPathElement(io.quarkus.bootstrap.classloading.ClassPathElement) ObjectOutputStream(java.io.ObjectOutputStream) Predicate(java.util.function.Predicate) AugmentActionImpl(io.quarkus.runner.bootstrap.AugmentActionImpl) Path(java.nio.file.Path) CodeGenData(io.quarkus.deployment.codegen.CodeGenData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) BindException(java.net.BindException) ApplicationStartException(io.quarkus.dev.appstate.ApplicationStartException) CommandLineException(org.apache.maven.shared.utils.cli.CommandLineException) IOException(java.io.IOException) BuildContext(io.quarkus.builder.BuildContext) ByteArrayInputStream(java.io.ByteArrayInputStream) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) DevModeType(io.quarkus.dev.spi.DevModeType) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with BuildContext

use of io.quarkus.builder.BuildContext in project quarkus by quarkusio.

the class SyntheticObserverTest method buildCustomizer.

static Consumer<BuildChainBuilder> buildCustomizer() {
    return new Consumer<BuildChainBuilder>() {

        @Override
        public void accept(BuildChainBuilder builder) {
            builder.addBuildStep(new BuildStep() {

                @Override
                public void execute(BuildContext context) {
                    ObserverRegistrationPhaseBuildItem observerRegistrationPhase = context.consume(ObserverRegistrationPhaseBuildItem.class);
                    context.produce(new ObserverConfiguratorBuildItem(observerRegistrationPhase.getContext().configure().beanClass(DotName.createSimple(SyntheticObserverTest.class.getName())).observedType(String.class).notify(mc -> {
                        ResultHandle events = mc.readStaticField(FieldDescriptor.of(MyObserver.class, "EVENTS", List.class));
                        mc.invokeInterfaceMethod(MethodDescriptor.ofMethod(List.class, "add", boolean.class, Object.class), events, mc.load("synthetic"));
                        mc.returnValue(null);
                    })));
                }
            }).consumes(ObserverRegistrationPhaseBuildItem.class).produces(ObserverConfiguratorBuildItem.class).build();
        }
    };
}
Also used : Consumer(java.util.function.Consumer) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) BuildStep(io.quarkus.builder.BuildStep) ResultHandle(io.quarkus.gizmo.ResultHandle) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ObserverRegistrationPhaseBuildItem(io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem) ObserverConfiguratorBuildItem(io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem)

Example 4 with BuildContext

use of io.quarkus.builder.BuildContext in project camel-quarkus by apache.

the class CamelContextCustomizerTest method buildCustomizer.

static Consumer<BuildChainBuilder> buildCustomizer() {
    return new Consumer<BuildChainBuilder>() {

        @Override
        public void accept(BuildChainBuilder builder) {
            builder.addBuildStep(new BuildStep() {

                @Override
                public void execute(BuildContext context) {
                    String methodName = "execute";
                    BytecodeRecorderImpl bri = new BytecodeRecorderImpl(true, getClass().getSimpleName(), methodName, Integer.toString(methodName.hashCode()), true, s -> null);
                    RuntimeValue<CamelContextCustomizer> value = bri.newInstance(RestConfigurationCustomizer.class.getName());
                    context.produce(new CamelContextCustomizerBuildItem(value));
                    context.produce(new StaticBytecodeRecorderBuildItem(bri));
                }
            }).produces(CamelContextCustomizerBuildItem.class).produces(StaticBytecodeRecorderBuildItem.class).build();
        }
    };
}
Also used : CamelContextCustomizer(org.apache.camel.spi.CamelContextCustomizer) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) Consumer(java.util.function.Consumer) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) BuildStep(io.quarkus.builder.BuildStep) StaticBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem) BytecodeRecorderImpl(io.quarkus.deployment.recording.BytecodeRecorderImpl)

Example 5 with BuildContext

use of io.quarkus.builder.BuildContext in project quarkus by quarkusio.

the class ExtensionLoader method loadStepsFromClass.

/**
 * Load all the build steps from the given class.
 *
 * @param clazz the class to load from (must not be {@code null})
 * @param readResult the build time configuration read result (must not be {@code null})
 * @param runTimeProxies the map of run time proxy objects to populate for recorders (must not be {@code null})
 * @return a consumer which adds the steps to the given chain builder
 */
private static Consumer<BuildChainBuilder> loadStepsFromClass(Class<?> clazz, BuildTimeConfigurationReader.ReadResult readResult, Map<Class<?>, Object> runTimeProxies, BooleanSupplierFactoryBuildItem supplierFactory) {
    final Constructor<?>[] constructors = clazz.getDeclaredConstructors();
    // this is the chain configuration that will contain all steps on this class and be returned
    Consumer<BuildChainBuilder> chainConfig = Functions.discardingConsumer();
    if (Modifier.isAbstract(clazz.getModifiers())) {
        return chainConfig;
    }
    // this is the step configuration that applies to all steps on this class
    Consumer<BuildStepBuilder> stepConfig = Functions.discardingConsumer();
    // this is the build step instance setup that applies to all steps on this class
    BiConsumer<BuildContext, Object> stepInstanceSetup = Functions.discardingBiConsumer();
    if (constructors.length != 1) {
        throw reportError(clazz, "Build step classes must have exactly one constructor");
    }
    EnumSet<ConfigPhase> consumingConfigPhases = EnumSet.noneOf(ConfigPhase.class);
    final Constructor<?> constructor = constructors[0];
    if (!(Modifier.isPublic(constructor.getModifiers())))
        constructor.setAccessible(true);
    final Parameter[] ctorParameters = constructor.getParameters();
    final List<Function<BuildContext, Object>> ctorParamFns;
    if (ctorParameters.length == 0) {
        ctorParamFns = Collections.emptyList();
    } else {
        ctorParamFns = new ArrayList<>(ctorParameters.length);
        for (Parameter parameter : ctorParameters) {
            Type parameterType = parameter.getParameterizedType();
            final Class<?> parameterClass = parameter.getType();
            final boolean weak = parameter.isAnnotationPresent(Weak.class);
            final boolean overridable = parameter.isAnnotationPresent(Overridable.class);
            if (rawTypeExtends(parameterType, SimpleBuildItem.class)) {
                final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOf(parameterType).asSubclass(SimpleBuildItem.class);
                stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                ctorParamFns.add(bc -> bc.consume(buildItemClass));
            } else if (isListOf(parameterType, MultiBuildItem.class)) {
                final Class<? extends MultiBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(MultiBuildItem.class);
                stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                ctorParamFns.add(bc -> bc.consumeMulti(buildItemClass));
            } else if (isConsumerOf(parameterType, BuildItem.class)) {
                deprecatedProducer(parameter);
                final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(BuildItem.class);
                if (overridable) {
                    if (weak) {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                    } else {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                    }
                } else {
                    if (weak) {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                    } else {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                    }
                }
                ctorParamFns.add(bc -> (Consumer<? extends BuildItem>) bc::produce);
            } else if (isBuildProducerOf(parameterType, BuildItem.class)) {
                deprecatedProducer(parameter);
                final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(BuildItem.class);
                if (overridable) {
                    if (weak) {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                    } else {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                    }
                } else {
                    if (weak) {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                    } else {
                        stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                    }
                }
                ctorParamFns.add(bc -> (BuildProducer<? extends BuildItem>) bc::produce);
            } else if (isOptionalOf(parameterType, SimpleBuildItem.class)) {
                final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(SimpleBuildItem.class);
                stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
                ctorParamFns.add(bc -> Optional.ofNullable(bc.consume(buildItemClass)));
            } else if (isSupplierOf(parameterType, SimpleBuildItem.class)) {
                final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(SimpleBuildItem.class);
                stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                ctorParamFns.add(bc -> (Supplier<? extends SimpleBuildItem>) () -> bc.consume(buildItemClass));
            } else if (isSupplierOfOptionalOf(parameterType, SimpleBuildItem.class)) {
                final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(rawTypeOfParameter(parameterType, 0), 0).asSubclass(SimpleBuildItem.class);
                stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
                ctorParamFns.add(bc -> (Supplier<Optional<? extends SimpleBuildItem>>) () -> Optional.ofNullable(bc.consume(buildItemClass)));
            } else if (rawTypeOf(parameterType) == Executor.class) {
                ctorParamFns.add(BuildContext::getExecutor);
            } else if (parameterClass.isAnnotationPresent(ConfigRoot.class)) {
                final ConfigRoot annotation = parameterClass.getAnnotation(ConfigRoot.class);
                final ConfigPhase phase = annotation.phase();
                consumingConfigPhases.add(phase);
                if (phase.isAvailableAtBuild()) {
                    ctorParamFns.add(bc -> bc.consume(ConfigurationBuildItem.class).getReadResult().requireObjectForClass(parameterClass));
                    if (phase == ConfigPhase.BUILD_AND_RUN_TIME_FIXED) {
                        runTimeProxies.computeIfAbsent(parameterClass, readResult::requireObjectForClass);
                    }
                } else if (phase.isReadAtMain()) {
                    throw reportError(parameter, phase + " configuration cannot be consumed here");
                } else {
                    throw reportError(parameterClass, "Unknown value for ConfigPhase");
                }
            } else if (isRecorder(parameterClass)) {
                throw reportError(parameter, "Bytecode recorders disallowed on constructor parameters");
            } else {
                throw reportError(parameter, "Unsupported constructor parameter type " + parameterType);
            }
        }
    }
    // index fields
    final Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        final int mods = field.getModifiers();
        if (Modifier.isStatic(mods)) {
            // ignore static fields
            continue;
        }
        if (Modifier.isFinal(mods)) {
            // ignore final fields
            continue;
        }
        if (!Modifier.isPublic(mods) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) {
            field.setAccessible(true);
        }
        // next, determine the type
        final Type fieldType = field.getGenericType();
        final Class<?> fieldClass = field.getType();
        final boolean weak = field.isAnnotationPresent(Weak.class);
        final boolean overridable = field.isAnnotationPresent(Overridable.class);
        if (rawTypeExtends(fieldType, SimpleBuildItem.class)) {
            final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOf(fieldType).asSubclass(SimpleBuildItem.class);
            stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, bc.consume(buildItemClass)));
        } else if (isListOf(fieldType, MultiBuildItem.class)) {
            final Class<? extends MultiBuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(MultiBuildItem.class);
            stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, bc.consumeMulti(buildItemClass)));
        } else if (isConsumerOf(fieldType, BuildItem.class)) {
            deprecatedProducer(field);
            final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(BuildItem.class);
            if (overridable) {
                if (weak) {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                } else {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                }
            } else {
                if (weak) {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                } else {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                }
            }
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, (Consumer<? extends BuildItem>) bc::produce));
        } else if (isBuildProducerOf(fieldType, BuildItem.class)) {
            deprecatedProducer(field);
            final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(BuildItem.class);
            if (overridable) {
                if (weak) {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                } else {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                }
            } else {
                if (weak) {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                } else {
                    stepConfig = stepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                }
            }
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, (BuildProducer<? extends BuildItem>) bc::produce));
        } else if (isOptionalOf(fieldType, SimpleBuildItem.class)) {
            final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(SimpleBuildItem.class);
            stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, Optional.ofNullable(bc.consume(buildItemClass))));
        } else if (isSupplierOf(fieldType, SimpleBuildItem.class)) {
            final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(SimpleBuildItem.class);
            stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, (Supplier<? extends SimpleBuildItem>) () -> bc.consume(buildItemClass)));
        } else if (isSupplierOfOptionalOf(fieldType, SimpleBuildItem.class)) {
            final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(rawTypeOfParameter(fieldType, 0), 0).asSubclass(SimpleBuildItem.class);
            stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, (Supplier<Optional<? extends SimpleBuildItem>>) () -> Optional.ofNullable(bc.consume(buildItemClass))));
        } else if (fieldClass == Executor.class) {
            stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, bc.getExecutor()));
        } else if (fieldClass.isAnnotationPresent(ConfigRoot.class)) {
            final ConfigRoot annotation = fieldClass.getAnnotation(ConfigRoot.class);
            final ConfigPhase phase = annotation.phase();
            consumingConfigPhases.add(phase);
            if (phase.isAvailableAtBuild()) {
                stepInstanceSetup = stepInstanceSetup.andThen((bc, o) -> {
                    final ConfigurationBuildItem configurationBuildItem = bc.consume(ConfigurationBuildItem.class);
                    ReflectUtil.setFieldVal(field, o, configurationBuildItem.getReadResult().requireObjectForClass(fieldClass));
                });
                if (phase == ConfigPhase.BUILD_AND_RUN_TIME_FIXED) {
                    runTimeProxies.computeIfAbsent(fieldClass, readResult::requireObjectForClass);
                }
            } else if (phase.isReadAtMain()) {
                throw reportError(field, phase + " configuration cannot be consumed here");
            } else {
                throw reportError(fieldClass, "Unknown value for ConfigPhase");
            }
        } else if (isRecorder(fieldClass)) {
            throw reportError(field, "Bytecode recorders disallowed on fields");
        } else {
            throw reportError(field, "Unsupported field type " + fieldType);
        }
    }
    // now iterate the methods
    final List<Method> methods = getMethods(clazz);
    for (Method method : methods) {
        final BuildStep buildStep = method.getAnnotation(BuildStep.class);
        if (buildStep == null) {
            continue;
        }
        if (Modifier.isStatic(method.getModifiers())) {
            throw new RuntimeException("A build step must be a non-static method: " + method);
        }
        if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) {
            method.setAccessible(true);
        }
        final Class<? extends BooleanSupplier>[] onlyIf = buildStep.onlyIf();
        final Class<? extends BooleanSupplier>[] onlyIfNot = buildStep.onlyIfNot();
        final Parameter[] methodParameters = method.getParameters();
        final Record recordAnnotation = method.getAnnotation(Record.class);
        final boolean isRecorder = recordAnnotation != null;
        final boolean identityComparison = isRecorder ? recordAnnotation.useIdentityComparisonForParameters() : true;
        if (isRecorder) {
            boolean recorderFound = false;
            for (Class<?> p : method.getParameterTypes()) {
                if (isRecorder(p)) {
                    recorderFound = true;
                    break;
                }
            }
            if (!recorderFound) {
                throw new RuntimeException(method + " is marked @Record but does not inject an @Recorder object");
            }
        }
        final List<BiFunction<BuildContext, BytecodeRecorderImpl, Object>> methodParamFns;
        Consumer<BuildStepBuilder> methodStepConfig = Functions.discardingConsumer();
        BooleanSupplier addStep = () -> true;
        for (boolean inv : new boolean[] { false, true }) {
            Class<? extends BooleanSupplier>[] testClasses = inv ? onlyIfNot : onlyIf;
            for (Class<? extends BooleanSupplier> testClass : testClasses) {
                BooleanSupplier bs = supplierFactory.get((Class<? extends BooleanSupplier>) testClass);
                if (inv) {
                    addStep = and(addStep, not(bs));
                } else {
                    addStep = and(addStep, bs);
                }
            }
        }
        final BooleanSupplier finalAddStep = addStep;
        if (isRecorder) {
            assert recordAnnotation != null;
            final ExecutionTime executionTime = recordAnnotation.value();
            final boolean optional = recordAnnotation.optional();
            methodStepConfig = methodStepConfig.andThen(bsb -> {
                bsb.produces(executionTime == ExecutionTime.STATIC_INIT ? StaticBytecodeRecorderBuildItem.class : MainBytecodeRecorderBuildItem.class, optional ? ProduceFlags.of(ProduceFlag.WEAK) : ProduceFlags.NONE);
            });
        }
        EnumSet<ConfigPhase> methodConsumingConfigPhases = consumingConfigPhases.clone();
        if (methodParameters.length == 0) {
            methodParamFns = Collections.emptyList();
        } else {
            methodParamFns = new ArrayList<>(methodParameters.length);
            for (Parameter parameter : methodParameters) {
                final boolean weak = parameter.isAnnotationPresent(Weak.class);
                final boolean overridable = parameter.isAnnotationPresent(Overridable.class);
                final Type parameterType = parameter.getParameterizedType();
                final Class<?> parameterClass = parameter.getType();
                if (rawTypeExtends(parameterType, SimpleBuildItem.class)) {
                    final Class<? extends SimpleBuildItem> buildItemClass = parameterClass.asSubclass(SimpleBuildItem.class);
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                    methodParamFns.add((bc, bri) -> bc.consume(buildItemClass));
                } else if (isListOf(parameterType, MultiBuildItem.class)) {
                    final Class<? extends MultiBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(MultiBuildItem.class);
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                    methodParamFns.add((bc, bri) -> bc.consumeMulti(buildItemClass));
                } else if (isConsumerOf(parameterType, BuildItem.class)) {
                    final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(BuildItem.class);
                    if (overridable) {
                        if (weak) {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                        } else {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                        }
                    } else {
                        if (weak) {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                        } else {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                        }
                    }
                    methodParamFns.add((bc, bri) -> (Consumer<? extends BuildItem>) bc::produce);
                } else if (isBuildProducerOf(parameterType, BuildItem.class)) {
                    final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(BuildItem.class);
                    if (overridable) {
                        if (weak) {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                        } else {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.OVERRIDABLE));
                        }
                    } else {
                        if (weak) {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass, ProduceFlag.WEAK));
                        } else {
                            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(buildItemClass));
                        }
                    }
                    methodParamFns.add((bc, bri) -> (BuildProducer<? extends BuildItem>) bc::produce);
                } else if (isOptionalOf(parameterType, SimpleBuildItem.class)) {
                    final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(SimpleBuildItem.class);
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
                    methodParamFns.add((bc, bri) -> Optional.ofNullable(bc.consume(buildItemClass)));
                } else if (isSupplierOf(parameterType, SimpleBuildItem.class)) {
                    final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0).asSubclass(SimpleBuildItem.class);
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
                    methodParamFns.add((bc, bri) -> (Supplier<? extends SimpleBuildItem>) () -> bc.consume(buildItemClass));
                } else if (isSupplierOfOptionalOf(parameterType, SimpleBuildItem.class)) {
                    final Class<? extends SimpleBuildItem> buildItemClass = rawTypeOfParameter(rawTypeOfParameter(parameterType, 0), 0).asSubclass(SimpleBuildItem.class);
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(buildItemClass, ConsumeFlags.of(ConsumeFlag.OPTIONAL)));
                    methodParamFns.add((bc, bri) -> (Supplier<Optional<? extends SimpleBuildItem>>) () -> Optional.ofNullable(bc.consume(buildItemClass)));
                } else if (rawTypeOf(parameterType) == Executor.class) {
                    methodParamFns.add((bc, bri) -> bc.getExecutor());
                } else if (parameterClass.isAnnotationPresent(ConfigRoot.class)) {
                    final ConfigRoot annotation = parameterClass.getAnnotation(ConfigRoot.class);
                    final ConfigPhase phase = annotation.phase();
                    methodConsumingConfigPhases.add(phase);
                    if (phase.isAvailableAtBuild()) {
                        methodParamFns.add((bc, bri) -> {
                            final ConfigurationBuildItem configurationBuildItem = bc.consume(ConfigurationBuildItem.class);
                            return configurationBuildItem.getReadResult().requireObjectForClass(parameterClass);
                        });
                        if (isRecorder && phase == ConfigPhase.BUILD_AND_RUN_TIME_FIXED) {
                            runTimeProxies.computeIfAbsent(parameterClass, readResult::requireObjectForClass);
                        }
                    } else if (phase.isReadAtMain()) {
                        if (isRecorder) {
                            methodParamFns.add((bc, bri) -> {
                                final RunTimeConfigurationProxyBuildItem proxies = bc.consume(RunTimeConfigurationProxyBuildItem.class);
                                return proxies.getProxyObjectFor(parameterClass);
                            });
                            runTimeProxies.computeIfAbsent(parameterClass, ConfigMappingUtils::newInstance);
                        } else {
                            throw reportError(parameter, phase + " configuration cannot be consumed here unless the method is a @Recorder");
                        }
                    } else {
                        throw reportError(parameterClass, "Unknown value for ConfigPhase");
                    }
                } else if (isRecorder(parameter.getType())) {
                    if (!isRecorder) {
                        throw reportError(parameter, "Cannot pass recorders to method which is not annotated with " + Record.class);
                    }
                    methodParamFns.add((bc, bri) -> {
                        assert bri != null;
                        return bri.getRecordingProxy(parameterClass);
                    });
                    // now look for recorder parameter injection
                    // as we now inject config directly into recorders we need to look at the constructor params
                    Constructor<?>[] ctors = parameter.getType().getDeclaredConstructors();
                    for (var ctor : ctors) {
                        if (ctors.length == 1 || ctor.isAnnotationPresent(Inject.class)) {
                            for (var type : ctor.getGenericParameterTypes()) {
                                Class<?> theType = null;
                                if (type instanceof ParameterizedType) {
                                    ParameterizedType pt = (ParameterizedType) type;
                                    if (pt.getRawType().equals(RuntimeValue.class)) {
                                        theType = (Class<?>) pt.getActualTypeArguments()[0];
                                    } else {
                                        throw new RuntimeException("Unknown recorder constructor parameter: " + type + " in recorder " + parameter.getType());
                                    }
                                } else {
                                    theType = (Class<?>) type;
                                }
                                ConfigRoot annotation = theType.getAnnotation(ConfigRoot.class);
                                if (annotation != null) {
                                    if (recordAnnotation.value() == ExecutionTime.STATIC_INIT) {
                                        methodConsumingConfigPhases.add(ConfigPhase.BUILD_AND_RUN_TIME_FIXED);
                                    } else {
                                        methodConsumingConfigPhases.add(annotation.phase());
                                    }
                                    if (annotation.phase().isReadAtMain()) {
                                        runTimeProxies.computeIfAbsent(theType, ConfigMappingUtils::newInstance);
                                    } else {
                                        runTimeProxies.computeIfAbsent(theType, readResult::requireObjectForClass);
                                    }
                                }
                            }
                        }
                    }
                } else if (parameter.getType() == RecorderContext.class || parameter.getType() == BytecodeRecorderImpl.class) {
                    if (!isRecorder) {
                        throw reportError(parameter, "Cannot pass recorder context to method which is not annotated with " + Record.class);
                    }
                    methodParamFns.add((bc, bri) -> bri);
                } else {
                    throw reportError(parameter, "Unsupported method parameter " + parameterType);
                }
            }
        }
        final BiConsumer<BuildContext, Object> resultConsumer;
        final Type returnType = method.getGenericReturnType();
        final boolean weak = method.isAnnotationPresent(Weak.class);
        final boolean overridable = method.isAnnotationPresent(Overridable.class);
        if (rawTypeIs(returnType, void.class)) {
            resultConsumer = Functions.discardingBiConsumer();
        } else if (rawTypeExtends(returnType, BuildItem.class)) {
            final Class<? extends BuildItem> type = method.getReturnType().asSubclass(BuildItem.class);
            if (overridable) {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE));
                }
            } else {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type));
                }
            }
            resultConsumer = (bc, o) -> {
                if (o != null)
                    bc.produce((BuildItem) o);
            };
        } else if (isOptionalOf(returnType, BuildItem.class)) {
            final Class<? extends BuildItem> type = rawTypeOfParameter(returnType, 0).asSubclass(BuildItem.class);
            if (overridable) {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE));
                }
            } else {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type));
                }
            }
            resultConsumer = (bc, o) -> ((Optional<? extends BuildItem>) o).ifPresent(bc::produce);
        } else if (isListOf(returnType, MultiBuildItem.class)) {
            final Class<? extends MultiBuildItem> type = rawTypeOfParameter(returnType, 0).asSubclass(MultiBuildItem.class);
            if (overridable) {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.OVERRIDABLE));
                }
            } else {
                if (weak) {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type, ProduceFlag.WEAK));
                } else {
                    methodStepConfig = methodStepConfig.andThen(bsb -> bsb.produces(type));
                }
            }
            resultConsumer = (bc, o) -> {
                if (o != null)
                    bc.produce((List<? extends MultiBuildItem>) o);
            };
        } else {
            throw reportError(method, "Unsupported method return type " + returnType);
        }
        if (methodConsumingConfigPhases.contains(ConfigPhase.BOOTSTRAP) || methodConsumingConfigPhases.contains(ConfigPhase.RUN_TIME)) {
            if (isRecorder && recordAnnotation.value() == ExecutionTime.STATIC_INIT) {
                throw reportError(method, "Bytecode recorder is static but an injected config object is declared as run time");
            }
            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(RunTimeConfigurationProxyBuildItem.class));
            if (methodConsumingConfigPhases.contains(ConfigPhase.BOOTSTRAP)) {
                methodStepConfig = methodStepConfig.andThen(bsb -> bsb.afterProduce(BootstrapConfigSetupCompleteBuildItem.class));
            }
            if (methodConsumingConfigPhases.contains(ConfigPhase.RUN_TIME)) {
                methodStepConfig = methodStepConfig.andThen(bsb -> bsb.afterProduce(RuntimeConfigSetupCompleteBuildItem.class));
            }
        }
        if (methodConsumingConfigPhases.contains(ConfigPhase.BUILD_AND_RUN_TIME_FIXED) || methodConsumingConfigPhases.contains(ConfigPhase.BUILD_TIME)) {
            methodStepConfig = methodStepConfig.andThen(bsb -> bsb.consumes(ConfigurationBuildItem.class));
        }
        final Consume[] consumes = method.getAnnotationsByType(Consume.class);
        if (consumes.length > 0) {
            methodStepConfig = methodStepConfig.andThen(bsb -> {
                for (Consume consume : consumes) {
                    bsb.afterProduce(consume.value());
                }
            });
        }
        final Produce[] produces = method.getAnnotationsByType(Produce.class);
        if (produces.length > 0) {
            methodStepConfig = methodStepConfig.andThen(bsb -> {
                for (Produce produce : produces) {
                    bsb.beforeConsume(produce.value());
                }
            });
        }
        final ProduceWeak[] produceWeaks = method.getAnnotationsByType(ProduceWeak.class);
        if (produceWeaks.length > 0) {
            methodStepConfig = methodStepConfig.andThen(bsb -> {
                for (ProduceWeak produceWeak : produceWeaks) {
                    bsb.beforeConsume(produceWeak.value(), ProduceFlag.WEAK);
                }
            });
        }
        final Consumer<BuildStepBuilder> finalStepConfig = stepConfig.andThen(methodStepConfig).andThen(buildStepBuilder -> buildStepBuilder.buildIf(finalAddStep));
        final BiConsumer<BuildContext, Object> finalStepInstanceSetup = stepInstanceSetup;
        final String name = clazz.getName() + "#" + method.getName();
        chainConfig = chainConfig.andThen(bcb -> {
            BuildStepBuilder bsb = bcb.addBuildStep(new io.quarkus.builder.BuildStep() {

                public void execute(final BuildContext bc) {
                    Object[] ctorArgs = new Object[ctorParamFns.size()];
                    for (int i = 0; i < ctorArgs.length; i++) {
                        ctorArgs[i] = ctorParamFns.get(i).apply(bc);
                    }
                    Object instance;
                    try {
                        instance = constructor.newInstance(ctorArgs);
                    } catch (InstantiationException e) {
                        throw ReflectUtil.toError(e);
                    } catch (IllegalAccessException e) {
                        throw ReflectUtil.toError(e);
                    } catch (InvocationTargetException e) {
                        try {
                            throw e.getCause();
                        } catch (RuntimeException | Error e2) {
                            throw e2;
                        } catch (Throwable t) {
                            throw new IllegalStateException(t);
                        }
                    }
                    finalStepInstanceSetup.accept(bc, instance);
                    Object[] methodArgs = new Object[methodParamFns.size()];
                    BytecodeRecorderImpl bri = isRecorder ? new BytecodeRecorderImpl(recordAnnotation.value() == ExecutionTime.STATIC_INIT, clazz.getSimpleName(), method.getName(), Integer.toString(Math.abs(method.toString().hashCode())), identityComparison, s -> {
                        if (s instanceof Class) {
                            var cfg = ((Class<?>) s).getAnnotation(ConfigRoot.class);
                            if (cfg == null || (cfg.phase() != ConfigPhase.BUILD_AND_RUN_TIME_FIXED && recordAnnotation.value() == ExecutionTime.STATIC_INIT)) {
                                throw new RuntimeException("Can only inject BUILD_AND_RUN_TIME_FIXED objects into a constructor, use RuntimeValue to inject runtime config: " + s);
                            }
                            return runTimeProxies.get(s);
                        }
                        if (s instanceof ParameterizedType) {
                            ParameterizedType p = (ParameterizedType) s;
                            if (p.getRawType() == RuntimeValue.class) {
                                Object object = runTimeProxies.get(p.getActualTypeArguments()[0]);
                                if (object == null) {
                                    return new RuntimeValue<>();
                                }
                                return new RuntimeValue<>(object);
                            }
                        }
                        return null;
                    }) : null;
                    for (int i = 0; i < methodArgs.length; i++) {
                        methodArgs[i] = methodParamFns.get(i).apply(bc, bri);
                    }
                    Object result;
                    try {
                        result = method.invoke(instance, methodArgs);
                    } catch (IllegalAccessException e) {
                        throw ReflectUtil.toError(e);
                    } catch (InvocationTargetException e) {
                        try {
                            throw e.getCause();
                        } catch (RuntimeException | Error e2) {
                            throw e2;
                        } catch (Throwable t) {
                            throw new IllegalStateException(t);
                        }
                    }
                    resultConsumer.accept(bc, result);
                    if (isRecorder) {
                        // commit recorded data
                        if (recordAnnotation.value() == ExecutionTime.STATIC_INIT) {
                            bc.produce(new StaticBytecodeRecorderBuildItem(bri));
                        } else {
                            bc.produce(new MainBytecodeRecorderBuildItem(bri));
                        }
                    }
                }

                public String toString() {
                    return name;
                }
            });
            finalStepConfig.accept(bsb);
        });
    }
    return chainConfig;
}
Also used : RootDefinition(io.quarkus.deployment.configuration.definition.RootDefinition) ReflectUtil.isSupplierOfOptionalOf(io.quarkus.deployment.util.ReflectUtil.isSupplierOfOptionalOf) RecorderContext(io.quarkus.deployment.recording.RecorderContext) BooleanSupplier(java.util.function.BooleanSupplier) Functions(org.wildfly.common.function.Functions) ReflectUtil.isSupplierOf(io.quarkus.deployment.util.ReflectUtil.isSupplierOf) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BytecodeCreator(io.quarkus.gizmo.BytecodeCreator) Recorder(io.quarkus.runtime.annotations.Recorder) ConsumeFlags(io.quarkus.builder.ConsumeFlags) RunTimeConfigurationProxyBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationProxyBuildItem) ReflectUtil.rawTypeIs(io.quarkus.deployment.util.ReflectUtil.rawTypeIs) KeyMap(io.smallrye.config.KeyMap) EnumSet(java.util.EnumSet) Consume(io.quarkus.deployment.annotations.Consume) Member(java.lang.reflect.Member) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem) StaticBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem) ReflectUtil.isBuildProducerOf(io.quarkus.deployment.util.ReflectUtil.isBuildProducerOf) InvocationTargetException(java.lang.reflect.InvocationTargetException) Weak(io.quarkus.deployment.annotations.Weak) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ConsumeFlag(io.quarkus.builder.ConsumeFlag) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) ConfigClassWithPrefix(io.smallrye.config.ConfigMappings.ConfigClassWithPrefix) ResultHandle(io.quarkus.gizmo.ResultHandle) AnnotatedElement(java.lang.reflect.AnnotatedElement) Record(io.quarkus.deployment.annotations.Record) ProduceWeak(io.quarkus.deployment.annotations.ProduceWeak) DevModeType(io.quarkus.dev.spi.DevModeType) ReflectUtil.rawTypeOf(io.quarkus.deployment.util.ReflectUtil.rawTypeOf) BuildStepBuilder(io.quarkus.builder.BuildStepBuilder) BuildItem(io.quarkus.builder.item.BuildItem) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ConfigRoot(io.quarkus.runtime.annotations.ConfigRoot) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) Parameter(java.lang.reflect.Parameter) BiConsumer(java.util.function.BiConsumer) KeyMapBackedConfigSource(io.smallrye.config.KeyMapBackedConfigSource) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) IOException(java.io.IOException) Field(java.lang.reflect.Field) FieldDescriptor(io.quarkus.gizmo.FieldDescriptor) ParameterizedType(java.lang.reflect.ParameterizedType) SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) ConfigPhase(io.quarkus.runtime.annotations.ConfigPhase) BiFunction(java.util.function.BiFunction) ProduceFlags(io.quarkus.builder.ProduceFlags) Overridable(io.quarkus.deployment.annotations.Overridable) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ConfigProviderResolver(org.eclipse.microprofile.config.spi.ConfigProviderResolver) ProduceFlag(io.quarkus.builder.ProduceFlag) ReflectUtil(io.quarkus.deployment.util.ReflectUtil) Method(java.lang.reflect.Method) BootstrapConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.BootstrapConfigSetupCompleteBuildItem) IdentityHashMap(java.util.IdentityHashMap) ReflectUtil.isOptionalOf(io.quarkus.deployment.util.ReflectUtil.isOptionalOf) ReflectUtil.rawTypeExtends(io.quarkus.deployment.util.ReflectUtil.rawTypeExtends) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Config(org.eclipse.microprofile.config.Config) DefaultValuesConfigurationSource(io.quarkus.deployment.configuration.DefaultValuesConfigurationSource) List(java.util.List) BuildContext(io.quarkus.builder.BuildContext) Type(java.lang.reflect.Type) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) ConfigMappingUtils(io.quarkus.deployment.configuration.ConfigMappingUtils) ConfigUtils(io.quarkus.runtime.configuration.ConfigUtils) Logger(org.jboss.logging.Logger) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) Function(java.util.function.Function) ReflectUtil.isConsumerOf(io.quarkus.deployment.util.ReflectUtil.isConsumerOf) Inject(javax.inject.Inject) ConfigurationBuildItem(io.quarkus.deployment.builditem.ConfigurationBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) ReflectUtil.isListOf(io.quarkus.deployment.util.ReflectUtil.isListOf) RuntimeValue(io.quarkus.runtime.RuntimeValue) RuntimeConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem) ObjectLoader(io.quarkus.deployment.recording.ObjectLoader) QuarkusConfigFactory(io.quarkus.runtime.configuration.QuarkusConfigFactory) BytecodeRecorderObjectLoaderBuildItem(io.quarkus.deployment.builditem.BytecodeRecorderObjectLoaderBuildItem) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) BuildTimeConfigurationReader(io.quarkus.deployment.configuration.BuildTimeConfigurationReader) Produce(io.quarkus.deployment.annotations.Produce) Consumer(java.util.function.Consumer) MultiBuildItem(io.quarkus.builder.item.MultiBuildItem) NameIterator(io.smallrye.config.NameIterator) ReflectUtil.rawTypeOfParameter(io.quarkus.deployment.util.ReflectUtil.rawTypeOfParameter) ServiceUtil(io.quarkus.deployment.util.ServiceUtil) BytecodeRecorderImpl(io.quarkus.deployment.recording.BytecodeRecorderImpl) Collections(java.util.Collections) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ConfigRoot(io.quarkus.runtime.annotations.ConfigRoot) Produce(io.quarkus.deployment.annotations.Produce) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) ConfigPhase(io.quarkus.runtime.annotations.ConfigPhase) Optional(java.util.Optional) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consume(io.quarkus.deployment.annotations.Consume) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) RuntimeValue(io.quarkus.runtime.RuntimeValue) MultiBuildItem(io.quarkus.builder.item.MultiBuildItem) RecorderContext(io.quarkus.deployment.recording.RecorderContext) BuildStep(io.quarkus.deployment.annotations.BuildStep) StaticBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem) ParameterizedType(java.lang.reflect.ParameterizedType) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Field(java.lang.reflect.Field) Executor(java.util.concurrent.Executor) BooleanSupplier(java.util.function.BooleanSupplier) Supplier(java.util.function.Supplier) Record(io.quarkus.deployment.annotations.Record) ConfigurationBuildItem(io.quarkus.deployment.builditem.ConfigurationBuildItem) BooleanSupplier(java.util.function.BooleanSupplier) BytecodeRecorderImpl(io.quarkus.deployment.recording.BytecodeRecorderImpl) Constructor(java.lang.reflect.Constructor) RunTimeConfigurationProxyBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationProxyBuildItem) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem) StaticBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem) BuildItem(io.quarkus.builder.item.BuildItem) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) BootstrapConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.BootstrapConfigSetupCompleteBuildItem) ConfigurationBuildItem(io.quarkus.deployment.builditem.ConfigurationBuildItem) RuntimeConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem) BytecodeRecorderObjectLoaderBuildItem(io.quarkus.deployment.builditem.BytecodeRecorderObjectLoaderBuildItem) MultiBuildItem(io.quarkus.builder.item.MultiBuildItem) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) DevModeType(io.quarkus.dev.spi.DevModeType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) BuildStepBuilder(io.quarkus.builder.BuildStepBuilder) BiFunction(java.util.function.BiFunction) RunTimeConfigurationProxyBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationProxyBuildItem) ProduceWeak(io.quarkus.deployment.annotations.ProduceWeak) Parameter(java.lang.reflect.Parameter) ReflectUtil.rawTypeOfParameter(io.quarkus.deployment.util.ReflectUtil.rawTypeOfParameter) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem)

Aggregations

BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)10 BuildContext (io.quarkus.builder.BuildContext)10 Consumer (java.util.function.Consumer)10 BuildStep (io.quarkus.builder.BuildStep)9 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 StaticBytecodeRecorderBuildItem (io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem)3 BytecodeRecorderImpl (io.quarkus.deployment.recording.BytecodeRecorderImpl)3 NonApplicationRootPathBuildItem (io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem)3 Method (java.lang.reflect.Method)3 AdditionalDependency (io.quarkus.bootstrap.app.AdditionalDependency)2 AugmentAction (io.quarkus.bootstrap.app.AugmentAction)2 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)2 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)2 RunningQuarkusApplication (io.quarkus.bootstrap.app.RunningQuarkusApplication)2 StartupAction (io.quarkus.bootstrap.app.StartupAction)2 ClassPathElement (io.quarkus.bootstrap.classloading.ClassPathElement)2 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)2 ApplicationClassPredicateBuildItem (io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem)2 AugmentActionImpl (io.quarkus.runner.bootstrap.AugmentActionImpl)2