You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by Lin Sun <li...@gmail.com> on 2010/07/06 20:46:47 UTC

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Hi

Quick question, does this mean if the aries application contains a
deployment.mf, the createApplication will fail with
ManagementException?


> +            } else if (deploymentMetadata != null) {
> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
> +            }

Also,  I don't see anywhere we set the deploymentMetadata (which I
might have missed it) to a value other than null in this method.

Thx

Lin

On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
> Author: mnuttall
> Date: Tue Jul  6 10:51:12 2010
> New Revision: 960866
>
> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
> Log:
> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>
> Added:
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
> Modified:
>    incubator/aries/trunk/application/application-api/pom.xml
>    incubator/aries/trunk/application/application-management/   (props changed)
>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>    incubator/aries/trunk/application/application-utils/pom.xml
>
> Modified: incubator/aries/trunk/application/application-api/pom.xml
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
> ==============================================================================
> --- incubator/aries/trunk/application/application-api/pom.xml (original)
> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
> @@ -43,7 +43,7 @@
>         <dependency>
>             <groupId>org.osgi</groupId>
>             <artifactId>org.osgi.core</artifactId>
> -            <version>4.0.0</version>
> +            <version>4.2.0</version>
>             <scope>provided</scope>
>         </dependency>
>     </dependencies>
>
> Propchange: incubator/aries/trunk/application/application-management/
> ------------------------------------------------------------------------------
> --- svn:ignore (original)
> +++ svn:ignore Tue Jul  6 10:51:12 2010
> @@ -2,3 +2,5 @@ target
>  .classpath
>  .project
>  .settings
> +ariesApplicationManagerImplTest
> +unittest
>
> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>     AriesApplicationImpl application = null;
>
>     try {
> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
> +
> +        /* We require that all other .jar and .war files included by-value be valid bundles
> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
> +         * wars to wabs, plain jars to bundles
> +         */
> +
> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
> +        for (IFile f : ebaFile) {
> +          if (f.isDirectory()) {
> +            continue;
> +          }
> +
> +          BundleManifest bm = getBundleManifest (f);
> +          if (bm != null) {
> +            if (bm.isValid()) {
> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
> +            } else if (deploymentMetadata != null) {
> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
> +            } else {
> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
> +                 BundleConversion convertedBinary = null;
> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
> +              List<ConversionException> conversionExceptions = Collections.emptyList();
> +              while (converters.hasNext() && convertedBinary == null) {
> +                try {
> +                  convertedBinary = converters.next().convert(ebaFile, f);
> +                } catch (ServiceException sx) {
> +                  // We'll get this if our optional BundleConverter has not been injected.
> +                } catch (ConversionException cx) {
> +                  conversionExceptions.add(cx);
> +                }
> +              }
> +              if (conversionExceptions.size() > 0) {
> +                for (ConversionException cx : conversionExceptions) {
> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
> +                }
> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
> +              }
> +              if (convertedBinary != null) {
> +                modifiedBundles.put (f.getName(), convertedBinary);
> +                bm = BundleManifest.fromBundle(f);
> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
> +              }
> +            }
> +          }
> +        }
> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
> +      String appName = ebaFile.getName();
> +      //If the application name is null, we will try to get the file name.
> +      if ((appName == null) || (appName.isEmpty())) {
> +         String fullPath = ebaFile.toString();
> +         if (fullPath.endsWith("/"))
> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
> +          int last_slash = fullPath.lastIndexOf("/");
> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
> +      }
> +
> +
> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
> -
>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>       if (deploymentManifest != null) {
>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>         }
>       }
>
> -      /* We require that all other .jar and .war files included by-value be valid bundles
> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
> -       * wars to wabs, plain jars to bundles
> -       */
> -
> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
> -      for (IFile f : ebaFile) {
> -        if (f.isDirectory()) {
> -          continue;
> -        }
> -
> -        BundleManifest bm = getBundleManifest (f);
> -        if (bm != null) {
> -          if (bm.isValid()) {
> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
> -          } else if (deploymentMetadata != null) {
> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
> -          } else {
> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
> -            BundleConversion convertedBinary = null;
> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
> -            List<ConversionException> conversionExceptions = Collections.emptyList();
> -            while (converters.hasNext() && convertedBinary == null) {
> -              try {
> -                convertedBinary = converters.next().convert(ebaFile, f);
> -              } catch (ServiceException sx) {
> -                // We'll get this if our optional BundleConverter has not been injected.
> -              } catch (ConversionException cx) {
> -                conversionExceptions.add(cx);
> -              }
> -            }
> -            if (conversionExceptions.size() > 0) {
> -              for (ConversionException cx : conversionExceptions) {
> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
> -              }
> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
> -            }
> -            if (convertedBinary != null) {
> -              modifiedBundles.put (f.getName(), convertedBinary);
> -              bm = BundleManifest.fromBundle(f);
> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
> -            }
> -          }
> -        }
> -      }
> +
>
>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>       application.setDeploymentMetadata(deploymentMetadata);
>
> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>  import static org.junit.Assert.assertTrue;
>
>  import java.io.File;
> +import java.io.FileInputStream;
>  import java.io.IOException;
> +import java.io.InputStream;
>  import java.lang.reflect.Field;
>  import java.util.ArrayList;
>  import java.util.HashSet;
>  import java.util.List;
>  import java.util.Set;
> +import java.util.jar.Manifest;
>
>  import org.apache.aries.application.ApplicationMetadata;
>  import org.apache.aries.application.ApplicationMetadataFactory;
> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>  import org.apache.aries.application.management.AriesApplication;
>  import org.apache.aries.application.management.AriesApplicationResolver;
> +import org.apache.aries.application.management.BundleConversion;
>  import org.apache.aries.application.management.BundleConverter;
>  import org.apache.aries.application.management.BundleInfo;
> +import org.apache.aries.application.management.ConversionException;
>  import org.apache.aries.application.management.LocalPlatform;
>  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.management.impl.AriesApplicationManagerImpl;
>  import org.apache.aries.application.utils.filesystem.FileSystem;
>  import org.apache.aries.application.utils.filesystem.IOUtils;
>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>       return File.createTempFile("ebaTmp", null);
>     }
>   }
> +
> +  static class DummyConverter implements BundleConverter {
>
> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
> +                       throws ConversionException {
> +               if (toBeConverted.getName().equals("helloWorld.war")) {
> +                       InputStream is = null;
> +            try {
> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
> +               Manifest warManifest = new Manifest(is);
> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
> +
> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
> +                final String location = toBeConverted.toString();
> +               return new BundleConversion() {
> +
> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
> +                                       }
> +
> +                                       public InputStream getInputStream() throws IOException {
> +                                               return jarIs;
> +                                       }
> +
> +                };
> +            } catch (IOException e) {
> +               e.printStackTrace();
> +            } finally {
> +               try {
> +               if (is != null)
> +                       is.close();
> +               } catch (Exception e) {
> +                       e.printStackTrace();
> +               }
> +            }
> +        }
> +
> +        return null;
> +    }
> +
> +
> +  }
>
> +
> +
> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>   @BeforeClass
>   public static void preTest() throws Exception {
> -    new File("ariesApplicationManagerImplTest").mkdir();
> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>     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);
> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>   }
>
>   AriesApplicationManagerImpl _appMgr;
>   ApplicationMetadataFactory _appMetaFactory;
>   DummyResolver _resolver;
> -
> +  DummyConverter _converter;
>   @Before
>   public void setup() {
>     _appMgr = new AriesApplicationManagerImpl ();
>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>
>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
> +    _converter = new DummyConverter();
>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
> -    _resolver = new DummyResolver();
> -
> +    bundleConverters.add(_converter);
> +    _resolver = new DummyResolver();
>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>     _appMgr.setDeploymentMetadataFactory(dmf);
>     _appMgr.setBundleConverters(bundleConverters);
> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>   }
>
>   @Test
> +  public void testCreateAndConversion() throws Exception {
> +               AriesApplication app = createApplication (CONVERSION_EBA);
> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
> +           List<Content> appContent = appMeta.getApplicationContents();
> +           assertEquals (appContent.size(), 2);
> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
> +           assertTrue (appContent.contains(fbw));
> +           assertTrue (appContent.contains(mbl));
> +
> +           DeploymentMetadata dm = app.getDeploymentMetadata();
> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
> +
> +           assertEquals (2, dcList.size());
> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
> +           assertTrue (dcList.contains(dc1));
> +           assertTrue (dcList.contains(dc2));
> +
> +           dcList = dm.getApplicationProvisionBundles();
> +
> +           assertEquals(1, dcList.size());
> +           assertTrue (dcList.contains(dc3));
> +  }
> +
> +  @Test
>   public void testStoreAndReload() throws Exception {
>     AriesApplication app = createApplication (TEST_EBA);
>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>     nextResolverResult.add(resolvedPersistenceLibrary);
>     _resolver.setNextResult(nextResolverResult);
>
> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>     AriesApplication app = _appMgr.createApplication(testEba);
>     app = _appMgr.resolve(app);
>     return app;
>
> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
> ==============================================================================
> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
> @@ -0,0 +1,11 @@
> +Manifest-Version: 1.0
> +Bundle-ManifestVersion: 2
> +Bundle-Name: helloWorld.war
> +Bundle-SymbolicName: helloWorld.war
> +Bundle-Version: 0.0.0
> +Bundle-Vendor: Apache.org
> +Bundle-ContextPath: /test
> +Export-Package: apache.org.helloWorldWar
> +
> +
> +
>
> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
> ==============================================================================
> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
> @@ -0,0 +1,9 @@
> +Manifest-Version: 1.0
> +Bundle-ManifestVersion: 2
> +Bundle-Name: HelloWorldJar
> +Bundle-SymbolicName: hello.world.jar
> +Bundle-Version: 1.1.0
> +Bundle-Vendor: Apache.org
> +Export-Package: apache.org.helloWorldJar
> +
> +
>
> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
> ==============================================================================
> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
> @@ -0,0 +1,3 @@
> +<web-app>
> +<display-name>Hello World</display-name>
> +</web-app>
> \ No newline at end of file
>
> Modified: incubator/aries/trunk/application/application-utils/pom.xml
> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
> ==============================================================================
> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
> @@ -67,7 +67,7 @@
>         <dependency>
>             <groupId>org.osgi</groupId>
>             <artifactId>org.osgi.core</artifactId>
> -            <version>4.0.0</version>
> +            <version>4.2.0</version>
>             <scope>provided</scope>
>         </dependency>
>         <dependency>
>
>
>

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Lin Sun <li...@gmail.com>.
+1 on Alasdair's note below.

Thank you both!

Lin

On Wed, Jul 7, 2010 at 8:57 AM, Emily Jiang <EM...@uk.ibm.com> wrote:
> Thanks Alasdair,
>
> I like your suggestion. I will raise a jira and get it fixed.
>
> Many thanks and kindest regards,
> Emily
> ===========================
> Emily Jiang
> WebSphere ESB Foundation Technologies
>
> MP 211, DE3A25, Winchester, Hampshire, England, SO21 2JN
> Phone:  +44 (0)1962 816278  Internal: 246278
>
> Email: emijiang@uk.ibm.com
> Lotus Notes: Emily Jiang/UK/IBM@IBMGB
>
>
>
>
> From:   Alasdair Nottingham <no...@apache.org>
> To:     "aries-dev@incubator.apache.org" <ar...@incubator.apache.org>
> Date:   07/07/2010 13:20
> Subject:        Re: svn commit: r960866 - in
> /incubator/aries/trunk/application: application-api/
> application-management/
> application-management/src/main/java/org/apache/aries/application/management/impl/
> application-management/src/test/java/org/apache/aries/applica
> Sent by:        Alasdair Nottingham <al...@gmail.com>
>
>
>
> Hi,
>
> That would be a change in behaviour, I'm not sure it is a major one
> though. Removing the if test though wont have the effect you describe
> though. First we will do conversion when there is a deployment.mf, which
> we don't do right now, and second there is no cross validation code, and
> I'm not sure there should be.
>
> So if you go down this route I would suggest you move the load of the
> deployment.mf to occur prior to the bundle conversion and change the if
> clause to ensure that the conversion logic is only called if the
> deployment.mf does not exist and don't raise the exception.
>
> Quick disclaimer I'm on holiday and am just going by the diff attached.
>
> Alasdair Nottingham
>

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Emily Jiang <EM...@uk.ibm.com>.
Thanks Alasdair,

I like your suggestion. I will raise a jira and get it fixed.

Many thanks and kindest regards,
Emily
===========================
Emily Jiang
WebSphere ESB Foundation Technologies

MP 211, DE3A25, Winchester, Hampshire, England, SO21 2JN
Phone:  +44 (0)1962 816278  Internal: 246278

Email: emijiang@uk.ibm.com 
Lotus Notes: Emily Jiang/UK/IBM@IBMGB




From:   Alasdair Nottingham <no...@apache.org>
To:     "aries-dev@incubator.apache.org" <ar...@incubator.apache.org>
Date:   07/07/2010 13:20
Subject:        Re: svn commit: r960866 - in 
/incubator/aries/trunk/application: application-api/ 
application-management/ 
application-management/src/main/java/org/apache/aries/application/management/impl/ 
application-management/src/test/java/org/apache/aries/applica
Sent by:        Alasdair Nottingham <al...@gmail.com>



Hi,

That would be a change in behaviour, I'm not sure it is a major one 
though. Removing the if test though wont have the effect you describe 
though. First we will do conversion when there is a deployment.mf, which 
we don't do right now, and second there is no cross validation code, and 
I'm not sure there should be.

So if you go down this route I would suggest you move the load of the 
deployment.mf to occur prior to the bundle conversion and change the if 
clause to ensure that the conversion logic is only called if the 
deployment.mf does not exist and don't raise the exception. 

Quick disclaimer I'm on holiday and am just going by the diff attached. 

Alasdair Nottingham

On 7 Jul 2010, at 11:47, Emily Jiang <EM...@uk.ibm.com> wrote:

> Hi Alasdair and Lin,
> 
> It might make more sense to say that all bundles mentioned by the 
> deployment.mf should be valid instead of all bundles included in EBA 
> should be valid if there is a deployment.mf. I suggest that we should 
> ignore the fact of having some utility jars in an EBA even if an 
> delployment.mf is present. I think it might be too much to throw an 
error 
> if there is a utility jar in an eba and the eba includes a 
deployment.mf? 
> Did I miss something? If I am correct, we can simply remove the else if 
> statement( line 134). 
> 
> 
> 
> Many thanks and kindest regards,
> Emily
> ===========================
> Emily Jiang
> WebSphere ESB Foundation Technologies
> 
> MP 211, DE3A25, Winchester, Hampshire, England, SO21 2JN
> Phone:  +44 (0)1962 816278  Internal: 246278
> 
> Email: emijiang@uk.ibm.com 
> Lotus Notes: Emily Jiang/UK/IBM@IBMGB
> 
> 
> 
> 
> From:   Alasdair Nottingham <no...@apache.org>
> To:     "aries-dev@incubator.apache.org" 
<ar...@incubator.apache.org>
> Date:   06/07/2010 21:55
> Subject:        Re: svn commit: r960866 - in 
> /incubator/aries/trunk/application: application-api/ 
> application-management/ 
> 
application-management/src/main/java/org/apache/aries/application/management/impl/ 

> application-management/src/test/java/org/apache/aries/applica
> Sent by:        Alasdair Nottingham <al...@gmail.com>
> 
> 
> 
> Hi,
> 
> Now I follow, the problem is we haven't even tried to load the 
deployment 
> manifest at that point, so you are correct there is a bug there. Either 
> loading the deployment manifest needs to occur sooner, or we need to set 
a 
> variable indicating whiter we converted and check that later.
> 
> Alasdair
> 
> Alasdair Nottingham
> 
> On 6 Jul 2010, at 21:44, Lin Sun <li...@gmail.com> wrote:
> 
>> Hi
>> 
>> So the code sets deploymentMetadata to null in the beginning (line
>> 112) but never set it to anything else before line 134,  so I don't
>> think we'll ever get to line 134.   Seems to me we should set the
>> deploymentMetadata (code around line 179) before the current line 134.
>> 
>> Please correct me if I missed anything.
>> 
>> Lin
>> 
>> On Tue, Jul 6, 2010 at 4:29 PM, Alasdair Nottingham <no...@apache.org> 
> wrote:
>>> I think the code checks for a valid bundle manifest and if it isn't 
> valid and there is a deployment manifest then it raises an error, 
> otherwise it converts the bundle. Isn't this what we want, or have I 
> missed something?
>>> 
>>> Alasdair Nottingham
>>> 
>>> On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:
>>> 
>>>> Hi
>>>> 
>>>> Right, I'd think so, if a deployment.mf exists, then bundles are 
valid
>>>> thus no conversion is needed.  However, the actual code seems to be
>>>> different.
>>>> 
>>>> Lin
>>>> 
>>>> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> 
> wrote:
>>>>> Hi,
>>>>> 
>>>>> It should means that if a deployment manifest exists the content 
must 
> be valid bundles. It does not mean you need a deployment.mf.
>>>>> 
>>>>> Alasdair Nottingham
>>>>> 
>>>>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>>>>> 
>>>>>> Hi
>>>>>> 
>>>>>> Quick question, does this mean if the aries application contains a
>>>>>> deployment.mf, the createApplication will fail with
>>>>>> ManagementException?
>>>>>> 
>>>>>> 
>>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>>> +              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> +            }
>>>>>> 
>>>>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>>>>> might have missed it) to a value other than null in this method.
>>>>>> 
>>>>>> Thx
>>>>>> 
>>>>>> Lin
>>>>>> 
>>>>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>>>>> Author: mnuttall
>>>>>>> Date: Tue Jul  6 10:51:12 2010
>>>>>>> New Revision: 960866
>>>>>>> 
>>>>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>>>>> Log:
>>>>>>> ARIES-192: Convert bundles before generating the application 
> content. From a patch submitted by Emily Jiang.
>>>>>>> 
>>>>>>> Added:
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>>> Modified:
>>>>>>>   incubator/aries/trunk/application/application-api/pom.xml
>>>>>>>   incubator/aries/trunk/application/application-management/ (props 

> changed)
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>>>> 
> 
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>>>>   incubator/aries/trunk/application/application-utils/pom.xml
>>>>>>> 
>>>>>>> Modified: 
incubator/aries/trunk/application/application-api/pom.xml
>>>>>>> URL: 
> 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff

