Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 82061 invoked from network); 7 Jan 2010 18:01:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Jan 2010 18:01:53 -0000 Received: (qmail 38067 invoked by uid 500); 7 Jan 2010 18:01:53 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 37970 invoked by uid 500); 7 Jan 2010 18:01:53 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 37960 invoked by uid 99); 7 Jan 2010 18:01:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2010 18:01:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2010 18:01:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7DC8523888CD; Thu, 7 Jan 2010 18:01:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r896945 - in /incubator/aries/trunk/application/application-management/src: main/java/org/apache/aries/application/management/impl/ main/java/org/apache/aries/application/management/messages/ main/resources/OSGI-INF/blueprint/ test/java/org... Date: Thu, 07 Jan 2010 18:01:28 -0000 To: aries-commits@incubator.apache.org From: mnuttall@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100107180128.7DC8523888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; private ApplicationMetadata _applicationMetadata; private DeploymentMetadata _deploymentMetadata; + private LocalPlatform _localPlatform; // Placeholders for information we'll need for store() private boolean _applicationManifestChanged = false; private Map _modifiedBundles = null; - public AriesApplicationImpl(ApplicationMetadata meta, Set bundleInfo) { + public AriesApplicationImpl(ApplicationMetadata meta, Set 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 modifiedBundles) { + public void setModifiedBundles (Map 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 _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 modifiedBundles = new HashMap(); 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 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 @@ + @@ -32,6 +33,7 @@ interface="org.apache.aries.application.management.BundleConverter" availability="optional"/> + 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();