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);
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations