Skip to content

Commit

Permalink
Sort by filename instead of path
Browse files Browse the repository at this point in the history
Currently, the scripts are loaded based on the lexicographical order of
the absolute paths of the scripts. This makes it difficult to control
the load order. This change bases the load order solely on the filename,
as was originally used before
eclipse-archived/smarthome#3855, and preserves the
ability to use scripts with the same filename.

Signed-off-by: Scott Rushworth <openhab@5iver.com>
  • Loading branch information
Scott Rushworth committed Apr 15, 2019
1 parent 5f880e1 commit af97c72
Showing 1 changed file with 12 additions and 3 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.nio.file.WatchEvent.Kind;
import java.util.Comparator;
Expand Down Expand Up @@ -252,9 +253,17 @@ private void checkFiles() {
SortedSet<URL> reimportUrls = new TreeSet<URL>(new Comparator<URL>() {
@Override
public int compare(URL o1, URL o2) {
String f1 = o1.getPath();
String f2 = o2.getPath();
return String.CASE_INSENSITIVE_ORDER.compare(f1, f2);
Path path1 = Paths.get(o1.getPath());
Path path2 = Paths.get(o2.getPath());
String name1 = path1.getFileName().toString();
String name2 = path2.getFileName().toString();
int nameCompare = name1.compareToIgnoreCase(name2);
if (nameCompare != 0) {
return nameCompare;
} else {
int pathCompare = path1.getParent().toString().compareToIgnoreCase(path2.getParent().toString());
return pathCompare;
}
}
});

Expand Down

0 comments on commit af97c72

Please sign in to comment.