geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r555869 - in /geronimo/server/trunk/modules: geronimo-deployment/src/main/java/org/apache/geronimo/deployment/ geronimo-deployment/src/test/java/org/apache/geronimo/deployment/ geronimo-openejb-builder/src/main/java/org/apache/geronimo/open...
Date Fri, 13 Jul 2007 04:34:56 GMT
Author: djencks
Date: Thu Jul 12 21:34:52 2007
New Revision: 555869

URL: http://svn.apache.org/viewvc?view=rev&rev=555869
Log:
GERONIMO-3307 Unit tests and a whole lotta fixes

Modified:
    geronimo/server/trunk/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/server/trunk/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?view=diff&rev=555869&r1=555868&r2=555869
==============================================================================
--- geronimo/server/trunk/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
Thu Jul 12 21:34:52 2007
@@ -254,23 +254,57 @@
         resourceContext.addInclude(targetPath, source);
     }
 
+    interface JarFileFactory {
+        JarFile newJarFile(URI relativeURI) throws IOException;
+        String getManifestClassPath(JarFile jarFile) throws IOException;
+    }
+
+    private class DefaultJarFileFactory implements JarFileFactory {
+
+        public JarFile newJarFile(URI relativeURI) throws IOException {
+            File targetFile = getTargetFile(relativeURI);
+            return new JarFile(targetFile);
+        }
+
+        public String getManifestClassPath(JarFile jarFile) throws IOException {
+            Manifest manifest = jarFile.getManifest();
+            if (manifest == null) {
+            return null;
+            }
+            return manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
+        }
+    }
+
+    public void getCompleteManifestClassPath(JarFile moduleFile, URI moduleBaseUri, URI resolutionUri,
ClassPathList classpath, ModuleList exclusions) throws DeploymentException {
+         getCompleteManifestClassPath(moduleFile,  moduleBaseUri, resolutionUri, classpath,
exclusions, new DefaultJarFileFactory());
+    }
+
     /**
      * Recursively construct the complete set of paths in the ear for the manifest classpath
of the supplied modulefile.
      * Used only in PersistenceUnitBuilder to figure out if a persistence.xml relates to
the starting module.  Having a classloader for
      * each ejb module would eliminate the need for this and be more elegant.
+     *
+     * @param moduleFile the module that we start looking at classpaths at, in the car.
+     *
+     * @param moduleBaseUri where the moduleFile is inside the car file.  For an (unpacked)
war this ends with / which means we also need:
+     *
+     * @param resolutionUri the uri to resolve against.  For a (packed) jar module this is
the same as moduleBaseUri.  For a war it removes the last segment.
+     *
+     * @param classpath the classpath list we are constructing.
+     *
+     * @param exclusions the paths to not investigate.  These are typically the other modules
in the ear/car file: they will have their contents processed for themselves.
+     *
+     * @param factory
+     * @throws org.apache.geronimo.common.DeploymentException if something goes wrong.
      */
