use of org.eclipse.epp.mpc.core.model.IIus in project epp.mpc by eclipse.
the class SolutionCompatibilityFilterTest method testIncompatibleNode.
public void testIncompatibleNode() throws CoreException {
assumeFalse("Skipping test - this solution and Eclipse/OS are compatible", compatible);
INode node = queryNode();
String updateurl = node.getUpdateurl();
assertNull("Incompatible node {1} should not have an update url, but has {0}", updateurl, node);
IIus ius = node.getIus();
assertNull("Incompatible node {1} should not have an <ius> element", ius, node);
}
use of org.eclipse.epp.mpc.core.model.IIus in project epp.mpc by eclipse.
the class SolutionCompatibilityFilterTest method testCompatibleNonInstallableNode.
public void testCompatibleNonInstallableNode() throws CoreException {
assumeTrue("Skipping test - this solution and Eclipse/OS are incompatible", compatible);
assumeFalse("Skipping test - this solution is installable", solution.installable());
INode node = queryNode();
String updateurl = node.getUpdateurl();
assertNull("Uninstallable node {1} should not have an update url, but has {0}", updateurl, node);
IIus ius = node.getIus();
assertNull("Uninstallable node {1} should not have an <ius> element", ius, node);
}
use of org.eclipse.epp.mpc.core.model.IIus in project epp.mpc by eclipse.
the class MarketplaceCatalogTest method setupCatalog.
protected void setupCatalog() throws MalformedURLException {
final SearchResult discoveryResult = new SearchResult();
discoveryResult.setNodes(discoveryNodes);
CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {
final MarketplaceCategory category = new MarketplaceCategory();
{
category.setId("<root>");
}
@Override
public void performDiscovery(IProgressMonitor monitor) throws CoreException {
if (!categories.contains(category)) {
categories.add(category);
}
handleSearchResult(category, discoveryResult, new NullProgressMonitor());
}
@Override
protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
for (INode node : installedNodes) {
IIus ius = node.getIus();
if (ius != null) {
for (IIu iu : ius.getIuElements()) {
String featureId = iu.getId() + ".feature.group";
InstallableUnit installableUnit = new InstallableUnit();
installableUnit.setId(featureId);
installedIus.put(featureId, installableUnit);
}
}
}
return installedIus;
}
@Override
protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
return category;
}
};
catalog = new MarketplaceCatalog() {
@Override
protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
checkedForUpdate.add(item.getData());
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
boolean hasUpdate = updateAvailable.contains(item.getData());
for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
iuItem.setUpdateAvailable(hasUpdate);
}
}
return Status.OK_STATUS;
}
};
catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
use of org.eclipse.epp.mpc.core.model.IIus in project epp.mpc by eclipse.
the class SolutionCompatibilityFilterTest method testCompatibleInstallableNode.
public void testCompatibleInstallableNode() throws CoreException {
assumeTrue("Skipping test - this solution and Eclipse/OS are incompatible", compatible);
assumeTrue("Skipping test - this solution is not installable", solution.installable());
INode node = queryNode();
String updateurl = node.getUpdateurl();
assertThat("Node {1} has no update url", updateurl, not(isEmptyOrNullString()), node);
IIus ius = node.getIus();
assertNotNull("Node {1} is missing <ius> element", ius, node);
List<IIu> iuElements = ius.getIuElements();
assertNotNull(iuElements);
assertThat("Node {1} has no IUs", iuElements, not(empty()), node);
if (version != null) {
assertEquals("Node {2} has wrong version", version, node.getVersion(), node);
}
if (site != null) {
assertEquals("Node {2} has wrong update site", site, node.getUpdateurl(), node);
}
if (features != null) {
Set<String> allIUs = new HashSet<String>();
for (IIu iu : iuElements) {
allIUs.add(iu.getId());
}
assertThat("Node {1} is missing some features", allIUs, hasItems(features), node);
assertThat("Node {1} has some unexpected features", allIUs, hasSize(features.length), node);
}
}
use of org.eclipse.epp.mpc.core.model.IIus in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method handleSearchResult.
protected void handleSearchResult(MarketplaceCategory catalogCategory, ISearchResult result, final IProgressMonitor monitor) {
List<CatalogItem> items = getItems();
if (items != null && !result.getNodes().isEmpty()) {
int nodeWork = 1000;
int favoritesWork = catalogCategory.getContents() == Contents.USER_FAVORITES ? 0 : 1000;
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_loadingResources, result.getNodes().size() * nodeWork + favoritesWork);
try {
boolean userFavoritesSupported = false;
if (catalogCategory.getContents() == Contents.USER_FAVORITES) {
userFavoritesSupported = true;
} else if (hasUserFavoritesService()) {
try {
applyShellProvider();
marketplaceService.userFavorites(result.getNodes(), progress.newChild(favoritesWork));
userFavoritesSupported = true;
} catch (NotAuthorizedException e1) {
// user is not logged in. we just ignore this.
} catch (UnsupportedOperationException e1) {
// ignore
} catch (Exception e1) {
// something went wrong. log and proceed.
MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, e1);
}
}
for (final INode node : result.getNodes()) {
String id = node.getId();
try {
final MarketplaceNodeCatalogItem catalogItem = new MarketplaceNodeCatalogItem();
catalogItem.setMarketplaceUrl(catalogDescriptor.getUrl());
catalogItem.setId(id);
catalogItem.setName(getCatalogItemName(node));
catalogItem.setCategoryId(catalogCategory.getId());
ICategories categories = node.getCategories();
if (categories != null) {
for (ICategory category : categories.getCategory()) {
catalogItem.addTag(new Tag(ICategory.class, category.getId(), category.getName()));
}
}
catalogItem.setData(node);
catalogItem.setSource(source);
catalogItem.setLicense(node.getLicense());
catalogItem.setUserFavorite(userFavoritesSupported ? node.getUserFavorite() : null);
IIus ius = node.getIus();
if (ius != null) {
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = new ArrayList<MarketplaceNodeInstallableUnitItem>();
for (IIu iu : ius.getIuElements()) {
MarketplaceNodeInstallableUnitItem iuItem = new MarketplaceNodeInstallableUnitItem();
iuItem.init(iu);
installableUnitItems.add(iuItem);
}
catalogItem.setInstallableUnitItems(installableUnitItems);
}
if (node.getShortdescription() == null && node.getBody() != null) {
// bug 306653 <!--break--> marks the end of the short description.
String descriptionText = node.getBody();
Matcher matcher = BREAK_PATTERN.matcher(node.getBody());
if (matcher.find()) {
int start = matcher.start();
if (start > 0) {
String shortDescriptionText = descriptionText.substring(0, start).trim();
if (shortDescriptionText.length() > 0) {
descriptionText = shortDescriptionText;
}
}
}
catalogItem.setDescription(descriptionText);
} else {
catalogItem.setDescription(node.getShortdescription());
}
catalogItem.setProvider(node.getCompanyname());
String updateurl = node.getUpdateurl();
if (updateurl != null) {
try {
// trim is important!
updateurl = updateurl.trim();
URLUtil.toURL(updateurl);
catalogItem.setSiteUrl(updateurl);
} catch (MalformedURLException e) {
// don't use malformed URLs
}
}
if (catalogItem.getInstallableUnits() == null || catalogItem.getInstallableUnits().isEmpty() || catalogItem.getSiteUrl() == null) {
catalogItem.setAvailable(false);
}
if (node.getImage() != null) {
if (!source.getResourceProvider().containsResource(node.getImage())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getImage());
}
createIcon(catalogItem, node);
}
if (node.getBody() != null || node.getScreenshot() != null) {
final Overview overview = new Overview();
overview.setItem(catalogItem);
overview.setSummary(node.getBody());
overview.setUrl(node.getUrl());
catalogItem.setOverview(overview);
if (node.getScreenshot() != null) {
if (!source.getResourceProvider().containsResource(node.getScreenshot())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getScreenshot());
}
overview.setScreenshot(node.getScreenshot());
}
}
items.add(catalogItem);
marketplaceInfo.map(catalogItem.getMarketplaceUrl(), node);
marketplaceInfo.computeInstalled(computeInstalledFeatures(progress.newChild(nodeWork)), catalogItem);
} catch (RuntimeException ex) {
MarketplaceClientUi.error(NLS.bind(Messages.MarketplaceDiscoveryStrategy_ParseError, // $NON-NLS-1$
node == null ? "null" : id), ex);
}
}
} finally {
progress.done();
}
if (result.getMatchCount() != null) {
catalogCategory.setMatchCount(result.getMatchCount());
if (result.getMatchCount() > result.getNodes().size()) {
// add an item here to indicate that the search matched more items than were returned by the server
addCatalogItem(catalogCategory);
}
}
}
}
Aggregations