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 2013/02/05 19:10:39 UTC
svn commit: r1442682 - in /geronimo/server/branches/3.0/plugins:
aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/
aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/
openejb/geronimo-openejb-builder/src/main/java/...
Author: gawor
Date: Tue Feb 5 18:10:39 2013
New Revision: 1442682
URL: http://svn.apache.org/viewvc?rev=1442682&view=rev
Log:
GERONIMO-6434: in-place deployment for OSGi applications
Added:
geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java (with props)
Modified:
geronimo/server/branches/3.0/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationConfigBuilder.java
geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java
geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/UnpackEBATypeHandler.java
geronimo/server/branches/3.0/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationConfigBuilder.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationConfigBuilder.java (original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationConfigBuilder.java Tue Feb 5 18:10:39 2013
@@ -18,21 +18,15 @@ package org.apache.geronimo.aries.builde
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collection;
import java.util.jar.JarFile;
-import java.util.jar.Manifest;
import org.apache.aries.application.ApplicationMetadata;
-import org.apache.aries.application.ApplicationMetadataFactory;
-import org.apache.aries.application.filesystem.IDirectory;
-import org.apache.aries.application.filesystem.IFile;
import org.apache.aries.application.management.AriesApplication;
-import org.apache.aries.application.management.AriesApplicationManager;
-import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.management.ManagementException;
import org.apache.aries.application.utils.filesystem.FileSystem;
-import org.apache.aries.application.utils.manifest.ManifestDefaultsInjector;
-import org.apache.aries.application.utils.manifest.ManifestProcessor;
+import org.apache.geronimo.aries.ApplicationInstaller;
+import org.apache.geronimo.aries.GeronimoApplicationManager;
import org.apache.geronimo.common.DeploymentException;
import org.apache.geronimo.deployment.ConfigurationBuilder;
import org.apache.geronimo.deployment.DeploymentContext;
@@ -48,10 +42,9 @@ import org.apache.geronimo.kernel.config
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.ArtifactResolver;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.geronimo.aries.ApplicationInstaller;
+
/**
* @version $Rev:385232 $ $Date$
*/
@@ -81,26 +74,6 @@ public class ApplicationConfigBuilder im
doStop();
}
- private AriesApplicationManager getAriesApplicationManager() {
- ServiceReference ref =
- bundleContext.getServiceReference(AriesApplicationManager.class.getName());
- if (ref != null) {
- return (AriesApplicationManager) bundleContext.getService(ref);
- } else {
- return null;
- }
- }
-
- private ApplicationMetadataFactory getApplicationMetadataFactory() {
- ServiceReference ref =
- bundleContext.getServiceReference(ApplicationMetadataFactory.class.getName());
- if (ref != null) {
- return (ApplicationMetadataFactory) bundleContext.getService(ref);
- } else {
- return null;
- }
- }
-
public Object getDeploymentPlan(File planFile,
JarFile jarFile,
ModuleIDBuilder idBuilder)
@@ -120,22 +93,13 @@ public class ApplicationConfigBuilder im
JarFile jarFile,
ModuleIDBuilder idBuilder)
throws IOException, DeploymentException {
- ApplicationMetadataFactory factory = getApplicationMetadataFactory();
- IDirectory ebaFile = FileSystem.getFSRoot(new File(jarFile.getName()));
- IFile applicationManifestFile = ebaFile.getFile(AppConstants.APPLICATION_MF);
- Manifest applicationManifest;
- if (applicationManifestFile != null) {
- InputStream in = applicationManifestFile.open();
- try {
- applicationManifest = ManifestProcessor.parseManifest(in);
- } finally {
- try { in.close(); } catch (IOException ignore) {}
- }
- } else {
- applicationManifest = new Manifest();
+ GeronimoApplicationManager appManager = installer.getGeronimoApplicationManager();
+ ApplicationMetadata metadata;
+ try {
+ metadata = appManager.getApplicationMetadata(jarFile);
+ } catch (ManagementException e) {
+ throw new DeploymentException("Error getting Aries Application manifest", e);
}
- ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
- ApplicationMetadata metadata = factory.createApplicationMetadata(applicationManifest);
return ApplicationInstaller.getConfigId(metadata);
}
@@ -153,11 +117,17 @@ public class ApplicationConfigBuilder im
ConfigurationStore targetConfigurationStore)
throws IOException, DeploymentException {
- AriesApplicationManager appManager = getAriesApplicationManager();
+ GeronimoApplicationManager appManager = installer.getGeronimoApplicationManager();
+ File ebaFile = new File(jarFile.getName());
+
AriesApplication app = null;
try {
- app = appManager.createApplication(FileSystem.getFSRoot(new File(jarFile.getName())));
+ if (inPlaceDeployment) {
+ app = appManager.createApplication(jarFile);
+ } else {
+ app = appManager.createApplication(FileSystem.getFSRoot(ebaFile));
+ }
} catch (Exception e) {
throw new DeploymentException("Error creating Aries Application", e);
}
@@ -170,7 +140,7 @@ public class ApplicationConfigBuilder im
}
}
- DeploymentContext context = installer.startInstall(app, targetConfigurationStore);
+ DeploymentContext context = installer.startInstall(app, (inPlaceDeployment) ? ebaFile : null, targetConfigurationStore);
return context;
}
Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java (original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java Tue Feb 5 18:10:39 2013
@@ -26,7 +26,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import org.apache.aries.application.ApplicationMetadataFactory;
import org.apache.aries.application.DeploymentContent;
import org.apache.aries.application.DeploymentMetadata;
import org.apache.aries.application.DeploymentMetadataFactory;
@@ -82,39 +81,26 @@ public class ApplicationGBean implements
public ApplicationGBean(@ParamSpecial(type = SpecialAttributeType.kernel) Kernel kernel,
@ParamSpecial(type = SpecialAttributeType.bundle) Bundle bundle,
@ParamAttribute(name="configId") Artifact configId,
+ @ParamAttribute(name="location") File inPlaceLocation,
@ParamReference(name="Installer") ApplicationInstaller installer)
throws Exception {
this.bundle = bundle;
this.installer = installer;
this.configId = configId;
this.updateHelper = new ApplicationUpdateHelper(this);
-
- BundleContext bundleContext = bundle.getBundleContext();
- DeploymentMetadataFactory deploymentFactory = null;
- ApplicationMetadataFactory applicationFactory = null;
-
- ServiceReference deploymentFactoryReference =
- bundleContext.getServiceReference(DeploymentMetadataFactory.class.getName());
- ServiceReference applicationFactoryReference =
- bundleContext.getServiceReference(ApplicationMetadataFactory.class.getName());
-
- try {
- deploymentFactory = getService(deploymentFactoryReference, DeploymentMetadataFactory.class);
- applicationFactory = getService(applicationFactoryReference, ApplicationMetadataFactory.class);
-
- this.application = new GeronimoApplication(bundle, applicationFactory, deploymentFactory);
-
- install(deploymentFactory);
- } finally {
- if (deploymentFactory != null) {
- bundleContext.ungetService(deploymentFactoryReference);
- }
- if (applicationFactory != null) {
- bundleContext.ungetService(applicationFactoryReference);
- }
+ GeronimoApplicationManager appManager = installer.getGeronimoApplicationManager();
+
+ if (inPlaceLocation == null) {
+ this.application = appManager.loadApplication(bundle);
+ } else {
+ this.application = appManager.loadApplication(inPlaceLocation);
}
+
+ DeploymentMetadataFactory deploymentFactory = appManager.getDeploymentMetadataFactory();
+ install(deploymentFactory);
+ BundleContext bundleContext = bundle.getBundleContext();
ServiceReference applicationManagerReference =
bundleContext.getServiceReference(AriesApplicationContextManager.class.getName());
Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java (original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java Tue Feb 5 18:10:39 2013
@@ -27,9 +27,9 @@ import java.util.zip.ZipInputStream;
import org.apache.aries.application.ApplicationMetadata;
import org.apache.aries.application.DeploymentMetadata;
import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationContext.ApplicationState;
import org.apache.aries.application.management.AriesApplicationListener;
import org.apache.aries.application.management.BundleInfo;
-import org.apache.aries.application.management.AriesApplicationContext.ApplicationState;
import org.apache.aries.application.utils.AppConstants;
import org.apache.geronimo.common.DeploymentException;
import org.apache.geronimo.deployment.DeploymentContext;
@@ -83,7 +83,8 @@ public class ApplicationInstaller implem
private Collection<? extends Repository> repositories;
private Collection<ConfigurationStore> configurationStores;
private Environment defaultEnvironment;
-
+ private GeronimoApplicationManager applicationManager;
+
public ApplicationInstaller(@ParamReference(name = "Store", namingType = "ConfigurationStore") Collection<ConfigurationStore> configurationStores,
@ParamReference(name = "Repositories", namingType = "Repository") Collection<? extends Repository> repositories,
@ParamAttribute(name = "defaultEnvironment") Environment defaultEnvironment,
@@ -99,11 +100,13 @@ public class ApplicationInstaller implem
this.configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
this.defaultEnvironment = defaultEnvironment;
this.webApplicationTracker = new WebApplicationTracker(bundleContext);
+ this.applicationManager = new GeronimoApplicationManager(bundleContext);
}
public void doStart() throws Exception {
registration = bundleContext.registerService(ApplicationInstaller.class.getName(), this, null);
webApplicationTracker.start();
+ applicationManager.doStart();
if (getUnpackApplicationBundles()) {
for (Repository repository : repositories) {
@@ -119,12 +122,17 @@ public class ApplicationInstaller implem
registration.unregister();
}
webApplicationTracker.stop();
+ applicationManager.doStop();
}
public void doFail() {
doStop();
}
+ public GeronimoApplicationManager getGeronimoApplicationManager() {
+ return applicationManager;
+ }
+
protected ConfigurationManager getConfigurationManager() {
return configurationManager;
}
@@ -132,8 +140,8 @@ public class ApplicationInstaller implem
protected WebApplicationTracker getWebApplicationTracker() {
return webApplicationTracker;
}
-
- public DeploymentContext startInstall(AriesApplication app, ConfigurationStore targetConfigurationStore)
+
+ public DeploymentContext startInstall(AriesApplication app, File inPlaceLocation, ConfigurationStore targetConfigurationStore)
throws ConfigurationAlreadyExistsException, IOException, DeploymentException {
Artifact configId = getConfigId(app.getApplicationMetadata());
@@ -163,12 +171,17 @@ public class ApplicationInstaller implem
context.flush();
context.initializeConfiguration();
- // UnpackEBATypeHandler will unpack the application bundles if necessary at install time
- storeApplication(app, tempDirectory, false);
+ if (inPlaceLocation == null) {
+ // UnpackEBATypeHandler will unpack the application bundles if necessary at install time
+ storeApplication(app, tempDirectory, false);
+ } else {
+ storeInPlaceApplication(app, inPlaceLocation);
+ }
AbstractName name = naming.createChildName(moduleName, "AriesApplication", "GBean");
GBeanData data = new GBeanData(name, ApplicationGBean.class);
data.setAttribute("configId", configId);
+ data.setAttribute("location", inPlaceLocation);
data.setReferencePattern("Installer", abstractName);
context.addGBean(data);
@@ -227,6 +240,17 @@ public class ApplicationInstaller implem
}
}
}
+
+ private void storeInPlaceApplication(AriesApplication app, File inPlaceLocation) throws IOException {
+ // save DEPLOYMENT.MF if it was not there before and application is resolved
+ File deploymentMF = new File(inPlaceLocation, AppConstants.DEPLOYMENT_MF);
+ if (!deploymentMF.exists()) {
+ DeploymentMetadata deploymentMetadata = app.getDeploymentMetadata();
+ if (deploymentMetadata != null) {
+ deploymentMetadata.store(deploymentMF);
+ }
+ }
+ }
public ConfigurationData finishInstall(DeploymentContext context, ConfigurationStore targetConfigurationStore)
throws ConfigurationAlreadyExistsException, DeploymentException {
@@ -246,7 +270,7 @@ public class ApplicationInstaller implem
if (store == null) {
throw new DeploymentException("No ConfigurationStore");
}
- DeploymentContext context = startInstall(app, store);
+ DeploymentContext context = startInstall(app, null, store);
ConfigurationData configurationData = finishInstall(context, store);
try {
Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java (original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java Tue Feb 5 18:10:39 2013
@@ -19,25 +19,13 @@ package org.apache.geronimo.aries;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Set;
import org.apache.aries.application.ApplicationMetadata;
-import org.apache.aries.application.ApplicationMetadataFactory;
import org.apache.aries.application.DeploymentMetadata;
-import org.apache.aries.application.DeploymentMetadataFactory;
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.BundleInfo;
-import org.apache.aries.application.utils.AppConstants;
-import org.apache.aries.application.utils.management.SimpleBundleInfo;
-import org.apache.aries.application.utils.manifest.BundleManifest;
-import org.apache.geronimo.kernel.util.IOUtils;
-import org.apache.xbean.osgi.bundle.util.BundleUtils;
-import org.osgi.framework.Bundle;
/**
* @version $Rev:385232 $ $Date$
@@ -48,39 +36,12 @@ public class GeronimoApplication impleme
private final Set<BundleInfo> bundleInfo;
private DeploymentMetadata deploymentMetadata;
- public GeronimoApplication(Bundle bundle,
- ApplicationMetadataFactory applicationFactory,
- DeploymentMetadataFactory deploymentFactory)
- throws IOException {
-
- URL applicationMF = bundle.getEntry(AppConstants.APPLICATION_MF);
- InputStream applicationMFStream = null;
- try {
- applicationMFStream = applicationMF.openStream();
- applicationMetadata = applicationFactory.parseApplicationMetadata(applicationMFStream);
- } finally {
- IOUtils.close(applicationMFStream);
- }
-
- bundleInfo = new HashSet<BundleInfo>();
-
- File bundleFile = BundleUtils.toFile(bundle);
- if (bundleFile != null && bundleFile.isDirectory()) {
- collectFileSystemBasedBundleInfos(bundleFile, applicationFactory);
- } else {
- collectBundleEntryBasedBundleInfos(bundle, applicationFactory);
- }
-
- URL deploymentMF = bundle.getEntry(AppConstants.DEPLOYMENT_MF);
- if (deploymentMF != null) {
- InputStream deploymentMFStream = null;
- try {
- deploymentMFStream = deploymentMF.openStream();
- deploymentMetadata = deploymentFactory.createDeploymentMetadata(deploymentMFStream);
- } finally {
- IOUtils.close(deploymentMFStream);
- }
- }
+ public GeronimoApplication(ApplicationMetadata applicationMetadata,
+ DeploymentMetadata deploymentMetadata,
+ Set<BundleInfo> bundleInfo) {
+ this.applicationMetadata = applicationMetadata;
+ this.deploymentMetadata = deploymentMetadata;
+ this.bundleInfo = bundleInfo;
}
public ApplicationMetadata getApplicationMetadata() {
@@ -107,45 +68,4 @@ public class GeronimoApplication impleme
throw new UnsupportedOperationException();
}
- private void collectFileSystemBasedBundleInfos(File baseDir, ApplicationMetadataFactory applicationFactory) throws IOException {
- for (File file : baseDir.listFiles()) {
- if (file.isDirectory()) {
- if (file.getName().endsWith(".jar")) {
- BundleManifest bm = BundleManifest.fromBundle(file);
- if (bm != null && bm.isValid()) {
- bundleInfo.add(new SimpleBundleInfo(applicationFactory, bm, "reference:" + file.toURI().toString()));
- }
- } else {
- collectFileSystemBasedBundleInfos(file, applicationFactory);
- continue;
- }
- } else {
- BundleManifest bm = BundleManifest.fromBundle(file);
- if (bm != null && bm.isValid()) {
- /*
- * Pass file:// url instead of reference:file:// as bundle location to make sure
- * Equinox has its own copy of the jar. That is, to prevent strange ZipErrors when
- * application bundles are updated at runtime, specifically, when
- * ApplicationGBean.hotSwapApplicationContent() is called.
- */
- bundleInfo.add(new SimpleBundleInfo(applicationFactory, bm, file.toURI().toString()));
- }
- }
- }
- }
-
- private void collectBundleEntryBasedBundleInfos(Bundle bundle, ApplicationMetadataFactory applicationFactory) throws IOException {
- Enumeration<URL> e = bundle.findEntries("/", "*", true);
- while (e.hasMoreElements()) {
- URL url = e.nextElement();
- if (url.getPath().endsWith("/")) {
- continue;
- }
- BundleManifest bm = BundleManifest.fromBundle(url.openStream());
- if (bm != null && bm.isValid()) {
- bundleInfo.add(new SimpleBundleInfo(applicationFactory, bm, url.toExternalForm()));
- }
- }
- }
-
}
\ No newline at end of file
Added: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java?rev=1442682&view=auto
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java (added)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java Tue Feb 5 18:10:39 2013
@@ -0,0 +1,328 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.aries;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.ApplicationMetadataFactory;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.DeploymentMetadataFactory;
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationManager;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ManagementException;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.management.SimpleBundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.application.utils.manifest.ManifestDefaultsInjector;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.geronimo.kernel.util.JarUtils;
+import org.apache.xbean.osgi.bundle.util.BundleUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceException;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev:385232 $ $Date$
+ */
+public class GeronimoApplicationManager {
+
+ private static final Attributes.Name APPLICATION_CONTENT_NAME = new Attributes.Name(AppConstants.APPLICATION_CONTENT);
+
+ private static final Logger LOG = LoggerFactory.getLogger(GeronimoApplicationManager.class);
+
+ private BundleContext bundleContext;
+
+ private ServiceTracker deploymentFactoryTracker;
+ private ServiceTracker applicationFactoryTracker;
+ private ServiceTracker applicationManagerTracker;
+
+ public GeronimoApplicationManager(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ this.deploymentFactoryTracker = new ServiceTracker(bundleContext, DeploymentMetadataFactory.class.getName(), null);
+ this.applicationFactoryTracker = new ServiceTracker(bundleContext, ApplicationMetadataFactory.class.getName(), null);
+ this.applicationManagerTracker = new ServiceTracker(bundleContext, AriesApplicationManager.class.getName(), null);
+ }
+
+ public void doStart() throws Exception {
+ deploymentFactoryTracker.open();
+ applicationFactoryTracker.open();
+ applicationManagerTracker.open();
+ }
+
+ public void doStop() {
+ deploymentFactoryTracker.close();
+ applicationFactoryTracker.close();
+ applicationManagerTracker.close();
+ }
+
+ public DeploymentMetadataFactory getDeploymentMetadataFactory() throws ManagementException {
+ DeploymentMetadataFactory service = (DeploymentMetadataFactory) deploymentFactoryTracker.getService();
+ if (service == null) {
+ throw new ManagementException(new ServiceException(DeploymentMetadataFactory.class.getName(), ServiceException.UNREGISTERED));
+ }
+ return service;
+ }
+
+ public ApplicationMetadataFactory getApplicationMetadataFactory() throws ManagementException {
+ ApplicationMetadataFactory service = (ApplicationMetadataFactory) applicationFactoryTracker.getService();
+ if (service == null) {
+ throw new ManagementException(new ServiceException(ApplicationMetadataFactory.class.getName(), ServiceException.UNREGISTERED));
+ }
+ return service;
+ }
+
+ private AriesApplicationManager getAriesApplicationManager() throws ManagementException {
+ AriesApplicationManager service = (AriesApplicationManager) applicationManagerTracker.getService();
+ if (service == null) {
+ throw new ManagementException(new ServiceException(AriesApplicationManager.class.getName(), ServiceException.UNREGISTERED));
+ }
+ return service;
+ }
+
+ public AriesApplication createApplication(JarFile ebaJarFile) throws IOException, ManagementException {
+ File ebaFile = new File(ebaJarFile.getName());
+
+ if (!ebaFile.isDirectory()) {
+ throw new IOException("Must be expanded Aries Application");
+ }
+
+ Manifest applicationMF = readApplicationManifest(ebaJarFile);
+
+ Set<BundleInfo> bundleInfos = getBundleInfos(ebaFile);
+
+ if (applicationMF.getMainAttributes().get(APPLICATION_CONTENT_NAME) == null) {
+ String appContent = buildAppContent(bundleInfos);
+ applicationMF.getMainAttributes().put(APPLICATION_CONTENT_NAME, appContent);
+ }
+
+ ManifestDefaultsInjector.updateManifest(applicationMF, ebaFile.getName(), ebaFile);
+ ApplicationMetadata applicationMetadata = getApplicationMetadataFactory().createApplicationMetadata(applicationMF);
+
+ DeploymentMetadata deploymentMetadata = readDeploymentManifest(ebaJarFile);
+
+ return new GeronimoApplication(applicationMetadata, deploymentMetadata, bundleInfos);
+ }
+
+ public GeronimoApplication loadApplication(JarFile ebaJarFile) throws IOException, ManagementException {
+ return (GeronimoApplication) createApplication(ebaJarFile);
+ }
+
+ public GeronimoApplication loadApplication(Bundle bundle) throws IOException, ManagementException {
+ ApplicationMetadata applicationMetadata = null;
+ URL applicationMF = bundle.getEntry(AppConstants.APPLICATION_MF);
+ InputStream applicationMFStream = null;
+ try {
+ applicationMFStream = applicationMF.openStream();
+ applicationMetadata = getApplicationMetadataFactory().parseApplicationMetadata(applicationMFStream);
+ } finally {
+ IOUtils.close(applicationMFStream);
+ }
+
+ DeploymentMetadata deploymentMetadata = null;
+ URL deploymentMF = bundle.getEntry(AppConstants.DEPLOYMENT_MF);
+ if (deploymentMF != null) {
+ InputStream deploymentMFStream = null;
+ try {
+ deploymentMFStream = deploymentMF.openStream();
+ deploymentMetadata = getDeploymentMetadataFactory().createDeploymentMetadata(deploymentMFStream);
+ } finally {
+ IOUtils.close(deploymentMFStream);
+ }
+ }
+
+ Set<BundleInfo> bundleInfos = null;
+ File bundleFile = BundleUtils.toFile(bundle);
+ if (bundleFile != null && bundleFile.isDirectory()) {
+ bundleInfos = getBundleInfos(bundleFile);
+ } else {
+ bundleInfos = getBundleInfos(bundle);
+ }
+
+ return new GeronimoApplication(applicationMetadata, deploymentMetadata, bundleInfos);
+ }
+
+ public GeronimoApplication loadApplication(File ebaFile) throws IOException, ManagementException {
+ JarFile jarFile = null;
+ try {
+ jarFile = JarUtils.createJarFile(ebaFile);
+ return loadApplication(jarFile);
+ } finally {
+ JarUtils.close(jarFile);
+ }
+ }
+
+ private Set<BundleInfo> getBundleInfos(File baseDir) throws IOException, ManagementException {
+ ApplicationMetadataFactory applicationMetadataFactory = getApplicationMetadataFactory();
+ Set<BundleInfo> bundleInfos = new HashSet<BundleInfo>();
+ collectBundleInfos(baseDir, applicationMetadataFactory, bundleInfos);
+ return bundleInfos;
+ }
+
+ private void collectBundleInfos(File baseDir, ApplicationMetadataFactory applicationMetadataFactory, Set<BundleInfo> bundleInfos) throws IOException, ManagementException {
+ for (File file : baseDir.listFiles()) {
+ if (file.isDirectory()) {
+ if (file.getName().endsWith(".jar")) {
+ BundleManifest bm = BundleManifest.fromBundle(file);
+ if (bm != null && bm.isValid()) {
+ bundleInfos.add(new SimpleBundleInfo(applicationMetadataFactory, bm, "reference:" + file.toURI().toString()));
+ }
+ } else {
+ collectBundleInfos(file, applicationMetadataFactory, bundleInfos);
+ continue;
+ }
+ } else {
+ BundleManifest bm = BundleManifest.fromBundle(file);
+ if (bm != null && bm.isValid()) {
+ /*
+ * Pass file:// url instead of reference:file:// as bundle location to make sure
+ * Equinox has its own copy of the jar. That is, to prevent strange ZipErrors when
+ * application bundles are updated at runtime, specifically, when
+ * ApplicationGBean.hotSwapApplicationContent() is called.
+ */
+ bundleInfos.add(new SimpleBundleInfo(applicationMetadataFactory, bm, file.toURI().toString()));
+ }
+ }
+ }
+ }
+
+ private Set<BundleInfo> getBundleInfos(Bundle bundle) throws IOException, ManagementException {
+ ApplicationMetadataFactory applicationMetadataFactory = getApplicationMetadataFactory();
+ Set<BundleInfo> bundleInfos = new HashSet<BundleInfo>();
+ Enumeration<URL> e = bundle.findEntries("/", "*", true);
+ while (e.hasMoreElements()) {
+ URL url = e.nextElement();
+ if (url.getPath().endsWith("/")) {
+ continue;
+ }
+ BundleManifest bm = BundleManifest.fromBundle(url.openStream());
+ if (bm != null && bm.isValid()) {
+ bundleInfos.add(new SimpleBundleInfo(applicationMetadataFactory, bm, url.toExternalForm()));
+ }
+ }
+ return bundleInfos;
+ }
+
+ private Manifest readApplicationManifest(JarFile ebaJarFile) throws IOException {
+ Manifest manifest;
+ ZipEntry entry = ebaJarFile.getEntry(AppConstants.APPLICATION_MF);
+ if (entry != null) {
+ InputStream applicationMFStream = null;
+ try {
+ applicationMFStream = ebaJarFile.getInputStream(entry);
+ manifest = ManifestProcessor.parseManifest(applicationMFStream);
+ } finally {
+ IOUtils.close(applicationMFStream);
+ }
+ } else {
+ manifest = new Manifest();
+ }
+ return manifest;
+ }
+
+ private DeploymentMetadata readDeploymentManifest(JarFile ebaJarFile) throws IOException, ManagementException {
+ DeploymentMetadata deploymentMetadata = null;
+ ZipEntry entry = ebaJarFile.getEntry(AppConstants.DEPLOYMENT_MF);
+ if (entry != null) {
+ InputStream deploymentMFStream = null;
+ try {
+ deploymentMFStream = ebaJarFile.getInputStream(entry);
+ deploymentMetadata = getDeploymentMetadataFactory().createDeploymentMetadata(deploymentMFStream);
+ } finally {
+ IOUtils.close(deploymentMFStream);
+ }
+ }
+ return deploymentMetadata;
+ }
+
+ private String buildAppContent(Set<BundleInfo> bundleInfos) {
+ StringBuilder builder = new StringBuilder();
+ Iterator<BundleInfo> iterator = bundleInfos.iterator();
+ while (iterator.hasNext()) {
+ BundleInfo info = iterator.next();
+ builder.append(info.getSymbolicName());
+
+ // bundle version is not a required manifest header
+ if (info.getVersion() != null) {
+ String version = info.getVersion().toString();
+ builder.append(";version=\"[");
+ builder.append(version);
+ builder.append(',');
+ builder.append(version);
+ builder.append("]\"");
+ }
+
+ if (iterator.hasNext()) {
+ builder.append(",");
+ }
+ }
+ return builder.toString();
+ }
+
+ public ApplicationMetadata getApplicationMetadata(JarFile ebaJarFile) throws IOException, ManagementException {
+ Manifest applicationMF = readApplicationManifest(ebaJarFile);
+
+ // this is to prevent unnecessary jar scanning by ManifestDefaultsInjector
+ boolean dummyAppContent = false;
+ if (applicationMF.getMainAttributes().get(APPLICATION_CONTENT_NAME) == null) {
+ applicationMF.getMainAttributes().put(APPLICATION_CONTENT_NAME, "none");
+ dummyAppContent = true;
+ }
+
+ File ebaFile = new File(ebaJarFile.getName());
+
+ ManifestDefaultsInjector.updateManifest(applicationMF, ebaFile.getName(), ebaFile);
+
+ if (dummyAppContent) {
+ applicationMF.getMainAttributes().remove(APPLICATION_CONTENT_NAME);
+ }
+
+ ApplicationMetadata applicationMetadata = getApplicationMetadataFactory().createApplicationMetadata(applicationMF);
+ return applicationMetadata;
+ }
+
+ public AriesApplication resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
+ try {
+ return getAriesApplicationManager().resolve(app, constraints);
+ } catch (ManagementException e) {
+ throw new ResolverException(e);
+ }
+ }
+
+ public AriesApplication createApplication(IDirectory ebaFile) throws ManagementException {
+ return getAriesApplicationManager().createApplication(ebaFile);
+ }
+}
Propchange: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/UnpackEBATypeHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/UnpackEBATypeHandler.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/UnpackEBATypeHandler.java (original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/UnpackEBATypeHandler.java Tue Feb 5 18:10:39 2013
@@ -58,8 +58,9 @@ public class UnpackEBATypeHandler implem
unpack(child, destination, buffer);
}
} else {
- ZipFile zipIn = new ZipFile(child);
+ ZipFile zipIn = null;
try {
+ zipIn = new ZipFile(child);
JarUtils.unzipToDirectory(zipIn, destination);
} catch (Exception e) {
FileUtils.copyFile(child, destination, buffer);
Modified: geronimo/server/branches/3.0/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?rev=1442682&r1=1442681&r2=1442682&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java (original)
+++ geronimo/server/branches/3.0/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java Tue Feb 5 18:10:39 2013
@@ -405,7 +405,7 @@ public class EjbModuleBuilder implements
// the getResourcesMap() method was unable to find them. In this "bad jar" scenario
// some extra features such as the openejb.altdd.prefix functionality will not work.
- String[] doubleCheck = {"ejb-jar.xml", "geronimo-openejb.xml", "openejb-jar.xml", "beans.xml", "env-entries.properties", "web.xml"};
+ String[] doubleCheck = {"ejb-jar.xml", "geronimo-openejb.xml", "openejb-jar.xml", "beans.xml", "env-entries.properties", "web.xml", "APPLICATION.MF"};
for (String entry : doubleCheck) {
try {
@@ -1383,6 +1383,10 @@ public class EjbModuleBuilder implements
return false;
}
+ if (descriptors.containsKey("APPLICATION.MF") || path.endsWith(".eba")) {
+ return false;
+ }
+
if (descriptors.containsKey("ejb-jar.xml") || descriptors.containsKey("beans.xml")) {
return true;
}