aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lin Sun <linsun....@gmail.com>
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
Date Tue, 06 Jul 2010 18:46:47 GMT
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,  <mnuttall@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>
>
>
>

Mime
View raw message