Search in sources :

Example 1 with StartupContext

use of io.quarkus.runtime.StartupContext in project quarkus by quarkusio.

the class BytecodeRecorderImpl method loadObjectInstanceImpl.

/**
 * Returns a representation of a serialized parameter.
 */
private DeferredParameter loadObjectInstanceImpl(Object param, Map<Object, DeferredParameter> existing, Class<?> expectedType, boolean relaxedValidation) {
    // null is easy
    if (param == null) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext creator, MethodCreator method, ResultHandle array) {
                return method.loadNull();
            }
        };
    }
    // check the loaded object support (i.e. config) to see if this is a config item
    DeferredParameter loadedObject = findLoaded(param);
    if (loadedObject != null) {
        return loadedObject;
    }
    // Handle empty collections as returned by the Collections object
    loadedObject = handleCollectionsObjects(param, existing, relaxedValidation);
    if (loadedObject != null) {
        return loadedObject;
    }
    // but some are quite complex when dealing with objects and collections
    if (substitutions.containsKey(param.getClass()) || substitutions.containsKey(expectedType)) {
        // check for substitution types, if present we invoke recursively on the substitution
        SubstitutionHolder holder = substitutions.get(param.getClass());
        if (holder == null) {
            holder = substitutions.get(expectedType);
        }
        try {
            ObjectSubstitution substitution = holder.sub.getDeclaredConstructor().newInstance();
            Object res = substitution.serialize(param);
            DeferredParameter serialized = loadObjectInstance(res, existing, holder.to, relaxedValidation);
            SubstitutionHolder finalHolder = holder;
            return new DeferredArrayStoreParameter(param, expectedType) {

                @Override
                void doPrepare(MethodContext context) {
                    serialized.prepare(context);
                    super.doPrepare(context);
                }

                @Override
                ResultHandle createValue(MethodContext creator, MethodCreator method, ResultHandle array) {
                    ResultHandle subInstance = method.newInstance(MethodDescriptor.ofConstructor(finalHolder.sub));
                    return method.invokeInterfaceMethod(ofMethod(ObjectSubstitution.class, "deserialize", Object.class, Object.class), subInstance, creator.loadDeferred(serialized));
                }
            };
        } catch (Exception e) {
            throw new RuntimeException("Failed to substitute " + param, e);
        }
    } else if (param instanceof Optional) {
        Optional val = (Optional) param;
        if (val.isPresent()) {
            DeferredParameter res = loadObjectInstance(val.get(), existing, Object.class, relaxedValidation);
            return new DeferredArrayStoreParameter(param, expectedType) {

                @Override
                void doPrepare(MethodContext context) {
                    res.prepare(context);
                    super.doPrepare(context);
                }

                @Override
                ResultHandle createValue(MethodContext context, MethodCreator method, ResultHandle array) {
                    // so we need to use 'ofNullable' and not 'of' here.
                    return method.invokeStaticMethod(ofMethod(Optional.class, "ofNullable", Optional.class, Object.class), context.loadDeferred(res));
                }
            };
        } else {
            return new DeferredArrayStoreParameter(param, expectedType) {

                @Override
                ResultHandle createValue(MethodContext context, MethodCreator method, ResultHandle array) {
                    return method.invokeStaticMethod(ofMethod(Optional.class, "empty", Optional.class));
                }
            };
        }
    } else if (param instanceof String) {
        if (((String) param).length() > 65535) {
            throw new RuntimeException("String too large to record: " + param);
        }
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((String) param);
            }
        };
    } else if (param instanceof URL) {
        String url = ((URL) param).toExternalForm();
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                AssignableResultHandle value = method.createVariable(URL.class);
                try (TryBlock et = method.tryBlock()) {
                    et.assign(value, et.newInstance(MethodDescriptor.ofConstructor(URL.class, String.class), et.load(url)));
                    try (CatchBlockCreator malformed = et.addCatch(MalformedURLException.class)) {
                        malformed.throwException(RuntimeException.class, "Malformed URL", malformed.getCaughtException());
                    }
                }
                return value;
            }
        };
    } else if (param instanceof Enum) {
        Enum e = (Enum) param;
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                ResultHandle nm = method.load(e.name());
                return method.invokeStaticMethod(ofMethod(e.getDeclaringClass(), "valueOf", e.getDeclaringClass(), String.class), nm);
            }
        };
    } else if (param instanceof ReturnedProxy) {
        // if this is a proxy we just grab the value from the StartupContext
        ReturnedProxy rp = (ReturnedProxy) param;
        if (!rp.__static$$init() && staticInit) {
            throw new RuntimeException("Invalid proxy passed to recorder. " + rp + " was created in a runtime recorder method, while this recorder is for a static init method. The object will not have been created at the time this method is run.");
        }
        String proxyId = rp.__returned$proxy$key();
        // we just load it from the startup context
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.invokeVirtualMethod(ofMethod(StartupContext.class, "getValue", Object.class, String.class), method.getMethodParam(0), method.load(proxyId));
            }
        };
    } else if (param instanceof Duration) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.invokeStaticMethod(ofMethod(Duration.class, "parse", Duration.class, CharSequence.class), method.load(param.toString()));
            }
        };
    } else if (param instanceof Class<?>) {
        if (!((Class) param).isPrimitive()) {
            // Only try to load the class by name if it is not a primitive class
            String name = classProxies.get(param);
            if (name == null) {
                name = ((Class) param).getName();
            }
            String finalName = name;
            return new DeferredParameter() {

                @Override
                ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                    ResultHandle currentThread = method.invokeStaticMethod(ofMethod(Thread.class, "currentThread", Thread.class));
                    ResultHandle tccl = method.invokeVirtualMethod(ofMethod(Thread.class, "getContextClassLoader", ClassLoader.class), currentThread);
                    return method.invokeStaticMethod(ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class), method.load(finalName), method.load(true), tccl);
                }
            };
        } else {
            // Else load the primitive type by reference; double.class => Class var9 = Double.TYPE;
            return new DeferredParameter() {

                @Override
                ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                    return method.loadClassFromTCCL((Class) param);
                }
            };
        }
    } else if (expectedType == boolean.class || expectedType == Boolean.class || param instanceof Boolean) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((boolean) param);
            }
        };
    } else if (expectedType == int.class || expectedType == Integer.class || param instanceof Integer) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((int) param);
            }
        };
    } else if (expectedType == short.class || expectedType == Short.class || param instanceof Short) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((short) param);
            }
        };
    } else if (expectedType == byte.class || expectedType == Byte.class || param instanceof Byte) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((byte) param);
            }
        };
    } else if (expectedType == char.class || expectedType == Character.class || param instanceof Character) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((char) param);
            }
        };
    } else if (expectedType == long.class || expectedType == Long.class || param instanceof Long) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((long) param);
            }
        };
    } else if (expectedType == float.class || expectedType == Float.class || param instanceof Float) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((float) param);
            }
        };
    } else if (expectedType == double.class || expectedType == Double.class || param instanceof Double) {
        return new DeferredParameter() {

            @Override
            ResultHandle doLoad(MethodContext context, MethodCreator method, ResultHandle array) {
                return method.load((double) param);
            }
        };
    } else if (expectedType.isArray()) {
        int length = Array.getLength(param);
        DeferredParameter[] components = new DeferredParameter[length];
        for (int i = 0; i < length; ++i) {
            DeferredParameter component = loadObjectInstance(Array.get(param, i), existing, expectedType.getComponentType(), relaxedValidation);
            components[i] = component;
        }
        return new DeferredArrayStoreParameter(param, expectedType) {

            @Override
            void doPrepare(MethodContext context) {
                for (int i = 0; i < length; ++i) {
                    components[i].prepare(context);
                }
                super.doPrepare(context);
            }

            @Override
            ResultHandle createValue(MethodContext context, MethodCreator method, ResultHandle array) {
                // TODO large arrays can still generate a fair bit of bytecode, and there appears to be a gizmo issue that prevents casting to an array
                // fix this later
                ResultHandle out = method.newArray(expectedType.getComponentType(), length);
                for (int i = 0; i < length; ++i) {
                    method.writeArrayValue(out, i, context.loadDeferred(components[i]));
                }
                return out;
            }
        };
    } else if (param instanceof AnnotationProxy) {
        // new com.foo.MyAnnotation_Proxy_AnnotationLiteral("foo")
        AnnotationProxy annotationProxy = (AnnotationProxy) param;
        List<MethodInfo> constructorParams = annotationProxy.getAnnotationClass().methods().stream().filter(m -> !m.name().equals("<clinit>") && !m.name().equals("<init>")).collect(Collectors.toList());
        Map<String, AnnotationValue> annotationValues = annotationProxy.getAnnotationInstance().values().stream().collect(Collectors.toMap(AnnotationValue::name, Function.identity()));
        DeferredParameter[] constructorParamsHandles = new DeferredParameter[constructorParams.size()];
        for (ListIterator<MethodInfo> iterator = constructorParams.listIterator(); iterator.hasNext(); ) {
            MethodInfo valueMethod = iterator.next();
            Object explicitValue = annotationProxy.getValues().get(valueMethod.name());
            if (explicitValue != null) {
                constructorParamsHandles[iterator.previousIndex()] = loadObjectInstance(explicitValue, existing, explicitValue.getClass(), relaxedValidation);
            } else {
                AnnotationValue value = annotationValues.get(valueMethod.name());
                if (value == null) {
                    // method.invokeInterfaceMethod(MAP_PUT, valuesHandle, method.load(entry.getKey()), loadObjectInstance(method, entry.getValue(),
                    // returnValueResults, entry.getValue().getClass()));
                    Object defaultValue = annotationProxy.getDefaultValues().get(valueMethod.name());
                    if (defaultValue != null) {
                        constructorParamsHandles[iterator.previousIndex()] = loadObjectInstance(defaultValue, existing, defaultValue.getClass(), relaxedValidation);
                        continue;
                    }
                    if (value == null) {
                        value = valueMethod.defaultValue();
                    }
                }
                if (value == null) {
                    throw new NullPointerException("Value not set for " + param);
                }
                DeferredParameter retValue = loadValue(value, annotationProxy.getAnnotationClass(), valueMethod);
                constructorParamsHandles[iterator.previousIndex()] = retValue;
            }
        }
        return new DeferredArrayStoreParameter(annotationProxy.getAnnotationLiteralType()) {

            @Override
            ResultHandle createValue(MethodContext context, MethodCreator method, ResultHandle array) {
                MethodDescriptor constructor = MethodDescriptor.ofConstructor(annotationProxy.getAnnotationLiteralType(), constructorParams.stream().map(m -> m.returnType().name().toString()).toArray());
                ResultHandle[] args = new ResultHandle[constructorParamsHandles.length];
                for (int i = 0; i < constructorParamsHandles.length; i++) {
                    DeferredParameter deferredParameter = constructorParamsHandles[i];
                    if (deferredParameter instanceof DeferredArrayStoreParameter) {
                        DeferredArrayStoreParameter arrayParam = (DeferredArrayStoreParameter) deferredParameter;
                        arrayParam.doPrepare(context);
                    }
                    args[i] = context.loadDeferred(deferredParameter);
                }
                return method.newInstance(constructor, args);
            }
        };
    } else {
        return loadComplexObject(param, existing, expectedType, relaxedValidation);
    }
}
Also used : Arrays(java.util.Arrays) Array(java.lang.reflect.Array) SortedSet(java.util.SortedSet) ListIterator(java.util.ListIterator) URL(java.net.URL) ClassOutput(io.quarkus.gizmo.ClassOutput) ClassInfo(org.jboss.jandex.ClassInfo) MethodInfo(org.jboss.jandex.MethodInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordableConstructor(io.quarkus.runtime.annotations.RecordableConstructor) Duration(java.time.Duration) Map(java.util.Map) BytecodeCreator(io.quarkus.gizmo.BytecodeCreator) StartupContext(io.quarkus.runtime.StartupContext) Method(java.lang.reflect.Method) AnnotationValue(org.jboss.jandex.AnnotationValue) Assert(org.wildfly.common.Assert) IdentityHashMap(java.util.IdentityHashMap) ProxyConfiguration(io.quarkus.deployment.proxy.ProxyConfiguration) Collection(java.util.Collection) Property(io.quarkus.deployment.recording.PropertyUtils.Property) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) Collectors(java.util.stream.Collectors) ProxyFactory(io.quarkus.deployment.proxy.ProxyFactory) List(java.util.List) RelaxedValidation(io.quarkus.runtime.annotations.RelaxedValidation) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) IgnoreProperty(io.quarkus.runtime.annotations.IgnoreProperty) ArrayType(org.jboss.jandex.ArrayType) ResultHandle(io.quarkus.gizmo.ResultHandle) SortedMap(java.util.SortedMap) TryBlock(io.quarkus.gizmo.TryBlock) MethodDescriptor.ofConstructor(io.quarkus.gizmo.MethodDescriptor.ofConstructor) CatchBlockCreator(io.quarkus.gizmo.CatchBlockCreator) Proxy(java.lang.reflect.Proxy) MethodCreator(io.quarkus.gizmo.MethodCreator) Type(org.jboss.jandex.Type) HashMap(java.util.HashMap) MethodDescriptor.ofMethod(io.quarkus.gizmo.MethodDescriptor.ofMethod) ClassCreator(io.quarkus.gizmo.ClassCreator) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Parameter(java.lang.reflect.Parameter) RuntimeValue(io.quarkus.runtime.RuntimeValue) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) StartupTask(io.quarkus.runtime.StartupTask) LinkedHashSet(java.util.LinkedHashSet) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) MalformedURLException(java.net.MalformedURLException) Field(java.lang.reflect.Field) FieldDescriptor(io.quarkus.gizmo.FieldDescriptor) AbstractMap(java.util.AbstractMap) ParameterizedType(java.lang.reflect.ParameterizedType) TreeMap(java.util.TreeMap) Closeable(java.io.Closeable) InvocationHandler(java.lang.reflect.InvocationHandler) AnnotationProxy(io.quarkus.deployment.recording.AnnotationProxyProvider.AnnotationProxy) ObjectSubstitution(io.quarkus.runtime.ObjectSubstitution) Collections(java.util.Collections) MalformedURLException(java.net.MalformedURLException) TryBlock(io.quarkus.gizmo.TryBlock) URL(java.net.URL) AnnotationProxy(io.quarkus.deployment.recording.AnnotationProxyProvider.AnnotationProxy) ObjectSubstitution(io.quarkus.runtime.ObjectSubstitution) ResultHandle(io.quarkus.gizmo.ResultHandle) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) List(java.util.List) ArrayList(java.util.ArrayList) Optional(java.util.Optional) Duration(java.time.Duration) ListIterator(java.util.ListIterator) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) MalformedURLException(java.net.MalformedURLException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MethodCreator(io.quarkus.gizmo.MethodCreator) AnnotationValue(org.jboss.jandex.AnnotationValue) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) MethodInfo(org.jboss.jandex.MethodInfo) CatchBlockCreator(io.quarkus.gizmo.CatchBlockCreator) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Example 2 with StartupContext

