@Override public T content() { if (content == null) { throw new IllegalStateException(type() + " does not have content"); } return content; }
@Override public T content() { if (content == null) { throw new IllegalStateException(type() + " does not have content"); } return content; }
private void ensureContent() { if (content == null) { throw new IllegalStateException(type() + " cannot have content: " + path); } }
private static boolean isPlugin(Repository metaRepo, Revision revision, String path) { if (!path.endsWith(".js")) { logger.warn("{} does not have '.js' extension; ignoring.", path); return false; } final Entry<?> e = metaRepo.getOrNull(revision, path).join(); if (e == null) { logger.warn("{} does not exist; ignoring.", path); return false; } if (e.type() != EntryType.TEXT) { logger.warn("{} is not a text file; ignoring.", path); return false; } return true; }
private static boolean isPlugin(Repository metaRepo, Revision revision, String path) { if (!path.endsWith(".js")) { logger.warn("{} does not have '.js' extension; ignoring.", path); return false; } final Entry<?> e = metaRepo.getOrNull(revision, path).join(); if (e == null) { logger.warn("{} does not exist; ignoring.", path); return false; } if (e.type() != EntryType.TEXT) { logger.warn("{} is not a text file; ignoring.", path); return false; } return true; }
@Override public void listFiles(String projectName, String repositoryName, Revision revision, String pathPattern, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .find(convert(revision), pathPattern, FIND_ALL_WITHOUT_CONTENT) .thenApply(entries -> { final List<Entry> ret = new ArrayList<>(entries.size()); entries.forEach((path, entry) -> ret.add( new Entry(path, convert(entry.type())))); return ret; }), resultHandler); }
@Override public void listFiles(String projectName, String repositoryName, Revision revision, String pathPattern, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .find(convert(revision), pathPattern, NO_FETCH_CONTENT) .thenApply(entries -> { final List<Entry> ret = new ArrayList<>(entries.size()); entries.forEach((path, entry) -> ret.add( new Entry(path, convert(entry.type())))); return ret; }), resultHandler); }
@Override public void listFiles(String projectName, String repositoryName, Revision revision, String pathPattern, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .find(convert(revision), pathPattern, FIND_ALL_WITHOUT_CONTENT) .thenApply(entries -> { final List<Entry> ret = new ArrayList<>(entries.size()); entries.forEach((path, entry) -> ret.add( new Entry(path, convert(entry.type())))); return ret; }), resultHandler); }
@Test(timeout = 10000) public void testWatchWithIdentityQuery() throws Exception { final Revision rev1 = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, textUpserts[0]).join(); final CompletableFuture<Entry<String>> f = repo.watch(rev1, Query.ofText(textPaths[0])); final Revision rev2 = repo.commit(HEAD, 0L, Author.UNKNOWN, SUMMARY, textPatches[1]).join(); final Entry<String> res = f.get(3, TimeUnit.SECONDS); assertThat(res.revision()).isEqualTo(rev2); assertThat(res.type()).isEqualTo(EntryType.TEXT); // Text must be sanitized so that the last line ends with \n. assertThat(res.content()).isEqualTo(textUpserts[1].content() + '\n'); }
@Test public void testGetFilesWithDirectory() throws Exception { final String testRootWithoutSlash = TEST_ROOT.substring(0, TEST_ROOT.length() - 1); final Map<String, Entry<?>> files = rule.client().getFiles( rule.project(), rule.repo1(), Revision.HEAD, testRootWithoutSlash + ", " + TEST_ROOT + '*').join(); assertThat(files).hasSize(NUM_FILES + 1); final Entry<?> dir = files.get(testRootWithoutSlash); assertThat(dir.type()).isEqualTo(EntryType.DIRECTORY); assertThat(dir.path()).isEqualTo(testRootWithoutSlash); assertThat(dir.hasContent()).isFalse(); assertThatThrownBy(dir::content).isInstanceOf(IllegalStateException.class); files.values().forEach(f -> { if (f.type() != EntryType.DIRECTORY) { assertThatJson(f.content()).isEqualTo("{}"); } }); }
@Override public void getFile(String projectName, String repositoryName, Revision revision, Query query, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .get(convert(revision), convert(query)) .thenApply(res -> new GetFileResult(convert(res.type()), res.contentAsText())), resultHandler); }
@Override public void getFile(String projectName, String repositoryName, Revision revision, Query query, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .get(convert(revision), convert(query)) .thenApply(res -> new GetFileResult(convert(res.type()), res.contentAsText())), resultHandler); }
@Override public void getFile(String projectName, String repositoryName, Revision revision, Query query, AsyncMethodCallback resultHandler) { handle(projectManager.get(projectName).repos().get(repositoryName) .get(convert(revision), convert(query)) .thenApply(res -> new GetFileResult(convert(res.type()), res.contentAsText())), resultHandler); }
private static void handleWatchFileResult( CompletableFuture<com.linecorp.centraldogma.common.Entry<Object>> future, AsyncMethodCallback resultHandler) { future.handle((res, cause) -> { if (cause == null) { final WatchFileResult wfr = new WatchFileResult(); wfr.setRevision(convert(res.revision())); wfr.setType(convert(res.type())); wfr.setContent(res.contentAsText()); resultHandler.onComplete(wfr); } else if (cause instanceof CancellationException) { resultHandler.onComplete(CentralDogmaConstants.EMPTY_WATCH_FILE_RESULT); } else { logAndInvokeOnError("watchFile", resultHandler, cause); } return null; }); }
static EntryDto convert(Entry<?> entry) { final EntryDto dto = new EntryDto(); dto.setRevision(entry.revision().text()); dto.setPath(entry.path()); dto.setType(entry.type().name()); dto.setContent(entry.contentAsText()); return dto; }
static EntryDto convert(Entry<?> entry) { final EntryDto dto = new EntryDto(); dto.setRevision(entry.revision().text()); dto.setPath(entry.path()); dto.setType(entry.type().name()); dto.setContent(entry.contentAsText()); return dto; }
static EntryDto convert(Entry<?> entry) { final EntryDto dto = new EntryDto(); dto.setRevision(entry.revision().text()); dto.setPath(entry.path()); dto.setType(entry.type().name()); dto.setContent(entry.contentAsText()); return dto; }