Skip to content

Commit

Permalink
Move repository location to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Jun 5, 2024
1 parent cf1b784 commit e179c71
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/java/genepi/haplogrep3/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void loadConfiguration(String configFilename) {

configuration = Configuration.loadFromFile(configFile, parent);
treeRepository = new PhylotreeRepository();
treeRepository.loadFromConfiguration(configuration, parent);
treeRepository.loadFromConfiguration(configuration);

jobQueue = new JobQueue(configuration.getThreads());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public Integer call() throws Exception {
public Phylotree loadPhylotree(String id) throws FileNotFoundException, IOException {
PhylotreeRepository repository = new PhylotreeRepository();
Configuration configuration = Configuration.loadFromFile(new File(CONFIG_FILE), "");
String parent = ".";
repository.loadFromConfiguration(configuration, parent);
repository.loadFromConfiguration(configuration);
return repository.getById(id);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/genepi/haplogrep3/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Configuration {

private List<NavbarLink> navbar = new Vector<NavbarLink>();

private String parent = "";

public Configuration() {

}
Expand Down Expand Up @@ -146,6 +148,8 @@ public static Configuration loadFromFile(File file, String parent) throws IOExce
Configuration configuration = reader.read(Configuration.class);
reader.close();

configuration.parent = parent;

for (Dataset dataset : configuration.getExamples()) {
dataset.updateParent(parent);
}
Expand All @@ -163,4 +167,7 @@ public void save(File file) throws IOException {

}

public File getPluginsLocation() {
return new File(parent, "trees");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public PhylotreeRepository() {
trees = new Vector<Phylotree>();
}

public synchronized void loadFromConfiguration(Configuration configuration, String parent)
public synchronized void loadFromConfiguration(Configuration configuration)
throws FileNotFoundException, IOException {

trees = new Vector<Phylotree>();

PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, parent);
PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, configuration.getPluginsLocation());

for (String id : configuration.getPhylotrees()) {

Expand Down Expand Up @@ -61,9 +61,7 @@ public synchronized void loadFromConfiguration(Configuration configuration, Stri

public void install(String id, Configuration configuration) throws IOException {

String parent = ".";

PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, parent);
PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, configuration.getPluginsLocation());

Phylotree phylotree = null;

Expand Down
16 changes: 6 additions & 10 deletions src/main/java/genepi/haplogrep3/plugins/PluginRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ public class PluginRepository {

public static String LATEST_VERSION = null;

public File plugins_location = new File("trees");
public File pluginsLocation = new File("trees");

private List<List<Plugin>> repositories = new Vector<List<Plugin>>();

public PluginRepository(List<String> urls, boolean forceUpdate, String parent) throws IOException {

if (!parent.equals(".")) {
plugins_location = new File(FileUtil.path(parent, "trees"));
}

plugins_location.mkdirs();
public PluginRepository(List<String> urls, boolean forceUpdate, File pluginsLocation) throws IOException {
this.pluginsLocation = pluginsLocation;
pluginsLocation.mkdirs();

for (String url : urls) {
repositories.add(loadFromUrl(url, forceUpdate));
Expand Down Expand Up @@ -90,7 +86,7 @@ public InstalledPlugin resolveRelease(PluginRelease release) throws IOException

String filename = "tree.yaml";

File pluginPath = new File(plugins_location, FileUtil.path(id, release.getVersion()));
File pluginPath = new File(pluginsLocation, FileUtil.path(id, release.getVersion()));
InstalledPlugin plugin = new InstalledPlugin();
plugin.setRelease(release);
plugin.setPath(new File(pluginPath.getAbsolutePath(), filename));
Expand Down Expand Up @@ -132,7 +128,7 @@ private List<Plugin> loadFromUrl(String url, boolean forceUpdate) throws IOExcep
File indexFile = null;

if (isHttpProtocol(url)) {
indexFile = new File(plugins_location, getNameForUrl(url) + ".yaml");
indexFile = new File(pluginsLocation, getNameForUrl(url) + ".yaml");
if (!indexFile.exists() || forceUpdate) {
download(url, indexFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class ClassificationTaskTest {
public Phylotree loadPhylotree(String id) throws FileNotFoundException, IOException {
PhylotreeRepository repository = new PhylotreeRepository();
Configuration configuration = Configuration.loadFromFile(new File(CONFIG_FILE), "");
String parent = ".";
repository.loadFromConfiguration(configuration, parent);
repository.loadFromConfiguration(configuration);
return repository.getById(id);
}

Expand Down

0 comments on commit e179c71

Please sign in to comment.