Commits

Anonymous committed c947eb0

WW-3121 IllegalArgumentException using struts2-convention-plugin-2.1.6.jar on JBoss

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@2035e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 7bb3e01

Comments (0)

Files changed (2)

core/src/main/java/com/opensymphony/xwork2/util/finder/ClassFinder.java

 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
+import org.apache.commons.lang.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
             }
             String className = entry.getName();
             className = className.replaceFirst(".class$", "");
+
+            //war files are treated as .jar files, so takeout WEB-INF/classes
+            className = StringUtils.removeStart(className, "WEB-INF/classes/"); 
+
             className = className.replace('/', '.');
             classNames.add(className);
         }

core/src/main/java/com/opensymphony/xwork2/util/finder/UrlSet.java

 
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import com.opensymphony.xwork2.util.URLUtil;
 import org.apache.commons.lang.StringUtils;
 
 import java.io.File;
     private static final Logger LOG = LoggerFactory.getLogger(UrlSet.class);
     private final Map<String,URL> urls;
     private Set<String> protocols;
-    
+    private static final String CLASSES_DIR = "/WEB-INF/classes";
+
 
     public UrlSet(ClassLoaderInterface classLoader) throws IOException {
         this(getUrls(classLoader));
         return new ArrayList<URL>(urls.values());
     }
 
+    private static URL getClassesURL(ClassLoaderInterface classLoader) throws IOException {
+        List<URL> urls = Collections.list(classLoader.getResources(""));
+        for (URL url : urls) {
+            String externalForm = StringUtils.removeEnd(url.toExternalForm(), "/");
+            if (externalForm.endsWith(".war/WEB-INF/classes")) {
+                //if it is inside a war file, get the url to the file
+                externalForm = StringUtils.substringBefore(externalForm, CLASSES_DIR);
+                return URLUtil.normalizeToFileProtocol(new URL(externalForm));
+            } else if (externalForm.endsWith(CLASSES_DIR)) {
+                return URLUtil.normalizeToFileProtocol(url);
+            }
+        }
+
+        return null;
+    }
+
     private static List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
         List<URL> list = new ArrayList<URL>();
 
 
         }
 
-        //usually the "classes" dir
-        list.addAll(Collections.list(classLoader.getResources("")));
+        //get the "classes" dir
+        URL classesURL = getClassesURL(classLoader);
+        if (classesURL != null)
+            list.add(classesURL);
+
         return list;
     }
 
 
         }
 
-        //usually the "classes" dir
-        list.addAll(Collections.list(classLoader.getResources("")));
+        //get the "classes" dir
+        URL classesURL = getClassesURL(classLoader);
+        if (classesURL != null)
+            list.add(classesURL);
+        
         return list;
     }