use of io.quarkus.runtime.StartupContext in project quarkus by quarkusio.

the class RuntimeConfigSetupBuildStep method setupRuntimeConfig.

/**
 * Generates a StartupTask that sets up the final runtime configuration and thus runs before any StartupTask that uses
 * runtime configuration.
 * If there are recorders that produce a ConfigSourceProvider, these objects are used to set up the final runtime
 * configuration
 */
@BuildStep
@Consume(BootstrapConfigSetupCompleteBuildItem.class)
@Produce(RuntimeConfigSetupCompleteBuildItem.class)
void setupRuntimeConfig(List<RunTimeConfigurationSourceValueBuildItem> runTimeConfigurationSourceValues, BuildProducer<GeneratedClassBuildItem> generatedClass, BuildProducer<MainBytecodeRecorderBuildItem> mainBytecodeRecorder) {
    ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
    try (ClassCreator clazz = ClassCreator.builder().classOutput(classOutput).className(RUNTIME_CONFIG_STARTUP_TASK_CLASS_NAME).interfaces(StartupTask.class).build()) {
        try (MethodCreator method = clazz.getMethodCreator("deploy", void.class, StartupContext.class)) {
            method.invokeVirtualMethod(ofMethod(StartupContext.class, "setCurrentBuildStepName", void.class, String.class), method.getMethodParam(0), method.load("RuntimeConfigSetupBuildStep.setupRuntimeConfig"));
            ResultHandle config = method.readStaticField(C_INSTANCE);
            if (runTimeConfigurationSourceValues.isEmpty()) {
                method.invokeVirtualMethod(RunTimeConfigurationGenerator.C_READ_CONFIG, config, method.invokeStaticMethod(ofMethod(Collections.class, "emptyList", List.class)));
            } else {
                ResultHandle startupContext = method.getMethodParam(0);
                ResultHandle configSourcesProvidersList = method.newInstance(ofConstructor(ArrayList.class, int.class), method.load(runTimeConfigurationSourceValues.size()));
                for (RunTimeConfigurationSourceValueBuildItem runTimeConfigurationSourceValue : runTimeConfigurationSourceValues) {
                    RuntimeValue<ConfigSourceProvider> runtimeValue = runTimeConfigurationSourceValue.getConfigSourcesValue();
                    if (runtimeValue instanceof BytecodeRecorderImpl.ReturnedProxy) {
                        String proxyId = ((BytecodeRecorderImpl.ReturnedProxy) runtimeValue).__returned$proxy$key();
                        ResultHandle value = method.invokeVirtualMethod(ofMethod(StartupContext.class, "getValue", Object.class, String.class), startupContext, method.load(proxyId));
                        ResultHandle configSourceProvider = method.invokeVirtualMethod(ofMethod(RuntimeValue.class, "getValue", Object.class), method.checkCast(value, RuntimeValue.class));
                        method.invokeVirtualMethod(MethodDescriptor.ofMethod(ArrayList.class, "add", boolean.class, Object.class), configSourcesProvidersList, method.checkCast(configSourceProvider, ConfigSourceProvider.class));
                    } else {
                        log.warn("RuntimeValue " + runtimeValue + " was not produced by a recorder and it will thus be ignored");
                    }
                }
                method.invokeVirtualMethod(RunTimeConfigurationGenerator.C_READ_CONFIG, config, configSourcesProvidersList);
            }
            method.returnValue(null);
        }
    }
    mainBytecodeRecorder.produce(new MainBytecodeRecorderBuildItem(RUNTIME_CONFIG_STARTUP_TASK_CLASS_NAME));
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) ArrayList(java.util.ArrayList) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) ClassCreator(io.quarkus.gizmo.ClassCreator) StartupTask(io.quarkus.runtime.StartupTask) ConfigSourceProvider(org.eclipse.microprofile.config.spi.ConfigSourceProvider) MethodCreator(io.quarkus.gizmo.MethodCreator) ClassOutput(io.quarkus.gizmo.ClassOutput) ResultHandle(io.quarkus.gizmo.ResultHandle) RuntimeValue(io.quarkus.runtime.RuntimeValue) MainBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem) RunTimeConfigurationSourceValueBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem) Consume(io.quarkus.deployment.annotations.Consume) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with StartupContext

