tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: ensure we scan the classpath for tomee embedded even if the app loader if not a URLClassLoader + few java 9 fallbacks
Date Thu, 04 May 2017 16:12:58 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 31e2251cc -> c26f5923d


ensure we scan the classpath for tomee embedded even if the app loader if not a URLClassLoader
+ few java 9 fallbacks


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c26f5923
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c26f5923
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c26f5923

Branch: refs/heads/master
Commit: c26f5923de4ccd719eccf9cc822acfd4b187b485
Parents: 31e2251
Author: rmannibucau <rmannibucau@apache.org>
Authored: Thu May 4 18:12:51 2017 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Thu May 4 18:12:51 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/ziplock/JarLocation.java    |  6 +-
 .../src/main/resources/default.exclusions       |  2 +
 .../apache/openejb/loader/TomcatClassPath.java  | 40 ++++++-----
 .../openejb/itest/legacy/LegacyServerTest.java  |  3 +
 .../apache/openejb/maven/util/XmlFormatter.java |  2 +-
 maven/pom.xml                                   |  3 +-
 server/openejb-hessian/pom.xml                  | 22 +++++-
 .../tomee/catalina/TomEEWebappClassLoader.java  | 14 ++--
 tomee/tomee-embedded/pom.xml                    |  6 ++
 .../org/apache/tomee/embedded/SslTomEETest.java | 73 +++++++++++++++-----
 .../apache/tomee/jaxrs/ReloadingLoaderTest.java | 13 +++-
 .../apache/tomee/loader/TomEEJarScanner.java    | 72 +++++++++++++------
 utils/openejb-mockito/pom.xml                   |  2 +-
 .../openejb/mockito/MockitoExtension.java       |  3 +-
 14 files changed, 187 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/arquillian/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
