Search in sources :

Example 1 with ObrBundle

use of org.springframework.roo.obr.addon.search.model.ObrBundle in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method populateBundleCache.

/**
 * Method to populate current Bundles on installed repositories
 */
private void populateBundleCache() {
    // Refreshing Repositories
    populateRepositories();
    // Cleaning Bundle Cache
    bundleCache.clear();
    for (Repository repo : repositories) {
        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());
            // Getting Resource Capabilites
            Capability[] resourceCapabilities = repoResource.getCapabilities();
            for (Capability capability : resourceCapabilities) {
                // Getting resource commands
                if (capability.getName().equals(CAPABILITY_COMMANDS_NAME) || capability.getName().equals(CAPABILITY_JDBCDRIVER_NAME) || capability.getName().equals(CAPABILITY_LIBRARY_NAME)) {
                    // Getting all resource properties
                    Map<String, Object> capabilityProperties = capability.getPropertiesAsMap();
                    for (Entry capabilityProperty : capabilityProperties.entrySet()) {
                        String capabilityCommand = (String) capabilityProperty.getValue();
                        bundle.addCommand(capabilityCommand);
                    }
                    bundleCache.put(bundle.getSymbolicName(), bundle);
                }
            }
        }
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Entry(java.util.Map.Entry) Capability(org.apache.felix.bundlerepository.Capability) Resource(org.apache.felix.bundlerepository.Resource) ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle)

Example 2 with ObrBundle

use of org.springframework.roo.obr.addon.search.model.ObrBundle in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method addOnInfo.

@Override
public void addOnInfo(ObrAddOnBundleSymbolicName bsn) {
    Validate.notNull(bsn, "A valid add-on bundle symbolic name is required");
    // Refreshing bundle cache
    populateBundleCache();
    synchronized (mutex) {
        String bsnString = bsn.getKey();
        if (bsnString.contains(";")) {
            bsnString = bsnString.split(";")[0];
        }
        final ObrBundle bundle = bundleCache.get(bsnString);
        if (bundle == null) {
            LOGGER.warning("Unable to find specified bundle with symbolic name: " + bsn.getKey());
            return;
        }
        addOnInfo(bundle, bundle.getVersion());
    }
}
Also used : ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle)

Example 3 with ObrBundle

use of org.springframework.roo.obr.addon.search.model.ObrBundle in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method installAddOn.

@Override
public InstallOrUpgradeStatus installAddOn(String bundleId) {
    synchronized (mutex) {
        Validate.notBlank(bundleId, "A valid bundle ID is required");
        ObrBundle bundle = null;
        if (searchResultCache != null) {
            bundle = searchResultCache.get(String.format("%02d", Integer.parseInt(bundleId)));
        }
        if (bundle == null) {
            LOGGER.warning("To install an addon a valid bundle ID is required");
            return InstallOrUpgradeStatus.FAILED;
        }
        return installAddon(bundle, bundle.getSymbolicName());
    }
}
Also used : ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle)

Example 4 with ObrBundle

use of org.springframework.roo.obr.addon.search.model.ObrBundle 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 5 with ObrBundle

use of org.springframework.roo.obr.addon.search.model.ObrBundle in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method installAddOn.

@Override
public InstallOrUpgradeStatus installAddOn(ObrAddOnBundleSymbolicName bsn) {
    // Refreshing bundle cache
    populateBundleCache();
    synchronized (mutex) {
        Validate.notNull(bsn, "A valid add-on bundle symbolic name is required");
        String bsnString = bsn.getKey();
        if (bsnString.contains(";")) {
            bsnString = bsnString.split(";")[0];
        }
        final ObrBundle bundle = bundleCache.get(bsnString);
        if (bundle == null) {
            LOGGER.warning("Could not find specified bundle with symbolic name: " + bsn.getKey());
            return InstallOrUpgradeStatus.FAILED;
        }
        return installAddon(bundle, bsn.getKey());
    }
}
Also used : ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle)

Aggregations

ObrBundle (org.springframework.roo.obr.addon.search.model.ObrBundle)8 Entry (java.util.Map.Entry)2 Capability (org.apache.felix.bundlerepository.Capability)2 Repository (org.apache.felix.bundlerepository.Repository)2 Resource (org.apache.felix.bundlerepository.Resource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Completion (org.springframework.roo.shell.Completion)1