Author: mnuttall
Date: Thu Jan 7 18:01:27 2010
New Revision: 896945
URL: http://svn.apache.org/viewvc?rev=896945&view=rev
Log:
ARIES-89: Implement application support: work on store()
Added:
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/messages/
Modified:
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
Modified:
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
URL:
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java?rev=896945&r1=896944&r2=896945&view=diff
==============================================================================
---
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
(original)
+++
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
Thu Jan 7 18:01:27 2010
@@ -20,31 +20,42 @@
package org.apache.aries.application.management.impl;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.Content;
import org.apache.aries.application.DeploymentMetadata;
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.LocalPlatform;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.filesystem.IOUtils;
public class AriesApplicationImpl implements AriesApplication {
private Set<BundleInfo> _bundleInfo;
private ApplicationMetadata _applicationMetadata;
private DeploymentMetadata _deploymentMetadata;
+ private LocalPlatform _localPlatform;
// Placeholders for information we'll need for store()
private boolean _applicationManifestChanged = false;
private Map<String, InputStream> _modifiedBundles = null;
- public AriesApplicationImpl(ApplicationMetadata meta, Set<BundleInfo>
bundleInfo) {
+ public AriesApplicationImpl(ApplicationMetadata meta, Set<BundleInfo>
bundleInfo,
+ LocalPlatform lp) {
_applicationMetadata = meta;
_bundleInfo = bundleInfo;
_deploymentMetadata = null;
+ _localPlatform = lp;
}
@@ -59,29 +70,67 @@
public DeploymentMetadata getDeploymentMetadata() {
return _deploymentMetadata;
}
-
- public void store(File f) {
- // TODO Auto-generated method stub
-
- }
-
- public void store(OutputStream in) {
- // TODO Auto-generated method stub
-
- }
public void setDeploymentMetadata (DeploymentMetadata dm) {
_deploymentMetadata = dm;
}
-
- // When store() is called we'll need to know whether application.mf was
changed,
- // or any constituent .wars or .jars migrated to bundles in the course of
constructing
- // the AriesApplication.
- void setApplicationManifestChanged (boolean changed) {
- _applicationManifestChanged = changed;
- }
- void setModifiedBundles (Map<String, InputStream> modifiedBundles) {
+ public void setModifiedBundles (Map<String, InputStream> modifiedBundles) {
_modifiedBundles = modifiedBundles;
}
+
+ public void store(File f) throws FileNotFoundException, IOException {
+ OutputStream os = new FileOutputStream (f);
+ store(os);
+ os.close();
+ }
+
+ public void store(OutputStream targetStream) throws FileNotFoundException,
IOException {
+ // Construct an eba in a temporary directory
+ // Copy the eba to the target output stream
+ // Delete the temporary directory.
+ //
+ // This code will be run on various application server platforms, each of
which
+ // will have its own policy about where to create temporary directories.
We
+ // can't just ask the local filesystem for a temporary directory since it
may
+ // be quite large: the app server implementation will be better able to
select
+ // an appropriate location.
+ File tempDir = _localPlatform.getTemporaryDirectory();
+ OutputStream out = null;
+ InputStream in = null;
+ try {
+ out = IOUtils.getOutputStream(tempDir, AppConstants.APPLICATION_MF);
+ _applicationMetadata.store(out);
+
+ } finally {
+ IOUtils.close(out);
+ }
+ try {
+ out = IOUtils.getOutputStream(tempDir, AppConstants.DEPLOYMENT_MF);
+ _deploymentMetadata.store(out);
+ } finally {
+ IOUtils.close(out);
+ }
+
+ // Write the by-value eba files out
+ for (BundleInfo bi : _bundleInfo) {
+ // bi.getLocation() will return a URL to the source bundle. It may be of
the form
+ // file:/path/to/my/file.jar, or
+ // jar:file:/my/path/to/eba.jar!/myBundle.jar
+ String bundleLocation = bi.getLocation();
+ String bundleFileName =
bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
+ try {
+ out = IOUtils.getOutputStream(tempDir, bundleFileName);
+ URL bundleURL = new URL (bundleLocation);
+ InputStream is = bundleURL.openStream();
+ IOUtils.copy(is, out);
+ } finally {
+ IOUtils.close(out);
+ IOUtils.close(in);
+ }
+ }
+
+ // TODO: Write the migrated bundles out
+
+ }
}
Modified:
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java?rev=896945&r1=896944&r2=896945&view=diff
==============================================================================
---
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
(original)
+++
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
Thu Jan 7 18:01:27 2010
@@ -19,7 +19,6 @@
package org.apache.aries.application.management.impl;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -44,9 +43,10 @@
import org.apache.aries.application.management.AriesApplicationResolver;
import org.apache.aries.application.management.BundleConverter;
import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.LocalPlatform;
import org.apache.aries.application.management.ManagementException;
import org.apache.aries.application.utils.AppConstants;
-import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.filesystem.IOUtils;
import org.apache.aries.application.utils.manifest.BundleManifest;
import org.apache.aries.application.utils.manifest.ManifestDefaultsInjector;
import org.apache.aries.application.utils.manifest.ManifestProcessor;
@@ -58,6 +58,7 @@
private DeploymentMetadataFactory _deploymentMetadataFactory;
private List<BundleConverter> _bundleConverters;
private AriesApplicationResolver _resolver;
+ private LocalPlatform _localPlatform;
public void setApplicationMetadataManager (ApplicationMetadataManager amm) {
_applicationMetadataManager = amm;
@@ -74,7 +75,10 @@
public void setResolver (AriesApplicationResolver resolver) {
_resolver = resolver;
}
-
+
+ public void setLocalPlatform (LocalPlatform lp) {
+ _localPlatform = lp;
+ }
/**
@@ -86,18 +90,19 @@
DeploymentMetadata deploymentMetadata;
Map<String, InputStream> modifiedBundles = new HashMap<String,
InputStream>();
AriesApplicationImpl application = null;
- boolean manifestChanged = false;
+ /* Locate META-INF/APPLICATION.MF and ensure that the
+ * manifest has the necessary fields set
+ */
try {
- // Locate META-INF/APPLICATION.MF and ensure that the
- // manifest has the necessary fields set
Manifest applicationManifest = parseManifest (ebaFile,
AppConstants.APPLICATION_MF);
- manifestChanged =
ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(),
ebaFile);
+ ManifestDefaultsInjector.updateManifest(applicationManifest,
ebaFile.getName(), ebaFile);
applicationMetadata =
_applicationMetadataManager.createApplicationMetadata(applicationManifest);
Manifest deploymentManifest = parseManifest (ebaFile,
AppConstants.DEPLOYMENT_MF);
if (deploymentManifest != null) {
// If there's a deployment.mf present, check it matches
applicationManifest, and if so, use it
+ // TODO: Implement this bit
} else {
// -- Process any other files in the .eba, i.e. migrate wars to wabs,
plain jars to bundles
@@ -106,12 +111,11 @@
if (f.isDirectory()) {
continue;
}
- System.out.println ("Call getBundleManifest on " + f.getName());
BundleManifest bm = getBundleManifest (f);
if (bm != null) {
if (bm.isValid()) {
- extraBundlesInfo.add(new BundleInfoImpl(bm, null));
+ extraBundlesInfo.add(new BundleInfoImpl(bm,
f.toURL().toExternalForm()));
} else {
// We have a jar that needs converting to a bundle, or a war to
migrate to a WAB
InputStream is = null;
@@ -131,26 +135,21 @@
if (convertedBinary != null) {
modifiedBundles.put (f.getName(), convertedBinary);
bm = BundleManifest.fromBundle(is);
- extraBundlesInfo.add(new BundleInfoImpl(bm, null));
+ extraBundlesInfo.add(new BundleInfoImpl(bm, f.getName()));
}
} finally {
- try {
- if (is != null) is.close();
- } catch (IOException iox) {}
+ IOUtils.close(is);
}
}
}
}
- application = new AriesApplicationImpl (applicationMetadata,
extraBundlesInfo);
+ application = new AriesApplicationImpl (applicationMetadata,
extraBundlesInfo, _localPlatform);
Set<BundleInfo> additionalBundlesRequired =
_resolver.resolve(application);
deploymentMetadata =
_deploymentMetadataFactory.createDeploymentMetadata(application,
additionalBundlesRequired);
application.setDeploymentMetadata(deploymentMetadata);
- // We may have changed parts of its content. The application's store()
- // method needs to be able to work. Do something with modifiedBundles
- // and manifestChanged. We'll save them in the application for now.
- application.setApplicationManifestChanged (manifestChanged);
+ // Store a reference to any modified bundles
application.setModifiedBundles (modifiedBundles);
}
@@ -214,14 +213,11 @@
try {
is = f.open();
result = ManifestProcessor.parseManifest(is);
- is.close();
} catch (IOException iox) {
// TODO: log error
throw iox;
} finally {
- try {
- if (is != null) is.close();
- } catch (IOException iox) {}
+ IOUtils.close(is);
}
}
return result;
@@ -239,9 +235,7 @@
in = file.open();
mf = BundleManifest.fromBundle(in);
} finally {
- try {
- if (in != null) in.close();
- } catch (IOException iox) {}
+ IOUtils.close(in);
}
return mf;
}
Modified:
incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
URL:
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml?rev=896945&r1=896944&r2=896945&view=diff
==============================================================================
---
incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
(original)
+++
incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
Thu Jan 7 18:01:27 2010
@@ -24,6 +24,7 @@
<property name="deploymentMetadataFactory"
ref="deployment-metadata-factory"/>
<property name="bundleConverters" ref="bundle-converters"/>
<property name="resolver" ref="resolver"/>
+ <property name="localPlatform" ref="localPlatform"/>
</bean>
<reference id="app-metadata-manager"
interface="org.apache.aries.application.ApplicationMetadataManager"/>
@@ -32,6 +33,7 @@
interface="org.apache.aries.application.management.BundleConverter"
availability="optional"/>
<reference id="resolver"
interface="org.apache.aries.application.management.AriesApplicationResolver"/>
+ <reference id="localPlatform"
interface="org.apache.aries.application.management.LocalPlatform"/>
<service
interface="org.apache.aries.application.management.AriesApplicationManager"
ref="manager-service" />
Modified:
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
URL:
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java?rev=896945&r1=896944&r2=896945&view=diff
==============================================================================
---
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
(original)
+++
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
Thu Jan 7 18:01:27 2010
@@ -44,8 +44,6 @@
import org.apache.aries.application.management.AriesApplicationResolver;
import org.apache.aries.application.management.BundleConverter;
import org.apache.aries.application.management.BundleInfo;
-import
org.apache.aries.application.management.impl.AriesApplicationManagerImpl;
-import org.apache.aries.application.management.impl.BundleInfoImpl;
import org.apache.aries.application.utils.filesystem.FileSystem;
import org.apache.aries.application.utils.filesystem.IOUtils;
import org.apache.aries.application.utils.manifest.BundleManifest;
@@ -69,12 +67,12 @@
}
- static String _testEba = "./ariesApplicationManagerImplTest/test.eba";
+ static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
@BeforeClass
public static void setup() throws Exception {
new File("ariesApplicationManagerImplTest").mkdir();
- EbaUnitTestUtils.createEba("../src/test/resources/bundles/test.eba",
_testEba);
+ EbaUnitTestUtils.createEba("../src/test/resources/bundles/test.eba",
TEST_EBA);
File src = new File
("../src/test/resources/bundles/repository/a.handy.persistence.library.jar");
File dest = new File
("ariesApplicationManagerImplTest/a.handy.persistence.library.jar");
IOUtils.zipUp(src, dest);
@@ -108,7 +106,7 @@
nextResolverResult.add(resolvedPersistenceLibrary);
resolver.setNextResult(nextResolverResult);
- IDirectory testEba = FileSystem.getFSRoot(new File(_testEba));
+ IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
AriesApplication app = appMgr.createApplication(testEba);
ApplicationMetadata appMeta = app.getApplicationMetadata();