From 164e6d15b6ff4db7d40d12fefcafdb956bbeecc8 Mon Sep 17 00:00:00 2001 From: hengsin Date: Thu, 23 Sep 2021 21:14:47 +0800 Subject: [PATCH] IDEMPIERE-4842 Easier model registration (#895) * IDEMPIERE-4842 Easier model registration - Needs to enable jar scanning to support felix/console installation of plugin jar. - add rejectJars call to reduce startup delay after enable of jar scanning. keep the list short to reduce future maintenance hazard. - remove the not supported use of acceptPackagesNonRecursive and acceptClasses together. - change getAcceptClassesPatterns() default to X_* and M*. Withouut acceptPackages, we need to scan both X and M classes. * IDEMPIERE-4842 Easier model registration - remove use of rejectJars since the performance difference is small and need maintenance. - remove warning for not overriding getPackages(). Plugin that doesn't has many model class (< 100) doesn't have to override getPackages() as performance is good enough with the use of acceptClasses(...). --- .../base/AnnotationBasedModelFactory.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/base/AnnotationBasedModelFactory.java b/org.adempiere.base/src/org/adempiere/base/AnnotationBasedModelFactory.java index 6ce294df50..1cbb36d130 100644 --- a/org.adempiere.base/src/org/adempiere/base/AnnotationBasedModelFactory.java +++ b/org.adempiere.base/src/org/adempiere/base/AnnotationBasedModelFactory.java @@ -71,7 +71,7 @@ public class AnnotationBasedModelFactory extends AbstractModelFactory implements * @see ClassGraph#acceptClasses(String...) */ protected String[] getAcceptClassesPatterns() { - String[] patterns = new String[] {"*.X_*"}; + String[] patterns = new String[] {"*.X_*","*.M*"}; return patterns; } @@ -83,27 +83,29 @@ public class AnnotationBasedModelFactory extends AbstractModelFactory implements ClassGraph graph = new ClassGraph() .enableAnnotationInfo() .overrideClassLoaders(classLoader) - .disableJarScanning() .disableNestedJarScanning() .disableModuleScanning(); // narrow search to a list of packages + String[] packages = null; if(isAtCore()) - graph.acceptPackagesNonRecursive(CORE_PACKAGES); + packages = CORE_PACKAGES; + else + packages = getPackages(); + + //acceptClasses has no effect when acceptPackagesNonRecursive is use + if (packages != null && packages.length > 0) + { + graph.acceptPackagesNonRecursive(packages); + } else { - String[] packages = getPackages(); - if(packages==null || packages.length==0) - s_log.warning(this.getClass().getSimpleName() + " should override the getPackages method"); - else - graph.acceptPackagesNonRecursive(packages); + // narrow search to class names matching a set of patterns + String[] acceptClasses = getAcceptClassesPatterns(); + if(acceptClasses!=null && acceptClasses.length > 0) + graph.acceptClasses(acceptClasses); } - // narrow search to class names matching a set of patterns - String[] acceptClasses = getAcceptClassesPatterns(); - if(acceptClasses!=null && acceptClasses.length > 0) - graph.acceptClasses(acceptClasses); - try (ScanResult scanResult = graph.scan()) {