Search in sources :

Example 41 with Resource

use of org.apache.felix.bundlerepository.Resource in project aries by apache.

the class Aries1522Test method createRepositoryXml.

private URL createRepositoryXml(DataModelHelper helper) throws Exception {
    File dir;
    String cwd = new File("").getAbsolutePath();
    if (cwd.endsWith(File.separator + "target")) {
        dir = new File("test-classes/aries1523");
    } else {
        dir = new File("target/test-classes/aries1523");
    }
    File jar = new File(dir, "aries1523fragment.jar");
    assertTrue("The fragment jar does not exist: " + jar.getAbsolutePath(), jar.exists());
    Resource resource = helper.createResource(jar.toURI().toURL());
    Repository repository = helper.repository(new Resource[] { resource });
    File file = new File(dir, "repository.xml");
    FileWriter fw = new FileWriter(file);
    try {
        helper.writeRepository(repository, fw);
        return file.toURI().toURL();
    } finally {
        fw.close();
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) FileWriter(java.io.FileWriter) Resource(org.apache.felix.bundlerepository.Resource) File(java.io.File)

Example 42 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class SubsystemCommands method deploy.

public void deploy(String symbolicName) throws Exception {
    repositories = new ArrayList<Repository>();
    // Getting all installed repositories
    populateRepositories();
    // Getting subsystem resource from OBR Repository by resource
    // symbolicName
    Resource subsystemResource = getSubsystemResource(symbolicName);
    // Install related repositories or related subsystems if needed
    LOGGER.log(Level.INFO, "Subsystem dependency manager started.");
    LOGGER.log(Level.INFO, "");
    installSubsystemDependencies(subsystemResource);
    LOGGER.log(Level.INFO, "Subsystem dependency manager finished.");
    LOGGER.log(Level.INFO, "");
    // Install subsystem using symbolicName
    Subsystem subsystem = install(subsystemResource.getURI());
    // Starting installed subsystem
    start(subsystem.getSubsystemId());
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Subsystem(org.osgi.service.subsystem.Subsystem) Resource(org.apache.felix.bundlerepository.Resource)

Example 43 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method populateBundlesToInstall.

/**
 * Method to populate bundles to install. Depending of the search type, will be displayed
 * different kinds of bundles.
 *
 * @param requiresCommand
 * @param type
 */
private void populateBundlesToInstall(String searchTerms, SearchType type) {
    // Refreshing Repositories
    populateRepositories();
    // Cleaning Bundles to install
    bundlesToInstall.clear();
    // Cleaning previous search
    searchResultCache.clear();
    int bundleId = 0;
    for (Repository repo : repositories) {
        // Getting all resources from every repo
        Resource[] repoResources = repo.getResources();
        for (Resource repoResource : repoResources) {
            // Creating bundle of current resource
            ObrBundle bundle = new ObrBundle(repoResource.getSymbolicName(), repoResource.getPresentationName(), repoResource.getSize(), repoResource.getVersion(), repoResource.getURI());
            // If current bundle is installed, continue with the next one
            if (checkIfBundleIsInstalled(bundle)) {
                continue;
            }
            // Getting Resource Capabilites
            Capability[] resourceCapabilities = repoResource.getCapabilities();
            for (Capability capability : resourceCapabilities) {
                // capabilities
                if (type.equals(SearchType.ADDON)) {
                    // Getting resource commands
                    if (capability.getName().equals(CAPABILITY_COMMANDS_NAME)) {
                        // Getting all resource properties
                        Map<String, Object> capabilityProperties = capability.getPropertiesAsMap();
                        boolean match = false;
                        for (Entry capabilityProperty : capabilityProperties.entrySet()) {
                            String capabilityCommand = (String) capabilityProperty.getValue();
                            bundle.addCommand(capabilityCommand);
                            if (capabilityCommand.startsWith(searchTerms)) {
                                match = true;
                            }
                        }
                        if (match) {
                            bundleId++;
                            bundlesToInstall.add(bundle);
                            searchResultCache.put(String.format("%02d", bundleId), bundle);
                        }
                    }
                } else if (type.equals(SearchType.JDBCDRIVER)) {
                    // Getting resource driver
                    if (capability.getName().equals(CAPABILITY_JDBCDRIVER_NAME)) {
                        // Getting all resource properties
                        Map<String, Object> capabilityProperties = capability.getPropertiesAsMap();
                        boolean match = false;
                        for (Entry capabilityProperty : capabilityProperties.entrySet()) {
                            String capabilityKey = (String) capabilityProperty.getKey();
                            // Getting driver class
                            if (capabilityKey.toLowerCase().equals("driver")) {
                                String capabilityDriver = (String) capabilityProperty.getValue();
                                if (capabilityDriver.startsWith(searchTerms)) {
                                    match = true;
                                }
                            }
                        }
                        if (match) {
                            bundleId++;
                            bundlesToInstall.add(bundle);
                            searchResultCache.put(String.format("%02d", bundleId), bundle);
                        }
                    }
                } else if (type.equals(SearchType.LIBRARY)) {
                // TODO: Implement library bundle search
                }
            }
        }
    }
}
Also used : Capability(org.apache.felix.bundlerepository.Capability) Resource(org.apache.felix.bundlerepository.Resource) Repository(org.apache.felix.bundlerepository.Repository) Entry(java.util.Map.Entry) ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class BundleSymbolicNameConverter method getAllPossibleValues.

public boolean getAllPossibleValues(final List<Completion> completions, final Class<?> requiredType, final String originalUserInput, final String optionContext, final MethodTarget target) {
    boolean local = false;
    boolean obr = false;
    if ("".equals(optionContext)) {
        local = true;
    }
    if (optionContext.contains("local")) {
        local = true;
    }
    if (optionContext.contains("obr")) {
        obr = true;
    }
    if (local) {
        final Bundle[] bundles = context.getBundleContext().getBundles();
        if (bundles != null) {
            for (final Bundle bundle : bundles) {
                final String bsn = bundle.getSymbolicName();
                if (bsn != null && bsn.startsWith(originalUserInput)) {
                    completions.add(new Completion(bsn));
                }
            }
        }
    }
    if (obr) {
        final Repository[] repositories = repositoryAdmin.listRepositories();
        if (repositories != null) {
            for (final Repository repository : repositories) {
                final Resource[] resources = repository.getResources();
                if (resources != null) {
                    for (final Resource resource : resources) {
                        if (resource.getSymbolicName().startsWith(originalUserInput)) {
                            completions.add(new Completion(resource.getSymbolicName()));
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Completion(org.springframework.roo.shell.Completion) Bundle(org.osgi.framework.Bundle) Resource(org.apache.felix.bundlerepository.Resource)

Example 45 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class AddonSuiteOperationsImpl method listAllSubsystemsOnRepository.

@Override
public void listAllSubsystemsOnRepository(ObrRepositorySymbolicName obrRepository) {
    LOGGER.log(Level.INFO, "Getting all 'Roo Addon Suites' located on '" + obrRepository.getKey() + "' repository... ");
    LOGGER.log(Level.INFO, " ");
    int repos = 0;
    // Getting all repositories
    Repository[] repositories = getRepositoryAdmin().listRepositories();
    for (Repository repo : repositories) {
        if (repo.getURI().equals(obrRepository.getKey())) {
            // Getting all resources from repository
            Resource[] repositoryResource = repo.getResources();
            for (Resource resource : repositoryResource) {
                // If current resource ends with .esa, means that is a ROO Addon Suite
                if (resource.getURI().endsWith(".esa")) {
                    LOGGER.log(Level.INFO, "   " + resource.getSymbolicName());
                    repos++;
                }
            }
        }
    }
    LOGGER.log(Level.INFO, " ");
    LOGGER.log(Level.INFO, String.format("%s Roo Addon Suites were found on '%s' repository", repos, obrRepository.getKey()));
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Resource(org.apache.felix.bundlerepository.Resource)

Aggregations

Resource (org.apache.felix.bundlerepository.Resource)45 Repository (org.apache.felix.bundlerepository.Repository)19 Capability (org.apache.felix.bundlerepository.Capability)9 Resolver (org.apache.felix.bundlerepository.Resolver)9 ArrayList (java.util.ArrayList)8 ModelledResource (org.apache.aries.application.modelling.ModelledResource)8 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)8 Reason (org.apache.felix.bundlerepository.Reason)7 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)7 HashMap (java.util.HashMap)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 URL (java.net.URL)5 File (java.io.File)4 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)4 FileWriter (java.io.FileWriter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Requirement (org.apache.felix.bundlerepository.Requirement)3 BundleContext (org.osgi.framework.BundleContext)3