From: tcofoegbu Date: Thu, 4 Jun 2015 09:42:08 +0000 (+0100) Subject: JAL-1756 bug-fix X-Git-Tag: Release_2_10_0~640^2~3^2 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=492340a6ceedebe4c496d8a4673eb2f1ff835b38 JAL-1756 bug-fix --- diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index ff55400..b49c2e0 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -29,16 +29,18 @@ public class BioJsHTMLOutput private static TreeMap bioJsMSAVersions; + public static final String DEFAULT_DIR = System.getProperty("user.home") + + File.separatorChar + ".biojs_templates" + File.separatorChar; + public static final String BJS_TEMPLATES_LOCAL_DIRECTORY = jalview.bin.Cache - .getDefault("biojs_template_directory", "/biojs_templates/"); + .getDefault("biojs_template_directory", DEFAULT_DIR); public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache .getDefault( "biojs_template_git_repo", "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json"); - public BioJsHTMLOutput(AlignmentPanel ap, - FeatureRenderer fr1) + public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1) { if (ap != null) { @@ -149,8 +151,7 @@ public class BioJsHTMLOutput public void refreshBioJSVersionsInfo(String dirName) throws URISyntaxException { - URL url = getClass().getResource(dirName); - File directory = new File(url.toURI()); + File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY); Objects.requireNonNull(dirName, "dirName MUST not be null!"); Objects.requireNonNull(directory, "directory MUST not be null!"); TreeMap versionFileMap = new TreeMap(); @@ -182,21 +183,29 @@ public class BioJsHTMLOutput public void updateBioJS() { - try - { - String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO); - BioJSRepositoryPojo release = new BioJSRepositoryPojo(gitRepoPkgJson); - syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release); - refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY); - } catch (URISyntaxException e) + Thread updateThread = new Thread() { - e.printStackTrace(); - } + public void run() + { + try + { + String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO); + BioJSRepositoryPojo release = new BioJSRepositoryPojo( + gitRepoPkgJson); + syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release); + refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY); + } catch (URISyntaxException e) + { + e.printStackTrace(); + } + } + }; + updateThread.start(); + } public void syncUpdates(String localDir, BioJSRepositoryPojo repo) - throws URISyntaxException { for (BioJSReleasePojo bjsRelease : repo.getReleases()) { @@ -207,23 +216,22 @@ public class BioJsHTMLOutput { releaseFile = "Latest_BioJsMSA_" + releaseVersion + ".txt"; } - File file = null; - URL url = getClass().getResource( - BJS_TEMPLATES_LOCAL_DIRECTORY + releaseFile); - if (url == null) - { - String path = getClass().getResource(BJS_TEMPLATES_LOCAL_DIRECTORY) - .getPath(); - System.out.println("------> " + path); - file = new File(path + releaseFile); - } - else + + File biojsDirectory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY); + if (!biojsDirectory.exists()) { - file = new File(url.toURI()); + if (!biojsDirectory.mkdirs()) + { + System.out.println("Couldn't create local directory : " + + BJS_TEMPLATES_LOCAL_DIRECTORY); + return; + } } + File file = new File(BJS_TEMPLATES_LOCAL_DIRECTORY + releaseFile); if (!file.exists()) { + PrintWriter out = null; try {