vi-eclipse / Eclipse-JDT

Umbrella repository for managing a backlog of Eclipse-JDT-related features/issues
0 stars 0 forks source link

Entries of JAR Description Files Saved While Exporting a JAR Have no Deterministic Order #22

Closed HeikoKlare closed 11 months ago

HeikoKlare commented 1 year ago

Current Behavior

The JAR Exporter allows to export JAR files from a selection of resources in the workspace. The description for such an export can be saved in JAR description files (*.jardesc). From these descriptions, an export can be started:

Image

The export allows to save the description file, e.g., at the original location to update it with a modified selection of elements to be exported into the JAR:

Image

The generated *.jardesc file is an XML file containing the selected elements, e.g.:

<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
    <javaElement handleIdentifier="=JarDescriptionDemo/test=/test=/true=/"/>
    <javaElement handleIdentifier="=JarDescriptionDemo/src"/>
</selectedElements>

These elements are in arbitrary order, which can change upon every export.

Expected Behavior

In order to ease merging of these *.jardesc files, the order of the selected elements should be deterministic, e.g., simply by their name.

Additional Information

The write functionality for the JAR description file is defined in xmlWriteSelectedElements of org.eclipse.jdt.internal.ui.jarpackager.JarPackageWriter using the org.eclipse.jdt.ui.jarpackager.JarPackageData, in particular its selectedElements. These elements are initialized in the getSelectedElements method of the org.eclipse.jdt.internal.ui.jarpackager.JarPackageWizardPage, which, in turn, uses the getSelectedResources method of the WizardExportResourcesPage. The selected elements are extracted from values of a HashMap, which results in random orders. It should be sufficient to sort the elements either in the getSelectedResources method:

resourcesToExport.sort(Comparator.comparing(Object::toString));

or in the getSelectedElements method:

List<Object> resources = getSelectedResources();
resources.sort(Comparator.comparing(Object::toString));
return resources.toArray();
HeikoKlare commented 11 months ago

PR provided: eclipse-jdt/eclipse.jdt.ui#1025

HeikoKlare commented 11 months ago

PR has been merged.