You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by al...@apache.org on 2022/04/07 04:05:14 UTC

[fineract] branch develop updated: FINERACT-1562: Excluding persistence.xml from being picked up by Spring

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

aleks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 44e6d369e FINERACT-1562: Excluding persistence.xml from being picked up by Spring
44e6d369e is described below

commit 44e6d369e52f07e1165b39c516c98fefc7f60f1d
Author: Arnold Galovics <ga...@gmail.com>
AuthorDate: Wed Apr 6 23:16:08 2022 +0200

    FINERACT-1562: Excluding persistence.xml from being picked up by Spring
---
 fineract-provider/build.gradle                     |  7 ++-
 ...EntityScanningPersistenceUnitPostProcessor.java | 73 ----------------------
 .../resources/{META-INF => jpa}/persistence.xml    |  0
 3 files changed, 5 insertions(+), 75 deletions(-)

diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index 9e965888e..c1cbd73a6 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -31,8 +31,8 @@ compileJava.doLast {
     def mainSS = sourceSets.main
     def source = mainSS.java.classesDirectory.get()
     copy {
-        from "src/main/resources/"
-        into source
+        from "src/main/resources/jpa/"
+        into "${source}/META-INF/"
     }
     javaexec {
         description = 'Performs EclipseLink static weaving of entity classes'
@@ -41,6 +41,9 @@ compileJava.doLast {
         args '-persistenceinfo', source, '-classpath', configurations.runtimeClasspath, source, target
         classpath configurations.runtimeClasspath
     }
+    delete {
+        delete "${source}/META-INF/"
+    }
 }
 
 // Configuration for Swagger documentation generation task
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/persistence/EntityScanningPersistenceUnitPostProcessor.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/persistence/EntityScanningPersistenceUnitPostProcessor.java
deleted file mode 100644
index d42c41ace..000000000
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/persistence/EntityScanningPersistenceUnitPostProcessor.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fineract.infrastructure.core.persistence;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import javax.persistence.Entity;
-import org.apache.commons.collections4.CollectionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
-import org.springframework.core.type.filter.AnnotationTypeFilter;
-import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo;
-import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;
-
-public class EntityScanningPersistenceUnitPostProcessor implements PersistenceUnitPostProcessor, InitializingBean {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EntityScanningPersistenceUnitPostProcessor.class);
-
-    private List<String> packages;
-    private final Set<Class<?>> persistentClasses = new HashSet<>();
-
-    @Override
-    public void afterPropertiesSet() throws Exception {
-        if (CollectionUtils.isEmpty(packages)) {
-            throw new IllegalArgumentException("packages must be set");
-        }
-        LOG.debug("Looking for @Entity in {} ", packages);
-        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
-
-        scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
-
-        for (String p : packages) {
-            for (BeanDefinition bd : scanner.findCandidateComponents(p)) {
-                persistentClasses.add(Class.forName(bd.getBeanClassName()));
-            }
-        }
-
-        if (persistentClasses.isEmpty()) {
-            throw new IllegalArgumentException("No class annotated with @Entity found in: " + packages);
-        }
-    }
-
-    @Override
-    public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo persistenceUnitInfo) {
-        for (Class<?> c : persistentClasses) {
-            persistenceUnitInfo.addManagedClassName(c.getName());
-        }
-    }
-
-    public void setPackages(List<String> packages) {
-        this.packages = packages;
-    }
-}
diff --git a/fineract-provider/src/main/resources/META-INF/persistence.xml b/fineract-provider/src/main/resources/jpa/persistence.xml
similarity index 100%
rename from fineract-provider/src/main/resources/META-INF/persistence.xml
rename to fineract-provider/src/main/resources/jpa/persistence.xml