Skip to content

Commit ca19426

Browse files
committed
Removed support for JBoss AS 5's VFS variant (since we require JBoss AS 6+ now)
1 parent 21f680c commit ca19426

File tree

2 files changed

+16
-84
lines changed

2 files changed

+16
-84
lines changed

spring-core/src/main/java/org/springframework/core/io/VfsUtils.java

Lines changed: 13 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,36 +25,25 @@
2525
import java.net.URI;
2626
import java.net.URL;
2727

28-
import org.apache.commons.logging.Log;
29-
import org.apache.commons.logging.LogFactory;
30-
31-
import org.springframework.core.NestedIOException;
3228
import org.springframework.util.ReflectionUtils;
3329

3430
/**
3531
* Utility for detecting the JBoss VFS version available in the classpath.
36-
* JBoss AS 5+ uses VFS 2.x (package {@code org.jboss.virtual}) while
37-
* JBoss AS 6+ uses VFS 3.x (package {@code org.jboss.vfs}).
32+
* As of Spring 4.0, supports VFS 3.x on JBoss AS 6+ (package {@code org.jboss.vfs}).
3833
*
3934
* <p>Thanks go to Marius Bogoevici for the initial patch.
4035
*
4136
* <b>Note:</b> This is an internal class and should not be used outside the framework.
4237
*
4338
* @author Costin Leau
39+
* @author Juergen Hoeller
4440
* @since 3.0.3
4541
*/
4642
public abstract class VfsUtils {
4743

48-
private static final Log logger = LogFactory.getLog(VfsUtils.class);
49-
50-
private static final String VFS2_PKG = "org.jboss.virtual.";
5144
private static final String VFS3_PKG = "org.jboss.vfs.";
5245
private static final String VFS_NAME = "VFS";
5346

54-
private static enum VFS_VER { V2, V3 }
55-
56-
private static VFS_VER version;
57-
5847
private static Method VFS_METHOD_GET_ROOT_URL = null;
5948
private static Method VFS_METHOD_GET_ROOT_URI = null;
6049

@@ -71,54 +60,17 @@ private static enum VFS_VER { V2, V3 }
7160
protected static Class<?> VIRTUAL_FILE_VISITOR_INTERFACE;
7261
protected static Method VIRTUAL_FILE_METHOD_VISIT;
7362

74-
private static Method VFS_UTILS_METHOD_IS_NESTED_FILE = null;
75-
private static Method VFS_UTILS_METHOD_GET_COMPATIBLE_URI = null;
7663
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
7764
private static Method GET_PHYSICAL_FILE = null;
7865

7966
static {
8067
ClassLoader loader = VfsUtils.class.getClassLoader();
81-
String pkg;
82-
Class<?> vfsClass;
83-
84-
// check for JBoss 6
85-
try {
86-
vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
87-
version = VFS_VER.V3;
88-
pkg = VFS3_PKG;
89-
90-
if (logger.isDebugEnabled()) {
91-
logger.debug("JBoss VFS packages for JBoss AS 6 found");
92-
}
93-
}
94-
catch (ClassNotFoundException ex) {
95-
// fallback to JBoss 5
96-
if (logger.isDebugEnabled())
97-
logger.debug("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages");
98-
try {
99-
vfsClass = loader.loadClass(VFS2_PKG + VFS_NAME);
100-
101-
version = VFS_VER.V2;
102-
pkg = VFS2_PKG;
103-
104-
if (logger.isDebugEnabled())
105-
logger.debug("JBoss VFS packages for JBoss AS 5 found");
106-
}
107-
catch (ClassNotFoundException ex2) {
108-
logger.error("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled");
109-
throw new IllegalStateException("Cannot detect JBoss VFS packages", ex2);
110-
}
111-
}
112-
113-
// cache reflective information
11468
try {
115-
String methodName = (VFS_VER.V3.equals(version) ? "getChild" : "getRoot");
116-
117-
VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, methodName, URL.class);
118-
VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, methodName, URI.class);
119-
120-
Class<?> virtualFile = loader.loadClass(pkg + "VirtualFile");
69+
Class<?> vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
70+
VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, "getChild", URL.class);
71+
VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, "getChild", URI.class);
12172

