openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1801392 - in /openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src: main/java/org/apache/webbeans/arquillian/standalone/ test/java/org/apache/webbeans/arquillian/test/ test/resources/
Date Sun, 09 Jul 2017 20:53:13 GMT
Author: struberg
Date: Sun Jul  9 20:53:13 2017
New Revision: 1801392

URL: http://svn.apache.org/viewvc?rev=1801392&view=rev
Log:
OWB-1179 ignore classes which cannot be loaded properly

* fix double pickup of classes
* ignore classes which blow up with NoClassDefFound and LinkErrors

Added:
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianGetResourcesTest.java
      - copied, changed from r1801290, openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianWebJarDeploymentTest.java
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties
  (with props)
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties
  (with props)
Modified:
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
    openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbSWClassLoader.java

Modified: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java?rev=1801392&r1=1801391&r2=1801392&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbArquillianScannerService.java
Sun Jul  9 20:53:13 2017
@@ -46,12 +46,15 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Logger;
 
 /**
  *
  */
 public class OwbArquillianScannerService implements BdaScannerService
 {
+    private static final Logger logger = Logger.getLogger(OwbArquillianScannerService.class.getName());
+
 
     private static final String WEB_INF_CLASS_FOLDER = "/WEB-INF/classes/";
 
@@ -263,6 +266,11 @@ public class OwbArquillianScannerService
             {
                 throw new RuntimeException("Could not scan class", cnfe);
             }
+            catch (NoClassDefFoundError | UnsatisfiedLinkError ce)
+            {
+                logger.info("Error while loading class - ignoring class " + className + "
" + ce.getMessage());
+                continue;
+            }
 
             if (info != null && info.isClassExcluded(className))
             {

Modified: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbSWClassLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbSWClassLoader.java?rev=1801392&r1=1801391&r2=1801392&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbSWClassLoader.java
(original)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbSWClassLoader.java
Sun Jul  9 20:53:13 2017
@@ -162,15 +162,6 @@ public class OwbSWClassLoader extends UR
             urls.add(new URL(null, "archive:" + node, new ArchiveStreamHandler()));
         }
 
-        if (!useOnlyArchiveResources)
-        {
-            Enumeration<URL> parentResources = getParent().getResources(name);
-            while (parentResources.hasMoreElements())
-            {
-                urls.add(parentResources.nextElement());
-            }
-        }
-
         return Collections.enumeration(urls);
     }
 

Copied: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianGetResourcesTest.java
(from r1801290, openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianWebJarDeploymentTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianGetResourcesTest.java?p2=openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianGetResourcesTest.java&p1=openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianWebJarDeploymentTest.java&r1=1801290&r2=1801392&rev=1801392&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianWebJarDeploymentTest.java
(original)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/OwbArquillianGetResourcesTest.java
Sun Jul  9 20:53:13 2017
@@ -18,16 +18,14 @@
  */
 package org.apache.webbeans.arquillian.test;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.inject.Inject;
+import java.util.List;
+import java.util.Properties;
 
+import org.apache.webbeans.arquillian.standalone.OwbSWClassLoader;
 import org.apache.webbeans.arquillian.test.beans.SampleUser;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
@@ -46,58 +44,81 @@ import org.junit.runner.RunWith;
  * This test verifies the deployment of a JAR packaging.
  */
 @RunWith(Arquillian.class)
-public class OwbArquillianWebJarDeploymentTest
+public class OwbArquillianGetResourcesTest
 {
-    private static final String RESOURCE_NAME = "some/resource.properties";
-
-    @Inject
-    private SampleUser sampleUser;
 
+    public static final String INTESTCLASSPATH_PROPERTIES = "intestclasspath.properties";
+    public static final String INBOTHARCHIVEANDCLASSPATH_PROPERTIES = "inbotharchiveandclasspath.properties";
+    public static final String INJAR_PROPERTIES = "injar.properties";
+    public static final String INWAR_PROPERTIES = "inwar.properties";
 
     @Deployment
     public static Archive deploy()
     {
         JavaArchive testJar1 = ShrinkWrap
                 .create(JavaArchive.class, "sampleUserTest1.jar")
-                .addClass(OwbArquillianWebJarDeploymentTest.class)
+                .addClass(OwbArquillianGetResourcesTest.class)
                 .addPackage(SampleUser.class.getPackage())
-                .addAsResource(new StringAsset("hello1"), RESOURCE_NAME)
+                .addAsResource(new StringAsset("injar=true"), INJAR_PROPERTIES)
+                .addAsResource(new StringAsset("fromjar=true"), INBOTHARCHIVEANDCLASSPATH_PROPERTIES)
                 .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
 
-        JavaArchive testJar2 = ShrinkWrap
-                .create(JavaArchive.class, "sampleUserTest2.jar")
-                .addAsResource(new StringAsset("hello2"), RESOURCE_NAME);
-
 
         WebArchive testWar = ShrinkWrap
                 .create(WebArchive.class, "sampleUserTest.war")
-                .addAsResource(new StringAsset("hello3"), RESOURCE_NAME)
-                .addAsLibrary(testJar1)
-                .addAsLibrary(testJar2);
+                .addAsResource(new StringAsset("inwar=true"), INWAR_PROPERTIES)
+                .addAsLibrary(testJar1);
 
         return testWar;
     }
 
     @Test
-    public void testOwbArqContainerStartup() throws IOException {
-        Assert.assertNotNull(sampleUser);
-        Assert.assertEquals("Hans", sampleUser.getFirstName());
+    public void testOwbArqGetResources() throws IOException {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        Assert.assertNotNull(tccl);
+        Assert.assertTrue(tccl instanceof OwbSWClassLoader);
+
+        checkExpectedResources(INJAR_PROPERTIES, 1,
+            "injar", "true");
+
+        checkExpectedResources(INWAR_PROPERTIES, 1,
+            "inwar", "true");
+
+        checkExpectedResources(INTESTCLASSPATH_PROPERTIES, 1,
+            "intestclasspath", "1");
+
+        checkExpectedResources(INBOTHARCHIVEANDCLASSPATH_PROPERTIES, 2,
+            "fromtestclasspath", "true",
+            "fromjar", "true");
+    }
 
-        sampleUser.setFirstName("Karl");
-        Assert.assertEquals("Karl", sampleUser.getFirstName());
+    private void checkExpectedResources(String resourceName, int expectedUrls, String...
expectedProperties) throws IOException
+    {
+        List<URL> urls = getResources(resourceName);
+        Assert.assertEquals(expectedUrls, urls.size());
 
-        Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(RESOURCE_NAME);
-        Set<String> contents = new HashSet<>();
+        Properties props = new Properties();
+        for (URL url : urls)
+        {
+            props.load(url.openStream());
+        }
 
-        while (resources.hasMoreElements())
+        Assert.assertEquals(expectedProperties.length / 2, props.size());
+        for (int i = 0; i < expectedProperties.length; i+=2)
         {
-            URL url = resources.nextElement();
-            contents.add(new BufferedReader(new InputStreamReader(url.openStream())).readLine());
+            Assert.assertEquals(expectedProperties[1], props.getProperty(expectedProperties[0]));
         }
+    }
 
-        Assert.assertEquals(3, contents.size());
-        Assert.assertTrue(contents.contains("hello1"));
-        Assert.assertTrue(contents.contains("hello2"));
-        Assert.assertTrue(contents.contains("hello3"));
+    private List<URL> getResources(String name) throws IOException
+    {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        Enumeration<URL> resources = tccl.getResources(name);
+        List<URL> urls = new ArrayList<>();
+        while (resources.hasMoreElements())
+        {
+            urls.add(resources.nextElement());
+        }
+        return urls;
     }
 }

Added: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties?rev=1801392&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties
(added)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties
Sun Jul  9 20:53:13 2017
@@ -0,0 +1,19 @@
+# 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.
+
+
+fromtestclasspath=true
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/inbotharchiveandclasspath.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties?rev=1801392&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties
(added)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties
Sun Jul  9 20:53:13 2017
@@ -0,0 +1,19 @@
+# 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.
+
+
+intestclasspath=1
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/resources/intestclasspath.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message