Skip to content

Commit

Permalink
Merge pull request quarkusio#10087 from gsmet/9961-without-protected
Browse files Browse the repository at this point in the history
Usability improvements around Panache annotation processors without making the fields protected
  • Loading branch information
gsmet authored Jun 18, 2020
2 parents 2345bb4 + 6cd1f0a commit fd3ae46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/src/main/asciidoc/hibernate-orm-panache.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -950,3 +950,29 @@ by the presence of the marker file `META-INF/panache-archive.marker`. Panache in
annotation processor that will automatically create this file in archives that depend on
Panache (even indirectly). If you have disabled annotation processors you may need to create
this file manually in some cases.

WARNING: If you include the jpa-modelgen annotation processor this will exclude the Panache
annotation processor by default. If you do this you should either create the marker file
yourself, or add the `quarkus-panache-common` as well, as shown below:

[source,xml]
----
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-common</artifactId>
<version>${quarkus.platform.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
----
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand Down Expand Up @@ -101,6 +102,7 @@ PanacheEntityClassesBuildItem findEntityClasses(List<PanacheEntityClassBuildItem

@BuildStep
void build(CombinedIndexBuildItem index,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<BytecodeTransformerBuildItem> transformers,
HibernateEnhancersRegisteredBuildItem hibernateMarker,
List<PanacheEntityClassBuildItem> entityClasses,
Expand Down Expand Up @@ -144,11 +146,30 @@ void build(CombinedIndexBuildItem index,
PanacheFieldAccessEnhancer panacheFieldAccessEnhancer = new PanacheFieldAccessEnhancer(modelInfo);
QuarkusClassLoader tccl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
List<ClassPathElement> archives = tccl.getElementsWithResource(META_INF_PANACHE_ARCHIVE_MARKER);
Set<String> produced = new HashSet<>();
//we always transform the root archive, even though it should be run with the annotation
//processor on the CP it might not be if the user is using jpa-modelgen
//this won't cover every situation, but we have documented this, and as the fields are now
//made private the error should be very obvious
//we only do this for hibernate, as it is more common to have an additional annotation processor
for (ClassInfo i : applicationArchivesBuildItem.getRootArchive().getIndex().getKnownClasses()) {
String cn = i.name().toString();
if (!modelClasses.contains(cn)) {
produced.add(cn);
transformers.produce(
new BytecodeTransformerBuildItem(cn, panacheFieldAccessEnhancer, modelClassNamesInternal));
}
}

for (ClassPathElement i : archives) {
for (String res : i.getProvidedResources()) {
if (res.endsWith(".class")) {
String cn = res.replace("/", ".").substring(0, res.length() - 6);
if (produced.contains(cn)) {
continue;
}
if (!modelClasses.contains(cn)) {
produced.add(cn);
transformers.produce(
new BytecodeTransformerBuildItem(cn, panacheFieldAccessEnhancer, modelClassNamesInternal));
}
Expand Down

0 comments on commit fd3ae46

Please sign in to comment.