Skip to content

Commit 52a7217

Browse files
ctruedenclaude
andcommitted
Sort MimeType entries when writing .desktop files
Makes the field much easier to scan by eye. Order is irrelevant to the spec and all consumers, so this is a pure readability improvement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b3e12e6 commit 52a7217

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/org/scijava/desktop/platform/linux/DesktopFile.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ public void save() throws IOException {
172172
for (final Map.Entry<String, String> entry : entries.entrySet()) {
173173
writer.write(entry.getKey());
174174
writer.write('=');
175-
writer.write(entry.getValue());
175+
// Sort MimeType entries for readability.
176+
final String value = "MimeType".equals(entry.getKey()) ?
177+
sortedEntries(entry.getValue()) : entry.getValue();
178+
writer.write(value);
176179
writer.newLine();
177180
}
178181

@@ -334,6 +337,18 @@ public void setCategories(final String categories) {
334337
set("Categories", categories);
335338
}
336339

340+
// -- Helper methods --
341+
342+
/** Returns a semicolon-separated string with entries sorted. */
343+
private static String sortedEntries(final String value) {
344+
if (value == null || value.isEmpty()) return value;
345+
return java.util.Arrays.stream(value.split(";"))
346+
.map(String::trim)
347+
.filter(s -> !s.isEmpty())
348+
.sorted()
349+
.collect(java.util.stream.Collectors.joining(";", "", ";"));
350+
}
351+
337352
// -- MimeType handling --
338353

339354
/**

0 commit comments

Comments
 (0)