-    public void getCompleteManifestClassPath(JarFile moduleFile, URI moduleBaseUri, URI resolutionUri,
ClassPathList classpath, ModuleList exclusions) throws DeploymentException {
-        Manifest manifest;
+    public void getCompleteManifestClassPath(JarFile moduleFile, URI moduleBaseUri, URI resolutionUri,
ClassPathList classpath, ModuleList exclusions, JarFileFactory factory) throws DeploymentException
{
+        String manifestClassPath;
         try {
-            manifest = moduleFile.getManifest();
+            manifestClassPath = factory.getManifestClassPath(moduleFile);
         } catch (IOException e) {
             throw new DeploymentException("Could not read manifest: " + moduleBaseUri, e);
         }
 
-        if (manifest == null) {
-            return;
-        }
-        String manifestClassPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
         if (manifestClassPath == null) {
             return;
         }
@@ -296,26 +330,26 @@
             if (targetUri.getPath().endsWith("/")) {
                 throw new DeploymentException("target path must not end with a '/' character:
" + targetUri);
             }
-            String classpathEntry = targetUri.toString();
-            if (exclusions.contains(classpathEntry)) {
+            String targetEntry = targetUri.toString();
+            if (exclusions.contains(targetEntry)) {
                 continue;
             }
-            URI resolvedUri = resolutionUri.resolve(pathUri);
-            String resolvedEntry = resolvedUri.toString();
+            URI resolvedUri = resolutionUri.resolve(targetUri);
+            String classpathEntry = resolvedUri.toString();
             //don't get caught in circular references
-            if (classpath.contains(resolvedEntry)) {
+            if (classpath.contains(classpathEntry)) {
                 continue;
             }
-            classpath.add(resolvedEntry);
-            File targetFile = getTargetFile(resolvedUri);
+            classpath.add(classpathEntry);
+
             JarFile classPathJarFile;
             try {
-                classPathJarFile = new JarFile(targetFile);
+                classPathJarFile = factory.newJarFile(targetUri);
             } catch (IOException e) {
-                throw new DeploymentException("Manifest class path entries must be a valid
jar file (JAVAEE 5 Section 8.2): jarFile=" + targetFile + ", path=" + path, e);
+                throw new DeploymentException("Manifest class path entries must be a valid
jar file (JAVAEE 5 Section 8.2): jarFile=" + resolvedUri + ", path=" + path, e);
             }
 
-            getCompleteManifestClassPath(classPathJarFile, targetUri, resolutionUri, classpath,
exclusions);
+            getCompleteManifestClassPath(classPathJarFile, targetUri, resolutionUri, classpath,
exclusions, factory);
         }
     }
 

Modified: geronimo/server/trunk/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java?view=diff&rev=555869&r1=555868&r2=555869
==============================================================================
--- geronimo/server/trunk/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
Thu Jul 12 21:34:52 2007
@@ -17,10 +17,15 @@
 package org.apache.geronimo.deployment;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.jar.JarFile;
 
 import javax.sql.DataSource;
 
@@ -31,12 +36,24 @@
 import org.apache.geronimo.kernel.Jsr77Naming;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.SimpleConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationStore;
+import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.LifecycleResults;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
+import org.apache.geronimo.kernel.config.LifecycleException;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.LifecycleMonitor;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ArtifactManager;
 import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
 import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
+import org.apache.geronimo.kernel.repository.Version;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
+import org.apache.geronimo.gbean.AbstractName;
 
 /**
  * @version $Rev$ $Date$
@@ -88,4 +105,300 @@
         }
         file.delete();
     }
+
+
+    //test the getCompleteManifestClassPath method
+
+    private static class MockJarFile extends JarFile {
+        private final String manifestClasspath;
+
+
+        public MockJarFile(String manifestClasspath) throws IOException {
+            super(DeploymentUtil.DUMMY_JAR_FILE);
+            this.manifestClasspath = manifestClasspath;
+        }
+
+
+        public String getManifestClasspath() {
+            return manifestClasspath;
+        }
+    }
+
+    static class MockJarFileFactory implements DeploymentContext.JarFileFactory {
+
+        private final Map<URI, String> data;
+
+        public MockJarFileFactory(Map<URI, String> data) {
+            this.data = data;
+        }
+
+        public JarFile newJarFile(URI relativeURI) throws IOException {
+            String manifestcp = data.get(relativeURI);
+            return new MockJarFile(manifestcp);
+        }
+
+        public String getManifestClassPath(JarFile jarFile) throws IOException {
+            return ((MockJarFile)jarFile).getManifestClasspath();
+        }
+    }
+    
+    public void testManifestClassPath1() throws Exception {
+        //remember, the constructor takes the manifest classpath, not the location
+        JarFile start = new MockJarFile("lib1.jar");
+        URI moduleBaseURI = URI.create("ejb.jar");
+        URI resolutionURI = URI.create(".");
+        ModuleList exclusions = new ModuleList();
+        Map<URI, String> data = new HashMap<URI, String>();
+        data.put(URI.create("lib1.jar"), "lib1.jar lib2.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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(2, classPathList.size());
+    }
+
+    public void testManifestClassPath2() throws Exception {
+        JarFile start = new MockJarFile("../../lib1/lib1/lib1.jar");
+        URI moduleBaseURI = URI.create("ejb1/ejb1/ejb1.jar");
+        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");
+
+        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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(4, 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));
+    }
+
+    public void testManifestClassPathWar1() throws Exception {
+        JarFile start = new MockJarFile("lib1.jar");
+        URI moduleBaseURI = URI.create("war1.war");
+        URI resolutionURI = URI.create("../");
+        ModuleList exclusions = new ModuleList();
+        Map<URI, String> data = new HashMap<URI, String>();
+        data.put(URI.create("lib1.jar"), "lib1.jar lib2.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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(2, classPathList.size());
+        assertEquals("../lib1.jar", classPathList.get(0));
+        assertEquals("../lib2.jar", classPathList.get(1));
+        //should contain ../lib1.jar ../lib2.jar
+    }
+
+    public void testManifestClassPathWar2() throws Exception {
+        JarFile start = new MockJarFile("../../lib1/lib1/lib1.jar");
+        URI moduleBaseURI = URI.create("war1/war1/war1.war");
+        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/lib2.jar");
+        data.put(URI.create("lib2/lib2/lib2.jar"), "../lib2a/lib2a.jar");
+        data.put(URI.create("lib2/lib2a/lib2a.jar"), "../../lib3/lib3/lib3.jar ../../lib1/lib1/lib1.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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(4, classPathList.size());
+        assertEquals("../../../lib1/lib1/lib1.jar", classPathList.get(0));
+        assertEquals("../../../lib2/lib2/lib2.jar", classPathList.get(1));
+        assertEquals("../../../lib2/lib2a/lib2a.jar", classPathList.get(2));
+        assertEquals("../../../lib3/lib3/lib3.jar", classPathList.get(3));
+    }
+
+    public void testManifestClassPathWar3() throws Exception {
+        JarFile start = new MockJarFile("../../lib1/lib1/lib1.jar");
+        URI moduleBaseURI = URI.create("war1/war1/war1.war");
+        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");
+
+        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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(4, 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));
+    }
+
+    public void testManifestClassPathExcludeModules1() throws Exception {
+        JarFile start = new MockJarFile("lib1.jar");
+        URI moduleBaseURI = URI.create("ejb1.jar");
+        URI resolutionURI = URI.create(".");
+        ModuleList exclusions = new ModuleList();
+        exclusions.add("ejb1.jar");
+        exclusions.add("ejb2.jar");
+        Map<URI, String> data = new HashMap<URI, String>();
+        data.put(URI.create("lib1.jar"), "ejb2.jar lib2.jar");
+        data.put(URI.create("lib2.jar"), "ejb2.jar lib1.jar");
+        data.put(URI.create("ejb2.jar"), "lib3.jar lib4.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, moduleBaseURI, resolutionURI, classPathList,
exclusions, factory);
+        assertEquals(2, classPathList.size());
+    }
+
+
+    static class MockConfigurationManager implements ConfigurationManager {
+
+        public boolean isInstalled(Artifact configurationId) {
+            return false;
+        }
+
+        public boolean isLoaded(Artifact configurationId) {
+            return false;
+        }
+
+        public boolean isRunning(Artifact configurationId) {
+            return false;
+        }
+
+        public Artifact[] getInstalled(Artifact query) {
+            return new Artifact[0];
+        }
+
+        public Artifact[] getLoaded(Artifact query) {
+            return new Artifact[0];
+        }
+
+        public Artifact[] getRunning(Artifact query) {
+            return new Artifact[0];
+        }
+
+        public List listConfigurations() {
+            return null;
+        }
+
+        public List listStores() {
+            return null;
+        }
+
+        public ConfigurationStore[] getStores() {
+            return new ConfigurationStore[0];
+        }
+
+        public ConfigurationStore getStoreForConfiguration(Artifact configuration) {
+            return null;
+        }
+
+        public List listConfigurations(AbstractName store) throws NoSuchStoreException {
+            return null;
+        }
+
+        public boolean isConfiguration(Artifact artifact) {
+            return false;
+        }
+
+        public Configuration getConfiguration(Artifact configurationId) {
+            return null;
+        }
+
+        public LifecycleResults loadConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults loadConfiguration(ConfigurationData configurationData) throws
NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults loadConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults loadConfiguration(ConfigurationData configurationData, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults unloadConfiguration(Artifact configurationId) throws NoSuchConfigException
{
+            return null;
+        }
+
+        public LifecycleResults unloadConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException {
+            return null;
+        }
+
+        public LifecycleResults startConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults startConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults stopConfiguration(Artifact configurationId) throws NoSuchConfigException
{
+            return null;
+        }
+
+        public LifecycleResults stopConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException {
+            return null;
+        }
+
+        public LifecycleResults restartConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults restartConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, Version version)
throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, Version version,
LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(ConfigurationData configurationData)
throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(ConfigurationData configurationData,
LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public void uninstallConfiguration(Artifact configurationId) throws IOException,
NoSuchConfigException {
+        }
+
+        public ArtifactResolver getArtifactResolver() {
+            return null;
+        }
+
+        public boolean isOnline() {
+            return false;
+        }
+
+        public void setOnline(boolean online) {
+        }
+    }
+
+
 }

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?view=diff&rev=555869&r1=555868&r2=555869
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Thu Jul 12 21:34:52 2007
@@ -477,7 +477,7 @@
         EARContext moduleContext = module.getEarContext();
         ModuleList moduleLocations = (ModuleList) module.getRootEarContext().getGeneralData().get(ModuleList.class);
         URI baseUri = URI.create(module.getTargetPath());
-        moduleContext.getCompleteManifestClassPath(module.getModuleFile(), baseUri, baseUri,
manifestcp, moduleLocations);
+        moduleContext.getCompleteManifestClassPath(module.getModuleFile(), baseUri, URI.create("."),
manifestcp, moduleLocations);
         moduleContext.getGeneralData().put(ClassPathList.class, manifestcp);
 
         for (ModuleBuilderExtension builder : moduleBuilderExtensions) {



Mime
View raw message