Search in sources :

Example 1 with VersionStringComparator

use of org.talend.designer.maven.aether.comparator.VersionStringComparator in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionsGroup method buildAllVersionList.

private List<String> buildAllVersionList(IDynamicMonitor monitor) throws Exception {
    Set<String> allVersion = new HashSet<>();
    DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
    DynamicConfiguration dynamicConfiguration = new DynamicConfiguration();
    dynamicConfiguration.setDistribution(getDistribution());
    IDependencyResolver dependencyResolver = dynamicDistributionManager.getDependencyResolver(dynamicConfiguration);
    List<String> allHadoopVersions = dependencyResolver.listHadoopVersions(null, null, monitor);
    if (allHadoopVersions != null) {
        allVersion.addAll(allHadoopVersions);
    }
    List<String> versionList = new LinkedList<>(allVersion);
    Collections.sort(versionList, Collections.reverseOrder(new VersionStringComparator()));
    return new ArrayList<>(versionList);
}
Also used : VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) ArrayList(java.util.ArrayList) IDependencyResolver(org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 2 with VersionStringComparator

use of org.talend.designer.maven.aether.comparator.VersionStringComparator in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionsGroup method getCompatibleDistribution.

@Override
public IDynamicDistribution getCompatibleDistribution(IDynamicMonitor monitor, String version) throws Exception {
    if (monitor == null) {
        monitor = new DummyDynamicMonitor();
    }
    VersionStringComparator versionStringComparator = new VersionStringComparator();
    // 1. try to get dynamicDistribution from compatible list
    Set<Entry<IDynamicDistribution, List<String>>> entrySet = getCompatibleDistribuionVersionMap(monitor).entrySet();
    IDynamicDistribution bestDistribution = null;
    // choose the biggest distance, normally means compatible with higher versions
    int distance = -1;
    for (Entry<IDynamicDistribution, List<String>> entry : entrySet) {
        List<String> list = entry.getValue();
        Collections.sort(list, versionStringComparator);
        int size = list.size();
        int index = list.indexOf(version);
        if (0 <= index) {
            int curDistance = size - index;
            if (distance < curDistance) {
                distance = curDistance;
                bestDistribution = entry.getKey();
            }
        }
    }
    // 2. try to get dynamicDistribution from all list
    if (bestDistribution == null) {
        List<String> allVersions = new ArrayList<>();
        List<String> allVersionsCached = getAllVersionList(monitor);
        if (allVersionsCached != null) {
            allVersions.addAll(allVersionsCached);
        }
        Collections.sort(allVersions, versionStringComparator);
        // choose the shortest distance, normally means compatible with higher versions
        distance = -1;
        for (Entry<IDynamicDistribution, List<String>> entry : entrySet) {
            List<String> list = entry.getValue();
            Collections.sort(list, versionStringComparator);
            String topVersion = list.get(list.size() - 1);
            String baseVersion = list.get(0);
            int curDistance = -1;
            if (versionStringComparator.compare(version, baseVersion) < 0) {
                curDistance = allVersions.indexOf(baseVersion) - allVersions.indexOf(version);
            } else {
                curDistance = allVersions.indexOf(version) - allVersions.indexOf(topVersion);
            }
            if (distance < 0 || curDistance < distance) {
                distance = curDistance;
                bestDistribution = entry.getKey();
            }
        }
    }
    return bestDistribution;
}
Also used : Entry(java.util.Map.Entry) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 3 with VersionStringComparator

use of org.talend.designer.maven.aether.comparator.VersionStringComparator in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method onRefreshBtnClicked.

private void onRefreshBtnClicked() {
    try {
        List<String> versionList = getVersionList();
        if (versionList != null && !versionList.isEmpty()) {
            Collections.sort(versionList, Collections.reverseOrder(new VersionStringComparator()));
            String version = versionList.get(0);
            versionsComboViewer.setInput(versionList);
            versionsComboViewer.setSelection(new StructuredSelection(version));
        }
    } catch (Exception ex) {
        ExceptionHandler.process(ex);
    }
}
Also used : VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with VersionStringComparator

use of org.talend.designer.maven.aether.comparator.VersionStringComparator in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method getCompatibleTemplate.

@Override
public TemplateBean getCompatibleTemplate(IDynamicMonitor monitor, String version) throws Exception {
    if (monitor == null) {
        monitor = new DummyDynamicMonitor();
    }
    VersionStringComparator versionStringComparator = new VersionStringComparator();
    // 1. try to get compatible bean
    if (templateBeanCompatibleVersionMap == null) {
        getCompatibleVersions(monitor);
    }
    Set<Entry<TemplateBean, List<String>>> entrySet = templateBeanCompatibleVersionMap.entrySet();
    TemplateBean bestTemplateBean = null;
    // choose the biggest distance, normally means compatible with higher versions
    int distance = -1;
    for (Entry<TemplateBean, List<String>> entry : entrySet) {
        List<String> list = entry.getValue();
        Collections.sort(list, versionStringComparator);
        int size = list.size();
        int index = list.indexOf(version);
        if (0 <= index) {
            int curDistance = size - index;
            if (distance < curDistance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    // 2. try to get bean from all beans
    if (bestTemplateBean == null) {
        List<String> allVersions = getAllVersions(monitor);
        Collections.sort(allVersions, versionStringComparator);
        // choose the shorted distance, normally means compatible with higher versions
        distance = -1;
        for (Entry<TemplateBean, List<String>> entry : entrySet) {
            List<String> list = entry.getValue();
            Collections.sort(list, versionStringComparator);
            String topVersion = list.get(list.size() - 1);
            String baseVersion = list.get(0);
            int curDistance = -1;
            if (versionStringComparator.compare(version, baseVersion) < 0) {
                curDistance = allVersions.indexOf(baseVersion) - allVersions.indexOf(version);
            } else {
                curDistance = allVersions.indexOf(version) - allVersions.indexOf(topVersion);
            }
            if (distance < 0 || curDistance < distance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    return bestTemplateBean;
}
Also used : Entry(java.util.Map.Entry) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 5 with VersionStringComparator

use of org.talend.designer.maven.aether.comparator.VersionStringComparator in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method getCompatibleVersions.

@Override
public List<String> getCompatibleVersions(IDynamicMonitor monitor) throws Exception {
    Set<String> allCompatibleVersion = new HashSet<>();
    List<TemplateBean> templates = getTemplates(monitor);
    if (templates != null) {
        DynamicDistributionUtils.checkCancelOrNot(monitor);
        templateBeanCompatibleVersionMap = new HashMap<>();
        DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
        DynamicConfiguration dynamicConfiguration = new DynamicConfiguration();
        dynamicConfiguration.setDistribution(getDistributionName());
        IDependencyResolver dependencyResolver = dynamicDistributionManager.getDependencyResolver(dynamicConfiguration);
        List<String> allHadoopVersions = dependencyResolver.listHadoopVersions(null, null, monitor);
        if (allHadoopVersions != null) {
            for (TemplateBean templateBean : templates) {
                DynamicDistributionUtils.checkCancelOrNot(monitor);
                String baseVersion = templateBean.getBaseVersion();
                String topVersion = templateBean.getTopVersion();
                // $NON-NLS-1$
                String versionRange = "[";
                if (StringUtils.isEmpty(baseVersion)) {
                    // $NON-NLS-1$
                    versionRange = versionRange + "0";
                } else {
                    versionRange = versionRange + baseVersion;
                }
                // $NON-NLS-1$
                versionRange = versionRange + ",";
                if (StringUtils.isNotEmpty(topVersion)) {
                    versionRange = versionRange + topVersion;
                }
                // $NON-NLS-1$
                versionRange = versionRange + ")";
                List<String> filteredVersions = DynamicDistributionAetherUtils.filterVersions(allHadoopVersions, versionRange);
                if (filteredVersions != null && !filteredVersions.isEmpty()) {
                    allCompatibleVersion.addAll(filteredVersions);
                    templateBeanCompatibleVersionMap.put(templateBean, filteredVersions);
                }
            }
        }
    }
    List<String> compatibleVersionList = new LinkedList<>(allCompatibleVersion);
    Collections.sort(compatibleVersionList, Collections.reverseOrder(new VersionStringComparator()));
    return compatibleVersionList;
}
Also used : VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) IDependencyResolver(org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

VersionStringComparator (org.talend.designer.maven.aether.comparator.VersionStringComparator)6 LinkedList (java.util.LinkedList)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IDependencyResolver (org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)2 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1