Skip to content

Commit

Permalink
use cachedDir for local registry cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpoelen committed Mar 20, 2020
1 parent bf6e303 commit 9b256f0
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> namespaces = new ArrayList<>();

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
getTmpDir(),
createInputStreamFactory());

NodeFactoryNull nodeFactory = new NodeFactoryForDataset(writer, new DatasetProcessorForTSV());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void run(PrintStream out) {
DatasetRegistry registry = DatasetRegistryUtil.forCacheDirOrLocalDir(
getCacheDir(),
getWorkDir(),
getTmpDir(),
createInputStreamFactory());

InteractionWriter serializer = createSerializer(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void checkCacheOrRemote(List<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> namespaces = registry.findNamespaces();
return namespaces.isEmpty();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9b256f0

Please sign in to comment.