Skip to content

Handle deletion scenario for cleaning up empty exported packages#2292

Merged
HannesWell merged 1 commit into
eclipse-pde:masterfrom
nburnwal09:del_pkgEmpty
May 15, 2026
Merged

Handle deletion scenario for cleaning up empty exported packages#2292
HannesWell merged 1 commit into
eclipse-pde:masterfrom
nburnwal09:del_pkgEmpty

Conversation

@nburnwal09
Copy link
Copy Markdown
Contributor

@nburnwal09 nburnwal09 commented Apr 17, 2026

Enhancement added for handling class/type deletion scenario.
When all classes in a package are deleted via delete operation, the package(having no java files or any other resources) should be automatically removed from the Export-Package header in MANIFEST.MF if it was previously exported.

Addressing #2290

type.delete.refactor.mov
preview.part.mov

@nburnwal09
Copy link
Copy Markdown
Contributor Author

This is an enhancement to the previous task mentioned here

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

Test Results

  126 files  +   42    126 suites  +42   38m 28s ⏱️ + 16m 16s
3 502 tests ±    0  3 448 ✅ ±    0   54 💤 ± 0  0 ❌ ±0 
9 321 runs  +3 107  9 191 ✅ +3 064  130 💤 +43  0 ❌ ±0 

Results for commit 82b820a. ± Comparison against base commit 41cc62c.

♻️ This comment has been updated with latest results.

@nburnwal09
Copy link
Copy Markdown
Contributor Author

@laeubi
Kindly review this PR.
Addressed the earlier mentioned scenario here

}
}
} catch (CoreException e) {
e.printStackTrace();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Printing the stack trace instead of proper logging or handling the issue can cause the action to fail silently.

if (member instanceof IFile memberFile) {
String fileName = memberFile.getName();
String extension = memberFile.getFileExtension();
if ("class".equals(extension)) { //$NON-NLS-1$
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please check whether any constants exist in the PDE code for the file extensions that can be reused here, or create them at the class level instead of hardcoding them here.

}

@Override
public void addElement(Object element, RefactoringArguments arguments) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can the "element" be of a type other than IType and IPackageFragment? That should be handled in the 'else' case (probably via logging).

ManifestEditorContributor_externStringsActionName=Externalize Strings...

ManifestTypeRenameParticipant_composite=Rename classes referenced in plug-in manifest files
ManifestTypeDeleteParticipant_composite=Delete classes referenced in plug-in manifest files
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check the usage of this message and update it, as it's talking about deleting class references from the manifest, which isn't the case in this PR.

@Override
public void addElement(Object element, RefactoringArguments arguments) {
if (element instanceof IType type) {
fElements.put(element, type.getFullyQualifiedName());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is better to initialize "fElements" at declaration time to prevent any potential NPE here. Also, initializing it to empty in ManifestTypeDeleteParticipant#initialize will break the sharing behavior of ISharableParticipant in my view.

@Override
protected boolean initialize(Object element) {
if (element instanceof IType type) {
IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"getAncestor" can return null.

IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT);
IProject project = javaProject.getProject();
if (WorkspaceModelManager.isPluginProject(project)) {
fProject = javaProject.getProject();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"javaProject.getProject()" is called twice. Here and at line 45.

IProject project = javaProject.getProject();
if (WorkspaceModelManager.isPluginProject(project)) {
fProject = javaProject.getProject();
fElements = new HashMap<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See PDEDeleteParticipant, line 46 comment.

*/
private boolean willPackageBeEmpty(IPackageFragment pkg, List<IType> deletedTypes) throws CoreException {
IJavaElement[] javaChildren = pkg.getChildren();
if (javaChildren.length > deletedTypes.size()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the entire logic here assumes 1:1 mapping between IType and compilation units, which is not the case in JDT. For inner classes, multiple types exist in the same compilation unit. Deleting one inner class shouldn't mark the entire .java file as deleted. The logic should be updated to handle this.

@nburnwal09
Copy link
Copy Markdown
Contributor Author

@noopur2507
I have addressed all of your comments. Kindly review.

Copy link
Copy Markdown
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.

Thank you @nburnwal09 for this.
In general it looks good and works well.

But I have multiple comments below to stream-line the code.
Furthermore please make sure to properly format all new files and edited lines.

Additionally, do you think it makes sense to include the extra change from #2312 here too?
Then the changes could be reviewed together and more holistically.

@nburnwal09
Copy link
Copy Markdown
Contributor Author

Additionally, do you think it makes sense to include the extra change from #2312 here too? Then the changes could be reviewed together and more holistically.

I realised about package deletion part later(after raising this PR). Also as that is for package deletion (although the goal of removing the package from manifest is the same), I thought of taking that as a different commit.
But if you suggest, I will merge the change here so that it can be reviewed together.

@HannesWell
Copy link
Copy Markdown
Member

But if you suggest, I will merge the change here so that it can be reviewed together.

In this case I think it's similar and related enough to be together in one change.
Of course if you strongly prefer to keep it separated, that's also fine for me. It's just a suggestion from my side. :)

@nburnwal09
Copy link
Copy Markdown
Contributor Author

But if you suggest, I will merge the change here so that it can be reviewed together.

In this case I think it's similar and related enough to be together in one change. Of course if you strongly prefer to keep it separated, that's also fine for me. It's just a suggestion from my side. :)

Sure @HannesWell I will merge the changes in this PR.
Then I will make suggested updates. Thank you.

@nburnwal09 nburnwal09 changed the title Handle class deletion scenario for cleaning up empty exported packages Handle deletion scenario for cleaning up empty exported packages May 6, 2026
@nburnwal09
Copy link
Copy Markdown
Contributor Author

nburnwal09 commented May 6, 2026

@HannesWell
I have merged the package deletion part and have addressed all your suggestions.
Kindly review them.

Copy link
Copy Markdown
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.

Thank you @nburnwal09 for the updates, they look good.
I made a second pass through this considering the now included ManifestPackageDeleteParticipant and also looked again at the previous changes.
Please see the comments below.
With them resolved, I expect this to be ready.

Please squash all changes into one commit named, e.g.:
Handle class and package deletion for removing empty exported packages.

Furthermore, just a nitpick, please add new lines at the end of the new files. Github/git shows annoying markers at files without newline at the end.

Comment thread ui/org.eclipse.pde.ui/plugin.xml Outdated
@nburnwal09 nburnwal09 force-pushed the del_pkgEmpty branch 2 times, most recently from e69bc62 to 83389c3 Compare May 15, 2026 04:39
@nburnwal09
Copy link
Copy Markdown
Contributor Author

@HannesWell
Sorry for the delay. I was occupied with a hackathon at my company and couldn’t focus on this earlier.
I have now addressed all the comments. Kindly review the changes at your convenience.

@HannesWell
Copy link
Copy Markdown
Member

Sorry for the delay. I was occupied with a hackathon at my company and couldn’t focus on this earlier.
I have now addressed all the comments. Kindly review the changes at your convenience.

No problem and thanks for the update. I plan to review it later today.

@MohananRahul could you please hold-off M3 promotion planed for today? I'd like to have this (and maybe another change) included. I can run the promotion myself later today or tomorrow morning (if an extra I-build is not reasonable).

Copy link
Copy Markdown
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.

Thank you for all the updates. This is a great enhancement and I'm looking forward to have it.
It looks very good now and is ready for submission (just in time for M3).

@HannesWell HannesWell merged commit 4074bd4 into eclipse-pde:master May 15, 2026
16 of 19 checks passed
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.

4 participants