> 
>>>>>>> 
> 
==============================================================================
>>>>>>> --- incubator/aries/trunk/application/application-api/pom.xml 
> (original)
>>>>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue 
> Jul  6 10:51:12 2010
>>>>>>> @@ -43,7 +43,7 @@
>>>>>>>        <dependency>
>>>>>>>            <groupId>org.osgi</groupId>
>>>>>>>            <artifactId>org.osgi.core</artifactId>
>>>>>>> -            <version>4.0.0</version>
>>>>>>> +            <version>4.2.0</version>
>>>>>>>            <scope>provided</scope>
>>>>>>>        </dependency>
>>>>>>>    </dependencies>
>>>>>>> 
>>>>>>> Propchange: 
> incubator/aries/trunk/application/application-management/
>>>>>>> 
> 
------------------------------------------------------------------------------
>>>>>>> --- svn:ignore (original)
>>>>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>>>>> @@ -2,3 +2,5 @@ target
>>>>>>> .classpath
>>>>>>> .project
>>>>>>> .settings
>>>>>>> +ariesApplicationManagerImplTest
>>>>>>> +unittest
>>>>>>> 
>>>>>>> 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=960866&r1=960865&r2=960866&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 

> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>>>>    AriesApplicationImpl application = null;
>>>>>>> 
>>>>>>>    try {
>>>>>>> -      Manifest applicationManifest = parseApplicationManifest 
> (ebaFile);
>>>>>>> - ManifestDefaultsInjector.updateManifest(applicationManifest, 
> ebaFile.getName(), ebaFile);
>>>>>>> +
>>>>>>> +        /* We require that all other .jar and .war files included 

> by-value be valid bundles
>>>>>>> +         * because a DEPLOYMENT.MF has been provided. If no 
> DEPLOYMENT.MF, migrate
>>>>>>> +         * wars to wabs, plain jars to bundles
>>>>>>> +         */
>>>>>>> +
>>>>>>> +        Set<BundleInfo> extraBundlesInfo = new 
> HashSet<BundleInfo>();
>>>>>>> +        for (IFile f : ebaFile) {
>>>>>>> +          if (f.isDirectory()) {
>>>>>>> +            continue;
>>>>>>> +          }
>>>>>>> +
>>>>>>> +          BundleManifest bm = getBundleManifest (f);
>>>>>>> +          if (bm != null) {
>>>>>>> +            if (bm.isValid()) {
>>>>>>> +              extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, 
> f.toURL().toExternalForm()));
>>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>>> +              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> +            } else {
>>>>>>> +              // We have a jar that needs converting to a bundle, 

> or a war to migrate to a WAB
>>>>>>> +                 BundleConversion convertedBinary = null;
>>>>>>> +              Iterator<BundleConverter> converters = 
> _bundleConverters.iterator();
>>>>>>> +              List<ConversionException> conversionExceptions = 
> Collections.emptyList();
>>>>>>> +              while (converters.hasNext() && convertedBinary == 
> null) {
>>>>>>> +                try {
>>>>>>> +                  convertedBinary = 
> converters.next().convert(ebaFile, f);
>>>>>>> +                } catch (ServiceException sx) {
>>>>>>> +                  // We'll get this if our optional 
> BundleConverter has not been injected.
>>>>>>> +                } catch (ConversionException cx) {
>>>>>>> +                  conversionExceptions.add(cx);
>>>>>>> +                }
>>>>>>> +              }
>>>>>>> +              if (conversionExceptions.size() > 0) {
>>>>>>> +                for (ConversionException cx : 
> conversionExceptions) {
>>>>>>> +                  _logger.error("APPMANAGEMENT0004E", new 
> Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>>> +                }
>>>>>>> +                throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>>> +              }
>>>>>>> +              if (convertedBinary != null) {
>>>>>>> +                modifiedBundles.put (f.getName(), 
> convertedBinary);
>>>>>>> +                bm = BundleManifest.fromBundle(f);
>>>>>>> +                extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>>> +              }
>>>>>>> +            }
>>>>>>> +          }
>>>>>>> +        }
>>>>>>> +      Manifest applicationManifest = parseApplicationManifest 
> (ebaFile);
>>>>>>> +      String appName = ebaFile.getName();
>>>>>>> +      //If the application name is null, we will try to get the 
> file name.
>>>>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>>>>> +         String fullPath = ebaFile.toString();
>>>>>>> +         if (fullPath.endsWith("/"))
>>>>>>> +                 fullPath = fullPath.substring(0, 
> fullPath.length() -1);
>>>>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>>>>> +          appName = fullPath.substring(last_slash + 1, 
> fullPath.length());
>>>>>>> +      }
>>>>>>> +
>>>>>>> +
>>>>>>> + ManifestDefaultsInjector.updateManifest(applicationManifest, 
> appName, ebaFile);
>>>>>>>      applicationMetadata = 
> 
_applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>>>>> -
>>>>>>>      IFile deploymentManifest = 
> ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>>>>      if (deploymentManifest != null) {
>>>>>>>        deploymentMetadata = 
> _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>>>>        }
>>>>>>>      }
>>>>>>> 
>>>>>>> -      /* We require that all other .jar and .war files included 
> by-value be valid bundles
>>>>>>> -       * because a DEPLOYMENT.MF has been provided. If no 
> DEPLOYMENT.MF, migrate
>>>>>>> -       * wars to wabs, plain jars to bundles
>>>>>>> -       */
>>>>>>> -
>>>>>>> -      Set<BundleInfo> extraBundlesInfo = new 
> HashSet<BundleInfo>();
>>>>>>> -      for (IFile f : ebaFile) {
>>>>>>> -        if (f.isDirectory()) {
>>>>>>> -          continue;
>>>>>>> -        }
>>>>>>> -
>>>>>>> -        BundleManifest bm = getBundleManifest (f);
>>>>>>> -        if (bm != null) {
>>>>>>> -          if (bm.isValid()) {
>>>>>>> -            extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, 
> f.toURL().toExternalForm()));
>>>>>>> -          } else if (deploymentMetadata != null) {
>>>>>>> -            throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> -          } else {
>>>>>>> -            // We have a jar that needs converting to a bundle, 
or 
> a war to migrate to a WAB
>>>>>>> -            BundleConversion convertedBinary = null;
>>>>>>> -            Iterator<BundleConverter> converters = 
> _bundleConverters.iterator();
>>>>>>> -            List<ConversionException> conversionExceptions = 
> Collections.emptyList();
>>>>>>> -            while (converters.hasNext() && convertedBinary == 
> null) {
>>>>>>> -              try {
>>>>>>> -                convertedBinary = 
> converters.next().convert(ebaFile, f);
>>>>>>> -              } catch (ServiceException sx) {
>>>>>>> -                // We'll get this if our optional BundleConverter 

> has not been injected.
>>>>>>> -              } catch (ConversionException cx) {
>>>>>>> -                conversionExceptions.add(cx);
>>>>>>> -              }
>>>>>>> -            }
>>>>>>> -            if (conversionExceptions.size() > 0) {
>>>>>>> -              for (ConversionException cx : conversionExceptions) 

> {
>>>>>>> -                _logger.error("APPMANAGEMENT0004E", new 
> Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>>> -              }
>>>>>>> -              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>>> -            }
>>>>>>> -            if (convertedBinary != null) {
>>>>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>>>>> -              bm = BundleManifest.fromBundle(f);
>>>>>>> -              extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>>> -            }
>>>>>>> -          }
>>>>>>> -        }
>>>>>>> -      }
>>>>>>> +
>>>>>>> 
>>>>>>>      application = new AriesApplicationImpl (applicationMetadata, 
> extraBundlesInfo, _localPlatform);
>>>>>>>      application.setDeploymentMetadata(deploymentMetadata);
>>>>>>> 
>>>>>>> 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=960866&r1=960865&r2=960866&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 

> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>>>> import static org.junit.Assert.assertTrue;
>>>>>>> 
>>>>>>> import java.io.File;
>>>>>>> +import java.io.FileInputStream;
>>>>>>> import java.io.IOException;
>>>>>>> +import java.io.InputStream;
>>>>>>> import java.lang.reflect.Field;
>>>>>>> import java.util.ArrayList;
>>>>>>> import java.util.HashSet;
>>>>>>> import java.util.List;
>>>>>>> import java.util.Set;
>>>>>>> +import java.util.jar.Manifest;
>>>>>>> 
>>>>>>> import org.apache.aries.application.ApplicationMetadata;
>>>>>>> import org.apache.aries.application.ApplicationMetadataFactory;
>>>>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>>>> import 
> org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>>>> import org.apache.aries.application.management.AriesApplication;
>>>>>>> import 
> org.apache.aries.application.management.AriesApplicationResolver;
>>>>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>>>> import org.apache.aries.application.management.BundleConverter;
>>>>>>> import org.apache.aries.application.management.BundleInfo;
>>>>>>> +import 
> org.apache.aries.application.management.ConversionException;
>>>>>>> import org.apache.aries.application.management.LocalPlatform;
>>>>>>> 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.management.impl.AriesApplicationManagerImpl;
>>>>>>> import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>>>> import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>>>> import 
> org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>>>>      return File.createTempFile("ebaTmp", null);
>>>>>>>    }
>>>>>>>  }
>>>>>>> +
>>>>>>> +  static class DummyConverter implements BundleConverter {
>>>>>>> 
>>>>>>> -  static final String TEST_EBA = 
> "./ariesApplicationManagerImplTest/test.eba";
>>>>>>> +       public BundleConversion convert(IDirectory parentEba, 
IFile 
> toBeConverted)
>>>>>>> +                       throws ConversionException {
>>>>>>> +               if 
> (toBeConverted.getName().equals("helloWorld.war")) {
>>>>>>> +                       InputStream is = null;
>>>>>>> +            try {
>>>>>>> +               is = new FileInputStream(new 
> File("../src/test/resources/conversion/MANIFEST.MF"));
>>>>>>> +               Manifest warManifest = new Manifest(is);
>>>>>>> +               IOUtils.jarUp(new 
> File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), 
> new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), 

> warManifest);
>>>>>>> +               IOUtils.zipUp(new 
> File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), 
> new 
File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>>>>> +
>>>>>>> +               IOUtils.zipUp(new 
> File("./ariesApplicationManagerImplTest/conversion"), new 
> File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>>> +               final InputStream jarIs = new FileInputStream(new 
> File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>>> +                final String location = toBeConverted.toString();
>>>>>>> +               return new BundleConversion() {
>>>>>>> +
>>>>>>> +                                       public BundleInfo 
> getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>>>>> +                                               return new 
> SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>>>>> +                                       }
>>>>>>> +
>>>>>>> +                                       public InputStream 
> getInputStream() throws IOException {
>>>>>>> +                                               return jarIs;
>>>>>>> +                                       }
>>>>>>> +
>>>>>>> +                };
>>>>>>> +            } catch (IOException e) {
>>>>>>> +               e.printStackTrace();
>>>>>>> +            } finally {
>>>>>>> +               try {
>>>>>>> +               if (is != null)
>>>>>>> +                       is.close();
>>>>>>> +               } catch (Exception e) {
>>>>>>> +                       e.printStackTrace();
>>>>>>> +               }
>>>>>>> +            }
>>>>>>> +        }
>>>>>>> +
>>>>>>> +        return null;
>>>>>>> +    }
>>>>>>> +
>>>>>>> +
>>>>>>> +  }
>>>>>>> 
>>>>>>> +
>>>>>>> +
>>>>>>> +  static final String TEST_EBA = 
> "./ariesApplicationManagerImplTest/test.eba";
>>>>>>> +  static final String CONVERSION_EBA = 
> "./ariesApplicationManagerImplTest/conversion.eba";
>>>>>>>  @BeforeClass
>>>>>>>  public static void preTest() throws Exception {
>>>>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>>>>> +    new 
> File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>>>> 
> 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);
>>>>>>> + 
> 
EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", 

> CONVERSION_EBA);
>>>>>>>  }
>>>>>>> 
>>>>>>>  AriesApplicationManagerImpl _appMgr;
>>>>>>>  ApplicationMetadataFactory _appMetaFactory;
>>>>>>>  DummyResolver _resolver;
>>>>>>> -
>>>>>>> +  DummyConverter _converter;
>>>>>>>  @Before
>>>>>>>  public void setup() {
>>>>>>>    _appMgr = new AriesApplicationManagerImpl ();
>>>>>>>    _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>>>>> 
>>>>>>>    DeploymentMetadataFactory dmf = new 
> DeploymentMetadataFactoryImpl();
>>>>>>> +    _converter = new DummyConverter();
>>>>>>>    List<BundleConverter> bundleConverters = new 
> ArrayList<BundleConverter>();
>>>>>>> -    _resolver = new DummyResolver();
>>>>>>> -
>>>>>>> +    bundleConverters.add(_converter);
>>>>>>> +    _resolver = new DummyResolver();
>>>>>>>    _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>>>>    _appMgr.setDeploymentMetadataFactory(dmf);
>>>>>>>    _appMgr.setBundleConverters(bundleConverters);
>>>>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>>>>  }
>>>>>>> 
>>>>>>>  @Test
>>>>>>> +  public void testCreateAndConversion() throws Exception {
>>>>>>> +               AriesApplication app = createApplication 
> (CONVERSION_EBA);
>>>>>>> +           ApplicationMetadata appMeta = 
> app.getApplicationMetadata();
>>>>>>> +           assertEquals (appMeta.getApplicationName(), 
> "conversion.eba");
>>>>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), 
> "conversion.eba");
>>>>>>> +           assertEquals (appMeta.getApplicationVersion(), new 
> Version("0.0"));
>>>>>>> +           List<Content> appContent = 
> appMeta.getApplicationContents();
>>>>>>> +           assertEquals (appContent.size(), 2);
>>>>>>> +           Content fbw = new 
> ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>>>>> +           Content mbl = new 
> ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>>>>> +           assertTrue (appContent.contains(fbw));
>>>>>>> +           assertTrue (appContent.contains(mbl));
>>>>>>> +
>>>>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>>>>> +           List<DeploymentContent> dcList = 
> dm.getApplicationDeploymentContents();
>>>>>>> +
>>>>>>> +           assertEquals (2, dcList.size());
>>>>>>> +           DeploymentContent dc1 = new DeploymentContentImpl 
> ("hello.world.jar;deployed-version=1.1.0");
>>>>>>> +           DeploymentContent dc2 = new DeploymentContentImpl 
> ("helloWorld.war;deployed-version=0.0.0");
>>>>>>> +           DeploymentContent dc3 = new DeploymentContentImpl 
> ("a.handy.persistence.library;deployed-version=1.1.0");
>>>>>>> +           assertTrue (dcList.contains(dc1));
>>>>>>> +           assertTrue (dcList.contains(dc2));
>>>>>>> +
>>>>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>>>>> +
>>>>>>> +           assertEquals(1, dcList.size());
>>>>>>> +           assertTrue (dcList.contains(dc3));
>>>>>>> +  }
>>>>>>> +
>>>>>>> +  @Test
>>>>>>>  public void testStoreAndReload() throws Exception {
>>>>>>>    AriesApplication app = createApplication (TEST_EBA);
>>>>>>>    File dest = new File 
> ("ariesApplicationManagerImplTest/stored.eba");
>>>>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>>>>    nextResolverResult.add(resolvedPersistenceLibrary);
>>>>>>>    _resolver.setNextResult(nextResolverResult);
>>>>>>> 
>>>>>>> -    IDirectory testEba = FileSystem.getFSRoot(new 
File(TEST_EBA));
>>>>>>> +    IDirectory testEba = FileSystem.getFSRoot(new 
File(fileName));
>>>>>>>    AriesApplication app = _appMgr.createApplication(testEba);
>>>>>>>    app = _appMgr.resolve(app);
>>>>>>>    return app;
>>>>>>> 
>>>>>>> Added: 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>>> URL: 
> 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto

> 
>>>>>>> 
> 
==============================================================================
>>>>>>> --- 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 

> (added)
>>>>>>> +++ 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 

> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,11 @@
>>>>>>> +Manifest-Version: 1.0
>>>>>>> +Bundle-ManifestVersion: 2
>>>>>>> +Bundle-Name: helloWorld.war
>>>>>>> +Bundle-SymbolicName: helloWorld.war
>>>>>>> +Bundle-Version: 0.0.0
>>>>>>> +Bundle-Vendor: Apache.org
>>>>>>> +Bundle-ContextPath: /test
>>>>>>> +Export-Package: apache.org.helloWorldWar
>>>>>>> +
>>>>>>> +
>>>>>>> +
>>>>>>> 
>>>>>>> Added: 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>>> URL: 
> 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto

> 
>>>>>>> 
> 
==============================================================================
>>>>>>> --- 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 

> (added)
>>>>>>> +++ 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 

> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,9 @@
>>>>>>> +Manifest-Version: 1.0
>>>>>>> +Bundle-ManifestVersion: 2
>>>>>>> +Bundle-Name: HelloWorldJar
>>>>>>> +Bundle-SymbolicName: hello.world.jar
>>>>>>> +Bundle-Version: 1.1.0
>>>>>>> +Bundle-Vendor: Apache.org
>>>>>>> +Export-Package: apache.org.helloWorldJar
>>>>>>> +
>>>>>>> +
>>>>>>> 
>>>>>>> Added: 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>>> URL: 
> 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto

> 
>>>>>>> 
> 
==============================================================================
>>>>>>> --- 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 

> (added)
>>>>>>> +++ 
> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 

> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,3 @@
>>>>>>> +<web-app>
>>>>>>> +<display-name>Hello World</display-name>
>>>>>>> +</web-app>
>>>>>>> \ No newline at end of file
>>>>>>> 
>>>>>>> Modified: 
> incubator/aries/trunk/application/application-utils/pom.xml
>>>>>>> URL: 
> 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff

> 
>>>>>>> 
> 
==============================================================================
>>>>>>> --- incubator/aries/trunk/application/application-utils/pom.xml 
> (original)
>>>>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml 
Tue 
> Jul  6 10:51:12 2010
>>>>>>> @@ -67,7 +67,7 @@
>>>>>>>        <dependency>
>>>>>>>            <groupId>org.osgi</groupId>
>>>>>>>            <artifactId>org.osgi.core</artifactId>
>>>>>>> -            <version>4.0.0</version>
>>>>>>> +            <version>4.2.0</version>
>>>>>>>            <scope>provided</scope>
>>>>>>>        </dependency>
>>>>>>>        <dependency>
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>> 
>>> 
> 
> 
> 
> 
> 
> 
> 
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number 

> 741598. 
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 
3AU
> 
> 
> 
> 
> 







Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU






Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Alasdair Nottingham <no...@apache.org>.
Hi,

That would be a change in behaviour, I'm not sure it is a major one though. Removing the if test though wont have the effect you describe though. First we will do conversion when there is a deployment.mf, which we don't do right now, and second there is no cross validation code, and I'm not sure there should be.

So if you go down this route I would suggest you move the load of the deployment.mf to occur prior to the bundle conversion and change the if clause to ensure that the conversion logic is only called if the deployment.mf does not exist and don't raise the exception. 

Quick disclaimer I'm on holiday and am just going by the diff attached. 

Alasdair Nottingham

On 7 Jul 2010, at 11:47, Emily Jiang <EM...@uk.ibm.com> wrote:

> Hi Alasdair and Lin,
> 
> It might make more sense to say that all bundles mentioned by the 
> deployment.mf should be valid instead of all bundles included in EBA 
> should be valid if there is a deployment.mf. I suggest that we should 
> ignore the fact of having some utility jars in an EBA even if an 
> delployment.mf is present. I think it might be too much to throw an error 
> if there is a utility jar in an eba and the eba includes a deployment.mf? 
> Did I miss something? If I am correct, we can simply remove the else if 
> statement( line 134). 
> 
> 
> 
> Many thanks and kindest regards,
> Emily
> ===========================
> Emily Jiang
> WebSphere ESB Foundation Technologies
> 
> MP 211, DE3A25, Winchester, Hampshire, England, SO21 2JN
> Phone:  +44 (0)1962 816278  Internal: 246278
> 
> Email: emijiang@uk.ibm.com 
> Lotus Notes: Emily Jiang/UK/IBM@IBMGB
> 
> 
> 
> 
> From:   Alasdair Nottingham <no...@apache.org>
> To:     "aries-dev@incubator.apache.org" <ar...@incubator.apache.org>
> Date:   06/07/2010 21:55
> Subject:        Re: svn commit: r960866 - in 
> /incubator/aries/trunk/application: application-api/ 
> application-management/ 
> application-management/src/main/java/org/apache/aries/application/management/impl/ 
> application-management/src/test/java/org/apache/aries/applica
> Sent by:        Alasdair Nottingham <al...@gmail.com>
> 
> 
> 
> Hi,
> 
> Now I follow, the problem is we haven't even tried to load the deployment 
> manifest at that point, so you are correct there is a bug there. Either 
> loading the deployment manifest needs to occur sooner, or we need to set a 
> variable indicating whiter we converted and check that later.
> 
> Alasdair
> 
> Alasdair Nottingham
> 
> On 6 Jul 2010, at 21:44, Lin Sun <li...@gmail.com> wrote:
> 
>> Hi
>> 
>> So the code sets deploymentMetadata to null in the beginning (line
>> 112) but never set it to anything else before line 134,  so I don't
>> think we'll ever get to line 134.   Seems to me we should set the
>> deploymentMetadata (code around line 179) before the current line 134.
>> 
>> Please correct me if I missed anything.
>> 
>> Lin
>> 
>> On Tue, Jul 6, 2010 at 4:29 PM, Alasdair Nottingham <no...@apache.org> 
> wrote:
>>> I think the code checks for a valid bundle manifest and if it isn't 
> valid and there is a deployment manifest then it raises an error, 
> otherwise it converts the bundle. Isn't this what we want, or have I 
> missed something?
>>> 
>>> Alasdair Nottingham
>>> 
>>> On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:
>>> 
>>>> Hi
>>>> 
>>>> Right, I'd think so, if a deployment.mf exists, then bundles are valid
>>>> thus no conversion is needed.  However, the actual code seems to be
>>>> different.
>>>> 
>>>> Lin
>>>> 
>>>> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> 
> wrote:
>>>>> Hi,
>>>>> 
>>>>> It should means that if a deployment manifest exists the content must 
> be valid bundles. It does not mean you need a deployment.mf.
>>>>> 
>>>>> Alasdair Nottingham
>>>>> 
>>>>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>>>>> 
>>>>>> Hi
>>>>>> 
>>>>>> Quick question, does this mean if the aries application contains a
>>>>>> deployment.mf, the createApplication will fail with
>>>>>> ManagementException?
>>>>>> 
>>>>>> 
>>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>>> +              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> +            }
>>>>>> 
>>>>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>>>>> might have missed it) to a value other than null in this method.
>>>>>> 
>>>>>> Thx
>>>>>> 
>>>>>> Lin
>>>>>> 
>>>>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>>>>> Author: mnuttall
>>>>>>> Date: Tue Jul  6 10:51:12 2010
>>>>>>> New Revision: 960866
>>>>>>> 
>>>>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>>>>> Log:
>>>>>>> ARIES-192: Convert bundles before generating the application 
> content. From a patch submitted by Emily Jiang.
>>>>>>> 
>>>>>>> Added:
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>>> Modified:
>>>>>>>   incubator/aries/trunk/application/application-api/pom.xml
>>>>>>>   incubator/aries/trunk/application/application-management/ (props 
> changed)
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>>>> 
> incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>>>>   incubator/aries/trunk/application/application-utils/pom.xml
>>>>>>> 
>>>>>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>>>>>> URL: 
> http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
> 
>>>>>>> 
> ==============================================================================
>>>>>>> --- incubator/aries/trunk/application/application-api/pom.xml 
> (original)
>>>>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue 
> Jul  6 10:51:12 2010
>>>>>>> @@ -43,7 +43,7 @@
>>>>>>>        <dependency>
>>>>>>>            <groupId>org.osgi</groupId>
>>>>>>>            <artifactId>org.osgi.core</artifactId>
>>>>>>> -            <version>4.0.0</version>
>>>>>>> +            <version>4.2.0</version>
>>>>>>>            <scope>provided</scope>
>>>>>>>        </dependency>
>>>>>>>    </dependencies>
>>>>>>> 
>>>>>>> Propchange: 
> incubator/aries/trunk/application/application-management/
>>>>>>> 
> ------------------------------------------------------------------------------
>>>>>>> --- svn:ignore (original)
>>>>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>>>>> @@ -2,3 +2,5 @@ target
>>>>>>> .classpath
>>>>>>> .project
>>>>>>> .settings
>>>>>>> +ariesApplicationManagerImplTest
>>>>>>> +unittest
>>>>>>> 
>>>>>>> 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=960866&r1=960865&r2=960866&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 
> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>>>>    AriesApplicationImpl application = null;
>>>>>>> 
>>>>>>>    try {
>>>>>>> -      Manifest applicationManifest = parseApplicationManifest 
> (ebaFile);
>>>>>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, 
> ebaFile.getName(), ebaFile);
>>>>>>> +
>>>>>>> +        /* We require that all other .jar and .war files included 
> by-value be valid bundles
>>>>>>> +         * because a DEPLOYMENT.MF has been provided. If no 
> DEPLOYMENT.MF, migrate
>>>>>>> +         * wars to wabs, plain jars to bundles
>>>>>>> +         */
>>>>>>> +
>>>>>>> +        Set<BundleInfo> extraBundlesInfo = new 
> HashSet<BundleInfo>();
>>>>>>> +        for (IFile f : ebaFile) {
>>>>>>> +          if (f.isDirectory()) {
>>>>>>> +            continue;
>>>>>>> +          }
>>>>>>> +
>>>>>>> +          BundleManifest bm = getBundleManifest (f);
>>>>>>> +          if (bm != null) {
>>>>>>> +            if (bm.isValid()) {
>>>>>>> +              extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, 
> f.toURL().toExternalForm()));
>>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>>> +              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> +            } else {
>>>>>>> +              // We have a jar that needs converting to a bundle, 
> or a war to migrate to a WAB
>>>>>>> +                 BundleConversion convertedBinary = null;
>>>>>>> +              Iterator<BundleConverter> converters = 
> _bundleConverters.iterator();
>>>>>>> +              List<ConversionException> conversionExceptions = 
> Collections.emptyList();
>>>>>>> +              while (converters.hasNext() && convertedBinary == 
> null) {
>>>>>>> +                try {
>>>>>>> +                  convertedBinary = 
> converters.next().convert(ebaFile, f);
>>>>>>> +                } catch (ServiceException sx) {
>>>>>>> +                  // We'll get this if our optional 
> BundleConverter has not been injected.
>>>>>>> +                } catch (ConversionException cx) {
>>>>>>> +                  conversionExceptions.add(cx);
>>>>>>> +                }
>>>>>>> +              }
>>>>>>> +              if (conversionExceptions.size() > 0) {
>>>>>>> +                for (ConversionException cx : 
> conversionExceptions) {
>>>>>>> +                  _logger.error("APPMANAGEMENT0004E", new 
> Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>>> +                }
>>>>>>> +                throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>>> +              }
>>>>>>> +              if (convertedBinary != null) {
>>>>>>> +                modifiedBundles.put (f.getName(), 
> convertedBinary);
>>>>>>> +                bm = BundleManifest.fromBundle(f);
>>>>>>> +                extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>>> +              }
>>>>>>> +            }
>>>>>>> +          }
>>>>>>> +        }
>>>>>>> +      Manifest applicationManifest = parseApplicationManifest 
> (ebaFile);
>>>>>>> +      String appName = ebaFile.getName();
>>>>>>> +      //If the application name is null, we will try to get the 
> file name.
>>>>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>>>>> +         String fullPath = ebaFile.toString();
>>>>>>> +         if (fullPath.endsWith("/"))
>>>>>>> +                 fullPath = fullPath.substring(0, 
> fullPath.length() -1);
>>>>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>>>>> +          appName = fullPath.substring(last_slash + 1, 
> fullPath.length());
>>>>>>> +      }
>>>>>>> +
>>>>>>> +
>>>>>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, 
> appName, ebaFile);
>>>>>>>      applicationMetadata = 
> _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>>>>> -
>>>>>>>      IFile deploymentManifest = 
> ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>>>>      if (deploymentManifest != null) {
>>>>>>>        deploymentMetadata = 
> _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>>>>        }
>>>>>>>      }
>>>>>>> 
>>>>>>> -      /* We require that all other .jar and .war files included 
> by-value be valid bundles
>>>>>>> -       * because a DEPLOYMENT.MF has been provided. If no 
> DEPLOYMENT.MF, migrate
>>>>>>> -       * wars to wabs, plain jars to bundles
>>>>>>> -       */
>>>>>>> -
>>>>>>> -      Set<BundleInfo> extraBundlesInfo = new 
> HashSet<BundleInfo>();
>>>>>>> -      for (IFile f : ebaFile) {
>>>>>>> -        if (f.isDirectory()) {
>>>>>>> -          continue;
>>>>>>> -        }
>>>>>>> -
>>>>>>> -        BundleManifest bm = getBundleManifest (f);
>>>>>>> -        if (bm != null) {
>>>>>>> -          if (bm.isValid()) {
>>>>>>> -            extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, 
> f.toURL().toExternalForm()));
>>>>>>> -          } else if (deploymentMetadata != null) {
>>>>>>> -            throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
> ebaFile.getName()));
>>>>>>> -          } else {
>>>>>>> -            // We have a jar that needs converting to a bundle, or 
> a war to migrate to a WAB
>>>>>>> -            BundleConversion convertedBinary = null;
>>>>>>> -            Iterator<BundleConverter> converters = 
> _bundleConverters.iterator();
>>>>>>> -            List<ConversionException> conversionExceptions = 
> Collections.emptyList();
>>>>>>> -            while (converters.hasNext() && convertedBinary == 
> null) {
>>>>>>> -              try {
>>>>>>> -                convertedBinary = 
> converters.next().convert(ebaFile, f);
>>>>>>> -              } catch (ServiceException sx) {
>>>>>>> -                // We'll get this if our optional BundleConverter 
> has not been injected.
>>>>>>> -              } catch (ConversionException cx) {
>>>>>>> -                conversionExceptions.add(cx);
>>>>>>> -              }
>>>>>>> -            }
>>>>>>> -            if (conversionExceptions.size() > 0) {
>>>>>>> -              for (ConversionException cx : conversionExceptions) 
> {
>>>>>>> -                _logger.error("APPMANAGEMENT0004E", new 
> Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>>> -              }
>>>>>>> -              throw new ManagementException 
> (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>>> -            }
>>>>>>> -            if (convertedBinary != null) {
>>>>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>>>>> -              bm = BundleManifest.fromBundle(f);
>>>>>>> -              extraBundlesInfo.add(new 
> SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>>> -            }
>>>>>>> -          }
>>>>>>> -        }
>>>>>>> -      }
>>>>>>> +
>>>>>>> 
>>>>>>>      application = new AriesApplicationImpl (applicationMetadata, 
> extraBundlesInfo, _localPlatform);
>>>>>>>      application.setDeploymentMetadata(deploymentMetadata);
>>>>>>> 
>>>>>>> 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=960866&r1=960865&r2=960866&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 
> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>>>> import static org.junit.Assert.assertTrue;
>>>>>>> 
>>>>>>> import java.io.File;
>>>>>>> +import java.io.FileInputStream;
>>>>>>> import java.io.IOException;
>>>>>>> +import java.io.InputStream;
>>>>>>> import java.lang.reflect.Field;
>>>>>>> import java.util.ArrayList;
>>>>>>> import java.util.HashSet;
>>>>>>> import java.util.List;
>>>>>>> import java.util.Set;
>>>>>>> +import java.util.jar.Manifest;
>>>>>>> 
>>>>>>> import org.apache.aries.application.ApplicationMetadata;
>>>>>>> import org.apache.aries.application.ApplicationMetadataFactory;
>>>>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>>>> import 
> org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>>>> import org.apache.aries.application.management.AriesApplication;
>>>>>>> import 
> org.apache.aries.application.management.AriesApplicationResolver;
>>>>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>>>> import org.apache.aries.application.management.BundleConverter;
>>>>>>> import org.apache.aries.application.management.BundleInfo;
>>>>>>> +import 
> org.apache.aries.application.management.ConversionException;
>>>>>>> import org.apache.aries.application.management.LocalPlatform;
>>>>>>> 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.management.impl.AriesApplicationManagerImpl;
>>>>>>> import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>>>> import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>>>> import 
> org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>>>>      return File.createTempFile("ebaTmp", null);
>>>>>>>    }
>>>>>>>  }
>>>>>>> +
>>>>>>> +  static class DummyConverter implements BundleConverter {
>>>>>>> 
>>>>>>> -  static final String TEST_EBA = 
> "./ariesApplicationManagerImplTest/test.eba";
>>>>>>> +       public BundleConversion convert(IDirectory parentEba, IFile 
> toBeConverted)
>>>>>>> +                       throws ConversionException {
>>>>>>> +               if 
> (toBeConverted.getName().equals("helloWorld.war")) {
>>>>>>> +                       InputStream is = null;
>>>>>>> +            try {
>>>>>>> +               is = new FileInputStream(new 
> File("../src/test/resources/conversion/MANIFEST.MF"));
>>>>>>> +               Manifest warManifest = new Manifest(is);
>>>>>>> +               IOUtils.jarUp(new 
> File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), 
> new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), 
> warManifest);
>>>>>>> +               IOUtils.zipUp(new 
> File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), 
> new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>>>>> +
>>>>>>> +               IOUtils.zipUp(new 
> File("./ariesApplicationManagerImplTest/conversion"), new 
> File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>>> +               final InputStream jarIs = new FileInputStream(new 
> File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>>> +                final String location = toBeConverted.toString();
>>>>>>> +               return new BundleConversion() {
>>>>>>> +
>>>>>>> +                                       public BundleInfo 
> getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>>>>> +                                               return new 
> SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>>>>> +                                       }
>>>>>>> +
>>>>>>> +                                       public InputStream 
> getInputStream() throws IOException {
>>>>>>> +                                               return jarIs;
>>>>>>> +                                       }
>>>>>>> +
>>>>>>> +                };
>>>>>>> +            } catch (IOException e) {
>>>>>>> +               e.printStackTrace();
>>>>>>> +            } finally {
>>>>>>> +               try {
>>>>>>> +               if (is != null)
>>>>>>> +                       is.close();
>>>>>>> +               } catch (Exception e) {
>>>>>>> +                       e.printStackTrace();
>>>>>>> +               }
>>>>>>> +            }
>>>>>>> +        }
>>>>>>> +
>>>>>>> +        return null;
>>>>>>> +    }
>>>>>>> +
>>>>>>> +
>>>>>>> +  }
>>>>>>> 
>>>>>>> +
>>>>>>> +
>>>>>>> +  static final String TEST_EBA = 
> "./ariesApplicationManagerImplTest/test.eba";
>>>>>>> +  static final String CONVERSION_EBA = 
> "./ariesApplicationManagerImplTest/conversion.eba";
>>>>>>>  @BeforeClass
>>>>>>>  public static void preTest() throws Exception {
>>>>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>>>>> +    new 
> File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>>>> 
> 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);
>>>>>>> + 
> EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", 
> CONVERSION_EBA);
>>>>>>>  }
>>>>>>> 
>>>>>>>  AriesApplicationManagerImpl _appMgr;
>>>>>>>  ApplicationMetadataFactory _appMetaFactory;
>>>>>>>  DummyResolver _resolver;
>>>>>>> -
>>>>>>> +  DummyConverter _converter;
>>>>>>>  @Before
>>>>>>>  public void setup() {
>>>>>>>    _appMgr = new AriesApplicationManagerImpl ();
>>>>>>>    _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>>>>> 
>>>>>>>    DeploymentMetadataFactory dmf = new 
> DeploymentMetadataFactoryImpl();
>>>>>>> +    _converter = new DummyConverter();
>>>>>>>    List<BundleConverter> bundleConverters = new 
> ArrayList<BundleConverter>();
>>>>>>> -    _resolver = new DummyResolver();
>>>>>>> -
>>>>>>> +    bundleConverters.add(_converter);
>>>>>>> +    _resolver = new DummyResolver();
>>>>>>>    _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>>>>    _appMgr.setDeploymentMetadataFactory(dmf);
>>>>>>>    _appMgr.setBundleConverters(bundleConverters);
>>>>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>>>>  }
>>>>>>> 
>>>>>>>  @Test
>>>>>>> +  public void testCreateAndConversion() throws Exception {
>>>>>>> +               AriesApplication app = createApplication 
> (CONVERSION_EBA);
>>>>>>> +           ApplicationMetadata appMeta = 
> app.getApplicationMetadata();
>>>>>>> +           assertEquals (appMeta.getApplicationName(), 
> "conversion.eba");
>>>>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), 
> "conversion.eba");
>>>>>>> +           assertEquals (appMeta.getApplicationVersion(), new 
> Version("0.0"));
>>>>>>> +           List<Content> appContent = 
> appMeta.getApplicationContents();
>>>>>>> +           assertEquals (appContent.size(), 2);
>>>>>>> +           Content fbw = new 
> ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>>>>> +           Content mbl = new 
> ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>>>>> +           assertTrue (appContent.contains(fbw));
>>>>>>> +           assertTrue (appContent.contains(mbl));
>>>>>>> +
>>>>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>>>>> +           List<DeploymentContent> dcList = 
> dm.getApplicationDeploymentContents();
>>>>>>> +
>>>>>>> +           assertEquals (2, dcList.size());
>>>>>>> +           DeploymentContent dc1 = new DeploymentContentImpl 
> ("hello.world.jar;deployed-version=1.1.0");
>>>>>>> +           DeploymentContent dc2 = new DeploymentContentImpl 
> ("helloWorld.war;deployed-version=0.0.0");
>>>>>>> +           DeploymentContent dc3 = new DeploymentContentImpl 
> ("a.handy.persistence.library;deployed-version=1.1.0");
>>>>>>> +           assertTrue (dcList.contains(dc1));
>>>>>>> +           assertTrue (dcList.contains(dc2));
>>>>>>> +
>>>>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>>>>> +
>>>>>>> +           assertEquals(1, dcList.size());
>>>>>>> +           assertTrue (dcList.contains(dc3));
>>>>>>> +  }
>>>>>>> +
>>>>>>> +  @Test
>>>>>>>  public void testStoreAndReload() throws Exception {
>>>>>>>    AriesApplication app = createApplication (TEST_EBA);
>>>>>>>    File dest = new File 
> ("ariesApplicationManagerImplTest/stored.eba");
>>>>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>>>>    nextResolverResult.add(resolvedPersistenceLibrary);
>>>>>>>    _resolver.setNextResult(nextResolverResult);
>>>>>>> 
>>>>>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>>>>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>>>>>    AriesApplication app = _appMgr.createApplication(testEba);
>>>>>>>    app = _appMgr.resolve(app);
>>>>>>>    return app;
>>>>>>> 
>>>>>>> Added: 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>>> URL: 
> http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
> 
>>>>>>> 
> ==============================================================================
>>>>>>> --- 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 
> (added)
>>>>>>> +++ 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 
> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,11 @@
>>>>>>> +Manifest-Version: 1.0
>>>>>>> +Bundle-ManifestVersion: 2
>>>>>>> +Bundle-Name: helloWorld.war
>>>>>>> +Bundle-SymbolicName: helloWorld.war
>>>>>>> +Bundle-Version: 0.0.0
>>>>>>> +Bundle-Vendor: Apache.org
>>>>>>> +Bundle-ContextPath: /test
>>>>>>> +Export-Package: apache.org.helloWorldWar
>>>>>>> +
>>>>>>> +
>>>>>>> +
>>>>>>> 
>>>>>>> Added: 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>>> URL: 
> http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
> 
>>>>>>> 
> ==============================================================================
>>>>>>> --- 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 
> (added)
>>>>>>> +++ 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 
> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,9 @@
>>>>>>> +Manifest-Version: 1.0
>>>>>>> +Bundle-ManifestVersion: 2
>>>>>>> +Bundle-Name: HelloWorldJar
>>>>>>> +Bundle-SymbolicName: hello.world.jar
>>>>>>> +Bundle-Version: 1.1.0
>>>>>>> +Bundle-Vendor: Apache.org
>>>>>>> +Export-Package: apache.org.helloWorldJar
>>>>>>> +
>>>>>>> +
>>>>>>> 
>>>>>>> Added: 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>>> URL: 
> http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
> 
>>>>>>> 
> ==============================================================================
>>>>>>> --- 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 
> (added)
>>>>>>> +++ 
> incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 
> Tue Jul  6 10:51:12 2010
>>>>>>> @@ -0,0 +1,3 @@
>>>>>>> +<web-app>
>>>>>>> +<display-name>Hello World</display-name>
>>>>>>> +</web-app>
>>>>>>> \ No newline at end of file
>>>>>>> 
>>>>>>> Modified: 
> incubator/aries/trunk/application/application-utils/pom.xml
>>>>>>> URL: 
> http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
> 
>>>>>>> 
> ==============================================================================
>>>>>>> --- incubator/aries/trunk/application/application-utils/pom.xml 
> (original)
>>>>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue 
> Jul  6 10:51:12 2010
>>>>>>> @@ -67,7 +67,7 @@
>>>>>>>        <dependency>
>>>>>>>            <groupId>org.osgi</groupId>
>>>>>>>            <artifactId>org.osgi.core</artifactId>
>>>>>>> -            <version>4.0.0</version>
>>>>>>> +            <version>4.2.0</version>
>>>>>>>            <scope>provided</scope>
>>>>>>>        </dependency>
>>>>>>>        <dependency>
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>> 
>>> 
> 
> 
> 
> 
> 
> 
> 
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number 
> 741598. 
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
> 
> 
> 
> 
> 

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Emily Jiang <EM...@uk.ibm.com>.
Hi Alasdair and Lin,

It might make more sense to say that all bundles mentioned by the 
deployment.mf should be valid instead of all bundles included in EBA 
should be valid if there is a deployment.mf. I suggest that we should 
ignore the fact of having some utility jars in an EBA even if an 
delployment.mf is present. I think it might be too much to throw an error 
if there is a utility jar in an eba and the eba includes a deployment.mf? 
Did I miss something? If I am correct, we can simply remove the else if 
statement( line 134). 



Many thanks and kindest regards,
Emily
===========================
Emily Jiang
WebSphere ESB Foundation Technologies

MP 211, DE3A25, Winchester, Hampshire, England, SO21 2JN
Phone:  +44 (0)1962 816278  Internal: 246278

Email: emijiang@uk.ibm.com 
Lotus Notes: Emily Jiang/UK/IBM@IBMGB




From:   Alasdair Nottingham <no...@apache.org>
To:     "aries-dev@incubator.apache.org" <ar...@incubator.apache.org>
Date:   06/07/2010 21:55
Subject:        Re: svn commit: r960866 - in 
/incubator/aries/trunk/application: application-api/ 
application-management/ 
application-management/src/main/java/org/apache/aries/application/management/impl/ 
application-management/src/test/java/org/apache/aries/applica
Sent by:        Alasdair Nottingham <al...@gmail.com>



Hi,

Now I follow, the problem is we haven't even tried to load the deployment 
manifest at that point, so you are correct there is a bug there. Either 
loading the deployment manifest needs to occur sooner, or we need to set a 
variable indicating whiter we converted and check that later.

Alasdair

Alasdair Nottingham

On 6 Jul 2010, at 21:44, Lin Sun <li...@gmail.com> wrote:

> Hi
> 
> So the code sets deploymentMetadata to null in the beginning (line
> 112) but never set it to anything else before line 134,  so I don't
> think we'll ever get to line 134.   Seems to me we should set the
> deploymentMetadata (code around line 179) before the current line 134.
> 
> Please correct me if I missed anything.
> 
> Lin
> 
> On Tue, Jul 6, 2010 at 4:29 PM, Alasdair Nottingham <no...@apache.org> 
wrote:
>> I think the code checks for a valid bundle manifest and if it isn't 
valid and there is a deployment manifest then it raises an error, 
otherwise it converts the bundle. Isn't this what we want, or have I 
missed something?
>> 
>> Alasdair Nottingham
>> 
>> On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:
>> 
>>> Hi
>>> 
>>> Right, I'd think so, if a deployment.mf exists, then bundles are valid
>>> thus no conversion is needed.  However, the actual code seems to be
>>> different.
>>> 
>>> Lin
>>> 
>>> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> 
wrote:
>>>> Hi,
>>>> 
>>>> It should means that if a deployment manifest exists the content must 
be valid bundles. It does not mean you need a deployment.mf.
>>>> 
>>>> Alasdair Nottingham
>>>> 
>>>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>>>> 
>>>>> Hi
>>>>> 
>>>>> Quick question, does this mean if the aries application contains a
>>>>> deployment.mf, the createApplication will fail with
>>>>> ManagementException?
>>>>> 
>>>>> 
>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>> +              throw new ManagementException 
(MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
ebaFile.getName()));
>>>>>> +            }
>>>>> 
>>>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>>>> might have missed it) to a value other than null in this method.
>>>>> 
>>>>> Thx
>>>>> 
>>>>> Lin
>>>>> 
>>>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>>>> Author: mnuttall
>>>>>> Date: Tue Jul  6 10:51:12 2010
>>>>>> New Revision: 960866
>>>>>> 
>>>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>>>> Log:
>>>>>> ARIES-192: Convert bundles before generating the application 
content. From a patch submitted by Emily Jiang.
>>>>>> 
>>>>>> Added:
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>> Modified:
>>>>>>    incubator/aries/trunk/application/application-api/pom.xml
>>>>>>    incubator/aries/trunk/application/application-management/ (props 
changed)
>>>>>> 
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>>> 
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>>>    incubator/aries/trunk/application/application-utils/pom.xml
>>>>>> 
>>>>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>>>>> URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff

>>>>>> 
==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-api/pom.xml 
(original)
>>>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue 
Jul  6 10:51:12 2010
>>>>>> @@ -43,7 +43,7 @@
>>>>>>         <dependency>
>>>>>>             <groupId>org.osgi</groupId>
>>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>>> -            <version>4.0.0</version>
>>>>>> +            <version>4.2.0</version>
>>>>>>             <scope>provided</scope>
>>>>>>         </dependency>
>>>>>>     </dependencies>
>>>>>> 
>>>>>> Propchange: 
incubator/aries/trunk/application/application-management/
>>>>>> 
------------------------------------------------------------------------------
>>>>>> --- svn:ignore (original)
>>>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>>>> @@ -2,3 +2,5 @@ target
>>>>>>  .classpath
>>>>>>  .project
>>>>>>  .settings
>>>>>> +ariesApplicationManagerImplTest
>>>>>> +unittest
>>>>>> 
>>>>>> 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=960866&r1=960865&r2=960866&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 
Tue Jul  6 10:51:12 2010
>>>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>>>     AriesApplicationImpl application = null;
>>>>>> 
>>>>>>     try {
>>>>>> -      Manifest applicationManifest = parseApplicationManifest 
(ebaFile);
>>>>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, 
ebaFile.getName(), ebaFile);
>>>>>> +
>>>>>> +        /* We require that all other .jar and .war files included 
by-value be valid bundles
>>>>>> +         * because a DEPLOYMENT.MF has been provided. If no 
DEPLOYMENT.MF, migrate
>>>>>> +         * wars to wabs, plain jars to bundles
>>>>>> +         */
>>>>>> +
>>>>>> +        Set<BundleInfo> extraBundlesInfo = new 
HashSet<BundleInfo>();
>>>>>> +        for (IFile f : ebaFile) {
>>>>>> +          if (f.isDirectory()) {
>>>>>> +            continue;
>>>>>> +          }
>>>>>> +
>>>>>> +          BundleManifest bm = getBundleManifest (f);
>>>>>> +          if (bm != null) {
>>>>>> +            if (bm.isValid()) {
>>>>>> +              extraBundlesInfo.add(new 
SimpleBundleInfo(_applicationMetadataFactory, bm, 
f.toURL().toExternalForm()));
>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>> +              throw new ManagementException 
(MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
ebaFile.getName()));
>>>>>> +            } else {
>>>>>> +              // We have a jar that needs converting to a bundle, 
or a war to migrate to a WAB
>>>>>> +                 BundleConversion convertedBinary = null;
>>>>>> +              Iterator<BundleConverter> converters = 
_bundleConverters.iterator();
>>>>>> +              List<ConversionException> conversionExceptions = 
Collections.emptyList();
>>>>>> +              while (converters.hasNext() && convertedBinary == 
null) {
>>>>>> +                try {
>>>>>> +                  convertedBinary = 
converters.next().convert(ebaFile, f);
>>>>>> +                } catch (ServiceException sx) {
>>>>>> +                  // We'll get this if our optional 
BundleConverter has not been injected.
>>>>>> +                } catch (ConversionException cx) {
>>>>>> +                  conversionExceptions.add(cx);
>>>>>> +                }
>>>>>> +              }
>>>>>> +              if (conversionExceptions.size() > 0) {
>>>>>> +                for (ConversionException cx : 
conversionExceptions) {
>>>>>> +                  _logger.error("APPMANAGEMENT0004E", new 
Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>> +                }
>>>>>> +                throw new ManagementException 
(MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>> +              }
>>>>>> +              if (convertedBinary != null) {
>>>>>> +                modifiedBundles.put (f.getName(), 
convertedBinary);
>>>>>> +                bm = BundleManifest.fromBundle(f);
>>>>>> +                extraBundlesInfo.add(new 
SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>> +              }
>>>>>> +            }
>>>>>> +          }
>>>>>> +        }
>>>>>> +      Manifest applicationManifest = parseApplicationManifest 
(ebaFile);
>>>>>> +      String appName = ebaFile.getName();
>>>>>> +      //If the application name is null, we will try to get the 
file name.
>>>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>>>> +         String fullPath = ebaFile.toString();
>>>>>> +         if (fullPath.endsWith("/"))
>>>>>> +                 fullPath = fullPath.substring(0, 
fullPath.length() -1);
>>>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>>>> +          appName = fullPath.substring(last_slash + 1, 
fullPath.length());
>>>>>> +      }
>>>>>> +
>>>>>> +
>>>>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, 
appName, ebaFile);
>>>>>>       applicationMetadata = 
_applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>>>> -
>>>>>>       IFile deploymentManifest = 
ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>>>       if (deploymentManifest != null) {
>>>>>>         deploymentMetadata = 
_deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>>>         }
>>>>>>       }
>>>>>> 
>>>>>> -      /* We require that all other .jar and .war files included 
by-value be valid bundles
>>>>>> -       * because a DEPLOYMENT.MF has been provided. If no 
DEPLOYMENT.MF, migrate
>>>>>> -       * wars to wabs, plain jars to bundles
>>>>>> -       */
>>>>>> -
>>>>>> -      Set<BundleInfo> extraBundlesInfo = new 
HashSet<BundleInfo>();
>>>>>> -      for (IFile f : ebaFile) {
>>>>>> -        if (f.isDirectory()) {
>>>>>> -          continue;
>>>>>> -        }
>>>>>> -
>>>>>> -        BundleManifest bm = getBundleManifest (f);
>>>>>> -        if (bm != null) {
>>>>>> -          if (bm.isValid()) {
>>>>>> -            extraBundlesInfo.add(new 
SimpleBundleInfo(_applicationMetadataFactory, bm, 
f.toURL().toExternalForm()));
>>>>>> -          } else if (deploymentMetadata != null) {
>>>>>> -            throw new ManagementException 
(MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), 
ebaFile.getName()));
>>>>>> -          } else {
>>>>>> -            // We have a jar that needs converting to a bundle, or 
a war to migrate to a WAB
>>>>>> -            BundleConversion convertedBinary = null;
>>>>>> -            Iterator<BundleConverter> converters = 
_bundleConverters.iterator();
>>>>>> -            List<ConversionException> conversionExceptions = 
Collections.emptyList();
>>>>>> -            while (converters.hasNext() && convertedBinary == 
null) {
>>>>>> -              try {
>>>>>> -                convertedBinary = 
converters.next().convert(ebaFile, f);
>>>>>> -              } catch (ServiceException sx) {
>>>>>> -                // We'll get this if our optional BundleConverter 
has not been injected.
>>>>>> -              } catch (ConversionException cx) {
>>>>>> -                conversionExceptions.add(cx);
>>>>>> -              }
>>>>>> -            }
>>>>>> -            if (conversionExceptions.size() > 0) {
>>>>>> -              for (ConversionException cx : conversionExceptions) 
{
>>>>>> -                _logger.error("APPMANAGEMENT0004E", new 
Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>> -              }
>>>>>> -              throw new ManagementException 
(MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>> -            }
>>>>>> -            if (convertedBinary != null) {
>>>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>>>> -              bm = BundleManifest.fromBundle(f);
>>>>>> -              extraBundlesInfo.add(new 
SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>> -            }
>>>>>> -          }
>>>>>> -        }
>>>>>> -      }
>>>>>> +
>>>>>> 
>>>>>>       application = new AriesApplicationImpl (applicationMetadata, 
extraBundlesInfo, _localPlatform);
>>>>>>       application.setDeploymentMetadata(deploymentMetadata);
>>>>>> 
>>>>>> 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=960866&r1=960865&r2=960866&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 
Tue Jul  6 10:51:12 2010
>>>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>>>  import static org.junit.Assert.assertTrue;
>>>>>> 
>>>>>>  import java.io.File;
>>>>>> +import java.io.FileInputStream;
>>>>>>  import java.io.IOException;
>>>>>> +import java.io.InputStream;
>>>>>>  import java.lang.reflect.Field;
>>>>>>  import java.util.ArrayList;
>>>>>>  import java.util.HashSet;
>>>>>>  import java.util.List;
>>>>>>  import java.util.Set;
>>>>>> +import java.util.jar.Manifest;
>>>>>> 
>>>>>>  import org.apache.aries.application.ApplicationMetadata;
>>>>>>  import org.apache.aries.application.ApplicationMetadataFactory;
>>>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>>>  import 
org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>>>  import org.apache.aries.application.management.AriesApplication;
>>>>>>  import 
org.apache.aries.application.management.AriesApplicationResolver;
>>>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>>>  import org.apache.aries.application.management.BundleConverter;
>>>>>>  import org.apache.aries.application.management.BundleInfo;
>>>>>> +import 
org.apache.aries.application.management.ConversionException;
>>>>>>  import org.apache.aries.application.management.LocalPlatform;
>>>>>>  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.management.impl.AriesApplicationManagerImpl;
>>>>>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>>>  import 
org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>>>       return File.createTempFile("ebaTmp", null);
>>>>>>     }
>>>>>>   }
>>>>>> +
>>>>>> +  static class DummyConverter implements BundleConverter {
>>>>>> 
>>>>>> -  static final String TEST_EBA = 
"./ariesApplicationManagerImplTest/test.eba";
>>>>>> +       public BundleConversion convert(IDirectory parentEba, IFile 
toBeConverted)
>>>>>> +                       throws ConversionException {
>>>>>> +               if 
(toBeConverted.getName().equals("helloWorld.war")) {
>>>>>> +                       InputStream is = null;
>>>>>> +            try {
>>>>>> +               is = new FileInputStream(new 
File("../src/test/resources/conversion/MANIFEST.MF"));
>>>>>> +               Manifest warManifest = new Manifest(is);
>>>>>> +               IOUtils.jarUp(new 
File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), 
new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), 
warManifest);
>>>>>> +               IOUtils.zipUp(new 
File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), 
new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>>>> +
>>>>>> +               IOUtils.zipUp(new 
File("./ariesApplicationManagerImplTest/conversion"), new 
File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>> +               final InputStream jarIs = new FileInputStream(new 
File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>> +                final String location = toBeConverted.toString();
>>>>>> +               return new BundleConversion() {
>>>>>> +
>>>>>> +                                       public BundleInfo 
getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>>>> +                                               return new 
SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>>>> +                                       }
>>>>>> +
>>>>>> +                                       public InputStream 
getInputStream() throws IOException {
>>>>>> +                                               return jarIs;
>>>>>> +                                       }
>>>>>> +
>>>>>> +                };
>>>>>> +            } catch (IOException e) {
>>>>>> +               e.printStackTrace();
>>>>>> +            } finally {
>>>>>> +               try {
>>>>>> +               if (is != null)
>>>>>> +                       is.close();
>>>>>> +               } catch (Exception e) {
>>>>>> +                       e.printStackTrace();
>>>>>> +               }
>>>>>> +            }
>>>>>> +        }
>>>>>> +
>>>>>> +        return null;
>>>>>> +    }
>>>>>> +
>>>>>> +
>>>>>> +  }
>>>>>> 
>>>>>> +
>>>>>> +
>>>>>> +  static final String TEST_EBA = 
"./ariesApplicationManagerImplTest/test.eba";
>>>>>> +  static final String CONVERSION_EBA = 
"./ariesApplicationManagerImplTest/conversion.eba";
>>>>>>   @BeforeClass
>>>>>>   public static void preTest() throws Exception {
>>>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>>>> +    new 
File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>>> 
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);
>>>>>> + 
EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", 
CONVERSION_EBA);
>>>>>>   }
>>>>>> 
>>>>>>   AriesApplicationManagerImpl _appMgr;
>>>>>>   ApplicationMetadataFactory _appMetaFactory;
>>>>>>   DummyResolver _resolver;
>>>>>> -
>>>>>> +  DummyConverter _converter;
>>>>>>   @Before
>>>>>>   public void setup() {
>>>>>>     _appMgr = new AriesApplicationManagerImpl ();
>>>>>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>>>> 
>>>>>>     DeploymentMetadataFactory dmf = new 
DeploymentMetadataFactoryImpl();
>>>>>> +    _converter = new DummyConverter();
>>>>>>     List<BundleConverter> bundleConverters = new 
ArrayList<BundleConverter>();
>>>>>> -    _resolver = new DummyResolver();
>>>>>> -
>>>>>> +    bundleConverters.add(_converter);
>>>>>> +    _resolver = new DummyResolver();
>>>>>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>>>>>     _appMgr.setBundleConverters(bundleConverters);
>>>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>>>   }
>>>>>> 
>>>>>>   @Test
>>>>>> +  public void testCreateAndConversion() throws Exception {
>>>>>> +               AriesApplication app = createApplication 
(CONVERSION_EBA);
>>>>>> +           ApplicationMetadata appMeta = 
app.getApplicationMetadata();
>>>>>> +           assertEquals (appMeta.getApplicationName(), 
"conversion.eba");
>>>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), 
"conversion.eba");
>>>>>> +           assertEquals (appMeta.getApplicationVersion(), new 
Version("0.0"));
>>>>>> +           List<Content> appContent = 
appMeta.getApplicationContents();
>>>>>> +           assertEquals (appContent.size(), 2);
>>>>>> +           Content fbw = new 
ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>>>> +           Content mbl = new 
ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>>>> +           assertTrue (appContent.contains(fbw));
>>>>>> +           assertTrue (appContent.contains(mbl));
>>>>>> +
>>>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>>>> +           List<DeploymentContent> dcList = 
dm.getApplicationDeploymentContents();
>>>>>> +
>>>>>> +           assertEquals (2, dcList.size());
>>>>>> +           DeploymentContent dc1 = new DeploymentContentImpl 
("hello.world.jar;deployed-version=1.1.0");
>>>>>> +           DeploymentContent dc2 = new DeploymentContentImpl 
("helloWorld.war;deployed-version=0.0.0");
>>>>>> +           DeploymentContent dc3 = new DeploymentContentImpl 
("a.handy.persistence.library;deployed-version=1.1.0");
>>>>>> +           assertTrue (dcList.contains(dc1));
>>>>>> +           assertTrue (dcList.contains(dc2));
>>>>>> +
>>>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>>>> +
>>>>>> +           assertEquals(1, dcList.size());
>>>>>> +           assertTrue (dcList.contains(dc3));
>>>>>> +  }
>>>>>> +
>>>>>> +  @Test
>>>>>>   public void testStoreAndReload() throws Exception {
>>>>>>     AriesApplication app = createApplication (TEST_EBA);
>>>>>>     File dest = new File 
("ariesApplicationManagerImplTest/stored.eba");
>>>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>>>>>     _resolver.setNextResult(nextResolverResult);
>>>>>> 
>>>>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>>>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>>>>     AriesApplication app = _appMgr.createApplication(testEba);
>>>>>>     app = _appMgr.resolve(app);
>>>>>>     return app;
>>>>>> 
>>>>>> Added: 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>> URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto

>>>>>> 
==============================================================================
>>>>>> --- 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 
(added)
>>>>>> +++ 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF 
Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,11 @@
>>>>>> +Manifest-Version: 1.0
>>>>>> +Bundle-ManifestVersion: 2
>>>>>> +Bundle-Name: helloWorld.war
>>>>>> +Bundle-SymbolicName: helloWorld.war
>>>>>> +Bundle-Version: 0.0.0
>>>>>> +Bundle-Vendor: Apache.org
>>>>>> +Bundle-ContextPath: /test
>>>>>> +Export-Package: apache.org.helloWorldWar
>>>>>> +
>>>>>> +
>>>>>> +
>>>>>> 
>>>>>> Added: 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>> URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto

>>>>>> 
==============================================================================
>>>>>> --- 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 
(added)
>>>>>> +++ 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF 
Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,9 @@
>>>>>> +Manifest-Version: 1.0
>>>>>> +Bundle-ManifestVersion: 2
>>>>>> +Bundle-Name: HelloWorldJar
>>>>>> +Bundle-SymbolicName: hello.world.jar
>>>>>> +Bundle-Version: 1.1.0
>>>>>> +Bundle-Vendor: Apache.org
>>>>>> +Export-Package: apache.org.helloWorldJar
>>>>>> +
>>>>>> +
>>>>>> 
>>>>>> Added: 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>> URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto

>>>>>> 
==============================================================================
>>>>>> --- 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 
(added)
>>>>>> +++ 
incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml 
Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,3 @@
>>>>>> +<web-app>
>>>>>> +<display-name>Hello World</display-name>
>>>>>> +</web-app>
>>>>>> \ No newline at end of file
>>>>>> 
>>>>>> Modified: 
incubator/aries/trunk/application/application-utils/pom.xml
>>>>>> URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff

>>>>>> 
==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-utils/pom.xml 
(original)
>>>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue 
Jul  6 10:51:12 2010
>>>>>> @@ -67,7 +67,7 @@
>>>>>>         <dependency>
>>>>>>             <groupId>org.osgi</groupId>
>>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>>> -            <version>4.0.0</version>
>>>>>> +            <version>4.2.0</version>
>>>>>>             <scope>provided</scope>
>>>>>>         </dependency>
>>>>>>         <dependency>
>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>> 







Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU






Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Alasdair Nottingham <no...@apache.org>.
Hi,

Now I follow, the problem is we haven't even tried to load the deployment manifest at that point, so you are correct there is a bug there. Either loading the deployment manifest needs to occur sooner, or we need to set a variable indicating whiter we converted and check that later.

Alasdair

Alasdair Nottingham

On 6 Jul 2010, at 21:44, Lin Sun <li...@gmail.com> wrote:

> Hi
> 
> So the code sets deploymentMetadata to null in the beginning (line
> 112) but never set it to anything else before line 134,  so I don't
> think we'll ever get to line 134.   Seems to me we should set the
> deploymentMetadata (code around line 179) before the current line 134.
> 
> Please correct me if I missed anything.
> 
> Lin
> 
> On Tue, Jul 6, 2010 at 4:29 PM, Alasdair Nottingham <no...@apache.org> wrote:
>> I think the code checks for a valid bundle manifest and if it isn't valid and there is a deployment manifest then it raises an error, otherwise it converts the bundle. Isn't this what we want, or have I missed something?
>> 
>> Alasdair Nottingham
>> 
>> On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:
>> 
>>> Hi
>>> 
>>> Right, I'd think so, if a deployment.mf exists, then bundles are valid
>>> thus no conversion is needed.  However, the actual code seems to be
>>> different.
>>> 
>>> Lin
>>> 
>>> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> wrote:
>>>> Hi,
>>>> 
>>>> It should means that if a deployment manifest exists the content must be valid bundles. It does not mean you need a deployment.mf.
>>>> 
>>>> Alasdair Nottingham
>>>> 
>>>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>>>> 
>>>>> Hi
>>>>> 
>>>>> Quick question, does this mean if the aries application contains a
>>>>> deployment.mf, the createApplication will fail with
>>>>> ManagementException?
>>>>> 
>>>>> 
>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>>> +            }
>>>>> 
>>>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>>>> might have missed it) to a value other than null in this method.
>>>>> 
>>>>> Thx
>>>>> 
>>>>> Lin
>>>>> 
>>>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>>>> Author: mnuttall
>>>>>> Date: Tue Jul  6 10:51:12 2010
>>>>>> New Revision: 960866
>>>>>> 
>>>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>>>> Log:
>>>>>> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>>>>>> 
>>>>>> Added:
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>> Modified:
>>>>>>    incubator/aries/trunk/application/application-api/pom.xml
>>>>>>    incubator/aries/trunk/application/application-management/   (props changed)
>>>>>>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>>>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>>>    incubator/aries/trunk/application/application-utils/pom.xml
>>>>>> 
>>>>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>>>> ==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-api/pom.xml (original)
>>>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
>>>>>> @@ -43,7 +43,7 @@
>>>>>>         <dependency>
>>>>>>             <groupId>org.osgi</groupId>
>>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>>> -            <version>4.0.0</version>
>>>>>> +            <version>4.2.0</version>
>>>>>>             <scope>provided</scope>
>>>>>>         </dependency>
>>>>>>     </dependencies>
>>>>>> 
>>>>>> Propchange: incubator/aries/trunk/application/application-management/
>>>>>> ------------------------------------------------------------------------------
>>>>>> --- svn:ignore (original)
>>>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>>>> @@ -2,3 +2,5 @@ target
>>>>>>  .classpath
>>>>>>  .project
>>>>>>  .settings
>>>>>> +ariesApplicationManagerImplTest
>>>>>> +unittest
>>>>>> 
>>>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>>>     AriesApplicationImpl application = null;
>>>>>> 
>>>>>>     try {
>>>>>> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
>>>>>> +
>>>>>> +        /* We require that all other .jar and .war files included by-value be valid bundles
>>>>>> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>>>> +         * wars to wabs, plain jars to bundles
>>>>>> +         */
>>>>>> +
>>>>>> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>>>> +        for (IFile f : ebaFile) {
>>>>>> +          if (f.isDirectory()) {
>>>>>> +            continue;
>>>>>> +          }
>>>>>> +
>>>>>> +          BundleManifest bm = getBundleManifest (f);
>>>>>> +          if (bm != null) {
>>>>>> +            if (bm.isValid()) {
>>>>>> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>>>> +            } else if (deploymentMetadata != null) {
>>>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>>> +            } else {
>>>>>> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>>>> +                 BundleConversion convertedBinary = null;
>>>>>> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>>>> +              List<ConversionException> conversionExceptions = Collections.emptyList();
>>>>>> +              while (converters.hasNext() && convertedBinary == null) {
>>>>>> +                try {
>>>>>> +                  convertedBinary = converters.next().convert(ebaFile, f);
>>>>>> +                } catch (ServiceException sx) {
>>>>>> +                  // We'll get this if our optional BundleConverter has not been injected.
>>>>>> +                } catch (ConversionException cx) {
>>>>>> +                  conversionExceptions.add(cx);
>>>>>> +                }
>>>>>> +              }
>>>>>> +              if (conversionExceptions.size() > 0) {
>>>>>> +                for (ConversionException cx : conversionExceptions) {
>>>>>> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>> +                }
>>>>>> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>> +              }
>>>>>> +              if (convertedBinary != null) {
>>>>>> +                modifiedBundles.put (f.getName(), convertedBinary);
>>>>>> +                bm = BundleManifest.fromBundle(f);
>>>>>> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>> +              }
>>>>>> +            }
>>>>>> +          }
>>>>>> +        }
>>>>>> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>>>> +      String appName = ebaFile.getName();
>>>>>> +      //If the application name is null, we will try to get the file name.
>>>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>>>> +         String fullPath = ebaFile.toString();
>>>>>> +         if (fullPath.endsWith("/"))
>>>>>> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
>>>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>>>> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
>>>>>> +      }
>>>>>> +
>>>>>> +
>>>>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>>>>>>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>>>> -
>>>>>>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>>>       if (deploymentManifest != null) {
>>>>>>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>>>         }
>>>>>>       }
>>>>>> 
>>>>>> -      /* We require that all other .jar and .war files included by-value be valid bundles
>>>>>> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>>>> -       * wars to wabs, plain jars to bundles
>>>>>> -       */
>>>>>> -
>>>>>> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>>>> -      for (IFile f : ebaFile) {
>>>>>> -        if (f.isDirectory()) {
>>>>>> -          continue;
>>>>>> -        }
>>>>>> -
>>>>>> -        BundleManifest bm = getBundleManifest (f);
>>>>>> -        if (bm != null) {
>>>>>> -          if (bm.isValid()) {
>>>>>> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>>>> -          } else if (deploymentMetadata != null) {
>>>>>> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>>> -          } else {
>>>>>> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>>>> -            BundleConversion convertedBinary = null;
>>>>>> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>>>> -            List<ConversionException> conversionExceptions = Collections.emptyList();
>>>>>> -            while (converters.hasNext() && convertedBinary == null) {
>>>>>> -              try {
>>>>>> -                convertedBinary = converters.next().convert(ebaFile, f);
>>>>>> -              } catch (ServiceException sx) {
>>>>>> -                // We'll get this if our optional BundleConverter has not been injected.
>>>>>> -              } catch (ConversionException cx) {
>>>>>> -                conversionExceptions.add(cx);
>>>>>> -              }
>>>>>> -            }
>>>>>> -            if (conversionExceptions.size() > 0) {
>>>>>> -              for (ConversionException cx : conversionExceptions) {
>>>>>> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>>>> -              }
>>>>>> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>>> -            }
>>>>>> -            if (convertedBinary != null) {
>>>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>>>> -              bm = BundleManifest.fromBundle(f);
>>>>>> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>>> -            }
>>>>>> -          }
>>>>>> -        }
>>>>>> -      }
>>>>>> +
>>>>>> 
>>>>>>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>>>>>>       application.setDeploymentMetadata(deploymentMetadata);
>>>>>> 
>>>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>>>  import static org.junit.Assert.assertTrue;
>>>>>> 
>>>>>>  import java.io.File;
>>>>>> +import java.io.FileInputStream;
>>>>>>  import java.io.IOException;
>>>>>> +import java.io.InputStream;
>>>>>>  import java.lang.reflect.Field;
>>>>>>  import java.util.ArrayList;
>>>>>>  import java.util.HashSet;
>>>>>>  import java.util.List;
>>>>>>  import java.util.Set;
>>>>>> +import java.util.jar.Manifest;
>>>>>> 
>>>>>>  import org.apache.aries.application.ApplicationMetadata;
>>>>>>  import org.apache.aries.application.ApplicationMetadataFactory;
>>>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>>>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>>>  import org.apache.aries.application.management.AriesApplication;
>>>>>>  import org.apache.aries.application.management.AriesApplicationResolver;
>>>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>>>  import org.apache.aries.application.management.BundleConverter;
>>>>>>  import org.apache.aries.application.management.BundleInfo;
>>>>>> +import org.apache.aries.application.management.ConversionException;
>>>>>>  import org.apache.aries.application.management.LocalPlatform;
>>>>>>  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.management.impl.AriesApplicationManagerImpl;
>>>>>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>>>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>>>       return File.createTempFile("ebaTmp", null);
>>>>>>     }
>>>>>>   }
>>>>>> +
>>>>>> +  static class DummyConverter implements BundleConverter {
>>>>>> 
>>>>>> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>>>> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
>>>>>> +                       throws ConversionException {
>>>>>> +               if (toBeConverted.getName().equals("helloWorld.war")) {
>>>>>> +                       InputStream is = null;
>>>>>> +            try {
>>>>>> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
>>>>>> +               Manifest warManifest = new Manifest(is);
>>>>>> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
>>>>>> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>>>> +
>>>>>> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>>> +                final String location = toBeConverted.toString();
>>>>>> +               return new BundleConversion() {
>>>>>> +
>>>>>> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>>>> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>>>> +                                       }
>>>>>> +
>>>>>> +                                       public InputStream getInputStream() throws IOException {
>>>>>> +                                               return jarIs;
>>>>>> +                                       }
>>>>>> +
>>>>>> +                };
>>>>>> +            } catch (IOException e) {
>>>>>> +               e.printStackTrace();
>>>>>> +            } finally {
>>>>>> +               try {
>>>>>> +               if (is != null)
>>>>>> +                       is.close();
>>>>>> +               } catch (Exception e) {
>>>>>> +                       e.printStackTrace();
>>>>>> +               }
>>>>>> +            }
>>>>>> +        }
>>>>>> +
>>>>>> +        return null;
>>>>>> +    }
>>>>>> +
>>>>>> +
>>>>>> +  }
>>>>>> 
>>>>>> +
>>>>>> +
>>>>>> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>>>> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>>>>>>   @BeforeClass
>>>>>>   public static void preTest() throws Exception {
>>>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>>>> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>>>     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);
>>>>>> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>>>>>>   }
>>>>>> 
>>>>>>   AriesApplicationManagerImpl _appMgr;
>>>>>>   ApplicationMetadataFactory _appMetaFactory;
>>>>>>   DummyResolver _resolver;
>>>>>> -
>>>>>> +  DummyConverter _converter;
>>>>>>   @Before
>>>>>>   public void setup() {
>>>>>>     _appMgr = new AriesApplicationManagerImpl ();
>>>>>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>>>> 
>>>>>>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
>>>>>> +    _converter = new DummyConverter();
>>>>>>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
>>>>>> -    _resolver = new DummyResolver();
>>>>>> -
>>>>>> +    bundleConverters.add(_converter);
>>>>>> +    _resolver = new DummyResolver();
>>>>>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>>>>>     _appMgr.setBundleConverters(bundleConverters);
>>>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>>>   }
>>>>>> 
>>>>>>   @Test
>>>>>> +  public void testCreateAndConversion() throws Exception {
>>>>>> +               AriesApplication app = createApplication (CONVERSION_EBA);
>>>>>> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
>>>>>> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
>>>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
>>>>>> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
>>>>>> +           List<Content> appContent = appMeta.getApplicationContents();
>>>>>> +           assertEquals (appContent.size(), 2);
>>>>>> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>>>> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>>>> +           assertTrue (appContent.contains(fbw));
>>>>>> +           assertTrue (appContent.contains(mbl));
>>>>>> +
>>>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>>>> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
>>>>>> +
>>>>>> +           assertEquals (2, dcList.size());
>>>>>> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
>>>>>> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
>>>>>> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
>>>>>> +           assertTrue (dcList.contains(dc1));
>>>>>> +           assertTrue (dcList.contains(dc2));
>>>>>> +
>>>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>>>> +
>>>>>> +           assertEquals(1, dcList.size());
>>>>>> +           assertTrue (dcList.contains(dc3));
>>>>>> +  }
>>>>>> +
>>>>>> +  @Test
>>>>>>   public void testStoreAndReload() throws Exception {
>>>>>>     AriesApplication app = createApplication (TEST_EBA);
>>>>>>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
>>>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>>>>>     _resolver.setNextResult(nextResolverResult);
>>>>>> 
>>>>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>>>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>>>>     AriesApplication app = _appMgr.createApplication(testEba);
>>>>>>     app = _appMgr.resolve(app);
>>>>>>     return app;
>>>>>> 
>>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
>>>>>> ==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
>>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,11 @@
>>>>>> +Manifest-Version: 1.0
>>>>>> +Bundle-ManifestVersion: 2
>>>>>> +Bundle-Name: helloWorld.war
>>>>>> +Bundle-SymbolicName: helloWorld.war
>>>>>> +Bundle-Version: 0.0.0
>>>>>> +Bundle-Vendor: Apache.org
>>>>>> +Bundle-ContextPath: /test
>>>>>> +Export-Package: apache.org.helloWorldWar
>>>>>> +
>>>>>> +
>>>>>> +
>>>>>> 
>>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
>>>>>> ==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
>>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,9 @@
>>>>>> +Manifest-Version: 1.0
>>>>>> +Bundle-ManifestVersion: 2
>>>>>> +Bundle-Name: HelloWorldJar
>>>>>> +Bundle-SymbolicName: hello.world.jar
>>>>>> +Bundle-Version: 1.1.0
>>>>>> +Bundle-Vendor: Apache.org
>>>>>> +Export-Package: apache.org.helloWorldJar
>>>>>> +
>>>>>> +
>>>>>> 
>>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
>>>>>> ==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
>>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
>>>>>> @@ -0,0 +1,3 @@
>>>>>> +<web-app>
>>>>>> +<display-name>Hello World</display-name>
>>>>>> +</web-app>
>>>>>> \ No newline at end of file
>>>>>> 
>>>>>> Modified: incubator/aries/trunk/application/application-utils/pom.xml
>>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>>>> ==============================================================================
>>>>>> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
>>>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
>>>>>> @@ -67,7 +67,7 @@
>>>>>>         <dependency>
>>>>>>             <groupId>org.osgi</groupId>
>>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>>> -            <version>4.0.0</version>
>>>>>> +            <version>4.2.0</version>
>>>>>>             <scope>provided</scope>
>>>>>>         </dependency>
>>>>>>         <dependency>
>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>> 

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Lin Sun <li...@gmail.com>.
Hi

So the code sets deploymentMetadata to null in the beginning (line
112) but never set it to anything else before line 134,  so I don't
think we'll ever get to line 134.   Seems to me we should set the
deploymentMetadata (code around line 179) before the current line 134.

Please correct me if I missed anything.

Lin

On Tue, Jul 6, 2010 at 4:29 PM, Alasdair Nottingham <no...@apache.org> wrote:
> I think the code checks for a valid bundle manifest and if it isn't valid and there is a deployment manifest then it raises an error, otherwise it converts the bundle. Isn't this what we want, or have I missed something?
>
> Alasdair Nottingham
>
> On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:
>
>> Hi
>>
>> Right, I'd think so, if a deployment.mf exists, then bundles are valid
>> thus no conversion is needed.  However, the actual code seems to be
>> different.
>>
>> Lin
>>
>> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> wrote:
>>> Hi,
>>>
>>> It should means that if a deployment manifest exists the content must be valid bundles. It does not mean you need a deployment.mf.
>>>
>>> Alasdair Nottingham
>>>
>>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>>>
>>>> Hi
>>>>
>>>> Quick question, does this mean if the aries application contains a
>>>> deployment.mf, the createApplication will fail with
>>>> ManagementException?
>>>>
>>>>
>>>>> +            } else if (deploymentMetadata != null) {
>>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>> +            }
>>>>
>>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>>> might have missed it) to a value other than null in this method.
>>>>
>>>> Thx
>>>>
>>>> Lin
>>>>
>>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>>> Author: mnuttall
>>>>> Date: Tue Jul  6 10:51:12 2010
>>>>> New Revision: 960866
>>>>>
>>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>>> Log:
>>>>> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>>>>>
>>>>> Added:
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>> Modified:
>>>>>    incubator/aries/trunk/application/application-api/pom.xml
>>>>>    incubator/aries/trunk/application/application-management/   (props changed)
>>>>>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>>    incubator/aries/trunk/application/application-utils/pom.xml
>>>>>
>>>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>>> ==============================================================================
>>>>> --- incubator/aries/trunk/application/application-api/pom.xml (original)
>>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
>>>>> @@ -43,7 +43,7 @@
>>>>>         <dependency>
>>>>>             <groupId>org.osgi</groupId>
>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>> -            <version>4.0.0</version>
>>>>> +            <version>4.2.0</version>
>>>>>             <scope>provided</scope>
>>>>>         </dependency>
>>>>>     </dependencies>
>>>>>
>>>>> Propchange: incubator/aries/trunk/application/application-management/
>>>>> ------------------------------------------------------------------------------
>>>>> --- svn:ignore (original)
>>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>>> @@ -2,3 +2,5 @@ target
>>>>>  .classpath
>>>>>  .project
>>>>>  .settings
>>>>> +ariesApplicationManagerImplTest
>>>>> +unittest
>>>>>
>>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>>     AriesApplicationImpl application = null;
>>>>>
>>>>>     try {
>>>>> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
>>>>> +
>>>>> +        /* We require that all other .jar and .war files included by-value be valid bundles
>>>>> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>>> +         * wars to wabs, plain jars to bundles
>>>>> +         */
>>>>> +
>>>>> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>>> +        for (IFile f : ebaFile) {
>>>>> +          if (f.isDirectory()) {
>>>>> +            continue;
>>>>> +          }
>>>>> +
>>>>> +          BundleManifest bm = getBundleManifest (f);
>>>>> +          if (bm != null) {
>>>>> +            if (bm.isValid()) {
>>>>> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>>> +            } else if (deploymentMetadata != null) {
>>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>> +            } else {
>>>>> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>>> +                 BundleConversion convertedBinary = null;
>>>>> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>>> +              List<ConversionException> conversionExceptions = Collections.emptyList();
>>>>> +              while (converters.hasNext() && convertedBinary == null) {
>>>>> +                try {
>>>>> +                  convertedBinary = converters.next().convert(ebaFile, f);
>>>>> +                } catch (ServiceException sx) {
>>>>> +                  // We'll get this if our optional BundleConverter has not been injected.
>>>>> +                } catch (ConversionException cx) {
>>>>> +                  conversionExceptions.add(cx);
>>>>> +                }
>>>>> +              }
>>>>> +              if (conversionExceptions.size() > 0) {
>>>>> +                for (ConversionException cx : conversionExceptions) {
>>>>> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>>> +                }
>>>>> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>> +              }
>>>>> +              if (convertedBinary != null) {
>>>>> +                modifiedBundles.put (f.getName(), convertedBinary);
>>>>> +                bm = BundleManifest.fromBundle(f);
>>>>> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>> +              }
>>>>> +            }
>>>>> +          }
>>>>> +        }
>>>>> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>>> +      String appName = ebaFile.getName();
>>>>> +      //If the application name is null, we will try to get the file name.
>>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>>> +         String fullPath = ebaFile.toString();
>>>>> +         if (fullPath.endsWith("/"))
>>>>> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
>>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>>> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
>>>>> +      }
>>>>> +
>>>>> +
>>>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>>>>>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>>> -
>>>>>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>>       if (deploymentManifest != null) {
>>>>>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>>         }
>>>>>       }
>>>>>
>>>>> -      /* We require that all other .jar and .war files included by-value be valid bundles
>>>>> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>>> -       * wars to wabs, plain jars to bundles
>>>>> -       */
>>>>> -
>>>>> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>>> -      for (IFile f : ebaFile) {
>>>>> -        if (f.isDirectory()) {
>>>>> -          continue;
>>>>> -        }
>>>>> -
>>>>> -        BundleManifest bm = getBundleManifest (f);
>>>>> -        if (bm != null) {
>>>>> -          if (bm.isValid()) {
>>>>> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>>> -          } else if (deploymentMetadata != null) {
>>>>> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>>> -          } else {
>>>>> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>>> -            BundleConversion convertedBinary = null;
>>>>> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>>> -            List<ConversionException> conversionExceptions = Collections.emptyList();
>>>>> -            while (converters.hasNext() && convertedBinary == null) {
>>>>> -              try {
>>>>> -                convertedBinary = converters.next().convert(ebaFile, f);
>>>>> -              } catch (ServiceException sx) {
>>>>> -                // We'll get this if our optional BundleConverter has not been injected.
>>>>> -              } catch (ConversionException cx) {
>>>>> -                conversionExceptions.add(cx);
>>>>> -              }
>>>>> -            }
>>>>> -            if (conversionExceptions.size() > 0) {
>>>>> -              for (ConversionException cx : conversionExceptions) {
>>>>> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>>> -              }
>>>>> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>>> -            }
>>>>> -            if (convertedBinary != null) {
>>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>>> -              bm = BundleManifest.fromBundle(f);
>>>>> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>>> -            }
>>>>> -          }
>>>>> -        }
>>>>> -      }
>>>>> +
>>>>>
>>>>>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>>>>>       application.setDeploymentMetadata(deploymentMetadata);
>>>>>
>>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>>  import static org.junit.Assert.assertTrue;
>>>>>
>>>>>  import java.io.File;
>>>>> +import java.io.FileInputStream;
>>>>>  import java.io.IOException;
>>>>> +import java.io.InputStream;
>>>>>  import java.lang.reflect.Field;
>>>>>  import java.util.ArrayList;
>>>>>  import java.util.HashSet;
>>>>>  import java.util.List;
>>>>>  import java.util.Set;
>>>>> +import java.util.jar.Manifest;
>>>>>
>>>>>  import org.apache.aries.application.ApplicationMetadata;
>>>>>  import org.apache.aries.application.ApplicationMetadataFactory;
>>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>>  import org.apache.aries.application.management.AriesApplication;
>>>>>  import org.apache.aries.application.management.AriesApplicationResolver;
>>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>>  import org.apache.aries.application.management.BundleConverter;
>>>>>  import org.apache.aries.application.management.BundleInfo;
>>>>> +import org.apache.aries.application.management.ConversionException;
>>>>>  import org.apache.aries.application.management.LocalPlatform;
>>>>>  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.management.impl.AriesApplicationManagerImpl;
>>>>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>>       return File.createTempFile("ebaTmp", null);
>>>>>     }
>>>>>   }
>>>>> +
>>>>> +  static class DummyConverter implements BundleConverter {
>>>>>
>>>>> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>>> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
>>>>> +                       throws ConversionException {
>>>>> +               if (toBeConverted.getName().equals("helloWorld.war")) {
>>>>> +                       InputStream is = null;
>>>>> +            try {
>>>>> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
>>>>> +               Manifest warManifest = new Manifest(is);
>>>>> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
>>>>> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>>> +
>>>>> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>>> +                final String location = toBeConverted.toString();
>>>>> +               return new BundleConversion() {
>>>>> +
>>>>> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>>> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>>> +                                       }
>>>>> +
>>>>> +                                       public InputStream getInputStream() throws IOException {
>>>>> +                                               return jarIs;
>>>>> +                                       }
>>>>> +
>>>>> +                };
>>>>> +            } catch (IOException e) {
>>>>> +               e.printStackTrace();
>>>>> +            } finally {
>>>>> +               try {
>>>>> +               if (is != null)
>>>>> +                       is.close();
>>>>> +               } catch (Exception e) {
>>>>> +                       e.printStackTrace();
>>>>> +               }
>>>>> +            }
>>>>> +        }
>>>>> +
>>>>> +        return null;
>>>>> +    }
>>>>> +
>>>>> +
>>>>> +  }
>>>>>
>>>>> +
>>>>> +
>>>>> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>>> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>>>>>   @BeforeClass
>>>>>   public static void preTest() throws Exception {
>>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>>> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>>     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);
>>>>> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>>>>>   }
>>>>>
>>>>>   AriesApplicationManagerImpl _appMgr;
>>>>>   ApplicationMetadataFactory _appMetaFactory;
>>>>>   DummyResolver _resolver;
>>>>> -
>>>>> +  DummyConverter _converter;
>>>>>   @Before
>>>>>   public void setup() {
>>>>>     _appMgr = new AriesApplicationManagerImpl ();
>>>>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>>>
>>>>>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
>>>>> +    _converter = new DummyConverter();
>>>>>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
>>>>> -    _resolver = new DummyResolver();
>>>>> -
>>>>> +    bundleConverters.add(_converter);
>>>>> +    _resolver = new DummyResolver();
>>>>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>>>>     _appMgr.setBundleConverters(bundleConverters);
>>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>>   }
>>>>>
>>>>>   @Test
>>>>> +  public void testCreateAndConversion() throws Exception {
>>>>> +               AriesApplication app = createApplication (CONVERSION_EBA);
>>>>> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
>>>>> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
>>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
>>>>> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
>>>>> +           List<Content> appContent = appMeta.getApplicationContents();
>>>>> +           assertEquals (appContent.size(), 2);
>>>>> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>>> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>>> +           assertTrue (appContent.contains(fbw));
>>>>> +           assertTrue (appContent.contains(mbl));
>>>>> +
>>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>>> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
>>>>> +
>>>>> +           assertEquals (2, dcList.size());
>>>>> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
>>>>> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
>>>>> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
>>>>> +           assertTrue (dcList.contains(dc1));
>>>>> +           assertTrue (dcList.contains(dc2));
>>>>> +
>>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>>> +
>>>>> +           assertEquals(1, dcList.size());
>>>>> +           assertTrue (dcList.contains(dc3));
>>>>> +  }
>>>>> +
>>>>> +  @Test
>>>>>   public void testStoreAndReload() throws Exception {
>>>>>     AriesApplication app = createApplication (TEST_EBA);
>>>>>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
>>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>>>>     _resolver.setNextResult(nextResolverResult);
>>>>>
>>>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>>>     AriesApplication app = _appMgr.createApplication(testEba);
>>>>>     app = _appMgr.resolve(app);
>>>>>     return app;
>>>>>
>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
>>>>> ==============================================================================
>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>>> @@ -0,0 +1,11 @@
>>>>> +Manifest-Version: 1.0
>>>>> +Bundle-ManifestVersion: 2
>>>>> +Bundle-Name: helloWorld.war
>>>>> +Bundle-SymbolicName: helloWorld.war
>>>>> +Bundle-Version: 0.0.0
>>>>> +Bundle-Vendor: Apache.org
>>>>> +Bundle-ContextPath: /test
>>>>> +Export-Package: apache.org.helloWorldWar
>>>>> +
>>>>> +
>>>>> +
>>>>>
>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
>>>>> ==============================================================================
>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>>> @@ -0,0 +1,9 @@
>>>>> +Manifest-Version: 1.0
>>>>> +Bundle-ManifestVersion: 2
>>>>> +Bundle-Name: HelloWorldJar
>>>>> +Bundle-SymbolicName: hello.world.jar
>>>>> +Bundle-Version: 1.1.0
>>>>> +Bundle-Vendor: Apache.org
>>>>> +Export-Package: apache.org.helloWorldJar
>>>>> +
>>>>> +
>>>>>
>>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
>>>>> ==============================================================================
>>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
>>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
>>>>> @@ -0,0 +1,3 @@
>>>>> +<web-app>
>>>>> +<display-name>Hello World</display-name>
>>>>> +</web-app>
>>>>> \ No newline at end of file
>>>>>
>>>>> Modified: incubator/aries/trunk/application/application-utils/pom.xml
>>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>>> ==============================================================================
>>>>> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
>>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
>>>>> @@ -67,7 +67,7 @@
>>>>>         <dependency>
>>>>>             <groupId>org.osgi</groupId>
>>>>>             <artifactId>org.osgi.core</artifactId>
>>>>> -            <version>4.0.0</version>
>>>>> +            <version>4.2.0</version>
>>>>>             <scope>provided</scope>
>>>>>         </dependency>
>>>>>         <dependency>
>>>>>
>>>>>
>>>>>
>>>
>

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Alasdair Nottingham <no...@apache.org>.
I think the code checks for a valid bundle manifest and if it isn't valid and there is a deployment manifest then it raises an error, otherwise it converts the bundle. Isn't this what we want, or have I missed something? 

Alasdair Nottingham

On 6 Jul 2010, at 20:36, Lin Sun <li...@gmail.com> wrote:

> Hi
> 
> Right, I'd think so, if a deployment.mf exists, then bundles are valid
> thus no conversion is needed.  However, the actual code seems to be
> different.
> 
> Lin
> 
> On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> wrote:
>> Hi,
>> 
>> It should means that if a deployment manifest exists the content must be valid bundles. It does not mean you need a deployment.mf.
>> 
>> Alasdair Nottingham
>> 
>> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>> 
>>> Hi
>>> 
>>> Quick question, does this mean if the aries application contains a
>>> deployment.mf, the createApplication will fail with
>>> ManagementException?
>>> 
>>> 
>>>> +            } else if (deploymentMetadata != null) {
>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>> +            }
>>> 
>>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>>> might have missed it) to a value other than null in this method.
>>> 
>>> Thx
>>> 
>>> Lin
>>> 
>>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>>> Author: mnuttall
>>>> Date: Tue Jul  6 10:51:12 2010
>>>> New Revision: 960866
>>>> 
>>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>>> Log:
>>>> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>>>> 
>>>> Added:
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>> Modified:
>>>>    incubator/aries/trunk/application/application-api/pom.xml
>>>>    incubator/aries/trunk/application/application-management/   (props changed)
>>>>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>>    incubator/aries/trunk/application/application-utils/pom.xml
>>>> 
>>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>> ==============================================================================
>>>> --- incubator/aries/trunk/application/application-api/pom.xml (original)
>>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
>>>> @@ -43,7 +43,7 @@
>>>>         <dependency>
>>>>             <groupId>org.osgi</groupId>
>>>>             <artifactId>org.osgi.core</artifactId>
>>>> -            <version>4.0.0</version>
>>>> +            <version>4.2.0</version>
>>>>             <scope>provided</scope>
>>>>         </dependency>
>>>>     </dependencies>
>>>> 
>>>> Propchange: incubator/aries/trunk/application/application-management/
>>>> ------------------------------------------------------------------------------
>>>> --- svn:ignore (original)
>>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>>> @@ -2,3 +2,5 @@ target
>>>>  .classpath
>>>>  .project
>>>>  .settings
>>>> +ariesApplicationManagerImplTest
>>>> +unittest
>>>> 
>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>>     AriesApplicationImpl application = null;
>>>> 
>>>>     try {
>>>> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
>>>> +
>>>> +        /* We require that all other .jar and .war files included by-value be valid bundles
>>>> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>> +         * wars to wabs, plain jars to bundles
>>>> +         */
>>>> +
>>>> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>> +        for (IFile f : ebaFile) {
>>>> +          if (f.isDirectory()) {
>>>> +            continue;
>>>> +          }
>>>> +
>>>> +          BundleManifest bm = getBundleManifest (f);
>>>> +          if (bm != null) {
>>>> +            if (bm.isValid()) {
>>>> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>> +            } else if (deploymentMetadata != null) {
>>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>> +            } else {
>>>> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>> +                 BundleConversion convertedBinary = null;
>>>> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>> +              List<ConversionException> conversionExceptions = Collections.emptyList();
>>>> +              while (converters.hasNext() && convertedBinary == null) {
>>>> +                try {
>>>> +                  convertedBinary = converters.next().convert(ebaFile, f);
>>>> +                } catch (ServiceException sx) {
>>>> +                  // We'll get this if our optional BundleConverter has not been injected.
>>>> +                } catch (ConversionException cx) {
>>>> +                  conversionExceptions.add(cx);
>>>> +                }
>>>> +              }
>>>> +              if (conversionExceptions.size() > 0) {
>>>> +                for (ConversionException cx : conversionExceptions) {
>>>> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>> +                }
>>>> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>> +              }
>>>> +              if (convertedBinary != null) {
>>>> +                modifiedBundles.put (f.getName(), convertedBinary);
>>>> +                bm = BundleManifest.fromBundle(f);
>>>> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>> +              }
>>>> +            }
>>>> +          }
>>>> +        }
>>>> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>>> +      String appName = ebaFile.getName();
>>>> +      //If the application name is null, we will try to get the file name.
>>>> +      if ((appName == null) || (appName.isEmpty())) {
>>>> +         String fullPath = ebaFile.toString();
>>>> +         if (fullPath.endsWith("/"))
>>>> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
>>>> +          int last_slash = fullPath.lastIndexOf("/");
>>>> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
>>>> +      }
>>>> +
>>>> +
>>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>>>>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>>> -
>>>>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>>       if (deploymentManifest != null) {
>>>>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>>         }
>>>>       }
>>>> 
>>>> -      /* We require that all other .jar and .war files included by-value be valid bundles
>>>> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>>> -       * wars to wabs, plain jars to bundles
>>>> -       */
>>>> -
>>>> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>>> -      for (IFile f : ebaFile) {
>>>> -        if (f.isDirectory()) {
>>>> -          continue;
>>>> -        }
>>>> -
>>>> -        BundleManifest bm = getBundleManifest (f);
>>>> -        if (bm != null) {
>>>> -          if (bm.isValid()) {
>>>> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>>> -          } else if (deploymentMetadata != null) {
>>>> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>>> -          } else {
>>>> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>>> -            BundleConversion convertedBinary = null;
>>>> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>>> -            List<ConversionException> conversionExceptions = Collections.emptyList();
>>>> -            while (converters.hasNext() && convertedBinary == null) {
>>>> -              try {
>>>> -                convertedBinary = converters.next().convert(ebaFile, f);
>>>> -              } catch (ServiceException sx) {
>>>> -                // We'll get this if our optional BundleConverter has not been injected.
>>>> -              } catch (ConversionException cx) {
>>>> -                conversionExceptions.add(cx);
>>>> -              }
>>>> -            }
>>>> -            if (conversionExceptions.size() > 0) {
>>>> -              for (ConversionException cx : conversionExceptions) {
>>>> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>>> -              }
>>>> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>>> -            }
>>>> -            if (convertedBinary != null) {
>>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>>> -              bm = BundleManifest.fromBundle(f);
>>>> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>>> -            }
>>>> -          }
>>>> -        }
>>>> -      }
>>>> +
>>>> 
>>>>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>>>>       application.setDeploymentMetadata(deploymentMetadata);
>>>> 
>>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>>  import static org.junit.Assert.assertTrue;
>>>> 
>>>>  import java.io.File;
>>>> +import java.io.FileInputStream;
>>>>  import java.io.IOException;
>>>> +import java.io.InputStream;
>>>>  import java.lang.reflect.Field;
>>>>  import java.util.ArrayList;
>>>>  import java.util.HashSet;
>>>>  import java.util.List;
>>>>  import java.util.Set;
>>>> +import java.util.jar.Manifest;
>>>> 
>>>>  import org.apache.aries.application.ApplicationMetadata;
>>>>  import org.apache.aries.application.ApplicationMetadataFactory;
>>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>>  import org.apache.aries.application.management.AriesApplication;
>>>>  import org.apache.aries.application.management.AriesApplicationResolver;
>>>> +import org.apache.aries.application.management.BundleConversion;
>>>>  import org.apache.aries.application.management.BundleConverter;
>>>>  import org.apache.aries.application.management.BundleInfo;
>>>> +import org.apache.aries.application.management.ConversionException;
>>>>  import org.apache.aries.application.management.LocalPlatform;
>>>>  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.management.impl.AriesApplicationManagerImpl;
>>>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>>>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
>>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>>       return File.createTempFile("ebaTmp", null);
>>>>     }
>>>>   }
>>>> +
>>>> +  static class DummyConverter implements BundleConverter {
>>>> 
>>>> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
>>>> +                       throws ConversionException {
>>>> +               if (toBeConverted.getName().equals("helloWorld.war")) {
>>>> +                       InputStream is = null;
>>>> +            try {
>>>> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
>>>> +               Manifest warManifest = new Manifest(is);
>>>> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
>>>> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>>> +
>>>> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>>> +                final String location = toBeConverted.toString();
>>>> +               return new BundleConversion() {
>>>> +
>>>> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>>> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>>> +                                       }
>>>> +
>>>> +                                       public InputStream getInputStream() throws IOException {
>>>> +                                               return jarIs;
>>>> +                                       }
>>>> +
>>>> +                };
>>>> +            } catch (IOException e) {
>>>> +               e.printStackTrace();
>>>> +            } finally {
>>>> +               try {
>>>> +               if (is != null)
>>>> +                       is.close();
>>>> +               } catch (Exception e) {
>>>> +                       e.printStackTrace();
>>>> +               }
>>>> +            }
>>>> +        }
>>>> +
>>>> +        return null;
>>>> +    }
>>>> +
>>>> +
>>>> +  }
>>>> 
>>>> +
>>>> +
>>>> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>>> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>>>>   @BeforeClass
>>>>   public static void preTest() throws Exception {
>>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>>> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>>     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);
>>>> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>>>>   }
>>>> 
>>>>   AriesApplicationManagerImpl _appMgr;
>>>>   ApplicationMetadataFactory _appMetaFactory;
>>>>   DummyResolver _resolver;
>>>> -
>>>> +  DummyConverter _converter;
>>>>   @Before
>>>>   public void setup() {
>>>>     _appMgr = new AriesApplicationManagerImpl ();
>>>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>> 
>>>>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
>>>> +    _converter = new DummyConverter();
>>>>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
>>>> -    _resolver = new DummyResolver();
>>>> -
>>>> +    bundleConverters.add(_converter);
>>>> +    _resolver = new DummyResolver();
>>>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>>>     _appMgr.setBundleConverters(bundleConverters);
>>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>>   }
>>>> 
>>>>   @Test
>>>> +  public void testCreateAndConversion() throws Exception {
>>>> +               AriesApplication app = createApplication (CONVERSION_EBA);
>>>> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
>>>> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
>>>> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
>>>> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
>>>> +           List<Content> appContent = appMeta.getApplicationContents();
>>>> +           assertEquals (appContent.size(), 2);
>>>> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>>> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>>> +           assertTrue (appContent.contains(fbw));
>>>> +           assertTrue (appContent.contains(mbl));
>>>> +
>>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>>> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
>>>> +
>>>> +           assertEquals (2, dcList.size());
>>>> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
>>>> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
>>>> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
>>>> +           assertTrue (dcList.contains(dc1));
>>>> +           assertTrue (dcList.contains(dc2));
>>>> +
>>>> +           dcList = dm.getApplicationProvisionBundles();
>>>> +
>>>> +           assertEquals(1, dcList.size());
>>>> +           assertTrue (dcList.contains(dc3));
>>>> +  }
>>>> +
>>>> +  @Test
>>>>   public void testStoreAndReload() throws Exception {
>>>>     AriesApplication app = createApplication (TEST_EBA);
>>>>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
>>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>>>     _resolver.setNextResult(nextResolverResult);
>>>> 
>>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>>     AriesApplication app = _appMgr.createApplication(testEba);
>>>>     app = _appMgr.resolve(app);
>>>>     return app;
>>>> 
>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
>>>> ==============================================================================
>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>> @@ -0,0 +1,11 @@
>>>> +Manifest-Version: 1.0
>>>> +Bundle-ManifestVersion: 2
>>>> +Bundle-Name: helloWorld.war
>>>> +Bundle-SymbolicName: helloWorld.war
>>>> +Bundle-Version: 0.0.0
>>>> +Bundle-Vendor: Apache.org
>>>> +Bundle-ContextPath: /test
>>>> +Export-Package: apache.org.helloWorldWar
>>>> +
>>>> +
>>>> +
>>>> 
>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
>>>> ==============================================================================
>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>>> @@ -0,0 +1,9 @@
>>>> +Manifest-Version: 1.0
>>>> +Bundle-ManifestVersion: 2
>>>> +Bundle-Name: HelloWorldJar
>>>> +Bundle-SymbolicName: hello.world.jar
>>>> +Bundle-Version: 1.1.0
>>>> +Bundle-Vendor: Apache.org
>>>> +Export-Package: apache.org.helloWorldJar
>>>> +
>>>> +
>>>> 
>>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
>>>> ==============================================================================
>>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
>>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
>>>> @@ -0,0 +1,3 @@
>>>> +<web-app>
>>>> +<display-name>Hello World</display-name>
>>>> +</web-app>
>>>> \ No newline at end of file
>>>> 
>>>> Modified: incubator/aries/trunk/application/application-utils/pom.xml
>>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>>> ==============================================================================
>>>> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
>>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
>>>> @@ -67,7 +67,7 @@
>>>>         <dependency>
>>>>             <groupId>org.osgi</groupId>
>>>>             <artifactId>org.osgi.core</artifactId>
>>>> -            <version>4.0.0</version>
>>>> +            <version>4.2.0</version>
>>>>             <scope>provided</scope>
>>>>         </dependency>
>>>>         <dependency>
>>>> 
>>>> 
>>>> 
>> 

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Lin Sun <li...@gmail.com>.
Hi

Right, I'd think so, if a deployment.mf exists, then bundles are valid
thus no conversion is needed.  However, the actual code seems to be
different.

Lin

On Tue, Jul 6, 2010 at 3:05 PM, Alasdair Nottingham <no...@apache.org> wrote:
> Hi,
>
> It should means that if a deployment manifest exists the content must be valid bundles. It does not mean you need a deployment.mf.
>
> Alasdair Nottingham
>
> On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:
>
>> Hi
>>
>> Quick question, does this mean if the aries application contains a
>> deployment.mf, the createApplication will fail with
>> ManagementException?
>>
>>
>>> +            } else if (deploymentMetadata != null) {
>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>> +            }
>>
>> Also,  I don't see anywhere we set the deploymentMetadata (which I
>> might have missed it) to a value other than null in this method.
>>
>> Thx
>>
>> Lin
>>
>> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>>> Author: mnuttall
>>> Date: Tue Jul  6 10:51:12 2010
>>> New Revision: 960866
>>>
>>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>>> Log:
>>> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>>>
>>> Added:
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>> Modified:
>>>    incubator/aries/trunk/application/application-api/pom.xml
>>>    incubator/aries/trunk/application/application-management/   (props changed)
>>>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>>    incubator/aries/trunk/application/application-utils/pom.xml
>>>
>>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/application/application-api/pom.xml (original)
>>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
>>> @@ -43,7 +43,7 @@
>>>         <dependency>
>>>             <groupId>org.osgi</groupId>
>>>             <artifactId>org.osgi.core</artifactId>
>>> -            <version>4.0.0</version>
>>> +            <version>4.2.0</version>
>>>             <scope>provided</scope>
>>>         </dependency>
>>>     </dependencies>
>>>
>>> Propchange: incubator/aries/trunk/application/application-management/
>>> ------------------------------------------------------------------------------
>>> --- svn:ignore (original)
>>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>>> @@ -2,3 +2,5 @@ target
>>>  .classpath
>>>  .project
>>>  .settings
>>> +ariesApplicationManagerImplTest
>>> +unittest
>>>
>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>>     AriesApplicationImpl application = null;
>>>
>>>     try {
>>> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
>>> +
>>> +        /* We require that all other .jar and .war files included by-value be valid bundles
>>> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>> +         * wars to wabs, plain jars to bundles
>>> +         */
>>> +
>>> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>> +        for (IFile f : ebaFile) {
>>> +          if (f.isDirectory()) {
>>> +            continue;
>>> +          }
>>> +
>>> +          BundleManifest bm = getBundleManifest (f);
>>> +          if (bm != null) {
>>> +            if (bm.isValid()) {
>>> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>> +            } else if (deploymentMetadata != null) {
>>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>> +            } else {
>>> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>> +                 BundleConversion convertedBinary = null;
>>> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>> +              List<ConversionException> conversionExceptions = Collections.emptyList();
>>> +              while (converters.hasNext() && convertedBinary == null) {
>>> +                try {
>>> +                  convertedBinary = converters.next().convert(ebaFile, f);
>>> +                } catch (ServiceException sx) {
>>> +                  // We'll get this if our optional BundleConverter has not been injected.
>>> +                } catch (ConversionException cx) {
>>> +                  conversionExceptions.add(cx);
>>> +                }
>>> +              }
>>> +              if (conversionExceptions.size() > 0) {
>>> +                for (ConversionException cx : conversionExceptions) {
>>> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>> +                }
>>> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>> +              }
>>> +              if (convertedBinary != null) {
>>> +                modifiedBundles.put (f.getName(), convertedBinary);
>>> +                bm = BundleManifest.fromBundle(f);
>>> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>> +              }
>>> +            }
>>> +          }
>>> +        }
>>> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>>> +      String appName = ebaFile.getName();
>>> +      //If the application name is null, we will try to get the file name.
>>> +      if ((appName == null) || (appName.isEmpty())) {
>>> +         String fullPath = ebaFile.toString();
>>> +         if (fullPath.endsWith("/"))
>>> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
>>> +          int last_slash = fullPath.lastIndexOf("/");
>>> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
>>> +      }
>>> +
>>> +
>>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>>>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>>> -
>>>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>>       if (deploymentManifest != null) {
>>>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>>         }
>>>       }
>>>
>>> -      /* We require that all other .jar and .war files included by-value be valid bundles
>>> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>>> -       * wars to wabs, plain jars to bundles
>>> -       */
>>> -
>>> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>>> -      for (IFile f : ebaFile) {
>>> -        if (f.isDirectory()) {
>>> -          continue;
>>> -        }
>>> -
>>> -        BundleManifest bm = getBundleManifest (f);
>>> -        if (bm != null) {
>>> -          if (bm.isValid()) {
>>> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>>> -          } else if (deploymentMetadata != null) {
>>> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>>> -          } else {
>>> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>>> -            BundleConversion convertedBinary = null;
>>> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
>>> -            List<ConversionException> conversionExceptions = Collections.emptyList();
>>> -            while (converters.hasNext() && convertedBinary == null) {
>>> -              try {
>>> -                convertedBinary = converters.next().convert(ebaFile, f);
>>> -              } catch (ServiceException sx) {
>>> -                // We'll get this if our optional BundleConverter has not been injected.
>>> -              } catch (ConversionException cx) {
>>> -                conversionExceptions.add(cx);
>>> -              }
>>> -            }
>>> -            if (conversionExceptions.size() > 0) {
>>> -              for (ConversionException cx : conversionExceptions) {
>>> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>>> -              }
>>> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>>> -            }
>>> -            if (convertedBinary != null) {
>>> -              modifiedBundles.put (f.getName(), convertedBinary);
>>> -              bm = BundleManifest.fromBundle(f);
>>> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>>> -            }
>>> -          }
>>> -        }
>>> -      }
>>> +
>>>
>>>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>>>       application.setDeploymentMetadata(deploymentMetadata);
>>>
>>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>>  import static org.junit.Assert.assertTrue;
>>>
>>>  import java.io.File;
>>> +import java.io.FileInputStream;
>>>  import java.io.IOException;
>>> +import java.io.InputStream;
>>>  import java.lang.reflect.Field;
>>>  import java.util.ArrayList;
>>>  import java.util.HashSet;
>>>  import java.util.List;
>>>  import java.util.Set;
>>> +import java.util.jar.Manifest;
>>>
>>>  import org.apache.aries.application.ApplicationMetadata;
>>>  import org.apache.aries.application.ApplicationMetadataFactory;
>>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>>  import org.apache.aries.application.management.AriesApplication;
>>>  import org.apache.aries.application.management.AriesApplicationResolver;
>>> +import org.apache.aries.application.management.BundleConversion;
>>>  import org.apache.aries.application.management.BundleConverter;
>>>  import org.apache.aries.application.management.BundleInfo;
>>> +import org.apache.aries.application.management.ConversionException;
>>>  import org.apache.aries.application.management.LocalPlatform;
>>>  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.management.impl.AriesApplicationManagerImpl;
>>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
>>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>>       return File.createTempFile("ebaTmp", null);
>>>     }
>>>   }
>>> +
>>> +  static class DummyConverter implements BundleConverter {
>>>
>>> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
>>> +                       throws ConversionException {
>>> +               if (toBeConverted.getName().equals("helloWorld.war")) {
>>> +                       InputStream is = null;
>>> +            try {
>>> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
>>> +               Manifest warManifest = new Manifest(is);
>>> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
>>> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>>> +
>>> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
>>> +                final String location = toBeConverted.toString();
>>> +               return new BundleConversion() {
>>> +
>>> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>>> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>>> +                                       }
>>> +
>>> +                                       public InputStream getInputStream() throws IOException {
>>> +                                               return jarIs;
>>> +                                       }
>>> +
>>> +                };
>>> +            } catch (IOException e) {
>>> +               e.printStackTrace();
>>> +            } finally {
>>> +               try {
>>> +               if (is != null)
>>> +                       is.close();
>>> +               } catch (Exception e) {
>>> +                       e.printStackTrace();
>>> +               }
>>> +            }
>>> +        }
>>> +
>>> +        return null;
>>> +    }
>>> +
>>> +
>>> +  }
>>>
>>> +
>>> +
>>> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>>> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>>>   @BeforeClass
>>>   public static void preTest() throws Exception {
>>> -    new File("ariesApplicationManagerImplTest").mkdir();
>>> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>>     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);
>>> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>>>   }
>>>
>>>   AriesApplicationManagerImpl _appMgr;
>>>   ApplicationMetadataFactory _appMetaFactory;
>>>   DummyResolver _resolver;
>>> -
>>> +  DummyConverter _converter;
>>>   @Before
>>>   public void setup() {
>>>     _appMgr = new AriesApplicationManagerImpl ();
>>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>>>
>>>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
>>> +    _converter = new DummyConverter();
>>>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
>>> -    _resolver = new DummyResolver();
>>> -
>>> +    bundleConverters.add(_converter);
>>> +    _resolver = new DummyResolver();
>>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>>     _appMgr.setBundleConverters(bundleConverters);
>>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>>   }
>>>
>>>   @Test
>>> +  public void testCreateAndConversion() throws Exception {
>>> +               AriesApplication app = createApplication (CONVERSION_EBA);
>>> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
>>> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
>>> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
>>> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
>>> +           List<Content> appContent = appMeta.getApplicationContents();
>>> +           assertEquals (appContent.size(), 2);
>>> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>>> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>>> +           assertTrue (appContent.contains(fbw));
>>> +           assertTrue (appContent.contains(mbl));
>>> +
>>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>>> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
>>> +
>>> +           assertEquals (2, dcList.size());
>>> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
>>> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
>>> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
>>> +           assertTrue (dcList.contains(dc1));
>>> +           assertTrue (dcList.contains(dc2));
>>> +
>>> +           dcList = dm.getApplicationProvisionBundles();
>>> +
>>> +           assertEquals(1, dcList.size());
>>> +           assertTrue (dcList.contains(dc3));
>>> +  }
>>> +
>>> +  @Test
>>>   public void testStoreAndReload() throws Exception {
>>>     AriesApplication app = createApplication (TEST_EBA);
>>>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
>>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>>     _resolver.setNextResult(nextResolverResult);
>>>
>>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>>     AriesApplication app = _appMgr.createApplication(testEba);
>>>     app = _appMgr.resolve(app);
>>>     return app;
>>>
>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
>>> ==============================================================================
>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>> @@ -0,0 +1,11 @@
>>> +Manifest-Version: 1.0
>>> +Bundle-ManifestVersion: 2
>>> +Bundle-Name: helloWorld.war
>>> +Bundle-SymbolicName: helloWorld.war
>>> +Bundle-Version: 0.0.0
>>> +Bundle-Vendor: Apache.org
>>> +Bundle-ContextPath: /test
>>> +Export-Package: apache.org.helloWorldWar
>>> +
>>> +
>>> +
>>>
>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
>>> ==============================================================================
>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
>>> @@ -0,0 +1,9 @@
>>> +Manifest-Version: 1.0
>>> +Bundle-ManifestVersion: 2
>>> +Bundle-Name: HelloWorldJar
>>> +Bundle-SymbolicName: hello.world.jar
>>> +Bundle-Version: 1.1.0
>>> +Bundle-Vendor: Apache.org
>>> +Export-Package: apache.org.helloWorldJar
>>> +
>>> +
>>>
>>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
>>> ==============================================================================
>>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
>>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
>>> @@ -0,0 +1,3 @@
>>> +<web-app>
>>> +<display-name>Hello World</display-name>
>>> +</web-app>
>>> \ No newline at end of file
>>>
>>> Modified: incubator/aries/trunk/application/application-utils/pom.xml
>>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>>> ==============================================================================
>>> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
>>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
>>> @@ -67,7 +67,7 @@
>>>         <dependency>
>>>             <groupId>org.osgi</groupId>
>>>             <artifactId>org.osgi.core</artifactId>
>>> -            <version>4.0.0</version>
>>> +            <version>4.2.0</version>
>>>             <scope>provided</scope>
>>>         </dependency>
>>>         <dependency>
>>>
>>>
>>>
>

Re: svn commit: r960866 - in /incubator/aries/trunk/application: application-api/ application-management/ application-management/src/main/java/org/apache/aries/application/management/impl/ application-management/src/test/java/org/apache/aries/applica

Posted by Alasdair Nottingham <no...@apache.org>.
Hi,

It should means that if a deployment manifest exists the content must be valid bundles. It does not mean you need a deployment.mf.

Alasdair Nottingham

On 6 Jul 2010, at 19:46, Lin Sun <li...@gmail.com> wrote:

> Hi
> 
> Quick question, does this mean if the aries application contains a
> deployment.mf, the createApplication will fail with
> ManagementException?
> 
> 
>> +            } else if (deploymentMetadata != null) {
>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>> +            }
> 
> Also,  I don't see anywhere we set the deploymentMetadata (which I
> might have missed it) to a value other than null in this method.
> 
> Thx
> 
> Lin
> 
> On Tue, Jul 6, 2010 at 6:51 AM,  <mn...@apache.org> wrote:
>> Author: mnuttall
>> Date: Tue Jul  6 10:51:12 2010
>> New Revision: 960866
>> 
>> URL: http://svn.apache.org/viewvc?rev=960866&view=rev
>> Log:
>> ARIES-192: Convert bundles before generating the application content. From a patch submitted by Emily Jiang.
>> 
>> Added:
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/
>>    incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>> Modified:
>>    incubator/aries/trunk/application/application-api/pom.xml
>>    incubator/aries/trunk/application/application-management/   (props changed)
>>    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
>>    incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
>>    incubator/aries/trunk/application/application-utils/pom.xml
>> 
>> Modified: incubator/aries/trunk/application/application-api/pom.xml
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-api/pom.xml (original)
>> +++ incubator/aries/trunk/application/application-api/pom.xml Tue Jul  6 10:51:12 2010
>> @@ -43,7 +43,7 @@
>>         <dependency>
>>             <groupId>org.osgi</groupId>
>>             <artifactId>org.osgi.core</artifactId>
>> -            <version>4.0.0</version>
>> +            <version>4.2.0</version>
>>             <scope>provided</scope>
>>         </dependency>
>>     </dependencies>
>> 
>> Propchange: incubator/aries/trunk/application/application-management/
>> ------------------------------------------------------------------------------
>> --- svn:ignore (original)
>> +++ svn:ignore Tue Jul  6 10:51:12 2010
>> @@ -2,3 +2,5 @@ target
>>  .classpath
>>  .project
>>  .settings
>> +ariesApplicationManagerImplTest
>> +unittest
>> 
>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>> @@ -114,10 +114,66 @@ public class AriesApplicationManagerImpl
>>     AriesApplicationImpl application = null;
>> 
>>     try {
>> -      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>> -      ManifestDefaultsInjector.updateManifest(applicationManifest, ebaFile.getName(), ebaFile);
>> +
>> +        /* We require that all other .jar and .war files included by-value be valid bundles
>> +         * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>> +         * wars to wabs, plain jars to bundles
>> +         */
>> +
>> +        Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>> +        for (IFile f : ebaFile) {
>> +          if (f.isDirectory()) {
>> +            continue;
>> +          }
>> +
>> +          BundleManifest bm = getBundleManifest (f);
>> +          if (bm != null) {
>> +            if (bm.isValid()) {
>> +              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>> +            } else if (deploymentMetadata != null) {
>> +              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>> +            } else {
>> +              // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>> +                 BundleConversion convertedBinary = null;
>> +              Iterator<BundleConverter> converters = _bundleConverters.iterator();
>> +              List<ConversionException> conversionExceptions = Collections.emptyList();
>> +              while (converters.hasNext() && convertedBinary == null) {
>> +                try {
>> +                  convertedBinary = converters.next().convert(ebaFile, f);
>> +                } catch (ServiceException sx) {
>> +                  // We'll get this if our optional BundleConverter has not been injected.
>> +                } catch (ConversionException cx) {
>> +                  conversionExceptions.add(cx);
>> +                }
>> +              }
>> +              if (conversionExceptions.size() > 0) {
>> +                for (ConversionException cx : conversionExceptions) {
>> +                  _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>> +                }
>> +                throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>> +              }
>> +              if (convertedBinary != null) {
>> +                modifiedBundles.put (f.getName(), convertedBinary);
>> +                bm = BundleManifest.fromBundle(f);
>> +                extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>> +              }
>> +            }
>> +          }
>> +        }
>> +      Manifest applicationManifest = parseApplicationManifest (ebaFile);
>> +      String appName = ebaFile.getName();
>> +      //If the application name is null, we will try to get the file name.
>> +      if ((appName == null) || (appName.isEmpty())) {
>> +         String fullPath = ebaFile.toString();
>> +         if (fullPath.endsWith("/"))
>> +                 fullPath = fullPath.substring(0, fullPath.length() -1);
>> +          int last_slash = fullPath.lastIndexOf("/");
>> +          appName = fullPath.substring(last_slash + 1, fullPath.length());
>> +      }
>> +
>> +
>> +      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
>>       applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
>> -
>>       IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
>>       if (deploymentManifest != null) {
>>         deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
>> @@ -130,51 +186,7 @@ public class AriesApplicationManagerImpl
>>         }
>>       }
>> 
>> -      /* We require that all other .jar and .war files included by-value be valid bundles
>> -       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
>> -       * wars to wabs, plain jars to bundles
>> -       */
>> -
>> -      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
>> -      for (IFile f : ebaFile) {
>> -        if (f.isDirectory()) {
>> -          continue;
>> -        }
>> -
>> -        BundleManifest bm = getBundleManifest (f);
>> -        if (bm != null) {
>> -          if (bm.isValid()) {
>> -            extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.toURL().toExternalForm()));
>> -          } else if (deploymentMetadata != null) {
>> -            throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0003E", f.getName(), ebaFile.getName()));
>> -          } else {
>> -            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
>> -            BundleConversion convertedBinary = null;
>> -            Iterator<BundleConverter> converters = _bundleConverters.iterator();
>> -            List<ConversionException> conversionExceptions = Collections.emptyList();
>> -            while (converters.hasNext() && convertedBinary == null) {
>> -              try {
>> -                convertedBinary = converters.next().convert(ebaFile, f);
>> -              } catch (ServiceException sx) {
>> -                // We'll get this if our optional BundleConverter has not been injected.
>> -              } catch (ConversionException cx) {
>> -                conversionExceptions.add(cx);
>> -              }
>> -            }
>> -            if (conversionExceptions.size() > 0) {
>> -              for (ConversionException cx : conversionExceptions) {
>> -                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), ebaFile.getName(), cx});
>> -              }
>> -              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", ebaFile.getName()));
>> -            }
>> -            if (convertedBinary != null) {
>> -              modifiedBundles.put (f.getName(), convertedBinary);
>> -              bm = BundleManifest.fromBundle(f);
>> -              extraBundlesInfo.add(new SimpleBundleInfo(_applicationMetadataFactory, bm, f.getName()));
>> -            }
>> -          }
>> -        }
>> -      }
>> +
>> 
>>       application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
>>       application.setDeploymentMetadata(deploymentMetadata);
>> 
>> 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=960866&r1=960865&r2=960866&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 Tue Jul  6 10:51:12 2010
>> @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNot
>>  import static org.junit.Assert.assertTrue;
>> 
>>  import java.io.File;
>> +import java.io.FileInputStream;
>>  import java.io.IOException;
>> +import java.io.InputStream;
>>  import java.lang.reflect.Field;
>>  import java.util.ArrayList;
>>  import java.util.HashSet;
>>  import java.util.List;
>>  import java.util.Set;
>> +import java.util.jar.Manifest;
>> 
>>  import org.apache.aries.application.ApplicationMetadata;
>>  import org.apache.aries.application.ApplicationMetadataFactory;
>> @@ -45,13 +48,14 @@ import org.apache.aries.application.impl
>>  import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
>>  import org.apache.aries.application.management.AriesApplication;
>>  import org.apache.aries.application.management.AriesApplicationResolver;
>> +import org.apache.aries.application.management.BundleConversion;
>>  import org.apache.aries.application.management.BundleConverter;
>>  import org.apache.aries.application.management.BundleInfo;
>> +import org.apache.aries.application.management.ConversionException;
>>  import org.apache.aries.application.management.LocalPlatform;
>>  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.management.impl.AriesApplicationManagerImpl;
>>  import org.apache.aries.application.utils.filesystem.FileSystem;
>>  import org.apache.aries.application.utils.filesystem.IOUtils;
>>  import org.apache.aries.application.utils.management.SimpleBundleInfo;
>> @@ -98,31 +102,79 @@ public class AriesApplicationManagerImpl
>>       return File.createTempFile("ebaTmp", null);
>>     }
>>   }
>> +
>> +  static class DummyConverter implements BundleConverter {
>> 
>> -  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>> +       public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
>> +                       throws ConversionException {
>> +               if (toBeConverted.getName().equals("helloWorld.war")) {
>> +                       InputStream is = null;
>> +            try {
>> +               is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
>> +               Manifest warManifest = new Manifest(is);
>> +               IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war"), warManifest);
>> +               IOUtils.zipUp(new  File("../src/test/resources/conversion/conversion.eba/helloWorld.jar"), new File("./ariesApplicationManagerImplTest/conversion/helloWorld.jar"));
>> +
>> +               IOUtils.zipUp(new File("./ariesApplicationManagerImplTest/conversion"), new File("./ariesApplicationManagerImplTest/conversion.eba"));
>> +               final InputStream jarIs = new FileInputStream(new File("./ariesApplicationManagerImplTest/conversion.eba"));
>> +                final String location = toBeConverted.toString();
>> +               return new BundleConversion() {
>> +
>> +                                       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
>> +                                               return new SimpleBundleInfo(amf, BundleManifest.fromBundle(jarIs), location);
>> +                                       }
>> +
>> +                                       public InputStream getInputStream() throws IOException {
>> +                                               return jarIs;
>> +                                       }
>> +
>> +                };
>> +            } catch (IOException e) {
>> +               e.printStackTrace();
>> +            } finally {
>> +               try {
>> +               if (is != null)
>> +                       is.close();
>> +               } catch (Exception e) {
>> +                       e.printStackTrace();
>> +               }
>> +            }
>> +        }
>> +
>> +        return null;
>> +    }
>> +
>> +
>> +  }
>> 
>> +
>> +
>> +  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
>> +  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
>>   @BeforeClass
>>   public static void preTest() throws Exception {
>> -    new File("ariesApplicationManagerImplTest").mkdir();
>> +    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
>>     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);
>> +    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
>>   }
>> 
>>   AriesApplicationManagerImpl _appMgr;
>>   ApplicationMetadataFactory _appMetaFactory;
>>   DummyResolver _resolver;
>> -
>> +  DummyConverter _converter;
>>   @Before
>>   public void setup() {
>>     _appMgr = new AriesApplicationManagerImpl ();
>>     _appMetaFactory = new ApplicationMetadataFactoryImpl ();
>> 
>>     DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
>> +    _converter = new DummyConverter();
>>     List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
>> -    _resolver = new DummyResolver();
>> -
>> +    bundleConverters.add(_converter);
>> +    _resolver = new DummyResolver();
>>     _appMgr.setApplicationMetadataFactory(_appMetaFactory);
>>     _appMgr.setDeploymentMetadataFactory(dmf);
>>     _appMgr.setBundleConverters(bundleConverters);
>> @@ -163,6 +215,36 @@ public class AriesApplicationManagerImpl
>>   }
>> 
>>   @Test
>> +  public void testCreateAndConversion() throws Exception {
>> +               AriesApplication app = createApplication (CONVERSION_EBA);
>> +           ApplicationMetadata appMeta = app.getApplicationMetadata();
>> +           assertEquals (appMeta.getApplicationName(), "conversion.eba");
>> +           assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");
>> +           assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));
>> +           List<Content> appContent = appMeta.getApplicationContents();
>> +           assertEquals (appContent.size(), 2);
>> +           Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
>> +           Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
>> +           assertTrue (appContent.contains(fbw));
>> +           assertTrue (appContent.contains(mbl));
>> +
>> +           DeploymentMetadata dm = app.getDeploymentMetadata();
>> +           List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
>> +
>> +           assertEquals (2, dcList.size());
>> +           DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
>> +           DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
>> +           DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
>> +           assertTrue (dcList.contains(dc1));
>> +           assertTrue (dcList.contains(dc2));
>> +
>> +           dcList = dm.getApplicationProvisionBundles();
>> +
>> +           assertEquals(1, dcList.size());
>> +           assertTrue (dcList.contains(dc3));
>> +  }
>> +
>> +  @Test
>>   public void testStoreAndReload() throws Exception {
>>     AriesApplication app = createApplication (TEST_EBA);
>>     File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
>> @@ -211,7 +293,7 @@ public class AriesApplicationManagerImpl
>>     nextResolverResult.add(resolvedPersistenceLibrary);
>>     _resolver.setNextResult(nextResolverResult);
>> 
>> -    IDirectory testEba = FileSystem.getFSRoot(new File(TEST_EBA));
>> +    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
>>     AriesApplication app = _appMgr.createApplication(testEba);
>>     app = _appMgr.resolve(app);
>>     return app;
>> 
>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF?rev=960866&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF (added)
>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/MANIFEST.MF Tue Jul  6 10:51:12 2010
>> @@ -0,0 +1,11 @@
>> +Manifest-Version: 1.0
>> +Bundle-ManifestVersion: 2
>> +Bundle-Name: helloWorld.war
>> +Bundle-SymbolicName: helloWorld.war
>> +Bundle-Version: 0.0.0
>> +Bundle-Vendor: Apache.org
>> +Bundle-ContextPath: /test
>> +Export-Package: apache.org.helloWorldWar
>> +
>> +
>> +
>> 
>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=960866&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Tue Jul  6 10:51:12 2010
>> @@ -0,0 +1,9 @@
>> +Manifest-Version: 1.0
>> +Bundle-ManifestVersion: 2
>> +Bundle-Name: HelloWorldJar
>> +Bundle-SymbolicName: hello.world.jar
>> +Bundle-Version: 1.1.0
>> +Bundle-Vendor: Apache.org
>> +Export-Package: apache.org.helloWorldJar
>> +
>> +
>> 
>> Added: incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=960866&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
>> +++ incubator/aries/trunk/application/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Tue Jul  6 10:51:12 2010
>> @@ -0,0 +1,3 @@
>> +<web-app>
>> +<display-name>Hello World</display-name>
>> +</web-app>
>> \ No newline at end of file
>> 
>> Modified: incubator/aries/trunk/application/application-utils/pom.xml
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=960866&r1=960865&r2=960866&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/pom.xml (original)
>> +++ incubator/aries/trunk/application/application-utils/pom.xml Tue Jul  6 10:51:12 2010
>> @@ -67,7 +67,7 @@
>>         <dependency>
>>             <groupId>org.osgi</groupId>
>>             <artifactId>org.osgi.core</artifactId>
>> -            <version>4.0.0</version>
>> +            <version>4.2.0</version>
>>             <scope>provided</scope>
>>         </dependency>
>>         <dependency>
>> 
>> 
>>