Skip to content

Commit

Permalink
Simplify by splitting extension conf prefix and provider conf prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jtama committed Dec 15, 2023
1 parent 5efe46b commit c0c1a2a
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 515 deletions.
2 changes: 1 addition & 1 deletion conference-provider/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/quarkus-approximation-corrector-en-provider-jvm .
# docker build -f src/main/docker/Dockerfile.jvm -t quay.io/jtama/acme-provider:jvm .
#
# Then run the container using:
#
Expand Down
89 changes: 0 additions & 89 deletions conference-provider/src/main/docker/Dockerfile.legacy-jar

This file was deleted.

27 changes: 0 additions & 27 deletions conference-provider/src/main/docker/Dockerfile.native

This file was deleted.

4 changes: 2 additions & 2 deletions conference-provider/src/main/docker/Dockerfile.native-micro
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/quarkus-approximation-corrector-en-provider .
# docker build -f src/main/docker/Dockerfile.native-micro -t quay.io/jtama/acme-provider:native .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/quarkus-approximation-corrector-en-provider
# docker run -i --rm -p 8080:8080 quay.io/jtama/acme-provider:native
#
###
FROM quay.io/quarkus/quarkus-micro-image:2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class ConferencesResource {

static {
conferences = new HashMap<>(Map.of(
"maryCoreTech", new Conference("A mandonné, ça fatigue !", "Myra Cool"),
"daminouTech", new Conference("Tchou la bise !", "Super Daminou"),
"snowcamp", new Conference("Quarkus: Greener, Better, Faster, Stronger", "j.tama"),
"devoxxFR", new Conference("#RetourAuxSources : Le cache HTTP", "h.sablonnière ❤"),
"devoxxFR", new Conference("#RetourAuxSources : Le cache HTTP", "Hubert Sablonnière ❤"),
"dummy", new Conference("Why does Elmyra Duff love animals so much ?", "Malvin le Martien")
));
}
Expand Down
283 changes: 0 additions & 283 deletions conference-provider/src/main/resources/META-INF/resources/index.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ public class ConferencesResourceTest {


@Test
public void testHelloEndpoint() {
Map<String, Map<String, String>> result = given()
.when().get("/conferences")
public void testUnknownConference() {
ConferencesResource.Conference result = given()
.when().get("/conferences/unknown")
.then()
.statusCode(200)
.extract()
.body()
.as(Map.class);
Assertions.assertEquals("Quarkus: Greener, Better, Faster, Stronger", result.get("snowcamp").get("title"));
Assertions.assertEquals("#RetourAuxSources : Le cache HTTP", result.get("devoxxFR").get("title"));
.as(ConferencesResource.Conference.class);
Assertions.assertEquals("Always Look on the Bright Side of Life", result.title());
Assertions.assertEquals("Monty Python", result.author());
}

@Test
public void testDummyConference() {
ConferencesResource.Conference result = given()
.when().get("/conferences/dummy")
.then()
.statusCode(200)
.extract()
.body()
.as(ConferencesResource.Conference.class);
Assertions.assertEquals("Why does Elmyra Duff love animals so much ?", result.title());
Assertions.assertEquals("Malvin le Martien", result.author());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.quarkus.runtime.annotations.ConfigRoot;
import org.acme.configurationProvider.deployment.devservice.DevServicesConfig;

@ConfigRoot(prefix = "acme", name = ConfigItem.PARENT, phase = ConfigPhase.BUILD_TIME)
@ConfigRoot(prefix = "acme", name = "", phase = ConfigPhase.BUILD_TIME)
public class AcmeConfigurationBuildTimeConfiguration {

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void askForAppllicationScan(ApplicationIndexBuildItem index,
.stream()
.map(AnnotationInstance::values)
.flatMap(List::stream)
.filter(value -> value.asString().startsWith("acme"))
.filter(value -> value.asString().startsWith("env."))
.findFirst()
.ifPresent(annotationInstance -> buildProducer.produce(new AcmeEnvironmentBuildItem()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

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.ApplicationIndexBuildItem;
import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
import io.quarkus.gizmo.Gizmo;
import org.acme.configurationProvider.runtime.UtilsAreBadLogger;
import org.jboss.logging.Logger;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
Expand All @@ -17,20 +20,29 @@
* Please clearly state what your class is doing...
*/
class NoUtilsClassTransformerProcessor {
private static final Logger logger = Logger.getLogger(NoUtilsClassTransformerProcessor.class);

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void build(ApplicationIndexBuildItem applicationIndex,
BuildProducer<BytecodeTransformerBuildItem> transformers) {
AcmeConfigurationBuildTimeConfiguration compileConfiguration,
BuildProducer<BytecodeTransformerBuildItem> transformers,
UtilsAreBadLogger utilsAreBadLogger) {
List<String> utilsClasses = applicationIndex.getIndex()
.getKnownClasses()
.stream()
.filter(info -> info.name().toString().endsWith("Utils"))
.map(info -> info.name().toString())
.toList();
for (String className : utilsClasses) {
transformers.produce(new BytecodeTransformerBuildItem(className,
(name, classVisitor) -> new NoUtilsClassVisitor(Gizmo.ASM_API_VERSION, classVisitor)));
if (compileConfiguration.strict.isUtilsStrict) {
logger.infof("Someone may not be happy in the future, but you were warned...");
for (String className : utilsClasses) {
transformers.produce(new BytecodeTransformerBuildItem(className,
(name, classVisitor) -> new NoUtilsClassVisitor(Gizmo.ASM_API_VERSION, classVisitor)));
}
return;
}
utilsAreBadLogger.nope(utilsClasses);
}

private static class NoUtilsClassVisitor extends ClassVisitor {
Expand All @@ -50,8 +62,6 @@ public void visit(
final String[] interfaces) {

super.visit(version, access, name, signature, superName, interfaces);
logger.warnf("💀 I told you not do this!", name);
logger.warnf("💀 Your code will panic at runtime -> %s", name);
MethodVisitor mv = visitMethod(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "<clinit>",
"()V", null,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,60 @@ class ThisIsNotRestTransformerProcessor {
public void warn(
AcmeConfigurationBuildTimeConfiguration compileConfiguration,
ApplicationIndexBuildItem applicationIndexBuildItem,
BuildProducer<AnnotationsTransformerBuildItem> transformers,
ThisIsNotRestLogger thisIsNotRestLogger) {
if (compileConfiguration.strict.isRestStrict) {
logger.infof("Correcting your approximations if any. We'll see at runtime !");
transformers.produce(new AnnotationsTransformerBuildItem(new RestMethodCorrector(compileConfiguration)));
return;
}
Stream<MethodInfo> restEndpoints = applicationIndexBuildItem.getIndex().getKnownClasses().stream()
.flatMap(classInfo -> classInfo.methods().stream())
.filter(isRestEndpoint);

thisIsNotRestLogger.youAreNotDoingREST(restEndpoints
.map(methodInfo -> "You think you method \"%s#%s\" is doing rest but it's more JSON over HTTP actually.".formatted(methodInfo.declaringClass().toString(), methodInfo.toString()))
.toList());
}

@BuildStep(onlyIf = ReactiveResteasyEnabled.class)
public void process(
AcmeConfigurationBuildTimeConfiguration compileConfiguration,
BuildProducer<AnnotationsTransformerBuildItem> transformers) {
if (!compileConfiguration.strict.isRestStrict) {
return;
public static class ReactiveResteasyEnabled implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return QuarkusClassLoader.isClassPresentAtRuntime("org.jboss.resteasy.reactive.ResponseHeader");
}
logger.infof("Correcting your approximations if any.");
transformers.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

private final boolean mustRecordWarning = true;
}

@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return AnnotationTarget.Kind.METHOD == kind;
}
private class RestMethodCorrector implements AnnotationsTransformer {

@Override
public void transform(TransformationContext context) {
MethodInfo method = context.getTarget().asMethod();
if (isRestEndpoint.test(method)) {
if (!compileConfiguration.strict.isRestStrict) {
private final boolean mustRecordWarning = true;
private AcmeConfigurationBuildTimeConfiguration compileConfiguration;

}
Transformation transform = context.transform();
transform.add(DotName.createSimple(ResponseHeader.class),
AnnotationValue.createStringValue("name", "X-ApproximationCorrector"),
AnnotationValue.createArrayValue("value", Collections
.singletonList(AnnotationValue.createStringValue("", "It's more JSON over http really."))));
transform.done();
if (mustRecordWarning) {
private RestMethodCorrector(AcmeConfigurationBuildTimeConfiguration compileConfiguration) {
this.compileConfiguration = compileConfiguration;
}

}
}
}
@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return AnnotationTarget.Kind.METHOD == kind;
}

}));
@Override
public void transform(AnnotationsTransformer.TransformationContext context) {
MethodInfo method = context.getTarget().asMethod();
if (isRestEndpoint.test(method)) {
if (!compileConfiguration.strict.isRestStrict) {

}
}
Transformation transform = context.transform();
transform.add(DotName.createSimple(ResponseHeader.class),
AnnotationValue.createStringValue("name", "X-ApproximationCorrector"),
AnnotationValue.createArrayValue("value", Collections
.singletonList(AnnotationValue.createStringValue("", "It's more JSON over http really."))));
transform.done();
if (mustRecordWarning) {

public static class ReactiveResteasyEnabled implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return QuarkusClassLoader.isClassPresentAtRuntime("org.jboss.resteasy.reactive.ResponseHeader");
}
}
}

}
}
Loading

0 comments on commit c0c1a2a

Please sign in to comment.