You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/05/25 04:43:00 UTC

[isis] branch master updated: ISIS-3063: more cleaning up around scan interception

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 1925ca9f32 ISIS-3063: more cleaning up around scan interception
1925ca9f32 is described below

commit 1925ca9f32ef92afc7e763aa174cac4e3e1b0f76
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed May 25 06:42:48 2022 +0200

    ISIS-3063: more cleaning up around scan interception
---
 .../isis/core/config/beans/IsisBeanMetaData.java   |  7 ++++++
 .../beans/IsisComponentScanInterceptorImpl.java    | 18 ++++++--------
 .../core/config/beans/ScannedTypeMetaData.java     | 29 ++++++----------------
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanMetaData.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanMetaData.java
index d249647ce9..4a66bab965 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanMetaData.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanMetaData.java
@@ -34,6 +34,13 @@ public class IsisBeanMetaData {
         public boolean isUnspecified() {return this == ManagedBy.UNSPECIFIED; }
         public boolean isSpring() {return this == ManagedBy.SPRING; }
         public boolean isIsis() {return this == ManagedBy.ISIS; }
+        /**
+         * Whether Spring should make that underlying bean injectable.
+         * @implNote if not managed by Isis, let ultimately Spring decide
+         */
+        public boolean isInjectable() {
+            return !isIsis();
+        }
     }
 
     private final @NonNull BeanSort beanSort;
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisComponentScanInterceptorImpl.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisComponentScanInterceptorImpl.java
index 59540ff80d..88270cf300 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisComponentScanInterceptorImpl.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisComponentScanInterceptorImpl.java
@@ -71,31 +71,27 @@ implements IsisComponentScanInterceptor {
     @Override
     public void intercept(final ScannedTypeMetaData scanMeta) {
 
-        val classOrFailure = scanMeta.getUnderlyingClassOrFailure();
+        val classOrFailure = scanMeta.getUnderlyingClass();
         if(classOrFailure.isFailure()) {
             log.warn(classOrFailure.getFailure());
             return;
         }
 
-        val type = classOrFailure.getUnderlyingClass();
-        val typeMeta = isisBeanTypeClassifier.classify(type);
+        val correspondingClass = classOrFailure.getValue().get();
+        val typeMeta = isisBeanTypeClassifier.classify(correspondingClass);
 
-        val beanSort = typeMeta.getBeanSort();
-
-        scanMeta.setInjectable(!typeMeta.getManagedBy().isIsis());
+        scanMeta.setInjectable(typeMeta.getManagedBy().isInjectable());
         if(typeMeta.getManagedBy().isIsis()) {
-            // otherwise we don't care
+            // otherwise we don't interfere with naming strategies
             scanMeta.setBeanNameOverride(typeMeta.getLogicalType().getLogicalTypeName());
         }
 
+        val beanSort = typeMeta.getBeanSort();
         if(beanSort.isToBeIntrospected()) {
-            val correspondingClass = scanMeta.getUnderlyingClassOrFailure().getUnderlyingClass();
-
             introspectableTypes.put(correspondingClass, typeMeta);
-
             if(log.isDebugEnabled()) {
                 log.debug("to-be-introspected: {} [{}]",
-                                type,
+                                correspondingClass,
                                 beanSort.name());
             }
         }
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/ScannedTypeMetaData.java b/core/config/src/main/java/org/apache/isis/core/config/beans/ScannedTypeMetaData.java
index 7fa7a8ad7c..acd4b249d8 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/ScannedTypeMetaData.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/ScannedTypeMetaData.java
@@ -18,13 +18,13 @@
  */
 package org.apache.isis.core.config.beans;
 
+import org.apache.isis.commons.functional.Try;
 import org.apache.isis.commons.internal.base._Strings;
 import org.apache.isis.commons.internal.context._Context;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.Setter;
-import lombok.Value;
 import lombok.val;
 
 @RequiredArgsConstructor(staticName = "of")
@@ -51,7 +51,7 @@ final class ScannedTypeMetaData {
     @Getter @Setter private boolean injectable = true;
 
     @Getter(lazy=true)
-    private final ClassOrFailure underlyingClassOrFailure = resolveClass();
+    private final Try<Class<?>> underlyingClass = resolveClass();
 
     // -- UTILITY
 
@@ -63,28 +63,15 @@ final class ScannedTypeMetaData {
 
     // -- HELPER
 
-    /**
-     * Holds either the class or the failure string when attempting to load by name.
-     */
-    @Value(staticConstructor = "of")
-    static final class ClassOrFailure {
-        Class<?> underlyingClass;
-        String failure;
-        public boolean isFailure() {
-            return underlyingClass==null;
-        }
-    }
-
     /**
      * @return the underlying class of this TypeMetaData
      */
-    private ClassOrFailure resolveClass() {
-        try {
-            return ClassOrFailure.of(_Context.loadClass(className), null);
-        } catch (ClassNotFoundException e) {
-            val msg = String.format("Failed to load class for name '%s', throwing %s", className, e);
-            return ClassOrFailure.of(null, msg);
-        }
+    private Try<Class<?>> resolveClass() {
+        return Try.<Class<?>>call(()->_Context.loadClass(className))
+        .mapFailure(ex->{
+            val msg = String.format("Failed to load class for name '%s'", className);
+            return new RuntimeException(msg, ex);
+        });
     }