-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the need for a new BytecodeRecorder
- Loading branch information
Showing
12 changed files
with
117 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/deployment/src/main/java/io/quarkus/deployment/builditem/MainAfterStartupBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.quarkus.deployment.builditem; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.jboss.builder.item.SimpleBuildItem; | ||
|
||
import io.quarkus.gizmo.MethodCreator; | ||
import io.quarkus.gizmo.ResultHandle; | ||
|
||
public final class MainAfterStartupBuildItem extends SimpleBuildItem { | ||
|
||
private final Consumer<Input> bytecodeCreator; | ||
|
||
public MainAfterStartupBuildItem(Consumer<Input> bytecodeCreator) { | ||
this.bytecodeCreator = bytecodeCreator; | ||
} | ||
|
||
public Consumer<Input> getBytecodeCreator() { | ||
return bytecodeCreator; | ||
} | ||
|
||
public static class Input { | ||
private final MethodCreator doStartMethod; | ||
private final ResultHandle mainArgs; | ||
|
||
public Input(MethodCreator doStartMethod, ResultHandle mainArgs) { | ||
this.doStartMethod = doStartMethod; | ||
this.mainArgs = mainArgs; | ||
} | ||
|
||
public MethodCreator getDoStartMethod() { | ||
return doStartMethod; | ||
} | ||
|
||
public ResultHandle getMainArgs() { | ||
return mainArgs; | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
.../main/java/io/quarkus/deployment/builditem/MainAfterStartupBytecodeRecorderBuildItem.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
core/deployment/src/main/java/io/quarkus/deployment/builditem/MainArgsBuildItem.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
core/runtime/src/main/java/io/quarkus/runtime/MainArgsSupplier.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...r/deployment/src/main/java/io/quarkus/clrunner/deployment/CommandLineRunnerBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 65 additions & 29 deletions
94
...r/deployment/src/main/java/io/quarkus/clrunner/deployment/CommandLineRunnerProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,104 @@ | ||
package io.quarkus.clrunner.deployment; | ||
|
||
import static io.quarkus.gizmo.MethodDescriptor.ofMethod; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.arc.deployment.BeanContainerBuildItem; | ||
import io.quarkus.clrunner.CommandLineRunner; | ||
import io.quarkus.clrunner.runtime.CommandLineRunnerTemplate; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.MainArgsBuildItem; | ||
import io.quarkus.deployment.builditem.MainAfterStartupBuildItem; | ||
import io.quarkus.deployment.builditem.ShutdownBuildItem; | ||
import io.quarkus.deployment.recording.RecorderContext; | ||
import io.quarkus.gizmo.MethodCreator; | ||
import io.quarkus.gizmo.MethodDescriptor; | ||
import io.quarkus.gizmo.ResultHandle; | ||
|
||
public class CommandLineRunnerProcessor { | ||
|
||
private static final DotName COMMAND_LINER_RUNNER = DotName.createSimple(CommandLineRunner.class.getName()); | ||
|
||
@BuildStep | ||
List<CommandLineRunnerBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildItem) { | ||
final List<CommandLineRunnerBuildItem> result = new ArrayList<>(); | ||
void discover(CombinedIndexBuildItem combinedIndexBuildItem, | ||
BuildProducer<CommandLineRunnerBuildItem> producer) { | ||
final List<String> names = new ArrayList<>(); | ||
|
||
for (ClassInfo info : combinedIndexBuildItem.getIndex().getAllKnownImplementors(COMMAND_LINER_RUNNER)) { | ||
final DotName name = info.name(); | ||
names.add(name.toString()); | ||
} | ||
|
||
result.add(new CommandLineRunnerBuildItem(name.toString())); | ||
if (names.size() == 0) { | ||
return; | ||
} | ||
return result; | ||
if (names.size() > 1) { | ||
StringBuilder sb = new StringBuilder(); | ||
boolean first = true; | ||
for (String name : names) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
sb.append(","); | ||
} | ||
sb.append(name); | ||
} | ||
throw new RuntimeException("Multiple classes ( " + sb.toString() | ||
+ ") have been annotated with @ApplicationPath which is currently not supported"); | ||
} | ||
|
||
producer.produce(new CommandLineRunnerBuildItem(names.get(0))); | ||
} | ||
|
||
@BuildStep | ||
List<AdditionalBeanBuildItem> beans(List<CommandLineRunnerBuildItem> runners) { | ||
final List<AdditionalBeanBuildItem> result = new ArrayList<>(); | ||
for (CommandLineRunnerBuildItem runner : runners) { | ||
result.add(new AdditionalBeanBuildItem(false, runner.getClassName())); | ||
void beans(Optional<CommandLineRunnerBuildItem> runner, BuildProducer<AdditionalBeanBuildItem> producer) { | ||
if (runner.isPresent()) { | ||
producer.produce(new AdditionalBeanBuildItem(false, runner.get().getClassName())); | ||
} | ||
return result; | ||
} | ||
|
||
@BuildStep | ||
ShutdownBuildItem shutdown() { | ||
void shutdown(BuildProducer<ShutdownBuildItem> producer) { | ||
// TODO: this has to be conditional only set when various things are not present | ||
return new ShutdownBuildItem(); | ||
producer.produce(new ShutdownBuildItem()); | ||
} | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.AFTER_STARTUP) | ||
public void runners(List<CommandLineRunnerBuildItem> runners, | ||
BeanContainerBuildItem beanContainerBuildItem, | ||
MainArgsBuildItem mainArgsBuildItem, | ||
CommandLineRunnerTemplate template, | ||
RecorderContext context) { | ||
void bytecodeCreation(Optional<CommandLineRunnerBuildItem> bi, BuildProducer<MainAfterStartupBuildItem> producer) { | ||
if (bi.isPresent()) { | ||
final Consumer<MainAfterStartupBuildItem.Input> bytecodeCreator = new Consumer<MainAfterStartupBuildItem.Input>() { | ||
@Override | ||
public void accept(MainAfterStartupBuildItem.Input input) { | ||
MethodCreator mv = input.getDoStartMethod(); | ||
ResultHandle clazz = mv.invokeStaticMethod( | ||
ofMethod(Class.class, "forName", Class.class, String.class), | ||
mv.load(bi.get().getClassName())); | ||
ResultHandle arcContainer = mv.invokeStaticMethod( | ||
MethodDescriptor.ofMethod(Arc.class, "container", ArcContainer.class)); | ||
ResultHandle instanceHandle = mv.invokeInterfaceMethod( | ||
MethodDescriptor.ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, | ||
Annotation[].class), | ||
arcContainer, clazz, mv.newArray(Annotation.class, mv.load(0))); | ||
ResultHandle runner = mv.invokeInterfaceMethod( | ||
ofMethod(InstanceHandle.class, "get", Object.class), | ||
instanceHandle); | ||
mv.invokeInterfaceMethod( | ||
MethodDescriptor.ofMethod(CommandLineRunner.class, "run", void.class, String[].class), | ||
runner, input.getMainArgs()); | ||
} | ||
}; | ||
|
||
Set<Class<? extends CommandLineRunner>> runnerClasses = new HashSet<>(); | ||
for (CommandLineRunnerBuildItem runner : runners) { | ||
runnerClasses.add((Class<? extends CommandLineRunner>) context.classProxy(runner.getClassName())); | ||
producer.produce(new MainAfterStartupBuildItem(bytecodeCreator)); | ||
} | ||
template.run(runnerClasses, beanContainerBuildItem.getValue(), mainArgsBuildItem); | ||
} | ||
} |
Oops, something went wrong.