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

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


The following commit(s) were added to refs/heads/master by this push:
     new 119df60  [OPENJPA-2824] simplify OpenJPADirectoriesEnhancer runtime 
when in auto mode
119df60 is described below

commit 119df603b8223043499b28410ce28a1edae22459
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
AuthorDate: Fri Jul 24 11:46:13 2020 +0200

    [OPENJPA-2824] simplify OpenJPADirectoriesEnhancer runtime when in auto mode
---
 .../internal/OpenJPADirectoriesEnhancer.java       | 37 ++++++++++++----------
 .../openjpa/junit5/internal/OpenJPAExtension.java  |  3 --
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git 
a/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPADirectoriesEnhancer.java
 
b/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPADirectoriesEnhancer.java
index 19b4419..dd8e169 100644
--- 
a/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPADirectoriesEnhancer.java
+++ 
b/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPADirectoriesEnhancer.java
@@ -53,6 +53,7 @@ import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Logger;
 import java.util.stream.Stream;
 
@@ -65,6 +66,8 @@ public class OpenJPADirectoriesEnhancer implements Runnable {
     private static final Logger LOGGER = 
Logger.getLogger(OpenJPADirectoriesEnhancer.class.getName());
     public static final StackTraceElement[] NO_STACK_TRACE = new 
StackTraceElement[0];
 
+    private static final AtomicBoolean AUTO_DONE = new AtomicBoolean(false);
+
     private final boolean auto;
     private final String[] entities;
     private final Class<?> logFactory;
@@ -84,22 +87,24 @@ public class OpenJPADirectoriesEnhancer implements Runnable 
{
         thread.setContextClassLoader(enhancementClassLoader);
         try {
             if (auto) {
-                try {
-                    
ClassLoaders.findUrls(enhancementClassLoader.getParent()).stream()
-                            .map(org.apache.xbean.finder.util.Files::toFile)
-                            .filter(File::isDirectory)
-                            .map(File::toPath)
-                            .forEach(dir -> {
-                                LOGGER.fine(() -> "Enhancing folder '" + dir + 
"'");
-                                try {
-                                    enhanceDirectory(enhancementClassLoader, 
dir);
-                                } catch (final IOException e) {
-                                    throw new IllegalStateException(e);
-                                }
-                            });
-                } catch (final IOException e) {
-                    throw new IllegalStateException(e);
-                }
+                if (AUTO_DONE.compareAndSet(false, true)) {
+                    try {
+                        
ClassLoaders.findUrls(enhancementClassLoader.getParent()).stream()
+                                
.map(org.apache.xbean.finder.util.Files::toFile)
+                                .filter(File::isDirectory)
+                                .map(File::toPath)
+                                .forEach(dir -> {
+                                    LOGGER.fine(() -> "Enhancing folder '" + 
dir + "'");
+                                    try {
+                                        
enhanceDirectory(enhancementClassLoader, dir);
+                                    } catch (final IOException e) {
+                                        throw new IllegalStateException(e);
+                                    }
+                                });
+                    } catch (final IOException e) {
+                        throw new IllegalStateException(e);
+                    }
+                } // else: already done, skip useless work
             } else {
                 Stream.of(entities).forEach(e -> {
                     try {
diff --git 
a/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPAExtension.java
 
b/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPAExtension.java
index 2cacd5e..86147e3 100644
--- 
a/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPAExtension.java
+++ 
b/openjpa-junit5/src/main/java/org/apache/openjpa/junit5/internal/OpenJPAExtension.java
@@ -23,10 +23,7 @@ import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.platform.commons.util.AnnotationUtils;
 
-import java.util.logging.Logger;
-
 public class OpenJPAExtension implements BeforeAllCallback {
-    private static final Logger LOGGER = 
Logger.getLogger(OpenJPAExtension.class.getName());
 
     @Override
     public void beforeAll(final ExtensionContext context) {

Reply via email to