Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the conflict of bundle when updating. #385

Closed
wants to merge 1 commit into from

Conversation

yaohaizh
Copy link
Contributor

@yaohaizh yaohaizh commented Oct 13, 2017

Signed-off-by: Yaohai Zheng [email protected]

Fix the issue: microsoft/vscode-java-debug#54

In this change, it makes sure the extension symbolic name is unique and doesn't support multiple version of bundles. These limitation should not be problems for jdt.ls extensions.
@fbricon @gorkem @tsmaeder

@yaohaizh yaohaizh changed the title Fix the issue conflict of bundle when updating. Fix the conflict of bundle when updating. Oct 13, 2017

private static BundleInfo getBundleInfo(String bundleLocation) throws IOException {
JarFile jarFile = new JarFile(bundleLocation);
Manifest manifest = jarFile.getManifest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to check if manifest != null

}

return new BundleInfo(bundleVersion, symbolicName);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static BundleInfo getBundleInfo(String bundleLocation) throws IOException {
	try (JarFile jarFile = new JarFile(bundleLocation)){
		Manifest manifest = jarFile.getManifest();
		if (manifest != null) {
			Attributes mainAttributes = manifest.getMainAttributes();
			String bundleVersion = mainAttributes.getValue(Constants.BUNDLE_VERSION);
			String symbolicName = mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
			if (StringUtils.isNotBlank(symbolicName) && symbolicName.indexOf(";") >= 0) {
				symbolicName = symbolicName.substring(0, symbolicName.indexOf(";"));
			}							
			return new BundleInfo(bundleVersion, symbolicName);
		}
	}
	return null;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, throw IOException instead of returning null

@@ -57,17 +84,27 @@ public static void loadBundles(Collection<String> bundleLocations) throws CoreEx

String location = getBundleLocation(bundleLocation, true);

Bundle bundle = context.getBundle(location);
boolean needInstall = true;
BundleInfo bundleInfo = getBundleInfo(bundleLocation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if bundleInfo is null?

@fbricon
Copy link
Contributor

fbricon commented Oct 13, 2017

Other than making getBundleInfo(...) more robust, this PR looks good. We'll include it in the next release.

@fbricon fbricon added this to the Mid October 2017 milestone Oct 13, 2017
@yaohaizh
Copy link
Contributor Author

Update the changes.

@fbricon
Copy link
Contributor

fbricon commented Oct 16, 2017

Merged as 7dc20a2 (after adding a null check on bundle version)

@fbricon fbricon closed this Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants