|
|
|
@ -23,7 +23,9 @@ import java.io.IOException;
|
|
|
|
|
import java.nio.file.NoSuchFileException; |
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.Comparator; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -33,21 +35,43 @@ import java.util.List;
|
|
|
|
|
public class BasePluginRepository implements PluginRepository { |
|
|
|
|
|
|
|
|
|
protected final Path pluginsRoot; |
|
|
|
|
|
|
|
|
|
protected FileFilter filter; |
|
|
|
|
protected Comparator<File> comparator; |
|
|
|
|
|
|
|
|
|
public BasePluginRepository(Path pluginsRoot) { |
|
|
|
|
this.pluginsRoot = pluginsRoot; |
|
|
|
|
this(pluginsRoot, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public BasePluginRepository(Path pluginsRoot, FileFilter filter) { |
|
|
|
|
this.pluginsRoot = pluginsRoot; |
|
|
|
|
this.filter = filter; |
|
|
|
|
|
|
|
|
|
// last modified file is first
|
|
|
|
|
this.comparator = new Comparator<File>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int compare(File o1, File o2) { |
|
|
|
|
return (int) (o2.lastModified() - o1.lastModified()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setFilter(FileFilter filter) { |
|
|
|
|
this.filter = filter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set a {@link File} {@link Comparator} used to sort the listed files from {@code pluginsRoot}. |
|
|
|
|
* This comparator is used in {@link #getPluginPaths()} method. |
|
|
|
|
* By default is used a file comparator that returns the last modified files first. |
|
|
|
|
* If you don't want a file comparator, then call this method with {@code null}. |
|
|
|
|
*/ |
|
|
|
|
public void setComparator(Comparator<File> comparator) { |
|
|
|
|
this.comparator = comparator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<Path> getPluginPaths() { |
|
|
|
|
File[] files = pluginsRoot.toFile().listFiles(filter); |
|
|
|
@ -56,6 +80,10 @@ public class BasePluginRepository implements PluginRepository {
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (comparator != null) { |
|
|
|
|
Arrays.sort(files, comparator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Path> paths = new ArrayList<>(files.length); |
|
|
|
|
for (File file : files) { |
|
|
|
|
paths.add(file.toPath()); |
|
|
|
|