73+
Class<?> virtualFile = loader.loadClass(VFS3_PKG + "VirtualFile");
12274
VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils.findMethod(virtualFile, "exists");
12375
VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils.findMethod(virtualFile, "openStream");
12476
VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils.findMethod(virtualFile, "getSize");
@@ -128,25 +80,16 @@ private static enum VFS_VER { V2, V3 }
12880
VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils.findMethod(virtualFile, "getName");
12981
VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils.findMethod(virtualFile, "getPathName");
13082
GET_PHYSICAL_FILE = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");
83+
VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils.findMethod(virtualFile, "getChild", String.class);
13184

132-
methodName = (VFS_VER.V3.equals(version) ? "getChild" : "findChild");
133-
134-
VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils.findMethod(virtualFile, methodName, String.class);
135-
136-
Class<?> utilsClass = loader.loadClass(pkg + "VFSUtils");
137-
138-
VFS_UTILS_METHOD_GET_COMPATIBLE_URI = ReflectionUtils.findMethod(utilsClass, "getCompatibleURI",
139-
virtualFile);
140-
VFS_UTILS_METHOD_IS_NESTED_FILE = ReflectionUtils.findMethod(utilsClass, "isNestedFile", virtualFile);
141-
142-
VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(pkg + "VirtualFileVisitor");
85+
VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(VFS3_PKG + "VirtualFileVisitor");
14386
VIRTUAL_FILE_METHOD_VISIT = ReflectionUtils.findMethod(virtualFile, "visit", VIRTUAL_FILE_VISITOR_INTERFACE);
14487

145-
Class<?> visitorAttributesClass = loader.loadClass(pkg + "VisitorAttributes");
88+
Class<?> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
14689
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
14790
}
14891
catch (ClassNotFoundException ex) {
149-
throw new IllegalStateException("Could not detect the JBoss VFS infrastructure", ex);
92+
throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
15093
}
15194
}
15295

@@ -224,20 +167,7 @@ static Object getChild(Object vfsResource, String path) throws IOException {
224167
}
225168

226169
static File getFile(Object vfsResource) throws IOException {
227-
if (VFS_VER.V2.equals(version)) {
228-
if ((Boolean) invokeVfsMethod(VFS_UTILS_METHOD_IS_NESTED_FILE, null, vfsResource)) {
229-
throw new IOException("File resolution not supported for nested resource: " + vfsResource);
230-
}
231-
try {
232-
return new File((URI) invokeVfsMethod(VFS_UTILS_METHOD_GET_COMPATIBLE_URI, null, vfsResource));
233-
}
234-
catch (Exception ex) {
235-
throw new NestedIOException("Failed to obtain File reference for " + vfsResource, ex);
236-
}
237-
}
238-
else {
239-
return (File) invokeVfsMethod(GET_PHYSICAL_FILE, vfsResource);
240-
}
170+
return (File) invokeVfsMethod(GET_PHYSICAL_FILE, vfsResource);
241171
}
242172

243173
static Object getRoot(URI url) throws IOException {
@@ -257,4 +187,5 @@ protected static Object doGetVisitorAttribute() {
257187
protected static String doGetPath(Object resource) {
258188
return (String) ReflectionUtils.invokeMethod(VIRTUAL_FILE_METHOD_GET_PATH_NAME, resource);
259189
}
190+
260191
}

spring-core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ static Object findRoot(URL url) throws IOException {
4545
}
4646

4747
static void visit(Object resource, InvocationHandler visitor) throws IOException {
48-
Object visitorProxy = Proxy.newProxyInstance(VIRTUAL_FILE_VISITOR_INTERFACE.getClassLoader(),
49-
new Class<?>[] { VIRTUAL_FILE_VISITOR_INTERFACE }, visitor);
48+
Object visitorProxy = Proxy.newProxyInstance(
49+
VIRTUAL_FILE_VISITOR_INTERFACE.getClassLoader(),
50+
new Class<?>[] {VIRTUAL_FILE_VISITOR_INTERFACE}, visitor);
5051
invokeVfsMethod(VIRTUAL_FILE_METHOD_VISIT, resource, visitorProxy);
5152
}
5253

0 commit comments

Comments
 (0)