Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ApplicationIndexBuildItem with CombinedIndexBuildItem where it makes sense #8001

Merged
merged 1 commit into from
Mar 26, 2020

Conversation

aloubyansky
Copy link
Member

.. and search for resources in all the application archives instead of only in the root one

I am not sure whether it all makes sense. I'm doing some refactoring and these changes did help.

@boring-cyborg boring-cyborg bot added area/arc Issue related to ARC (dependency injection) area/infinispan Infinispan area/panache area/security area/spring Issues relating to the Spring integration labels Mar 19, 2020
@gsmet
Copy link
Member

gsmet commented Mar 19, 2020

Let’s not rush this thing in. We need to be very careful about it as we did the opposite change in various places a few months ago.

@aloubyansky
Copy link
Member Author

I'd like to clarify though whether it makes sense or not pretty much asap.

@gsmet
Copy link
Member

gsmet commented Mar 20, 2020

@mkouba any chance you could have a look at that one? IIRC, one issue is that CombinedIndexBuildItem will not contain the generated classes or the result of the transformations so we need to be sure it's safe to use it.

@mkouba
Copy link
Contributor

mkouba commented Mar 20, 2020

@gsmet ApplicationIndexBuildItem does not contain the generated classes and the result of the transformations either. I can take a look. But in general, it always depends on whether an extension needs to include the classes from other modules and third-party libs.

@@ -89,7 +87,7 @@ void setup(CombinedIndexBuildItem combinedIndex,
boolean needsValidation = ClassConfigPropertiesUtil.addProducerMethodForClassConfigProperties(
deploymentClassLoader.getClassLoader(), classInfo, producerClassCreator,
configPropertiesMetadata.getPrefix(), configPropertiesMetadata.getNamingStrategy(),
applicationIndex.getIndex(), configProperties);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoand do you remember the reason why class-based @ConfigProperties requied the ApplicationIndexBuildItem? I think it's safe to use the CombinedIndexBuildItem here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's probably just an oversight on my part

@aloubyansky
Copy link
Member Author

But in general, it always depends on whether an extension needs to include the classes from other modules and third-party libs.

Right, that's what this change is about.

@@ -109,7 +107,7 @@ void build(CombinedIndexBuildItem index,
MetamodelInfo<EntityModel<EntityField>> modelInfo = modelEnhancer.getModelInfo();
if (modelInfo.hasEntities()) {
PanacheFieldAccessEnhancer panacheFieldAccessEnhancer = new PanacheFieldAccessEnhancer(modelInfo);
for (ClassInfo classInfo : applicationIndex.getIndex().getKnownClasses()) {
for (ClassInfo classInfo : index.getIndex().getKnownClasses()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FroMage modelClasses are built from the CombinedIndexBuildItem so it should be safe to use it here as well, or?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would probably solve the bug where people access entities outside the root application, but might be costly since we still don't have any way to index users of specific classes.

@aloubyansky
Copy link
Member Author

aloubyansky commented Mar 24, 2020

@mkouba how about this?

+++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java
@@ -56,6 +56,7 @@ import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
 import io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem;
 import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
 import io.quarkus.deployment.builditem.CapabilityBuildItem;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
 import io.quarkus.deployment.builditem.ExecutorBuildItem;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
@@ -78,7 +79,7 @@ import io.quarkus.runner.bootstrap.BootstrapDebug;
  * <li>{@link ValidationPhaseBuildItem}</li>
  * </ol>
  * These build items are especially useful if an extension needs to produce other build items within the given phase.
- * 
+ *
  * @see BeanProcessor
  */
 public class ArcProcessor {
@@ -115,7 +116,8 @@ public class ArcProcessor {
             Optional<TestClassPredicateBuildItem> testClassPredicate,
             Capabilities capabilities,
             BuildProducer<FeatureBuildItem> feature,
-            CustomScopeAnnotationsBuildItem scopes) {
+            CustomScopeAnnotationsBuildItem scopes,
+            CombinedIndexBuildItem combinedIndex) {
 
         if (!arcConfig.isRemoveUnusedBeansFieldValid()) {
             throw new IllegalArgumentException("Invalid configuration value set for 'quarkus.arc.remove-unused-beans'." +
@@ -128,7 +130,7 @@ public class ArcProcessor {
         Set<DotName> generatedClassNames = beanArchiveIndex.getGeneratedClassNames();
         IndexView index = beanArchiveIndex.getIndex();
         BeanProcessor.Builder builder = BeanProcessor.builder();
-        IndexView applicationClassesIndex = applicationArchivesBuildItem.getRootArchive().getIndex();
+        IndexView applicationClassesIndex = combinedIndex.getIndex();

This allows to pickup beans from all the application archives instead of just from the root one.

@mkouba
Copy link
Contributor

mkouba commented Mar 24, 2020

This allows to pickup beans from all the application archives instead of just from the root one.

@aloubyansky ArC is using a special index build in the BeanArchiveProcessor and it does pick up classes from all app archives. CombinedIndexBuildItem is not the way to go.

@aloubyansky
Copy link
Member Author

Ok, the change I pasted does fix the issue though. So it's just not a proper index then.

@aloubyansky
Copy link
Member Author

This did work

-        IndexView applicationClassesIndex = applicationArchivesBuildItem.getRootArchive().getIndex();
+        IndexView applicationClassesIndex = beanArchiveIndex.getIndex();

Thanks.

@aloubyansky aloubyansky force-pushed the prefer-combined-index branch from c889a72 to d60adec Compare March 24, 2020 10:37
@mkouba
Copy link
Contributor

mkouba commented Mar 24, 2020

@aloubyansky Hm, I don't think we should use the BeanArchiveIndex for this predicate. It should only return true for application classes, i.e. classes from the root and possibly other modules. Actually, it's a bit more complicated, because it includes ApplicationClassPredicateBuildItem and others. What's the issue anyway?

On the other hand, it may not be needed after the class loading changes... @stuartwdouglas Any idea?

@aloubyansky
Copy link
Member Author

The issue I'm fixing is a use-case of io.quarkus.arc.test.remove.RemoveFwkBeansTest but when UnusedBean is not in the root app archive. Would that be a completely test?

@aloubyansky
Copy link
Member Author

Looks like it broke the TS. I'll keep looking into it.

…rch for resources in all the application archives instead of only in the root where it makes sense
@aloubyansky aloubyansky force-pushed the prefer-combined-index branch from d60adec to 403bf6c Compare March 24, 2020 12:52
@aloubyansky
Copy link
Member Author

I rolled that one back.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got approval from various people on Zulip.

Let's merge it early.

@gsmet gsmet merged commit d67747f into quarkusio:master Mar 26, 2020
@gsmet gsmet added this to the 1.4.0 milestone Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/infinispan Infinispan area/panache area/security area/spring Issues relating to the Spring integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants