diff --git a/src/main/java/genepi/haplogrep3/App.java b/src/main/java/genepi/haplogrep3/App.java index b688dd9..83bff7a 100644 --- a/src/main/java/genepi/haplogrep3/App.java +++ b/src/main/java/genepi/haplogrep3/App.java @@ -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()); diff --git a/src/main/java/genepi/haplogrep3/commands/ClusterHaplogroupsCommand.java b/src/main/java/genepi/haplogrep3/commands/ClusterHaplogroupsCommand.java index 3bcec3e..596cfb9 100644 --- a/src/main/java/genepi/haplogrep3/commands/ClusterHaplogroupsCommand.java +++ b/src/main/java/genepi/haplogrep3/commands/ClusterHaplogroupsCommand.java @@ -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); } diff --git a/src/main/java/genepi/haplogrep3/config/Configuration.java b/src/main/java/genepi/haplogrep3/config/Configuration.java index 55a78c7..4f65a1b 100644 --- a/src/main/java/genepi/haplogrep3/config/Configuration.java +++ b/src/main/java/genepi/haplogrep3/config/Configuration.java @@ -37,6 +37,8 @@ public class Configuration { private List navbar = new Vector(); + private String parent = ""; + public Configuration() { } @@ -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); } @@ -163,4 +167,7 @@ public void save(File file) throws IOException { } + public File getPluginsLocation() { + return new File(parent, "trees"); + } } diff --git a/src/main/java/genepi/haplogrep3/model/PhylotreeRepository.java b/src/main/java/genepi/haplogrep3/model/PhylotreeRepository.java index 406d66f..5c0e89b 100644 --- a/src/main/java/genepi/haplogrep3/model/PhylotreeRepository.java +++ b/src/main/java/genepi/haplogrep3/model/PhylotreeRepository.java @@ -27,12 +27,12 @@ public PhylotreeRepository() { trees = new Vector(); } - public synchronized void loadFromConfiguration(Configuration configuration, String parent) + public synchronized void loadFromConfiguration(Configuration configuration) throws FileNotFoundException, IOException { trees = new Vector(); - PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, parent); + PluginRepository repository = new PluginRepository(configuration.getRepositories(), forceUpdate, configuration.getPluginsLocation()); for (String id : configuration.getPhylotrees()) { @@ -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; diff --git a/src/main/java/genepi/haplogrep3/plugins/PluginRepository.java b/src/main/java/genepi/haplogrep3/plugins/PluginRepository.java index c7aa9c4..0c6328f 100644 --- a/src/main/java/genepi/haplogrep3/plugins/PluginRepository.java +++ b/src/main/java/genepi/haplogrep3/plugins/PluginRepository.java @@ -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> repositories = new Vector>(); - public PluginRepository(List urls, boolean forceUpdate, String parent) throws IOException { - - if (!parent.equals(".")) { - plugins_location = new File(FileUtil.path(parent, "trees")); - } - - plugins_location.mkdirs(); + public PluginRepository(List urls, boolean forceUpdate, File pluginsLocation) throws IOException { + this.pluginsLocation = pluginsLocation; + pluginsLocation.mkdirs(); for (String url : urls) { repositories.add(loadFromUrl(url, forceUpdate)); @@ -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)); @@ -132,7 +128,7 @@ private List 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); } diff --git a/src/test/java/genepi/haplogrep3/tasks/ClassificationTaskTest.java b/src/test/java/genepi/haplogrep3/tasks/ClassificationTaskTest.java index 9dfb88e..84fa84f 100644 --- a/src/test/java/genepi/haplogrep3/tasks/ClassificationTaskTest.java +++ b/src/test/java/genepi/haplogrep3/tasks/ClassificationTaskTest.java @@ -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); }