Search in sources :

Example 1 with OnmsUpgradeComparator

use of org.opennms.upgrade.api.OnmsUpgradeComparator in project opennms by OpenNMS.

the class Upgrade method getUpgradeObjects.

/**
 * Gets the upgrade objects.
 *
 * @return the upgrade objects
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 */
protected List<OnmsUpgrade> getUpgradeObjects() throws OnmsUpgradeException {
    List<OnmsUpgrade> upgrades = new ArrayList<>();
    try {
        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
        provider.addIncludeFilter(new AssignableTypeFilter(OnmsUpgrade.class));
        Set<BeanDefinition> components = provider.findCandidateComponents(getClassScope());
        for (BeanDefinition component : components) {
            if (component.isAbstract()) {
                continue;
            }
            Class<?> cls = Class.forName(component.getBeanClassName());
            if (cls.getAnnotation(Ignore.class) != null) {
                continue;
            }
            OnmsUpgrade upgrade = (OnmsUpgrade) cls.newInstance();
            upgrades.add(upgrade);
            log("Found upgrade task %s\n", upgrade.getId());
        }
        Collections.sort(upgrades, new OnmsUpgradeComparator());
    } catch (Exception e) {
        throw new OnmsUpgradeException("  Can't find the upgrade classes because: " + e.getMessage(), e);
    }
    return upgrades;
}
Also used : Ignore(org.opennms.upgrade.api.Ignore) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) ArrayList(java.util.ArrayList) OnmsUpgrade(org.opennms.upgrade.api.OnmsUpgrade) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) OnmsUpgradeComparator(org.opennms.upgrade.api.OnmsUpgradeComparator) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter)

Aggregations

ArrayList (java.util.ArrayList)1 Ignore (org.opennms.upgrade.api.Ignore)1 OnmsUpgrade (org.opennms.upgrade.api.OnmsUpgrade)1 OnmsUpgradeComparator (org.opennms.upgrade.api.OnmsUpgradeComparator)1 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)1 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)1