Package org.osgi.service.obr

Examples of org.osgi.service.obr.RepositoryAdmin


            // prepare the repository resolver
            DummyBundleContext bc = new DummyBundleContext(this.ctx.getBundleContext());
            bc.setProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP,
                repoFile.toURI().toURL().toExternalForm());
            RepositoryAdmin ra = new RepositoryAdminImpl(bc);
            Set resources = new HashSet();

            // add the servlet container bundles first
            for (int i = 0; i < REQUIRED_BUNDLES.length; i++) {
                String filter = "(symbolicName=" + REQUIRED_BUNDLES[i]
                    + ")";
                this.resolveResource(ra, filter, resources);
            }

            // find all resources in the repository
            for (int i=0; i < bundleNames.length; i++) {
                Resource res = this.repository.getResource(bundleNames[i]);
                if (res != null) {
                    VersionRange vr = new VersionRange(res.getVersion());
                    String filter = "(&(symbolicName=" + res.getSymbolicName()
                        + ")" + vr.getFilter() + ")";
                    this.resolveResource(ra, filter, resources);
                }
            }

            // prepare the resolver
            Resolver resolver = ra.resolver();
            for (Iterator ri=resources.iterator(); ri.hasNext(); ) {
                resolver.add((org.osgi.service.obr.Resource) ri.next());
            }

            // resolve the resources
View Full Code Here


    }


    String getData( final String filter, final boolean details, Bundle[] bundles )
    {
        RepositoryAdmin admin = ( RepositoryAdmin ) getRepositoryAdmin();
        if ( admin != null )
        {
            JSONObject json = new JSONObject();
            try
            {
                json.put( "status", true ); //$NON-NLS-1$
                json.put( "details", details ); //$NON-NLS-1$

                final Repository repositories[] = admin.listRepositories();
                for ( int i = 0; repositories != null && i < repositories.length; i++ )
                {
                    json.append( "repositories", new JSONObject() //$NON-NLS-1$
                        .put( "lastModified", repositories[i].getLastModified() ) //$NON-NLS-1$
                        .put( "name", repositories[i].getName() ) //$NON-NLS-1$
                        .put( "url", repositories[i].getURL() ) ); //$NON-NLS-1$
                }

                Resource[] resources = admin.discoverResources( filter );
                for ( int i = 0; resources != null && i < resources.length; i++ )
                {
                    json.append( "resources", toJSON( resources[i], bundles, details ) ); //$NON-NLS-1$
                }
            }
View Full Code Here

        return "{}"; //$NON-NLS-1$
    }

    void doAction( String action, String urlParam ) throws IOException, ServletException
    {
        RepositoryAdmin admin = ( RepositoryAdmin ) getRepositoryAdmin();
        Repository[] repos = admin.listRepositories();
        Repository repo = getRepository( repos, urlParam );

        URL uri = repo != null ? repo.getURL() : new URL( urlParam );

        if ( "delete".equals( action ) ) //$NON-NLS-1$
        {
            if ( !admin.removeRepository( uri ) )
            {
                throw new ServletException( "Failed to remove repository with URL " + uri );
            }
        }
        else if ( "add".equals( action ) || "refresh".equals( action ) ) //$NON-NLS-1$ //$NON-NLS-2$
        {
            try
            {
                admin.addRepository( uri );
            }
            catch ( IOException e )
            {
                throw e;
            }
View Full Code Here

        {
            logger.log( "No resources to deploy" );
            return;
        }

        RepositoryAdmin repoAdmin = ( RepositoryAdmin ) getRepositoryAdmin();
        Resolver resolver = repoAdmin.resolver();

        // prepare the deployment
        for ( int i = 0; i < bundles.length; i++ )
        {
            String bundle = bundles[i];
            if ( bundle == null || bundle.equals( "-" ) )
            {
                continue;
            }

            String filter = "(id=" + bundle + ")";
            Resource[] resources = repoAdmin.discoverResources( filter );
            if ( resources != null && resources.length > 0 )
            {
                resolver.add( resources[0] );
            }
        }
View Full Code Here

                    .put( "name", reqs[i].getName() ) //$NON-NLS-1$
                    .put( "filter", reqs[i].getFilter() ) //$NON-NLS-1$
                    .put( "optional", reqs[i].isOptional() ) ); //$NON-NLS-1$
            }

            final RepositoryAdmin admin = ( RepositoryAdmin ) getRepositoryAdmin();
            Resolver resolver = admin.resolver();
            resolver.add( resource );
            resolver.resolve(); // (Resolver.NO_OPTIONAL_RESOURCES);
            Resource[] required = resolver.getRequiredResources();
            for ( int i = 0; required != null && i < required.length; i++ )
            {
View Full Code Here

        return false;
    }

    private boolean updateFromOsgiOBR()
    {
        RepositoryAdmin ra = ( RepositoryAdmin ) getService( "org.osgi.service.obr.RepositoryAdmin" );
        if ( ra != null )
        {
            getLog().log( LogService.LOG_DEBUG, "Trying to update from OSGi Bundle Repository (OSGi API)" );

            final Resolver resolver = ra.resolver();

            String version = ( String ) bundle.getHeaders().get( Constants.BUNDLE_VERSION );
            if ( version == null )
            {
                version = "0.0.0";
            }
            final String filter = "(&(symbolicname=" + bundle.getSymbolicName() + ")(!(version=" + version
                + "))(version>=" + version + "))";

            final Resource[] resources = ra.discoverResources( filter );
            final Resource resource = selectHighestVersion( resources );
            if ( resource != null )
            {
                resolver.add( resource );
View Full Code Here

  public void deploy(String location,String version){
    ServiceReference sref=this.bc.getServiceReference(RepositoryAdmin.class.getName());

    System.out.println("Starting "+location+" "+version);
    if (sref!=null){
      RepositoryAdmin brs=(RepositoryAdmin)this.bc.getService(sref);
      Resolver resolver=brs.resolver();
      Resource ressource = selectNewestVersion(searchRepository(brs, location, version));
      if (ressource!=null){
  resolver.add(ressource);
      }
      if ((resolver.getAddedResources() != null) &&
View Full Code Here

  @Test(expected=ResolverException.class)
  public void testBlogAppResolveFail() throws ResolverException, Exception
  {
    generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar");
   
    RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
   
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
      repositoryAdmin.removeRepository(repo.getURL());
    }
   
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());

    AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("blog.eba")));
    //installing requires a valid url for the bundle in repository.xml.
   
View Full Code Here

  @Test
  public void testBlogApp() throws Exception
  {
    generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar");
   
    RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
   
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
      repositoryAdmin.removeRepository(repo.getURL());
    }
   
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());

    AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("blog.eba")));
    //installing requires a valid url for the bundle in repository.xml.
   
View Full Code Here

    createdApplications = true;
  }

  @Test
  public void testAppWithApplicationManifest() throws Exception {
    RepositoryAdmin repositoryAdmin = getOsgiService(RepositoryAdmin.class);
   
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());

    Repository[] repos = repositoryAdmin.listRepositories();
   
    for (Repository repo : repos) {
      Resource[] resources = repo.getResources();
     
      for (Resource r : resources) {
View Full Code Here

TOP

Related Classes of org.osgi.service.obr.RepositoryAdmin

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.