mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3662 - improves support for JBoss server
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1297384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -139,7 +139,7 @@ public class FileManager {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Creating revision for URL: " +fileName);
|
||||
}
|
||||
if (URLUtil.isJBoss5Url(fileUrl)) {
|
||||
if (URLUtil.isJBossUrl(fileUrl)) {
|
||||
revision = JBossFileRevision.build(fileUrl);
|
||||
} else if (URLUtil.isJarURL(fileUrl)) {
|
||||
revision = JarEntryRevision.build(fileUrl);
|
||||
|
||||
@@ -15,19 +15,23 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
import java.net.URL;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Helper class to extract file paths from different urls
|
||||
*/
|
||||
public class URLUtil {
|
||||
|
||||
/**
|
||||
* Prefix for Jar files in JBoss Virtual File System
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(URLUtil.class);
|
||||
public static final String JBOSS5_VFS = "vfs";
|
||||
public static final String JBOSS5_VFSZIP = "vfszip";
|
||||
public static final String JBOSS5_VFSMEMORY = "vfsmemory";
|
||||
@@ -45,8 +49,8 @@ public class URLUtil {
|
||||
String fileName = url.toExternalForm();
|
||||
Matcher jarMatcher = JAR_PATTERN.matcher(fileName);
|
||||
try {
|
||||
if (isJBoss5Url(url)){
|
||||
return new URL("file", null, fileName.substring(fileName.indexOf(":") + 1));
|
||||
if (isJBossUrl(url)){
|
||||
return getJBossPhysicalUrl(url);
|
||||
} else if (jarMatcher.matches()) {
|
||||
String path = jarMatcher.group(JAR_FILE_PATH);
|
||||
return new URL("file", "", path);
|
||||
@@ -57,6 +61,9 @@ public class URLUtil {
|
||||
} catch (MalformedURLException e) {
|
||||
//can this ever happen?
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Error opening JBoss vfs file", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,10 +106,31 @@ public class URLUtil {
|
||||
* @param fileUrl
|
||||
* @return
|
||||
*/
|
||||
public static boolean isJBoss5Url(URL fileUrl) {
|
||||
public static boolean isJBossUrl(URL fileUrl) {
|
||||
final String protocol = fileUrl.getProtocol();
|
||||
return JBOSS5_VFSZIP.equals(protocol) || JBOSS5_VFSMEMORY.equals(protocol) || JBOSS5_VFS.equals(protocol)
|
||||
|| ("true".equals(System.getProperty("jboss.vfs.forceVfsJar")) && JBOSS5_VFSFILE.equals(protocol));
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to determine physical file location.
|
||||
*
|
||||
* @param url JBoss VFS URL
|
||||
* @return URL pointing to physical file or original URL
|
||||
* @throws IOException If conversion fails
|
||||
*/
|
||||
public static URL getJBossPhysicalUrl(URL url) throws IOException {
|
||||
Object content = url.openConnection().getContent();
|
||||
try {
|
||||
if (content.getClass().toString().startsWith("class org.jboss.vfs.VirtualFile")) {
|
||||
Method method = content.getClass().getDeclaredMethod("getPhysicalFile");
|
||||
File physicalFile = (File) method.invoke(content);
|
||||
return physicalFile.toURI().toURL();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error calling getPhysicalFile() on JBoss VirtualFile.", e);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -469,7 +469,9 @@ public class ClassFinder {
|
||||
} else if (file.getName().endsWith(".class")) {
|
||||
String name = file.getName();
|
||||
name = name.replaceFirst(".class$", "");
|
||||
classNames.add(packageName + name);
|
||||
// Classes packaged in an exploded .war (e.g. in a VFS file system) should not
|
||||
// have WEB-INF.classes in their package name.
|
||||
classNames.add(StringUtils.removeStart(packageName, "WEB-INF.classes.") + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,9 @@ public class UrlSet {
|
||||
URL finalUrl = (URL) ObjectUtils.defaultIfNull(normalizedUrl, warUrl);
|
||||
|
||||
Map<String, URL> newUrls = new HashMap<String, URL>(this.urls);
|
||||
newUrls.put(finalUrl.toExternalForm(), finalUrl);
|
||||
if ("jar".equals(finalUrl.getProtocol()) || "file".equals(finalUrl.getProtocol())) {
|
||||
newUrls.put(finalUrl.toExternalForm(), finalUrl);
|
||||
}
|
||||
return new UrlSet(newUrls);
|
||||
}
|
||||
}
|
||||
@@ -258,8 +260,16 @@ public class UrlSet {
|
||||
|
||||
}
|
||||
|
||||
//usually the "classes" dir
|
||||
list.addAll(Collections.list(classLoader.getResources("")));
|
||||
// Usually the "classes" dir.
|
||||
ArrayList<URL> classesList = Collections.list(classLoader.getResources(""));
|
||||
for (URL url : classesList) {
|
||||
if (URLUtil.isJBossUrl(url)) {
|
||||
list.add(URLUtil.getJBossPhysicalUrl(url));
|
||||
} else {
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,9 +161,9 @@ public class URLUtilTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testIsJBoss5Url() throws Exception {
|
||||
assertTrue(URLUtil.isJBoss5Url(new URL("vfszip:/c:/somewar.war/somelibrary.jar")));
|
||||
assertFalse(URLUtil.isJBoss5Url(new URL("vfsfile:/c:/somewar.war/somelibrary.jar")));
|
||||
assertFalse(URLUtil.isJBoss5Url(new URL("jar:file:/c:/somelibrary.jar")));
|
||||
assertTrue(URLUtil.isJBoss5Url(new URL("vfsmemory:/c:/somewar.war/somelibrary.jar")));
|
||||
assertTrue(URLUtil.isJBossUrl(new URL("vfszip:/c:/somewar.war/somelibrary.jar")));
|
||||
assertFalse(URLUtil.isJBossUrl(new URL("vfsfile:/c:/somewar.war/somelibrary.jar")));
|
||||
assertFalse(URLUtil.isJBossUrl(new URL("jar:file:/c:/somelibrary.jar")));
|
||||
assertTrue(URLUtil.isJBossUrl(new URL("vfsmemory:/c:/somewar.war/somelibrary.jar")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user