use of io.quarkus.runtime.StartupContext in project quarkus by quarkusio.

the class BytecodeRecorderTestCase method runTest.

void runTest(Consumer<BytecodeRecorderImpl> generator, Object... expected) throws Exception {
    TestRecorder.RESULT.clear();
    TestClassLoader tcl = new TestClassLoader(getClass().getClassLoader());
    BytecodeRecorderImpl recorder = new BytecodeRecorderImpl(tcl, false, TEST_CLASS);
    generator.accept(recorder);
    recorder.writeBytecode(new TestClassOutput(tcl));
    StartupTask task = (StartupTask) tcl.loadClass(TEST_CLASS).getDeclaredConstructor().newInstance();
    task.deploy(new StartupContext());
    assertEquals(expected.length, TestRecorder.RESULT.size());
    for (Object i : expected) {
        if (i.getClass().isArray()) {
            if (i instanceof int[]) {
                assertArrayEquals((int[]) i, (int[]) TestRecorder.RESULT.poll());
            } else if (i instanceof double[]) {
                assertArrayEquals((double[]) i, (double[]) TestRecorder.RESULT.poll(), 0);
            } else if (i instanceof Object[]) {
                assertArrayEquals((Object[]) i, (Object[]) TestRecorder.RESULT.poll());
            } else {
                throw new RuntimeException("not implemented");
            }
        } else {
            assertEquals(i, TestRecorder.RESULT.poll());
        }
    }
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) TestClassLoader(io.quarkus.deployment.TestClassLoader) StartupTask(io.quarkus.runtime.StartupTask)

