You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2009/02/12 21:30:00 UTC
svn commit: r743871 - in
/geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src:
main/java/org/apache/geronimo/deployment/DeploymentContext.java
test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
Author: gawor
Date: Thu Feb 12 20:30:00 2009
New Revision: 743871
URL: http://svn.apache.org/viewvc?rev=743871&view=rev
Log:
Handle directory entries in manifest. Patch from Ivan (GERONIMO-4251)
Modified:
geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=743871&r1=743870&r2=743871&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java Thu Feb 12 20:30:00 2009
@@ -74,7 +74,6 @@
private final File baseDir;
private final File inPlaceConfigurationDir;
private final ResourceContext resourceContext;
- private final byte[] buffer = new byte[4096];
private final Map<String, ConfigurationData> childConfigurationDatas = new LinkedHashMap<String, ConfigurationData>();
private final ConfigurationManager configurationManager;
private final Configuration configuration;
@@ -290,6 +289,10 @@
JarFile newJarFile(URI relativeURI) throws IOException;
String getManifestClassPath(JarFile jarFile) throws IOException;
+
+ boolean isDirectory(URI relativeURI) throws IOException;
+
+ File[] listFiles(URI relativeURI) throws IOException;
}
private class DefaultJarFileFactory implements JarFileFactory {
@@ -310,6 +313,21 @@
}
return manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
}
+
+ public boolean isDirectory(URI relativeURI) {
+ File targetFile = getTargetFile(relativeURI);
+ return targetFile.isDirectory();
+ }
+
+ public File[] listFiles(URI relativeURI) throws IOException {
+ File targetFile = getTargetFile(relativeURI);
+ if (targetFile.isDirectory()) {
+ File[] files = targetFile.listFiles();
+ return (files == null) ? new File[0] : files;
+ } else {
+ throw new IOException(targetFile + " is not a directory");
+ }
+ }
}
public void getCompleteManifestClassPath(JarFile moduleFile, URI moduleBaseUri, URI resolutionUri, ClassPathList classpath, ModuleList exclusions) throws DeploymentException {
@@ -364,62 +382,89 @@
problems.add(new DeploymentException(printInfo("Invalid manifest classpath entry, path= " + path, moduleBaseUri, classpath, exclusions)));
continue;
}
-
- if (!pathUri.getPath().endsWith(".jar")) {
- if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException(printInfo("Manifest class path entries must end with the .jar extension (J2EE 1.4 Section 8.2): path= " + path, moduleBaseUri, classpath, exclusions)));
- }
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n"+
- "Therefore, a manifest classpath entry which does not end with .jar, " + pathUri + " is being permitted and ignored.");
- }
- continue;
- }
+
if (pathUri.isAbsolute()) {
problems.add(new DeploymentException(printInfo("Manifest class path entries must be relative (J2EE 1.4 Section 8.2): path= " + path, moduleBaseUri, classpath, exclusions)));
continue;
}
URI targetUri = moduleBaseUri.resolve(pathUri);
- if (targetUri.getPath().endsWith("/")) {
- if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException(printInfo("target path must not end with a '/' character: path= " + path + ", resolved to targetURI= " + targetUri, moduleBaseUri, classpath, exclusions)));
- }
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n"+
- "Therefore, a manifest classpath entry " + targetUri + " which does not end with a '/' character is being ignored.");
- }
- continue;
- }
- String targetEntry = targetUri.toString();
- if (exclusions.contains(targetEntry)) {
- continue;
- }
- URI resolvedUri = resolutionUri.resolve(targetUri);
- String classpathEntry = resolvedUri.toString();
- //don't get caught in circular references
- if (classpath.contains(classpathEntry)) {
- continue;
- }
- classpath.add(classpathEntry);
-
- JarFile classPathJarFile;
try {
- classPathJarFile = factory.newJarFile(targetUri);
+ if (factory.isDirectory(targetUri)) {
+ if (!targetUri.getPath().endsWith("/")) {
+ targetUri = URI.create(targetUri.getPath() + "/");
+ }
+ for (File file : factory.listFiles(targetUri)) {
+ if (file.isDirectory()) {
+ log.debug("Sub directory [" + file.getAbsolutePath() + "] in the manifest entry directory is ignored");
+ continue;
+ }
+ if (!file.getName().endsWith(".jar")) {
+ log.debug("Only jar files are added to classpath, file [" + file.getAbsolutePath() + "] is ignored");
+ continue;
+ }
+ addToClassPath(moduleBaseUri, resolutionUri, targetUri.resolve(file.getName()), classpath, exclusions, factory, problems);
+ }
+ } else {
+ if (!pathUri.getPath().endsWith(".jar")) {
+ if (manifestClassLoaderMode == MFCP_STRICT) {
+ problems.add(new DeploymentException(printInfo(
+ "Manifest class path entries must end with the .jar extension (J2EE 1.4 Section 8.2): path= "
+ + path, moduleBaseUri, classpath, exclusions)));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, a manifest classpath entry which does not end with .jar, "
+ + pathUri + " is being permitted and ignored.");
+ }
+ continue;
+ }
+ addToClassPath(moduleBaseUri, resolutionUri, targetUri, classpath, exclusions, factory, problems);
+ }
} catch (IOException e) {
if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException(printInfo("Manifest class path entries must be a valid jar file (JAVAEE 5 Section 8.2): path= " + path + ", resolved to targetURI= " + targetUri, moduleBaseUri, classpath, exclusions), e));
+ problems.add(new DeploymentException(
+ "An IOException resulting from manifest classpath : targetUri= " + targetUri, e));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, an IOException resulting from manifest classpath " + targetUri
+ + " is being ignored.");
}
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n" +
- "Therefore, an IOException resulting from manifest classpath " + targetUri + " is being ignored.");
- }
- continue;
}
+ }
+ }
- getCompleteManifestClassPath(classPathJarFile, targetUri, resolutionUri, classpath, exclusions, factory, problems);
+ private void addToClassPath(URI moduleBaseUri, URI resolutionUri, URI targetUri, ClassPathList classpath, ModuleList exclusions, JarFileFactory factory, List<DeploymentException> problems) throws DeploymentException {
+ String targetEntry = targetUri.toString();
+ if (exclusions.contains(targetEntry)) {
+ return;
}
+ URI resolvedUri = resolutionUri.resolve(targetUri);
+ String classpathEntry = resolvedUri.toString();
+ //don't get caught in circular references
+ if (classpath.contains(classpathEntry)) {
+ return;
+ }
+ classpath.add(classpathEntry);
+
+ JarFile classPathJarFile;
+ try {
+ classPathJarFile = factory.newJarFile(targetUri);
+ } catch (IOException e) {
+ if (manifestClassLoaderMode == MFCP_STRICT) {
+ problems.add(new DeploymentException(
+ printInfo(
+ "Manifest class path entries must be a valid jar file, or if it is a directory, all the files with jar suffix in it must be a valid jar file (JAVAEE 5 Section 8.2): resolved to targetURI= "
+ + targetUri, moduleBaseUri, classpath, exclusions), e));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, an IOException resulting from manifest classpath " + targetUri
+ + " is being ignored.");
+ }
+ return;
+ }
+
+ getCompleteManifestClassPath(classPathJarFile, targetUri, resolutionUri, classpath, exclusions, factory, problems);
}
private String printInfo(String message, URI moduleBaseUri, ClassPathList classpath, ModuleList exclusions) {
@@ -453,7 +498,7 @@
* @throws DeploymentException if there is a problem with the classpath in
* the manifest
*/
- public void addManifestClassPath(JarFile moduleFile, URI moduleBaseUri, JarFileFactory factory, List<DeploymentException> problems) throws DeploymentException {
+public void addManifestClassPath(JarFile moduleFile, URI moduleBaseUri, JarFileFactory factory, List<DeploymentException> problems) throws DeploymentException {
String manifestClassPath;
try {
manifestClassPath = factory.getManifestClassPath(moduleFile);
@@ -477,49 +522,73 @@
continue;
}
- if (!pathUri.getPath().endsWith(".jar")) {
- if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException("Manifest class path entries must end with the .jar extension (J2EE 1.4 Section 8.2): path= " + path + ", module= " + moduleBaseUri));
- }
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n"+
- "Therefore, a manifest classpath entry which does not end with .jar, " + pathUri + " is being permitted and ignored.");
- }
- continue;
- }
-
if (pathUri.isAbsolute()) {
problems.add(new DeploymentException("Manifest class path entries must be relative (J2EE 1.4 Section 8.2): path= " + path + ", module= " + moduleBaseUri));
continue;
}
URI targetUri = moduleBaseUri.resolve(pathUri);
- if (targetUri.getPath().endsWith("/")) {
- if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException("target path must not end with a '/' character: path= " + path + ", resolved to targetURI= " + targetUri));
- }
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n"+
- "Therefore, a manifest classpath entry " + targetUri + " which does not end with a '/' character is being ignored.");
- }
- continue;
- }
-
+
try {
- configuration.addToClassPath(targetUri.toString());
+ if (factory.isDirectory(targetUri)) {
+ if (!targetUri.getPath().endsWith("/")) {
+ targetUri = URI.create(targetUri.getPath() + "/");
+ }
+ for (File file : factory.listFiles(targetUri)) {
+ if (file.isDirectory()) {
+ log.debug("Sub directory [" + file.getAbsolutePath() + "] in the manifest entry directory is ignored");
+ continue;
+ }
+ if (!file.getName().endsWith(".jar")) {
+ log.debug("Only jar files are added to classpath, file [" + file.getAbsolutePath() + "] is ignored");
+ continue;
+ }
+ addToClassPath(targetUri.resolve(file.getName()), problems);
+ }
+ } else {
+ if (!pathUri.getPath().endsWith(".jar")) {
+ if (manifestClassLoaderMode == MFCP_STRICT) {
+ problems.add(new DeploymentException(
+ "Manifest class path entries must end with the .jar extension (J2EE 1.4 Section 8.2): path= "
+ + path + ", module= " + moduleBaseUri));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, a manifest classpath entry which does not end with .jar, "
+ + pathUri + " is being permitted and ignored.");
+ }
+ continue;
+ }
+ addToClassPath(targetUri, problems);
+ }
} catch (IOException e) {
if (manifestClassLoaderMode == MFCP_STRICT) {
- problems.add(new DeploymentException("Failure to add targetURI to configuration classpath: " + targetUri, e));
+ problems.add(new DeploymentException(
+ "An IOException resulting from manifest classpath : targetUri= " + targetUri, e));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, an IOException resulting from manifest classpath " + targetUri
+ + " is being ignored.");
}
- else {
- log.info("The "+manifestClassLoaderMessage+" processing mode is in effect.\n" +
- "Therefore, an IOException resulting from manifest classpath " + targetUri + " is being ignored.");
- }
- continue;
}
}
}
+ private void addToClassPath(URI targetUri, List<DeploymentException> problems) throws DeploymentException {
+ try {
+ configuration.addToClassPath(targetUri.getPath());
+ } catch (IOException e) {
+ if (manifestClassLoaderMode == MFCP_STRICT) {
+ problems.add(new DeploymentException(
+ "Failure to add targetURI to configuration classpath: " + targetUri.getPath(), e));
+ } else {
+ log.info("The " + manifestClassLoaderMessage + " processing mode is in effect.\n"
+ + "Therefore, an IOException resulting from manifest classpath " + targetUri.getPath()
+ + " is being ignored.");
+ }
+ return;
+ }
+ }
+
public void addClass(URI targetPath, String fqcn, byte[] bytes) throws IOException, URISyntaxException {
if (!targetPath.getPath().endsWith("/"))
throw new IllegalStateException("target path must end with a '/' character: " + targetPath);
@@ -553,6 +622,7 @@
OutputStream out = null;
try {
out = new FileOutputStream(targetFile);
+ byte[] buffer = new byte[4096];
int count;
while ((count = source.read(buffer)) > 0) {
out.write(buffer, 0, count);
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java?rev=743871&r1=743870&r2=743871&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java Thu Feb 12 20:30:00 2009
@@ -129,7 +129,9 @@
static class MockJarFileFactory implements DeploymentContext.JarFileFactory {
private final Map<URI, String> data;
-
+
+ private File[] filesInLib2 = {new File("../../libfolder/a.jar") ,new File( "../../libfolder/b.jar"),new File( "../../libfolder/c.txt"), new File("../../libfolder/subfolder")};
+
public MockJarFileFactory(Map<URI, String> data) {
this.data = data;
}
@@ -142,6 +144,20 @@
public String getManifestClassPath(JarFile jarFile) throws IOException {
return ((MockJarFile)jarFile).getManifestClasspath();
}
+
+ public boolean isDirectory(URI relativeURI) throws IOException {
+ return relativeURI.equals(URI.create("libfolder")) || relativeURI.equals(URI.create("libfolder/"))
+ || relativeURI.equals(URI.create("libfolder/subfolder"))
+ || relativeURI.equals(URI.create("libfolder/subfolder/"));
+ }
+
+ public File[] listFiles(URI relativeURI) throws IOException {
+ if (relativeURI.equals(URI.create("libfolder/")) || relativeURI.equals(URI.create("libfolder"))) {
+ return filesInLib2;
+ } else {
+ return new File[0];
+ }
+ }
}
public void testManifestClassPath1() throws Exception {
@@ -177,7 +193,32 @@
assertEquals("lib2/lib2a.jar", classPathList.get(2));
assertEquals("lib3.jar", classPathList.get(3));
}
+
+ public void testMainfestClassPath3() throws Exception {
+ MockJarFile start = new MockJarFile(URI.create("ejb1/ejb1/ejb1.jar"), "../../lib1/lib1/lib1.jar ../../libfolder");
+ URI resolutionURI = URI.create(".");
+ ModuleList exclusions = new ModuleList();
+ Map<URI, String> data = new HashMap<URI, String>();
+ data.put(URI.create("lib1/lib1/lib1.jar"), "../../lib2/lib2.jar");
+ data.put(URI.create("lib2/lib2.jar"), "lib2a.jar");
+ data.put(URI.create("lib2/lib2a.jar"), "../lib3.jar ../lib1/lib1/lib1.jar");
+ data.put(URI.create("libfolder/a.jar"), "");
+ data.put(URI.create("libfolder/b.jar"), "");
+ DeploymentContext.JarFileFactory factory = new MockJarFileFactory(data);
+ DeploymentContext context = new DeploymentContext(new File("."), null, new Environment(Artifact.create("test/foo/1/ear")), new AbstractName(URI.create("test/foo/1/ear?name=test")), ConfigurationModuleType.EAR, new Jsr77Naming(), new MockConfigurationManager());
+ ClassPathList classPathList = new ClassPathList();
+ context.getCompleteManifestClassPath(start, start.getRelativeURI(), resolutionURI, classPathList, exclusions, factory, new ArrayList<DeploymentException>());
+ assertEquals(6, classPathList.size());
+ assertEquals("lib1/lib1/lib1.jar", classPathList.get(0));
+ assertEquals("lib2/lib2.jar", classPathList.get(1));
+ assertEquals("lib2/lib2a.jar", classPathList.get(2));
+ assertEquals("lib3.jar", classPathList.get(3));
+ assertEquals("libfolder/a.jar", classPathList.get(4));
+ assertEquals("libfolder/b.jar", classPathList.get(5));
+
+ }
+
public void testManifestClassPathWar1() throws Exception {
MockJarFile start = new MockJarFile(URI.create("war1.war"), "lib1.jar");
URI resolutionURI = URI.create("../");