geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r740267 - /geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Date Tue, 03 Feb 2009 10:25:56 GMT
Author: vamsic007
Date: Tue Feb  3 10:25:55 2009
New Revision: 740267

URL: http://svn.apache.org/viewvc?rev=740267&view=rev
Log:
Support for application composite in EAR files.

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java?rev=740267&r1=740266&r2=740267&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Tue Feb  3 10:25:55 2009
@@ -101,7 +101,7 @@
     }
     
     public void createModule(Module module, Object plan, JarFile moduleFile, String targetPath,
URL specDDUrl, Environment environment, Object moduleContextInfo, AbstractName earName, Naming
naming, ModuleIDBuilder idBuilder) throws DeploymentException {
-        System.out.println("Inside TuscanyModuleBuilderExtension.createModule");
+        System.out.println("Inside TuscanyModuleBuilderExtension.createModule "+module.getName());
         // Merge environment only for SCA enhanced apps.
         if(module instanceof WebModule) {
             // TODO: Need a more general rule. For now look for web.composite
@@ -117,15 +117,18 @@
     }
 
     public void installModule(JarFile earFile, EARContext earContext, Module module, Collection
configurationStores, ConfigurationStore targetConfigurationStore, Collection repository) throws
DeploymentException {
-        System.out.println("Inside TuscanyModuleBuilderExtension.installModule");
+        System.out.println("Inside TuscanyModuleBuilderExtension.installModule "+module.getName());
     }
 
     public void initContext(EARContext earContext, Module module, ClassLoader cl) throws
DeploymentException {
-        System.out.println("Inside TuscanyModuleBuilderExtension.initContext");
+        System.out.println("Inside TuscanyModuleBuilderExtension.initContext "+module.getName());
     }
 
     public void addGBeans(EARContext earContext, Module module, ClassLoader cl, Collection
repository) throws DeploymentException {
-        System.out.println("Inside TuscanyModuleBuilderExtension.addGBeans");
+        System.out.println("Inside TuscanyModuleBuilderExtension.addGBeans "+module.getName());
+        if(!module.isStandAlone()) {
+            handleEarApplication(earContext, module, cl, repository);
+        }
         if(module instanceof WebModule) {
             handleWebModule(earContext, module, cl, repository);
         } else if(module instanceof EjbModule) {
@@ -133,6 +136,63 @@
         }
     }
 
+    private void handleEarApplication(EARContext earContext, Module module, ClassLoader cl,
Collection repository) throws DeploymentException {
+        System.out.println("Inside TuscanyModuleBuilderExtension.handleEarApplication");
+        // FIXME: Eliminate this hack.
+        // HACK: Create a JAR file with application.composite
+        // place it as META-INF/application-composite.jar to deploy to the SCA domain
+        File appCompositeFile = new File(earContext.getBaseDir(), "META-INF/application.composite");
+        File appCompositeJarFile = new File(earContext.getBaseDir(), "META-INF/application-composite.jar");
+        if(appCompositeJarFile.exists()) {
+            // The EAR file has already been handled when a previous module is processed.
+            return;
+        }
+        JarOutputStream jarOut = null;
+        FileInputStream fin = null;
+        try {
+            appCompositeJarFile.getParentFile().mkdirs();
+            jarOut = new JarOutputStream(new FileOutputStream(appCompositeJarFile));
+            if(appCompositeFile.exists()) {
+                fin = new FileInputStream(appCompositeFile);
+                jarOut.putNextEntry(new ZipEntry("application.composite"));
+                int b;
+                while((b = fin.read()) != -1) {
+                    jarOut.write(b);
+                }
+                jarOut.closeEntry();
+                IOUtil.close(fin);
+            }
+        } catch (Exception e) {
+            throw new DeploymentException(e);
+        } finally {
+            IOUtil.close(fin);
+            IOUtil.close(jarOut);
+        }
+        
+        Naming naming = earContext.getNaming();
+        
+        // Add EmbeddedRuntimeGBean to the application config.
+        AbstractName moduleName = earContext.getModuleName();
+        AbstractName abstractName = naming.createChildName(moduleName, "EmbeddedRuntime",
"GBean");
+        GBeanInfo gBeanInfo = GBeanInfo.getGBeanInfo(EmbeddedRuntimeGBean.class.getName(),
cl);
+        GBeanData data = new GBeanData(abstractName, gBeanInfo);        
+        data.setReferencePattern("embeddedSCADomainRef", embeddedSCADomainQuery);
+        data.setReferencePattern("Repository", new AbstractNameQuery(Repository.class.getName()));
+
+        data.setAttribute("jarFileName", "META-INF/application-composite.jar");
+        try {
+            earContext.addGBean(data);
+        } catch (GBeanAlreadyExistsException e) {
+            throw new DeploymentException(e);
+        }
+        
+
+        // Add dependency so that EmbeddedRuntime starts before the WebAppContext
+        // ((GBeanData)earContext.getConfiguration().findGBeanDatas(Collections.singleton(new
AbstractNameQuery(module.getModuleName()))).toArray()[0]).addDependency(abstractName);
+        // module name is not good enough to query the webappcontext gbean incase of web
modules in a EAR file
+        //((GBeanData)module.getEarContext().getConfiguration().findGBeanDatas(Collections.singleton(new
AbstractNameQuery("org.apache.geronimo.management.geronimo.WebModule"))).toArray()[0]).addDependency(abstractName);
+    }
+    
     private void handleWebModule(EARContext earContext, Module module, ClassLoader cl, Collection
repository) throws DeploymentException {
         System.out.println("Inside TuscanyModuleBuilderExtension.handleWebModule");
         Naming naming = earContext.getNaming();
@@ -208,15 +268,40 @@
         try {
             Contribution contribution = getEmbeddedSCADomain().getContributionService().contribute(appCompositeJarFile.toURL().toString(),
appCompositeJarFile.toURL(), modelResolver, false);
             for(Artifact artifact : contribution.getArtifacts()) {
+                if(thisComponentName != null) {
+                    break;
+                }
                 if (artifact.getModel() instanceof Composite && artifact.getURI().endsWith("web.composite"))
{
                     for(Component component : ((Composite)artifact.getModel()).getComponents())
{
                         if(component.getImplementation() instanceof WebImplementation) {
-                            // TODO: Check if the web-uri matches the module jar file
-                            thisComponentName = component.getName();
-                            break;
+                            WebImplementation webImpl = (WebImplementation) component.getImplementation();
+                            if(webImpl.getWebURI().equals(module.getName())) {
+                                thisComponentName = component.getName();
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if(!module.isStandAlone()) {
+                modelResolver = new ModelResolverImpl(earContext.getConfiguration().getConfigurationClassLoader());
+                File earAppCompositeJarFile = new File(earContext.getBaseDir(), "META-INF/application-composite.jar");
+                contribution = getEmbeddedSCADomain().getContributionService().contribute(earAppCompositeJarFile.toURL().toString(),
earAppCompositeJarFile.toURL(), modelResolver, false);
+                for(Artifact artifact : contribution.getArtifacts()) {
+                    if(thisComponentName != null) {
+                        break;
+                    }
+                    if (artifact.getModel() instanceof Composite) {
+                        for(Component component : ((Composite)artifact.getModel()).getComponents())
{
+                            if(component.getImplementation() instanceof WebImplementation)
{
+                                WebImplementation webImpl = (WebImplementation) component.getImplementation();
+                                if(webImpl.getWebURI().equals(module.getName())) {
+                                    thisComponentName = component.getName();
+                                    break;
+                                }
+                            }
                         }
                     }
-                    break;
                 }
             }
         } catch (Exception e1) {
@@ -395,7 +480,39 @@
                 if (artifact.getModel() instanceof Composite) {
                     for(Component component : ((Composite)artifact.getModel()).getComponents())
{
                         if(component.getImplementation() instanceof EJBImplementation) {
-                            ejb2component.put(((EJBImplementation)component.getImplementation()).getEJBLink(),
component.getName());
+                            String ejbLink = ((EJBImplementation)component.getImplementation()).getEJBLink();
+                            if(ejbLink.indexOf("#") == -1) {
+                                ejb2component.put(ejbLink, component.getName());
+                            } else {
+                                String modulePart = ejbLink.substring(0, ejbLink.indexOf("#"));
+                                if(modulePart.equals(module.getName())) {
+                                    String ejbPart = ejbLink.substring(ejbLink.indexOf("#")+1);
+                                    ejb2component.put(ejbPart, component.getName());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if(!module.isStandAlone()) {
+                modelResolver = new ModelResolverImpl(earContext.getConfiguration().getConfigurationClassLoader());
+                File earAppCompositeJarFile = new File(earContext.getBaseDir(), "META-INF/application-composite.jar");
+                contribution = getEmbeddedSCADomain().getContributionService().contribute(earAppCompositeJarFile.toURL().toString(),
earAppCompositeJarFile.toURL(), modelResolver, false);
+                for(Artifact artifact : contribution.getArtifacts()) {
+                    if (artifact.getModel() instanceof Composite) {
+                        for(Component component : ((Composite)artifact.getModel()).getComponents())
{
+                            if(component.getImplementation() instanceof EJBImplementation)
{
+                                String ejbLink = ((EJBImplementation)component.getImplementation()).getEJBLink();
+                                if(ejbLink.indexOf("#") == -1) {
+                                    ejb2component.put(ejbLink, component.getName());
+                                } else {
+                                    String modulePart = ejbLink.substring(0, ejbLink.indexOf("#"));
+                                    if(modulePart.equals(module.getName())) {
+                                        String ejbPart = ejbLink.substring(ejbLink.indexOf("#")+1);
+                                        ejb2component.put(ejbPart, component.getName());
+                                    }
+                                }
+                            }
                         }
                     }
                 }



Mime
View raw message