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

Quick-fix for Import-Package resolution failure due to missing mandatory attributes #678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alshamams
Copy link
Contributor

When a package is imported that has been exported with mandatory attributes, following are the possibilities:

  1. the import package is missing a mandatory attribute,
  2. the package has a mandatory attribute, but it does not match the importing package's export declaration verb,
  3. it has a mandatory attribute with the matching key, but there is a value mismatch

This commit aims to provide a quick-fix that queries the mandatory attributes and supplies them at the import site.

Fixes: #578

@github-actions
Copy link

github-actions bot commented Jul 23, 2023

Test Results

  255 files   -    29    255 suites   - 29   31m 6s ⏱️ - 12m 24s
  900 tests  - 2 627    864 ✅  - 2 603  34 💤  - 24  2 ❌ ±0 
2 454 runs   - 5 646  2 373 ✅  - 5 585  75 💤  - 65  6 ❌ +4 

For more details on these failures, see this check.

Results for commit aabd31d. ± Comparison against base commit 1d5bd08.

This pull request removes 2627 tests.
AllPDETests org.eclipse.pde.ui.tests.launcher.AllLauncherTests org.eclipse.pde.ui.tests.launcher.FeatureBasedLaunchTest ‑ Unknown test
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test1
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test2
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test3
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test4
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test5
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test6
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test7
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingApiFreezeAntTaskTests ‑ test1
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingApiFreezeAntTaskTests ‑ test2
…

♻️ This comment has been updated with latest results.

@HannesWell
Copy link
Member

HannesWell commented Jul 24, 2023

Thank you @alshamams.
From a very coarse look this seems fine.

I'll performe a more detailed review this/tomorrow evening.
Everyoneelse' review is of course welcome. :)

@HannesWell HannesWell self-requested a review July 24, 2023 06:21
@alshamams
Copy link
Contributor Author

Thank you @alshamams. From a very coarse look this seems fine.

I'll performe a more detailed review this/tomorrow evening. Everyoneelse' review is of course welcome. :)

@alshamams alshamams closed this Jul 24, 2023
@alshamams
Copy link
Contributor Author

Thank you @alshamams. From a very coarse look this seems fine.

I'll performe a more detailed review this/tomorrow evening. Everyoneelse' review is of course welcome. :)

Thank you @HannesWell !

@vik-chand
Copy link
Member

I think closed by mistake

@vik-chand vik-chand reopened this Jul 24, 2023
Copy link

@ahmed82 ahmed82 left a comment

Choose a reason for hiding this comment

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

lgtm

String[] mandatories = (String[]) exportDirectives.get(Constants.RESOLUTION_MANDATORY);
for (String mandatory : mandatories) {
if (importAttributes == null || !importAttributes.containsKey(mandatory)
|| importAttributes.get(mandatory).toString() != exportAttributes
Copy link
Member

Choose a reason for hiding this comment

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

You should (almost) never compare strings by their reference, since it is easy to have different string object with the same content.

Copy link
Member

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

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

I looked into this and in general this worked, nice job so far.
But there were a few places that needed fine-tuning (e.g. enhanced messages) or could be simplified/imported. I pushed another commit with those suggests.

What's currently missing is the handling in case there are multiple providers that export a package but with different attribute values.
In my suggestion commit I already made a change to get all exporters of a package, but it still has to be implemented that those multiple providers are considered in the error resolution.

This should be combined with the consideration of multiple mandatory/not-mandatory attributes.
I think it would be best to iterate over all exporters and create one resolution per exporter that each sets all mandatory attributes to the exporters value and set all non-mandatory attributes to the exporter's value, if the importer has another value.

Besides that a few test cases would be good. They could probably be added to BundleErrorReporterTest.

@laeubi
Copy link
Contributor

laeubi commented Aug 2, 2023

I think it would be great if this is already offered at the time when importing the package, maybe also add support for the import version as well.

@HannesWell
Copy link
Member

I think it would be great if this is already offered at the time when importing the package, maybe also add support for the import version as well.

That would be great but also would make this task much greater since the proposal would need to be enhanced as well. We could certainly do that, but I suggest we keep this focused on enhancing the error messages/quick-fix and leave the enhancement of the Import-Package proposals for a follow up.
Not suggesting to add the attributes initially also has the 'advantage' that users are very aware that they add a package-import with attributes which is usually a sign that something special is happening.

@alshamams
Copy link
Contributor Author

Hi @HannesWell ,
I have incorporated the changes as per your suggestion. Kindly look through and let me know.

Can you also have a look at the resolution window for the Quick Fix and suggest possible improvements, if any? Thanks in advance.

@HannesWell
Copy link
Member

Thanks. I will review it as soon as possible (probably in the next days).

@laeubi
Copy link
Contributor

laeubi commented Sep 6, 2023

We could certainly do that, but I suggest we keep this focused on enhancing the error messages/quick-fix and leave the enhancement of the Import-Package proposals for a follow up.

Sure but I think the main problem is that an invalid package import is added at the first place.

@alshamams you should rebase (and maybe squash) your commits here.

@alshamams
Copy link
Contributor Author

Hi @laeubi , @HannesWell,
I have just rebased my commit. Kindly review and let me know.

@HannesWell
Copy link
Member

Hi @laeubi , @HannesWell, I have just rebased my commit. Kindly review and let me know.

Sorry for the delay. Will review this ASAP.

@alshamams
Copy link
Contributor Author

Hi @laeubi , @HannesWell,
Just wanted to remind you that I await your review comments. Do let me know.🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants