|
|
@ -23,7 +23,9 @@ import java.io.IOException; |
|
|
|
import java.nio.file.NoSuchFileException; |
|
|
|
import java.nio.file.NoSuchFileException; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -33,21 +35,43 @@ import java.util.List; |
|
|
|
public class BasePluginRepository implements PluginRepository { |
|
|
|
public class BasePluginRepository implements PluginRepository { |
|
|
|
|
|
|
|
|
|
|
|
protected final Path pluginsRoot; |
|
|
|
protected final Path pluginsRoot; |
|
|
|
|
|
|
|
|
|
|
|
protected FileFilter filter; |
|
|
|
protected FileFilter filter; |
|
|
|
|
|
|
|
protected Comparator<File> comparator; |
|
|
|
|
|
|
|
|
|
|
|
public BasePluginRepository(Path pluginsRoot) { |
|
|
|
public BasePluginRepository(Path pluginsRoot) { |
|
|
|
this.pluginsRoot = pluginsRoot; |
|
|
|
this(pluginsRoot, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public BasePluginRepository(Path pluginsRoot, FileFilter filter) { |
|
|
|
public BasePluginRepository(Path pluginsRoot, FileFilter filter) { |
|
|
|
this.pluginsRoot = pluginsRoot; |
|
|
|
this.pluginsRoot = pluginsRoot; |
|
|
|
this.filter = filter; |
|
|
|
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) { |
|
|
|
public void setFilter(FileFilter filter) { |
|
|
|
this.filter = 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 |
|
|
|
@Override |
|
|
|
public List<Path> getPluginPaths() { |
|
|
|
public List<Path> getPluginPaths() { |
|
|
|
File[] files = pluginsRoot.toFile().listFiles(filter); |
|
|
|
File[] files = pluginsRoot.toFile().listFiles(filter); |
|
|
@ -56,6 +80,10 @@ public class BasePluginRepository implements PluginRepository { |
|
|
|
return Collections.emptyList(); |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (comparator != null) { |
|
|
|
|
|
|
|
Arrays.sort(files, comparator); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Path> paths = new ArrayList<>(files.length); |
|
|
|
List<Path> paths = new ArrayList<>(files.length); |
|
|
|
for (File file : files) { |
|
|
|
for (File file : files) { |
|
|
|
paths.add(file.toPath()); |
|
|
|
paths.add(file.toPath()); |
|
|
|