Skip to content

Commit

Permalink
Bug 564580: reduce the properties sent to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
l3-g5 committed Jun 29, 2020
1 parent d1708e7 commit aff3352
Showing 1 changed file with 12 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.eclipse.epp.internal.mpc.core.service.CachingMarketplaceService;
import org.eclipse.epp.internal.mpc.core.service.DefaultCatalogService;
Expand Down Expand Up @@ -566,54 +565,18 @@ public static synchronized IMarketplaceServiceLocator getCompatibilityLocator()

public static Map<String, String> computeDefaultRequestMetaParameters() {
Map<String, String> requestMetaParameters = new LinkedHashMap<>();
BundleContext bundleContext = FrameworkUtil.getBundle(MarketplaceClientCore.class).getBundleContext();

addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_CLIENT,
MarketplaceClientCore.BUNDLE_ID);
Bundle clientBundle = Platform.getBundle(MarketplaceClientCore.BUNDLE_ID);
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_CLIENT_VERSION,
clientBundle.getVersion().toString());

addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_OS,
Platform.getOS());
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_WS,
Platform.getWS());
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_NL,
Platform.getNL());
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_JAVA_VERSION,
bundleContext.getProperty("java.version")); //$NON-NLS-1$

IProduct product = Platform.getProduct();
String productId;
{
productId = bundleContext.getProperty("eclipse.product"); //$NON-NLS-1$
if (productId == null && product != null) {
productId = product.getId();
}
}
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_PRODUCT,
productId);
String productVersion = null;
if (productId != null) {
productVersion = bundleContext.getProperty("eclipse.buildId"); //$NON-NLS-1$
if (productVersion == null && product != null) {
Bundle productBundle = product.getDefiningBundle();
if (productBundle != null) {
productVersion = productBundle.getVersion().toString();
}
}
}
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_PRODUCT_VERSION,
productVersion);

Bundle runtimeBundle = Platform.getBundle("org.eclipse.core.runtime"); //$NON-NLS-1$
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_RUNTIME_VERSION,
runtimeBundle == null ? null : runtimeBundle.getVersion().toString());

// also send the platform version to distinguish between 3.x and 4.x platforms using the same runtime
Bundle platformBundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_PLATFORM_VERSION,
platformBundle == null ? null : platformBundle.getVersion().toString());
platformBundle == null ? null : shortenVersionString(platformBundle.getVersion().toString()));

return requestMetaParameters;
}
Expand All @@ -633,4 +596,15 @@ private static void addDefaultRequestMetaParameter(Map<String, String> requestMe
requestMetaParameters.put(key, value);
}
}

private static String shortenVersionString(String version) {
int index = version.indexOf('.');
if (index > -1) {
index = version.indexOf('.', index + 1);
if (index > -1) {
return version.substring(0, index);
}
}
return version;
}
}

0 comments on commit aff3352

Please sign in to comment.