Example 4 with StartupContext

use of io.quarkus.runtime.StartupContext in project quarkus by quarkusio.

the class MainClassBuildStep method writeRecordedBytecode.

private void writeRecordedBytecode(BytecodeRecorderImpl recorder, String fallbackGeneratedStartupTaskClassName, List<ObjectSubstitutionBuildItem> substitutions, List<RecordableConstructorBuildItem> recordableConstructorBuildItems, List<BytecodeRecorderObjectLoaderBuildItem> loaders, List<BytecodeRecorderConstantDefinitionBuildItem> constants, GeneratedClassGizmoAdaptor gizmoOutput, ResultHandle startupContext, BytecodeCreator bytecodeCreator) {
    if ((recorder == null || recorder.isEmpty()) && fallbackGeneratedStartupTaskClassName == null) {
        return;
    }
    if ((recorder != null) && !recorder.isEmpty()) {
        for (ObjectSubstitutionBuildItem sub : substitutions) {
            ObjectSubstitutionBuildItem.Holder holder1 = sub.holder;
            recorder.registerSubstitution(holder1.from, holder1.to, holder1.substitution);
        }
        for (BytecodeRecorderObjectLoaderBuildItem item : loaders) {
            recorder.registerObjectLoader(item.getObjectLoader());
        }
        for (var item : recordableConstructorBuildItems) {
            recorder.markClassAsConstructorRecordable(item.getClazz());
        }
        for (BytecodeRecorderConstantDefinitionBuildItem constant : constants) {
            constant.register(recorder);
        }
        recorder.writeBytecode(gizmoOutput);
    }
    ResultHandle dup = bytecodeCreator.newInstance(ofConstructor(recorder != null ? recorder.getClassName() : fallbackGeneratedStartupTaskClassName));
    bytecodeCreator.invokeInterfaceMethod(ofMethod(StartupTask.class, "deploy", void.class, StartupContext.class), dup, startupContext);
    bytecodeCreator.invokeStaticMethod(PRINT_STEP_TIME_METHOD, startupContext);
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) ObjectSubstitutionBuildItem(io.quarkus.deployment.builditem.ObjectSubstitutionBuildItem) BytecodeRecorderObjectLoaderBuildItem(io.quarkus.deployment.builditem.BytecodeRecorderObjectLoaderBuildItem) ResultHandle(io.quarkus.gizmo.ResultHandle) BytecodeRecorderConstantDefinitionBuildItem(io.quarkus.deployment.builditem.BytecodeRecorderConstantDefinitionBuildItem) StartupTask(io.quarkus.runtime.StartupTask)

