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(...).
This commit is contained in:
hengsin 2021-09-23 21:14:47 +08:00 committed by GitHub
parent 445ca8e0fa
commit 164e6d15b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -71,7 +71,7 @@ public class AnnotationBasedModelFactory extends AbstractModelFactory implements
* @see ClassGraph#acceptClasses(String...) * @see ClassGraph#acceptClasses(String...)
*/ */
protected String[] getAcceptClassesPatterns() { protected String[] getAcceptClassesPatterns() {
String[] patterns = new String[] {"*.X_*"}; String[] patterns = new String[] {"*.X_*","*.M*"};
return patterns; return patterns;
} }
@ -83,27 +83,29 @@ public class AnnotationBasedModelFactory extends AbstractModelFactory implements
ClassGraph graph = new ClassGraph() ClassGraph graph = new ClassGraph()
.enableAnnotationInfo() .enableAnnotationInfo()
.overrideClassLoaders(classLoader) .overrideClassLoaders(classLoader)
.disableJarScanning()
.disableNestedJarScanning() .disableNestedJarScanning()
.disableModuleScanning(); .disableModuleScanning();
// narrow search to a list of packages // narrow search to a list of packages
String[] packages = null;
if(isAtCore()) 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 else
{ {
String[] packages = getPackages(); // narrow search to class names matching a set of patterns
if(packages==null || packages.length==0) String[] acceptClasses = getAcceptClassesPatterns();
s_log.warning(this.getClass().getSimpleName() + " should override the getPackages method"); if(acceptClasses!=null && acceptClasses.length > 0)
else graph.acceptClasses(acceptClasses);
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);
try (ScanResult scanResult = graph.scan()) try (ScanResult scanResult = graph.scan())
{ {