From 9b256f07ca04d53dcb16f6487bd166d73ee5d274 Mon Sep 17 00:00:00 2001 From: jhpoelen Date: Fri, 20 Mar 2020 11:55:11 -0700 Subject: [PATCH] use cachedDir for local registry cache --- .../elton/cmd/CmdDatasets.java | 2 +- .../elton/cmd/CmdDefaultParams.java | 11 ----------- .../elton/cmd/CmdInteractions.java | 1 - .../elton/cmd/CmdList.java | 2 +- .../elton/cmd/CmdNames.java | 2 +- .../elton/cmd/CmdNanoPubs.java | 1 - .../elton/cmd/CmdReview.java | 2 +- .../elton/cmd/DatasetRegistryFactoryImpl.java | 1 - .../elton/util/DatasetRegistryUtil.java | 13 ++++++++----- .../elton/cmd/CmdReviewTest.java | 14 ++++++-------- 10 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDatasets.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDatasets.java index 54a56d4..3772dbb 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDatasets.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDatasets.java @@ -45,7 +45,7 @@ void run(PrintStream out) { serializer.writeHeader(); } - DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), getTmpDir(), createInputStreamFactory()); + DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), createInputStreamFactory()); try { CmdUtil.handleNamespaces(registry, diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDefaultParams.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDefaultParams.java index fd77e20..89290fe 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDefaultParams.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdDefaultParams.java @@ -15,9 +15,6 @@ abstract class CmdDefaultParams implements Runnable { @Parameter(names = {"--cache-dir", "-c"}, description = "cache directory") private String cacheDir = "./datasets"; - @Parameter(names = {"--tmp-dir"}, description = "tmp directory") - private String tmpDir = "./.elton/tmp"; - @Parameter(description = "[namespace1] [namespace2] ...") private List namespaces = new ArrayList<>(); @@ -69,14 +66,6 @@ public void setCacheDir(String cacheDir) { this.cacheDir = cacheDir; } - public String getTmpDir() { - return tmpDir; - } - - public String setTmpDir(String tmpDir) { - return this.tmpDir = tmpDir; - } - public void setWorkDir(URI workingDir) { this.workDir = workingDir; } diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdInteractions.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdInteractions.java index b4451d2..767821a 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdInteractions.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdInteractions.java @@ -189,7 +189,6 @@ void run(PrintStream out) { DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir( getCacheDir(), getWorkDir(), - getTmpDir(), createInputStreamFactory()); NodeFactoryNull nodeFactory = new NodeFactoryForDataset(writer, new DatasetProcessorForTSV()); diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdList.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdList.java index b1ad5e2..336e093 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdList.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdList.java @@ -24,7 +24,7 @@ public void run() { public void run(PrintStream out) { InputStreamFactoryLogging inputStreamFactory = createInputStreamFactory(); - DatasetRegistry registryLocal = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), getTmpDir(), inputStreamFactory); + DatasetRegistry registryLocal = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), inputStreamFactory); DatasetRegistry registry = isOnline() ? new DatasetRegistryProxy(Arrays.asList(new DatasetRegistryZenodo(inputStreamFactory), new DatasetRegistryGitHubArchive(inputStreamFactory), registryLocal)) : registryLocal; diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNames.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNames.java index 0eb7f80..cb07100 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNames.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNames.java @@ -35,7 +35,7 @@ void run(PrintStream out) { writer.writeHeader(); } - DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), getTmpDir(), createInputStreamFactory()); + DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(getCacheDir(), getWorkDir(), createInputStreamFactory()); NodeFactory nodeFactory = createFactory(writer); CmdUtil.handleNamespaces(registry, nodeFactory, getNamespaces(), "listing taxa", getStderr(), new NullImportLogger()); } diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNanoPubs.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNanoPubs.java index 7394794..9f58467 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNanoPubs.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdNanoPubs.java @@ -39,7 +39,6 @@ void run(PrintStream out) { DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir( getCacheDir(), getWorkDir(), - getTmpDir(), createInputStreamFactory()); InteractionWriter serializer = createSerializer(out); diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java index 4af1679..0859ccb 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/CmdReview.java @@ -113,7 +113,7 @@ private void checkCacheOrRemote(List namespaces, InputStreamFactory inpu } private void reviewLocal(URI workDir, InputStreamFactory inputStreamFactory) throws StudyImporterException { - DatasetRegistry registryLocal = DatasetRegistryUtil.forLocalDir(workDir, getTmpDir(), inputStreamFactory); + DatasetRegistry registryLocal = DatasetRegistryUtil.forLocalDir(workDir, getCacheDir(), inputStreamFactory); review("local", registryLocal, inputStreamFactory); } diff --git a/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java b/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java index 14f9f0a..e829cab 100644 --- a/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java +++ b/src/main/java/org/globalbioticinteractions/elton/cmd/DatasetRegistryFactoryImpl.java @@ -9,7 +9,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; diff --git a/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java b/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java index 420ff0f..f8b2abb 100644 --- a/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java +++ b/src/main/java/org/globalbioticinteractions/elton/util/DatasetRegistryUtil.java @@ -43,10 +43,13 @@ private static CacheFactory getCacheFactoryLocal(String cacheDir, InputStreamFac } public static DatasetRegistry forCacheDir(String cacheDir, InputStreamFactory streamFactory) { - return new DatasetRegistryLocal(cacheDir, getCacheFactoryLocal(cacheDir, streamFactory), streamFactory); + return new DatasetRegistryLocal( + cacheDir, + getCacheFactoryLocal(cacheDir, streamFactory), + streamFactory); } - public static boolean emptyFinder(DatasetRegistry registry) { + private static boolean isEmpty(DatasetRegistry registry) { try { Collection namespaces = registry.findNamespaces(); return namespaces.isEmpty(); @@ -55,10 +58,10 @@ public static boolean emptyFinder(DatasetRegistry registry) { } } - public static DatasetRegistry forCacheDirOrLocalDir(String cacheDir, URI workDir, String tmpDir, InputStreamFactory streamFactory) { + public static DatasetRegistry forCacheDirOrLocalDir(String cacheDir, URI workDir, InputStreamFactory streamFactory) { DatasetRegistry registry = forCacheDir(cacheDir, streamFactory); - if (emptyFinder(registry)) { - registry = forLocalDir(workDir, tmpDir, streamFactory); + if (isEmpty(registry)) { + registry = forLocalDir(workDir, cacheDir, streamFactory); } return registry; } diff --git a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdReviewTest.java b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdReviewTest.java index 503b5e4..1dada69 100644 --- a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdReviewTest.java +++ b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdReviewTest.java @@ -3,7 +3,6 @@ import com.beust.jcommander.JCommander; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.Range; import org.apache.commons.lang3.StringUtils; import org.codehaus.jackson.map.ObjectMapper; import org.eol.globi.data.LogUtil; @@ -26,7 +25,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.MissingFormatArgumentException; import java.util.UUID; import static junit.framework.TestCase.fail; @@ -38,12 +36,12 @@ public class CmdReviewTest { - private String testTmpDir = "target/test-cache"; + private String testCacheDir = "target/test-cache"; private CmdReview cmdReview; @Before public void init() { - this.testTmpDir = "target/test-cache/" + UUID.randomUUID(); + this.testCacheDir = "target/test-cache/" + UUID.randomUUID(); this.cmdReview = new CmdReview(); cmdReview.setDateFactory(() -> new Date(0)); cmdReview.setReviewerName("elton-dev"); @@ -52,11 +50,11 @@ public void init() { @After public void cleanCache() { - FileUtils.deleteQuietly(new File(getTestTmpDir())); + FileUtils.deleteQuietly(new File(getTestCacheDir())); } - private String getTestTmpDir() { - return testTmpDir; + private String getTestCacheDir() { + return testCacheDir; } @Test @@ -136,7 +134,7 @@ private void runCheck(String localTestPath, ByteArrayOutputStream errOs, ByteArr PrintStream out = new PrintStream(outOs); cmdReview.setStdout(out); cmdReview.setWorkDir(Paths.get(localTestPath).toUri()); - cmdReview.setTmpDir(getTestTmpDir()); + cmdReview.setCacheDir(getTestCacheDir()); cmdReview.setMaxLines(maxLines); cmdReview.setDesiredReviewCommentTypes(commentTypes); cmdReview.run();