Aggregations

StartupContext (io.quarkus.runtime.StartupContext)4 StartupTask (io.quarkus.runtime.StartupTask)4 ResultHandle (io.quarkus.gizmo.ResultHandle)3 ClassCreator (io.quarkus.gizmo.ClassCreator)2 ClassOutput (io.quarkus.gizmo.ClassOutput)2 MethodCreator (io.quarkus.gizmo.MethodCreator)2 RuntimeValue (io.quarkus.runtime.RuntimeValue)2 ArrayList (java.util.ArrayList)2 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)1 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)1 TestClassLoader (io.quarkus.deployment.TestClassLoader)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Consume (io.quarkus.deployment.annotations.Consume)1 Produce (io.quarkus.deployment.annotations.Produce)1 BytecodeRecorderConstantDefinitionBuildItem (io.quarkus.deployment.builditem.BytecodeRecorderConstantDefinitionBuildItem)1 BytecodeRecorderObjectLoaderBuildItem (io.quarkus.deployment.builditem.BytecodeRecorderObjectLoaderBuildItem)1 MainBytecodeRecorderBuildItem (io.quarkus.deployment.builditem.MainBytecodeRecorderBuildItem)1 ObjectSubstitutionBuildItem (io.quarkus.deployment.builditem.ObjectSubstitutionBuildItem)1 RunTimeConfigurationSourceValueBuildItem (io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem)1 ProxyConfiguration (io.quarkus.deployment.proxy.ProxyConfiguration)1