diff options
author | Carsten Reckord | 2017-06-14 18:23:33 +0000 |
---|---|---|
committer | Carsten Reckord | 2017-06-14 19:43:03 +0000 |
commit | d24c5e10336dbb289bb08b3b27eb326957d116a7 (patch) | |
tree | fe3d6c82db98e240c869b08349b223447266e594 | |
parent | ca12ba8325d93127d460a6adb5cd6d81d0442930 (diff) | |
download | org.eclipse.epp.mpc-d24c5e10336dbb289bb08b3b27eb326957d116a7.tar.gz org.eclipse.epp.mpc-d24c5e10336dbb289bb08b3b27eb326957d116a7.tar.xz org.eclipse.epp.mpc-d24c5e10336dbb289bb08b3b27eb326957d116a7.zip |
517221: Initialize Import Favorites with random favorites lists of other users
Allow api.eclipse.org favorite URLs in d&d handler filter
Bug: 517221
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=517221
3 files changed, 39 insertions, 6 deletions
diff --git a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/UserFavoritesService.java b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/UserFavoritesService.java index 41bcbf48..a39d9ee8 100644 --- a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/UserFavoritesService.java +++ b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/UserFavoritesService.java @@ -123,6 +123,9 @@ public class UserFavoritesService extends AbstractDataStorageService implements private static final Pattern JSON_OWNER_PROFILE_URL_ATTRIBUTE_PATTERN = Pattern .compile(String.format(JSON_ATTRIBUTE_REGEX, "html_profile_url"), Pattern.MULTILINE); //$NON-NLS-1$ + public static final Pattern FAVORITES_URL_PATTERN = Pattern + .compile("(?:^|/)user/([^/#?]+)(/favorites)?([/#?].*)?$"); //$NON-NLS-1$ + private static final String KEY = "mpc_favorites"; //$NON-NLS-1$ private static final int RETRY_COUNT = 3; @@ -238,6 +241,7 @@ public class UserFavoritesService extends AbstractDataStorageService implements private String getFavoritesListUrl(String entryBody, String id) { String marketplaceBaseUri = getMarketplaceBaseUri(); + //We use the HTML URL shown in the web frontend instead of the API URL, because that's what's advertised String explicitUrl = getAttribute(JSON_LIST_URL_ATTRIBUTE_PATTERN, null, entryBody); if (explicitUrl != null && explicitUrl.trim().length() > 0) { try { @@ -459,7 +463,24 @@ public class UserFavoritesService extends AbstractDataStorageService implements return toNodes(nodeIds); } - public static void validateURI(URI uri) { + private URI normalizeURI(URI uri) { + validateUri(uri); + String marketplaceBaseUri = getMarketplaceBaseUri(); + marketplaceBaseUri = URLUtil.appendPath(marketplaceBaseUri, ""); //$NON-NLS-1$ + marketplaceBaseUri = URLUtil.setScheme(marketplaceBaseUri, uri.getScheme()); + if (!uri.toString().startsWith(marketplaceBaseUri)) { + return uri; + } + Matcher matcher = FAVORITES_URL_PATTERN.matcher(uri.toString()); + if (matcher.find()) { + String name = matcher.group(1); + return getStorageService().getServiceUri() + .resolve("marketplace/favorites/?name=" + URLUtil.urlEncode(name)); + } + return uri; + } + + public static void validateUri(URI uri) { if ("".equals(uri.toString()) //$NON-NLS-1$ || ((uri.getHost() == null || "".equals(uri.getHost())) //$NON-NLS-1$ && (uri.getScheme() != null && uri.getScheme().toLowerCase().startsWith("http"))) //$NON-NLS-1$ @@ -471,9 +492,9 @@ public class UserFavoritesService extends AbstractDataStorageService implements } public List<String> getFavoriteIds(final URI uri, IProgressMonitor monitor) throws IOException { - validateURI(uri); + URI normalizedUri = normalizeURI(uri); try { - return new AbstractJSONListRequest<String>(uri, JSON_MPC_FAVORITES_PATTERN) { + return new AbstractJSONListRequest<String>(normalizedUri, JSON_MPC_FAVORITES_PATTERN) { @Override protected String parseListElement(String listElement) { diff --git a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/util/URLUtil.java b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/util/URLUtil.java index 4c9f564f..846238b5 100644 --- a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/util/URLUtil.java +++ b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/util/URLUtil.java @@ -124,4 +124,12 @@ public class URLUtil { return path; } } + + public static String setScheme(String url, String scheme) { + int schemeSeparator = url.indexOf(":"); //$NON-NLS-1$ + if (schemeSeparator == -1) { + throw new IllegalArgumentException(); + } + return scheme + url.substring(schemeSeparator); + } } diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketplaceUrlHandler.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketplaceUrlHandler.java index 5a95223a..36a959ee 100644 --- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketplaceUrlHandler.java +++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketplaceUrlHandler.java @@ -31,6 +31,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.epp.internal.mpc.core.MarketplaceClientCore; import org.eclipse.epp.internal.mpc.core.model.Node; import org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService; +import org.eclipse.epp.internal.mpc.core.service.UserFavoritesService; import org.eclipse.epp.internal.mpc.core.util.URLUtil; import org.eclipse.epp.internal.mpc.ui.CatalogRegistry; import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUi; @@ -62,8 +63,10 @@ public abstract class MarketplaceUrlHandler { private static final Pattern NODE_URL_PATTERN = Pattern.compile("(?:^|/)node/([^/#?]+)"); //$NON-NLS-1$ - private static final Pattern FAVORITES_URL_PATTERN = Pattern - .compile("(?:^|/)user/([^/#?]+)(/favorites)?([/#?].*)?$"); //$NON-NLS-1$ + private static final Pattern FAVORITES_URL_PATTERN = UserFavoritesService.FAVORITES_URL_PATTERN; + + private static final Pattern FAVORITES_API_URL_PATTERN = Pattern + .compile("(?:^|/)marketplace/favorites/?(?:\\?(?:[^#]*&)name=.*)?$"); //$NON-NLS-1$ public static class SolutionInstallationInfo { @@ -190,7 +193,8 @@ public abstract class MarketplaceUrlHandler { } public static boolean isPotentialFavoritesList(String url) { - return url != null && FAVORITES_URL_PATTERN.matcher(url).find(); + return url != null + && (FAVORITES_URL_PATTERN.matcher(url).find() || FAVORITES_API_URL_PATTERN.matcher(url).find()); } public static void triggerInstall(SolutionInstallationInfo info) { |