Package org.apache.aries.application

Examples of org.apache.aries.application.ApplicationMetadata


  }
 
  @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 (2, appContent.size());
      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));
View Full Code Here


 
  /**
   * Create an AriesApplication from a .eba file: a zip file with a '.eba' extension
   */
  public AriesApplication createApplication(IDirectory ebaFile) throws ManagementException {
    ApplicationMetadata applicationMetadata = null;
    DeploymentMetadata deploymentMetadata = null;
    Map<String, BundleConversion> modifiedBundles = new HashMap<String, BundleConversion>();
    AriesApplicationImpl application = null;
    String appPath = ebaFile.toString();
    try {  
      // try to read the app name out of the application.mf
      Manifest applicationManifest = parseApplicationManifest (ebaFile);
      String appName = applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_NAME);

      //If the application name is null, we will try to get the file name.
      if (appName == null || appName.isEmpty()) {
          String fullPath = appPath;
          if (fullPath.endsWith("/")) {
            fullPath = fullPath.substring(0, fullPath.length() -1)
          }
             
          int last_slash = fullPath.lastIndexOf("/");
          appName = fullPath.substring(last_slash + 1, fullPath.length());
      }
                 
      IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
      /* 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(bm, f.toURL().toExternalForm()));
          } else if (deploymentManifest == null) {
            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
            // We only do this if a DEPLOYMENT.MF does not exist.
            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(), appName, cx});
              }
              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", appName));
            }
            if (convertedBinary != null) {
              modifiedBundles.put (f.getName(), convertedBinary);            
              extraBundlesInfo.add(convertedBinary.getBundleInfo());
            }
          }
        }
      }
      // if Application-Content header was not specified build it based on the bundles included by value
      if (applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_CONTENT) == null) {
          String appContent = buildAppContent(extraBundlesInfo);
          applicationManifest.getMainAttributes().putValue(AppConstants.APPLICATION_CONTENT, appContent);
      }
     
      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
      applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
     
      if (deploymentManifest != null) {
        deploymentMetadata = _deploymentMetadataFactory.parseDeploymentMetadata(deploymentManifest);
       
        // Validate: symbolic names must match
        String appSymbolicName = applicationMetadata.getApplicationSymbolicName();
        String depSymbolicName = deploymentMetadata.getApplicationSymbolicName();
        if (!appSymbolicName.equals(depSymbolicName)) {
          throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0002E", appName, appSymbolicName, depSymbolicName));
        }
      }
View Full Code Here

  {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
   
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION3.MF");
   
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);

    assertEquals("Wrong number of bundles are in the application", 1, am.getApplicationContents().size());
    assertEquals("Wrong bundle name", "org.apache.aries.applications.test.bundle", am.getApplicationContents().get(0).getContentName());
  }
View Full Code Here

 
  @Test
  public void testCreate() throws Exception {
    AriesApplication app = createApplication (TEST_EBA);
   
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals (appMeta.getApplicationName(), "Test application");
    assertEquals (appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
    assertEquals (appMeta.getApplicationVersion(), new Version("1.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals (appContent.size(), 2);
    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
    assertTrue (appContent.contains(fbw));
    assertTrue (appContent.contains(mbl));
View Full Code Here

  }
 
  @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 (2, appContent.size());
      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));
View Full Code Here

{
  @Test
  public void testBasicMetadataCreation() throws IOException
  {
    ApplicationMetadataFactory manager = new ApplicationMetadataFactoryImpl();
    ApplicationMetadata app = manager.parseApplicationMetadata(getClass().getResourceAsStream("/META-INF/APPLICATION.MF"));
   
    Assert.assertEquals("Travel Reservation", app.getApplicationName());
  }
View Full Code Here

  @Test
  public void testManifestMetadata() throws Exception
  {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);

    assertEquals(am.getApplicationName(),appName);

    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents){
      if ("com.travel.reservation.web".equals(content.getContentName())){
        VersionRange vr = content.getVersion();
        assertEquals(vr.getMinimumVersion(),new Version("1.1.0"));
        assertEquals(vr.getMaximumVersion(),new Version("1.2.0"));
View Full Code Here

  {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
   
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION2.MF");
   
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);

    assertEquals(am.getApplicationName(),appName);

    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents){
      if ("com.travel.reservation.web".equals(content.getContentName())){
        VersionRange vr = content.getVersion();
        assertEquals(vr.getMinimumVersion(),new Version("1.1.0"));
        assertEquals(vr.getMaximumVersion(),new Version("1.2.0"));
View Full Code Here

  /**
   * Create an AriesApplication from a .eba file: a zip file with a '.eba' extension
   * as per http://incubator.apache.org/aries/applications.html
   */
  public AriesApplication createApplication(IDirectory ebaFile) throws ManagementException {
    ApplicationMetadata applicationMetadata = null;
    DeploymentMetadata deploymentMetadata = null;
    Map<String, BundleConversion> modifiedBundles = new HashMap<String, BundleConversion>();
    AriesApplicationImpl application = null;
    String appPath = ebaFile.toString();
    try {  
      // try to read the app name out of the application.mf
      Manifest applicationManifest = parseApplicationManifest (ebaFile);
      String appName = applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_NAME);

      //If the application name is null, we will try to get the file name.
      if (appName == null || appName.isEmpty()) {
          String fullPath = appPath;
          if (fullPath.endsWith("/")) {
            fullPath = fullPath.substring(0, fullPath.length() -1)
          }
             
          int last_slash = fullPath.lastIndexOf("/");
          appName = fullPath.substring(last_slash + 1, fullPath.length());
      }
                 
      IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
      /* 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 (deploymentManifest == null) {
            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
            // We only do this if a DEPLOYMENT.MF does not exist.
            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(), appName, cx});
              }
              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", appName));
            }
            if (convertedBinary != null) {
              modifiedBundles.put (f.getName(), convertedBinary);            
              extraBundlesInfo.add(convertedBinary.getBundleInfo(_applicationMetadataFactory));
            }
          }
        }
      }
      // if Application-Content header was not specified build it based on the bundles included by value
      if (applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_CONTENT) == null) {
          String appContent = buildAppContent(extraBundlesInfo);
          applicationManifest.getMainAttributes().putValue(AppConstants.APPLICATION_CONTENT, appContent);
      }
     
      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
      applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
     
      if (deploymentManifest != null) {
        deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest);
       
        // Validate: symbolic names must match
        String appSymbolicName = applicationMetadata.getApplicationSymbolicName();
        String depSymbolicName = deploymentMetadata.getApplicationSymbolicName();
        if (!appSymbolicName.equals(depSymbolicName)) {
          throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0002E", appName, appSymbolicName, depSymbolicName));
        }
      }
View Full Code Here

  public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException
  {
    log.trace("resolving {}", app);
    DataModelHelper helper = repositoryAdmin.getHelper();

    ApplicationMetadata appMeta = app.getApplicationMetadata();

    String appName = appMeta.getApplicationSymbolicName();
    Version appVersion = appMeta.getApplicationVersion();
    List<Content> appContent = appMeta.getApplicationContents();

    Repository appRepo;
   
    try {
      Document doc = RepositoryDescriptorGenerator.generateRepositoryDescriptor(appName + "_" + appVersion, app.getBundleInfo());
View Full Code Here

TOP

Related Classes of org.apache.aries.application.ApplicationMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.