Skip to content

Commit

Permalink
Bug 564534: Fixed NPE in DiscoverFileSupportJob
Browse files Browse the repository at this point in the history
Change-Id: I7a5418afa1e3de3e0ceafb4bb9cde99b477d2f8d
Signed-off-by: Carsten Reckord <reckord@yatta.de>
  • Loading branch information
creckord committed Jul 6, 2020
1 parent 83b024a commit f300da5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 @@ -242,8 +243,8 @@ public IMarketplaceStorageService registerStorageService(String marketplaceBaseU
}
try {
MarketplaceStorageService marketplaceStorageService = new MarketplaceStorageService();
registration = registerService(marketplaceBaseUrl,
IMarketplaceStorageService.class, marketplaceStorageService, config);
registration = registerService(marketplaceBaseUrl, IMarketplaceStorageService.class,
marketplaceStorageService, config);
BundleContext bundleContext = ServiceUtil.getBundleContext(registration);
if (bundleContext != null) {
marketplaceStorageService.activate(bundleContext, config);
Expand Down Expand Up @@ -281,16 +282,13 @@ public synchronized void activate(BundleContext context, Map<?, ?> properties) {
this.defaultMarketplaceUrl = marketplaceUrl;
} //else the default value from the constructor is used

marketplaceServiceTracker = new ServiceTracker<>(context,
IMarketplaceService.class, null);
marketplaceServiceTracker = new ServiceTracker<>(context, IMarketplaceService.class, null);
marketplaceServiceTracker.open(true);

catalogServiceTracker = new ServiceTracker<>(context, ICatalogService.class,
null);
catalogServiceTracker = new ServiceTracker<>(context, ICatalogService.class, null);
catalogServiceTracker.open(true);

storageServiceTracker = new ServiceTracker<>(context,
IMarketplaceStorageService.class,
storageServiceTracker = new ServiceTracker<>(context, IMarketplaceStorageService.class,
new ServiceTrackerCustomizer<IMarketplaceStorageService, IMarketplaceStorageService>() {

@Override
Expand Down Expand Up @@ -325,8 +323,7 @@ public void removedService(ServiceReference<IMarketplaceStorageService> referenc
});
storageServiceTracker.open(true);

favoritesServiceTracker = new ServiceTracker<>(context,
IUserFavoritesService.class,
favoritesServiceTracker = new ServiceTracker<>(context, IUserFavoritesService.class,
new ServiceTrackerCustomizer<IUserFavoritesService, IUserFavoritesService>() {
@Override
public IUserFavoritesService addingService(ServiceReference<IUserFavoritesService> reference) {
Expand Down Expand Up @@ -572,7 +569,6 @@ public static Map<String, String> computeDefaultRequestMetaParameters() {
addDefaultRequestMetaParameter(requestMetaParameters, DefaultMarketplaceService.META_PARAM_OS,
Platform.getOS());


// 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,
Expand All @@ -581,6 +577,36 @@ public static Map<String, String> computeDefaultRequestMetaParameters() {
return requestMetaParameters;
}

public static Map<String, String> computeProductInfo() {
Map<String, String> productInfo = new LinkedHashMap<>();

BundleContext bundleContext = FrameworkUtil.getBundle(MarketplaceClientCore.class).getBundleContext();

IProduct product = Platform.getProduct();
String productId;
{
productId = bundleContext.getProperty("eclipse.product"); //$NON-NLS-1$
if (productId == null && product != null) {
productId = product.getId();
}
}
addDefaultRequestMetaParameter(productInfo, 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(productInfo, DefaultMarketplaceService.META_PARAM_PRODUCT_VERSION,
productVersion);

return productInfo;
}

private static void addDefaultRequestMetaParameter(Map<String, String> requestMetaParameters, String key,
String value) {
if (MarketplaceClientCorePlugin.DEBUG_FAKE_CLIENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class Node extends Identifiable implements INode {
protected Integer installsTotal;
protected Integer installsRecent;
protected String type;
protected Categories categories;
protected Tags tags;

protected Categories categories = new Categories();

protected Tags tags = new Tags();
protected String owner;
protected String shortdescription;
protected String body;
Expand All @@ -43,8 +45,10 @@ public class Node extends Identifiable implements INode {
protected String eclipseversion;
protected String supporturl;
protected String updateurl;
protected Ius ius;
protected Platforms platforms;

protected Ius ius = new Ius();

protected Platforms platforms = new Platforms();

protected Boolean userFavorite;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,48 +130,13 @@ public class DefaultMarketplaceService extends RemoteMarketplaceService<Marketpl
*/
public static final String META_PARAM_CLIENT = "client"; //$NON-NLS-1$

/**
* parameter identifying client plugin version
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_CLIENT_VERSION = "client.version"; //$NON-NLS-1$

/**
* parameter identifying windowing system as reported by {@link org.eclipse.core.runtime.Platform#getWS()}
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_WS = "ws"; //$NON-NLS-1$

/**
* parameter identifying operating system as reported by {@link org.eclipse.core.runtime.Platform#getOS()}
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_OS = "os"; //$NON-NLS-1$

/**
* parameter identifying the current local as reported by {@link org.eclipse.core.runtime.Platform#getNL()}
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_NL = "nl"; //$NON-NLS-1$

/**
* parameter identifying Java version
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_JAVA_VERSION = "java.version"; //$NON-NLS-1$

/**
* parameter identifying the Eclipse runtime version (the version of the org.eclipse.core.runtime bundle)
*
* @see {@link #setRequestMetaParameters(Map)}
*/
public static final String META_PARAM_RUNTIME_VERSION = "runtime.version"; //$NON-NLS-1$

/**
* parameter identifying the Eclipse platform version (the version of the org.eclipse.platform bundle) This
* parameter is optional and only sent if the platform bundle is present. It is used to identify the actual running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ private static String getAgentDetail(BundleContext context) {
String productVersion = getProperty(context, "eclipse.buildId", null); //$NON-NLS-1$
String appId = getProperty(context, "eclipse.application", null); //$NON-NLS-1$
if (productId == null || productVersion == null) {
Map<String, String> defaultRequestMetaParameters = ServiceLocator.computeDefaultRequestMetaParameters();
productId = getProperty(defaultRequestMetaParameters, DefaultMarketplaceService.META_PARAM_PRODUCT,
Map<String, String> productInfo = ServiceLocator.computeProductInfo();
productId = getProperty(productInfo, DefaultMarketplaceService.META_PARAM_PRODUCT,
"unknownProduct"); //$NON-NLS-1$
productVersion = getProperty(defaultRequestMetaParameters,
productVersion = getProperty(productInfo,
DefaultMarketplaceService.META_PARAM_PRODUCT_VERSION, "unknownBuildId"); //$NON-NLS-1$
}
if (appId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private System(String os, String ws) {

public void applyTo(Map<String, String> metaParams) {
metaParams.put(DefaultMarketplaceService.META_PARAM_OS, os);
metaParams.put(DefaultMarketplaceService.META_PARAM_WS, ws);
}
}

Expand All @@ -107,37 +106,27 @@ public void applyTo(Map<String, String> metaParams) {
private static final String SDK_PRODUCT_ID = "org.eclipse.sdk.ide";

public static enum EclipseRelease {
UNKNOWN(null, null, null, null), //
INDIGO(JAVA_PRODUCT_ID, "1.4.2.20120131-1457", "3.7.0.v20110110", null), //
JUNO_3_8(SDK_PRODUCT_ID, "3.8.0.v201206081200", "3.8.0.v20120521-2346", null), //
JUNO_3_8_WITH_PLATFORM(SDK_PRODUCT_ID, JUNO_3_8.productVersion(), JUNO_3_8.runtimeVersion(),
"3.8.0.v201206081200"), //
JUNO(JAVA_PRODUCT_ID, "1.5.0.20120131-1544", "3.8.0.v20120521-2346", null), //
JUNO_WITH_PLATFORM(JAVA_PRODUCT_ID, JUNO.productVersion(), JUNO.runtimeVersion(), "4.2.0.v201206081400"), //
JUNO_SR2(JAVA_PRODUCT_ID, "1.5.2.20130110-1126", "3.8.0.v20120521-2346", "4.2.2.v201302041200"), //
KEPLER(JAVA_PRODUCT_ID, "2.0.0.20130613-0530", "3.9.0.v20130326-1255", "4.3.0.v20130605-2000"), //
KEPLER_SR2(JAVA_PRODUCT_ID, "2.0.2.20140224-0000", "3.9.100.v20131218-1515", "4.3.2.v20140221-1700"), //
LUNA(JAVA_PRODUCT_ID, "4.4.0.20140612-0500", "3.10.0.v20140318-2214", "4.4.0.v20140606-1215"), //
LUNA_SR2(JAVA_PRODUCT_ID, "4.4.2.20150219-0708", "3.10.0.v20140318-2214", "4.4.2.v20150204-1700"), //
MARS(JAVA_PRODUCT_ID, "4.5.0.20150326-0704", "3.10.0.v20150112-1422", "4.5.0.v20150203-1300");
UNKNOWN(null, null, null), //
KEPLER(JAVA_PRODUCT_ID, "2.0.0.20130613-0530", "4.3.0.v20130605-2000"), //
KEPLER_SR2(JAVA_PRODUCT_ID, "2.0.2.20140224-0000", "4.3.2.v20140221-1700"), //
LUNA(JAVA_PRODUCT_ID, "4.4.0.20140612-0500", "4.4.0.v20140606-1215"), //
LUNA_SR2(JAVA_PRODUCT_ID, "4.4.2.20150219-0708", "4.4.2.v20150204-1700"), //
MARS(JAVA_PRODUCT_ID, "4.5.0.20150326-0704", "4.5.0.v20150203-1300");

private final String productId;

private final String productVersion;

private final String runtimeVersion;

private final String platformVersion;

private EclipseRelease(String productId, String productVersion, String runtimeVersion, String platformVersion) {
private EclipseRelease(String productId, String productVersion, String platformVersion) {
this.productId = productId;
this.productVersion = productVersion;
this.runtimeVersion = runtimeVersion;
this.platformVersion = platformVersion;
}

private EclipseRelease(String productVersion, String runtimeVersion, String platformVersion) {
this(JAVA_PRODUCT_ID, productVersion, runtimeVersion, platformVersion);
private EclipseRelease(String productVersion, String platformVersion) {
this(JAVA_PRODUCT_ID, productVersion, platformVersion);
}

public String productId() {
Expand All @@ -148,10 +137,6 @@ public String productVersion() {
return productVersion;
}

public String runtimeVersion() {
return runtimeVersion;
}

public String platformVersion() {
return platformVersion;
}
Expand All @@ -164,11 +149,6 @@ public void applyTo(Map<String, String> metaParams) {
metaParams.put(DefaultMarketplaceService.META_PARAM_PRODUCT, productId);
metaParams.put(DefaultMarketplaceService.META_PARAM_PRODUCT_VERSION, productVersion);
}
if (runtimeVersion == null) {
metaParams.remove(DefaultMarketplaceService.META_PARAM_RUNTIME_VERSION);
} else {
metaParams.put(DefaultMarketplaceService.META_PARAM_RUNTIME_VERSION, runtimeVersion);
}
if (platformVersion == null) {
metaParams.remove(DefaultMarketplaceService.META_PARAM_PLATFORM_VERSION);
} else {
Expand All @@ -194,11 +174,9 @@ public static EclipseRelease next(EclipseRelease release) {
}

public static enum Solution {
JUNO("test-entry-juno", EclipseRelease.JUNO_3_8, EclipseRelease.JUNO_SR2), //
KEPLER("test-entry-kepler", EclipseRelease.KEPLER, EclipseRelease.KEPLER_SR2), //
LUNA("test-entry-luna", EclipseRelease.LUNA, EclipseRelease.LUNA_SR2), //
MARS("test-entry-mars", EclipseRelease.MARS, EclipseRelease.MARS), //
JUNO_AND_EARLIER("test-entry-juno-and-earlier", null, EclipseRelease.JUNO_SR2), //
KEPLER_AND_EARLIER("test-entry-kepler-and-earlier", null, EclipseRelease.KEPLER_SR2), //
KEPLER_LUNA("test-entry-kepler-luna", EclipseRelease.KEPLER, EclipseRelease.LUNA_SR2), //
KEPLER_MARS("test-entry-kepler-luna-mars", EclipseRelease.KEPLER, EclipseRelease.MARS), //
Expand Down Expand Up @@ -296,20 +274,10 @@ public boolean isCompatible(EclipseRelease release) {
@Parameters(name = "{index}__{0}__with__{1}_{2}")
public static Iterable<Object[]> data() {
List<Object[]> data = new ArrayList<>();
checkSolutionReleaseBounds(data, Solution.JUNO);
checkSolutionReleaseBounds(data, Solution.KEPLER);
checkSolutionReleaseBounds(data, Solution.LUNA);
checkSolutionReleaseBounds(data, Solution.MARS);

//bug 466627
checkSolutionWithEclipse(data, "Solution should not be installable in an older release", Solution.MARS,
EclipseRelease.INDIGO, null);
checkSolutionWithEclipse(data, "Solution should not be installable in an older release", Solution.MARS,
EclipseRelease.JUNO_3_8, null);
checkSolutionWithEclipse(data, "Solution should not be installable in an older release", Solution.MARS,
EclipseRelease.JUNO, null);

checkSolutionReleaseBounds(data, Solution.JUNO_AND_EARLIER);
checkSolutionReleaseBounds(data, Solution.KEPLER_AND_EARLIER);
checkSolutionReleaseBounds(data, Solution.KEPLER_LUNA);

Expand Down Expand Up @@ -344,9 +312,6 @@ public static Iterable<Object[]> data() {
Solution.LUNA_LINUX_MACOS, EclipseRelease.LUNA, System.MACOS);
checkSolutionWithEclipse(data, "Solution should not installable in an incompatible os",
Solution.LUNA_LINUX_MACOS, EclipseRelease.LUNA, System.WIN32);
checkSolutionData(data, "Solution should have version 1.1.0 features for Juno release", Solution.MULTI_VERSION,
EclipseRelease.JUNO, System.LINUX, "1.1.0", "http://example.org/juno-kepler",
"org.example.feature.juno.kepler");
checkSolutionData(data, "Solution should have version 1.1.0 features for Kepler release",
Solution.MULTI_VERSION, EclipseRelease.KEPLER, System.MACOS, "1.1.0", "http://example.org/juno-kepler",
"org.example.feature.juno.kepler");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -85,7 +84,7 @@ private IStatus run(IMarketplaceService marketplaceService, IProgressMonitor mon
try {
ISearchResult searchResult = marketplaceService.tagged(fileExtensionTags, monitor);
nodes = orderNodesByTagSubExtensionCount(searchResult.getNodes(), fileExtensionTags);
} catch (CoreException ex) {
} catch (Exception ex) {
IStatus status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID,
NLS.bind(Messages.DiscoverFileSupportJob_discoveryFailed, getFileExtensionLabel(fileName)), ex);
// Do not return this status as it would show an error, e.g. when the user is currently offline
Expand Down Expand Up @@ -123,6 +122,9 @@ private static List<? extends INode> orderNodesByTagSubExtensionCount(List<? ext

Map<String, List<INode>> nodesByTags = new HashMap<>();
for (INode iNode : nodes) {
if (iNode.getTags() == null || iNode.getTags().getTags() == null) {
continue;
}
for (ITag nodeTag : iNode.getTags().getTags()) {
boolean foundTag = false;
for (String tag : fileExtensionTags) {
Expand Down

0 comments on commit f300da5

Please sign in to comment.