----------------------------------------------------------------------
diff --git a/arquillian/ziplock/src/main/java/org/apache/ziplock/JarLocation.java b/arquillian/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
index d84f91d..244f0e2 100644
--- a/arquillian/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
+++ b/arquillian/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
@@ -41,7 +41,11 @@ public class JarLocation {
         try {
             final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader());
             for (final URL url : urls) {
-                final File f = new File(decode(url.getFile()));
+                final String decode = decode(url.getFile());
+                File f = new File(decode.replaceFirst("file:", ""));
+                if (!f.exists() && f.getPath().endsWith("!")) {
+                    f = new File(f.getPath().substring(0, f.getPath().length() - 1));
+                }
                 if (f.exists() && pattern.matcher(f.getName()).matches()) {
                     return f;
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/container/openejb-core/src/main/resources/default.exclusions
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/resources/default.exclusions b/container/openejb-core/src/main/resources/default.exclusions
index 311eb97..f0e543b 100644
--- a/container/openejb-core/src/main/resources/default.exclusions
+++ b/container/openejb-core/src/main/resources/default.exclusions
@@ -35,6 +35,7 @@ bcprov-
 bootstrap.jar
 bval-core
 bval-jsr
+byte-buddy
 c3p0-
 cassandra-driver-core
 catalina-
@@ -157,6 +158,7 @@ mysql-connector-java-
 neethi-
 nekohtml-
 netty-
+objenesis
 openejb-api
 openejb-client
 openejb-core

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java
----------------------------------------------------------------------
diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java
b/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java
index 9bbd71c..a092485 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java
@@ -42,7 +42,7 @@ public class TomcatClassPath extends BasicURLClassPath {
     private final ClassLoader commonLoader;
     private final ClassLoader serverLoader;
 
-    private final Method addRepositoryMethod;
+    private Method addRepositoryMethod;
 
     public TomcatClassPath() {
         this(getCommonLoader(getContextClassLoader()));
@@ -50,11 +50,6 @@ public class TomcatClassPath extends BasicURLClassPath {
 
     public TomcatClassPath(final ClassLoader classLoader) {
         this.commonLoader = classLoader;
-        try {
-            addRepositoryMethod = getAddRepositoryMethod();
-        } catch (final Exception e) {
-            throw new IllegalStateException("Ensure you use the right tomcat version (" +
e.getMessage() + ")");
-        }
 
         final ClassLoader serverLoader = getServerLoader(getContextClassLoader());
         if (serverLoader != null && serverLoader != commonLoader) {
@@ -137,7 +132,7 @@ public class TomcatClassPath extends BasicURLClassPath {
             classLoader = serverLoader;
         }
 
-        addRepositoryMethod.invoke(classLoader, jar);
+        getAddRepositoryMethod().invoke(classLoader, jar);
     }
 
     private boolean useServerClassLoader(final URL jar) {
@@ -211,20 +206,27 @@ public class TomcatClassPath extends BasicURLClassPath {
     }
 
     private Method getAddRepositoryMethod() throws Exception {
-        return AccessController.doPrivileged(new PrivilegedAction<Method>() {
-            @Override
-            public Method run() {
-                try {
-                    final Method method = URLClassLoader.class.getDeclaredMethod("addURL",
URL.class);
-                    if (!method.isAccessible()) {
-                        method.setAccessible(true);
+        if (addRepositoryMethod == null) {
+            try {
+                addRepositoryMethod = AccessController.doPrivileged(new PrivilegedAction<Method>()
{
+                    @Override
+                    public Method run() {
+                        try {
+                            final Method method = URLClassLoader.class.getDeclaredMethod("addURL",
URL.class);
+                            if (!method.isAccessible()) {
+                                method.setAccessible(true);
+                            }
+                            return method;
+                        } catch (final Exception e2) {
+                            throw (IllegalStateException) new IllegalStateException("Unable
to find or access the addRepository method in StandardClassLoader").initCause(e2);
+                        }
                     }
-                    return method;
-                } catch (final Exception e2) {
-                    throw (IllegalStateException) new IllegalStateException("Unable to find
or access the addRepository method in StandardClassLoader").initCause(e2);
-                }
+                });
+            } catch (final Exception e) {
+                throw new IllegalStateException("Ensure you use the right tomcat version
(" + e.getMessage() + ")", e);
             }
-        });
+        }
+        return addRepositoryMethod;
     }
 
     private static boolean isDirectory(final URL url) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/itests/legacy-server/src/test/java/org/apache/openejb/itest/legacy/LegacyServerTest.java
----------------------------------------------------------------------
diff --git a/itests/legacy-server/src/test/java/org/apache/openejb/itest/legacy/LegacyServerTest.java
b/itests/legacy-server/src/test/java/org/apache/openejb/itest/legacy/LegacyServerTest.java
index fd4d765..7a76d19 100644
--- a/itests/legacy-server/src/test/java/org/apache/openejb/itest/legacy/LegacyServerTest.java
+++ b/itests/legacy-server/src/test/java/org/apache/openejb/itest/legacy/LegacyServerTest.java
@@ -50,6 +50,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static org.apache.openejb.util.NetworkUtil.getNextAvailablePort;
+import static org.junit.Assume.assumeTrue;
 
 public class LegacyServerTest {
 
@@ -67,6 +68,8 @@ public class LegacyServerTest {
 
     @Test
     public void test() throws Exception {
+        final String jv = System.getProperty("java.version");
+        assumeTrue(jv.startsWith("1.7") || jv.startsWith("1.8"));
 
         //        To run in an IDE, uncomment and update this line
         //        System.setProperty("version", OpenEjbVersion.get().getVersion());

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
----------------------------------------------------------------------
diff --git a/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
b/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
index 7d36f13..0508675 100644
--- a/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
+++ b/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
@@ -50,7 +50,7 @@ public final class XmlFormatter {
                 final StringWriter stringWriter = new StringWriter();
                 lsOutput.setCharacterStream(stringWriter);
                 serializer.write(document, lsOutput);
-                return stringWriter.toString();
+                return stringWriter.toString().replace("\"UTF-8\"?><", "\"UTF-8\"?>\n<");
             }
 
             return in;

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/maven/pom.xml
----------------------------------------------------------------------
diff --git a/maven/pom.xml b/maven/pom.xml
index 8f5122e..1cc7373 100644
--- a/maven/pom.xml
+++ b/maven/pom.xml
@@ -101,6 +101,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-plugin-plugin</artifactId>
+        <version>3.5</version>
         <executions>
           <execution>
             <id>mojo-descriptor</id>
@@ -123,7 +124,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-plugin-plugin</artifactId>
-        <version>3.0</version>
+        <version>3.5</version>
       </plugin>
     </plugins>
   </reporting>

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/server/openejb-hessian/pom.xml
----------------------------------------------------------------------
diff --git a/server/openejb-hessian/pom.xml b/server/openejb-hessian/pom.xml
index c73e585..7ca03e7 100644
--- a/server/openejb-hessian/pom.xml
+++ b/server/openejb-hessian/pom.xml
@@ -54,8 +54,28 @@ limitations under the License.
     <dependency>
       <groupId>com.caucho</groupId>
       <artifactId>hessian</artifactId>
-      <version>4.0.7</version>
+      <version>4.0.38</version>
       <scope>provided</scope>
     </dependency>
   </dependencies>
+
+  <profiles>
+    <profile>
+      <id>java9</id>
+      <activation>
+        <jdk>9</jdk>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration> <!-- com.caucho.hessian.io.StackTraceElementDeserializer
doesnt support java 9 without "opens" -->
+              <skip>true</skip>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
index fd00a77..a83518d 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
@@ -98,7 +98,7 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader {
         hashCode = construct();
         setJavaseClassLoader(getSystemClassLoader());
         containerClassLoader = ParentClassLoaderFinder.Helper.get();
-        isEar = getParent() != null && !getParent().equals(containerClassLoader)
&& defaultEarBehavior();
+        isEar = getInternalParent() != null && !getInternalParent().equals(containerClassLoader)
&& defaultEarBehavior();
         originalDelegate = getDelegate();
     }
 
@@ -107,10 +107,14 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader
{
         hashCode = construct();
         setJavaseClassLoader(getSystemClassLoader());
         containerClassLoader = ParentClassLoaderFinder.Helper.get();
-        isEar = getParent() != null && !getParent().equals(containerClassLoader)
&& defaultEarBehavior();
+        isEar = getInternalParent() != null && !getInternalParent().equals(containerClassLoader)
&& defaultEarBehavior();
         originalDelegate = getDelegate();
     }
 
+    public ClassLoader getInternalParent() {
+        return getParent();
+    }
+
     private int construct() {
         setDelegate(isDelegate());
         configurer = INIT_CONFIGURER.get();
@@ -187,8 +191,8 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader
{
                 final boolean filter = filter(name, true);
                 filterTempCache.put(name, filter); // will be called again by super.loadClass()
so cache it
                 if (!filter) {
-                    if (URLClassLoaderFirst.class.isInstance(getParent())) { // true
-                        final URLClassLoaderFirst urlClassLoaderFirst = URLClassLoaderFirst.class.cast(getParent());
+                    if (URLClassLoaderFirst.class.isInstance(getInternalParent())) { // true
+                        final URLClassLoaderFirst urlClassLoaderFirst = URLClassLoaderFirst.class.cast(getInternalParent());
                         Class<?> c = urlClassLoaderFirst.findAlreadyLoadedClass(name);
                         if (c != null) {
                             return c;
@@ -499,7 +503,7 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader
{
 
     @Override
     public TomEEWebappClassLoader copyWithoutTransformers() {
-        final TomEEWebappClassLoader result = new TomEEWebappClassLoader(getParent());
+        final TomEEWebappClassLoader result = new TomEEWebappClassLoader(getInternalParent());
         result.additionalRepos = additionalRepos;
         result.configurer = configurer;
         super.copyStateWithoutTransformers(result);

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/tomee/tomee-embedded/pom.xml
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/pom.xml b/tomee/tomee-embedded/pom.xml
index 7247a2a..ecb7ce5 100644
--- a/tomee/tomee-embedded/pom.xml
+++ b/tomee/tomee-embedded/pom.xml
@@ -470,6 +470,12 @@
       <version>${version.shrinkwrap.shrinkwrap}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.bouncycastle</groupId>
+      <artifactId>bcmail-jdk15on</artifactId>
+      <version>1.54</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SslTomEETest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SslTomEETest.java
b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SslTomEETest.java
index b1c781a..3f5e711 100644
--- a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SslTomEETest.java
+++ b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/SslTomEETest.java
@@ -17,11 +17,29 @@
 package org.apache.tomee.embedded;
 
 import org.apache.openejb.loader.Files;
+import org.bouncycastle.asn1.x500.X500Name;
+import org.bouncycastle.cert.X509CertificateHolder;
+import org.bouncycastle.cert.X509v1CertificateBuilder;
+import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
+import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
+import org.junit.Assert;
 import org.junit.Test;
 
 import javax.management.ObjectName;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.lang.management.ManagementFactory;
+import java.math.BigInteger;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -36,28 +54,45 @@ public class SslTomEETest {
                 Files.delete(keystore);
             }
 
-            Class<?> keyToolClass;
-            try {
-                keyToolClass = Class.forName("sun.security.tools.KeyTool");
-            } catch (final ClassNotFoundException e) {
+            keystore.getParentFile().mkdirs();
+            try (final FileOutputStream fos = new FileOutputStream(keystore)) {
+                final KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
+                keyGenerator.initialize(1024);
+
+                final KeyPair pair = keyGenerator.generateKeyPair();
+
+                final boolean addBc = Security.getProvider("BC") == null;
+                if (addBc) {
+                    Security.addProvider(new BouncyCastleProvider());
+                }
                 try {
-                    // in jdk8, the tool changed ...
-                    keyToolClass = Class.forName("sun.security.tools.keytool.Main");
-                } catch (final ClassNotFoundException cnfe) {
-                    keyToolClass = Class.forName("com.ibm.crypto.tools.KeyTool");
+
+                    final X509v1CertificateBuilder x509v1CertificateBuilder = new JcaX509v1CertificateBuilder(
+                            new X500Name("cn=serveralias"),
+                            BigInteger.valueOf(1),
+                            new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)),
+                            new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)),
+                            new X500Name("cn=serveralias"),
+                            pair.getPublic());
+
+                    final X509CertificateHolder certHldr = x509v1CertificateBuilder
+                            .build(new JcaContentSignerBuilder("SHA1WithRSA")
+                                    .setProvider("BC").build(pair.getPrivate()));
+
+                    final X509Certificate cert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certHldr);
+
+                    final KeyStore ks = KeyStore.getInstance("JKS");
+                    ks.load(null, "changeit".toCharArray());
+                    ks.setKeyEntry("serveralias", pair.getPrivate(), "changeit".toCharArray(),
new Certificate[]{cert});
+                    ks.store(fos, "changeit".toCharArray());
+                } finally {
+                    if (addBc) {
+                        Security.removeProvider("BC");
+                    }
                 }
+            } catch (final Exception e) {
+                Assert.fail(e.getMessage());
             }
-
-            final String[] args = {
-                    "-genkey",
-                    "-alias", "serveralias",
-                    "-keypass", "changeit",
-                    "-keystore", keystore.getAbsolutePath(),
-                    "-storepass", "changeit",
-                    "-dname", "cn=serveralias",
-                    "-keyalg", "RSA"
-            };
-            keyToolClass.getMethod("main", String[].class).invoke(null, new Object[]{args});
         }
 
         final Configuration configuration = new Configuration();

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/tomee/tomee-jaxrs/src/test/java/org/apache/tomee/jaxrs/ReloadingLoaderTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-jaxrs/src/test/java/org/apache/tomee/jaxrs/ReloadingLoaderTest.java
b/tomee/tomee-jaxrs/src/test/java/org/apache/tomee/jaxrs/ReloadingLoaderTest.java
index 56c4d22..575582a 100644
--- a/tomee/tomee-jaxrs/src/test/java/org/apache/tomee/jaxrs/ReloadingLoaderTest.java
+++ b/tomee/tomee-jaxrs/src/test/java/org/apache/tomee/jaxrs/ReloadingLoaderTest.java
@@ -49,6 +49,7 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Collections;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -58,6 +59,7 @@ public class ReloadingLoaderTest {
     private AppInfo info;
     private AppContext context;
     private TomEEWebappClassLoader loader;
+    private AtomicReference<ClassLoader> parentInstance;
 
     @BeforeClass
     @AfterClass
@@ -81,7 +83,13 @@ public class ReloadingLoaderTest {
             }
         });
 
-        loader = new TomEEWebappClassLoader(ParentClassLoaderFinder.Helper.get()) {
+        parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
+        loader = new TomEEWebappClassLoader(parentInstance.get()) {
+            @Override
+            public ClassLoader getInternalParent() {
+                return parentInstance.get();
+            }
+
             @Override
             protected void clearReferences() {
                 // no-op: this test should be reworked to support it but in real life a loader
is not stopped/started
@@ -168,7 +176,8 @@ public class ReloadingLoaderTest {
             resources.start();
             loader.start();
             // TomcatWebAppBuilder ill catch start event from StandardContext and force a
classloader
-            Reflections.set(loader, "parent", ParentClassLoaderFinder.Helper.get());
+            // Reflections.set(loader, "parent", ParentClassLoaderFinder.Helper.get());
+            parentInstance.set(ParentClassLoaderFinder.Helper.get());
 
             server.afterApplicationCreated(new AssemblerAfterApplicationCreated(info, context,
Collections.<BeanContext>emptyList()));
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomEEJarScanner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomEEJarScanner.java
b/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomEEJarScanner.java
index 9624c34..b76d91f 100644
--- a/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomEEJarScanner.java
+++ b/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomEEJarScanner.java
@@ -33,9 +33,17 @@ import javax.servlet.ServletContext;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.Set;
 
+import static java.lang.ClassLoader.getSystemClassLoader;
+
 // todo: share common tld parsing, tomcat has a built in method for it, ensure we reuse it
 public class TomEEJarScanner extends StandardJarScanner {
     private static final TomEEFilter DEFAULT_JAR_SCAN_FILTER = new TomEEFilter(null);
@@ -59,36 +67,56 @@ public class TomEEJarScanner extends StandardJarScanner {
     @Override
     public void scan(final JarScanType scanType, final ServletContext context, final JarScannerCallback
callback) {
         super.scan(scanType, context, callback);
-        embeddedSurefireScanning(scanType, context, callback);
+        if (!embeddedSurefireScanning(scanType, context, callback) && isScanClassPath()
&& !URLClassLoader.class.isInstance(getSystemClassLoader())
+                && !Boolean.getBoolean("tomee.classpath.scanning.disabled")) {
+            // TODO: check on tomcat upgrade if it is fixed
+            final String cp = System.getProperty("java.class.path");
+            final Collection<URL> urls = new HashSet<>();
+            for (final String jar : cp.split(File.pathSeparator)) {
+                try {
+                    urls.add(new File(jar).toURI().toURL());
+                } catch (MalformedURLException e) {
+                    // no-op
+                }
+            }
+            doScan(scanType, callback, new LinkedList<>(urls));
+        }
     }
 
-    private void embeddedSurefireScanning(final JarScanType scanType, final ServletContext
context, final JarScannerCallback callback) {
+    private boolean embeddedSurefireScanning(final JarScanType scanType, final ServletContext
context, final JarScannerCallback callback) {
         if (isScanClassPath() && System.getProperty("surefire.real.class.path") !=
null) {
-            Method process = null;
             try {
                 final Set<URL> urls = ClassLoaders.findUrls(context.getClassLoader().getParent());
-                final boolean scanAllDirectories = isScanAllDirectories();
-                for (final URL url : urls) {
-                    final File cpe = URLs.toFile(url);
-                    if ((cpe.getName().endsWith(".jar") ||
-                            scanType == JarScanType.PLUGGABILITY ||
-                            scanAllDirectories) &&
-                            getJarScanFilter().check(scanType, cpe.getName())) {
-                        try {
-                            if (process == null) {
-                                process = StandardJarScanner.class.getDeclaredMethod("process",
JarScanType.class, JarScannerCallback.class, URL.class, String.class, boolean.class);
-                                if (!process.isAccessible()) {
-                                    process.setAccessible(true);
-                                }
-                            }
-                            process.invoke(this, scanType, callback, url, null, true);
-                        } catch (final Exception ioe) {
-                            // no-op
+                doScan(scanType, callback, new LinkedList<>(urls));
+                return true;
+            } catch (final IOException e) {
+                // no-op
+            }
+        }
+        return false;
+    }
+
+    private void doScan(final JarScanType scanType, final JarScannerCallback callback, final
Deque<URL> urls) {
+        Method process = null;
+        final boolean scanAllDirectories = isScanAllDirectories();
+        for (final URL url : urls) {
+            final File cpe = URLs.toFile(url);
+            if ((cpe.getName().endsWith(".jar") ||
+                    scanType == JarScanType.PLUGGABILITY ||
+                    scanAllDirectories) &&
+                    getJarScanFilter().check(scanType, cpe.getName())) {
+                try {
+                    if (process == null) {
+                        process = StandardJarScanner.class.getDeclaredMethod("process",
+                                JarScanType.class, JarScannerCallback.class, URL.class, String.class,
boolean.class, Deque.class);
+                        if (!process.isAccessible()) {
+                            process.setAccessible(true);
                         }
                     }
+                    process.invoke(this, scanType, callback, url, null, true, urls);
+                } catch (final Exception ioe) {
+                    // no-op
                 }
-            } catch (final IOException e) {
-                // no-op
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/utils/openejb-mockito/pom.xml
----------------------------------------------------------------------
diff --git a/utils/openejb-mockito/pom.xml b/utils/openejb-mockito/pom.xml
index e154847..90c881a 100644
--- a/utils/openejb-mockito/pom.xml
+++ b/utils/openejb-mockito/pom.xml
@@ -38,7 +38,7 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
-      <version>1.9.0</version>
+      <version>2.7.9</version>
       <exclusions>
         <exclusion>
           <artifactId>hamcrest-core</artifactId>

http://git-wip-us.apache.org/repos/asf/tomee/blob/c26f5923/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java
----------------------------------------------------------------------
diff --git a/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java
b/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java
index 854a536..359e85d 100644
--- a/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java
+++ b/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java
@@ -21,7 +21,6 @@ import org.apache.openejb.loader.SystemInstance;
 import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.annotation.NamedLiteral;
-import org.mockito.cglib.proxy.Factory;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
@@ -84,7 +83,7 @@ public class MockitoExtension implements Extension {
                     }
                 }
                 for (Class<?> itf : clazz.getInterfaces()) {
-                    if (Factory.class.isAssignableFrom(itf)) {
+                    if (itf.getName().startsWith("org.mockito")) {
                         continue;
                     }
 


Mime
View raw message