resourcePage = iterator.next();
- emptyPage = resourcePage.isEmpty();
- if (emptyPage)
- break;
- for (E resource : resourcePage) {
- resource = register(resource);
- if (resource == null)
- continue;
- resources.put(getId(resource), resource);
- }
- }
- // Set page to count value if first call after call to reset()
- if (count > 1) {
- page = count;
- count = 1;
- }
-
- page++;
- } catch (NoSuchPageException e) {
- hasMore = false;
- throw e.getCause();
- }
- hasMore = iterator.hasNext() && !emptyPage;
- return hasMore;
- }
-
- /**
- * Are more pages available to request?
- *
- * @return true if the last call to {@link #next()} returned true, false
- * otherwise
- */
- public boolean hasMore() {
- return hasMore;
- }
-
- /**
- * Callback to register a fetched resource before it is stored in this pager
- *
- * Sub-classes may override
- *
- * @param resource
- * @return resource
- */
- protected E register(final E resource) {
- return resource;
- }
-
- /**
- * Get id for resource
- *
- * @param resource
- * @return id
- */
- protected abstract Object getId(E resource);
-
- /**
- * Create iterator to return given page and size
- *
- * @param page
- * @param size
- * @return iterator
- */
- public abstract PageIterator createIterator(final int page,
- final int size);
-}
diff --git a/app/src/main/java/com/github/mobile/core/UrlMatcher.java b/app/src/main/java/com/github/mobile/core/UrlMatcher.java
deleted file mode 100644
index eab3cd63f..000000000
--- a/app/src/main/java/com/github/mobile/core/UrlMatcher.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core;
-
-import android.text.TextUtils;
-
-import java.util.regex.Matcher;
-
-/**
- * Base URL matcher with utilities for sub-classes to use
- */
-public abstract class UrlMatcher {
-
- /**
- * Is given input URL a match?
- *
- * This method ignores null and empty URLs and does not reset the matcher
- * with them
- *
- * @param url
- * @param matcher
- * @return true if matcher matches, false otherwise
- */
- protected boolean isMatch(final String url, final Matcher matcher) {
- return !TextUtils.isEmpty(url) && matcher.reset(url).matches();
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/code/FullTree.java b/app/src/main/java/com/github/mobile/core/code/FullTree.java
deleted file mode 100644
index bd5f32ae7..000000000
--- a/app/src/main/java/com/github/mobile/core/code/FullTree.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.code;
-
-import static java.lang.String.CASE_INSENSITIVE_ORDER;
-import static org.eclipse.egit.github.core.TreeEntry.TYPE_BLOB;
-import static org.eclipse.egit.github.core.TreeEntry.TYPE_TREE;
-import android.text.TextUtils;
-
-import com.github.mobile.core.commit.CommitUtils;
-import com.github.mobile.core.ref.RefUtils;
-
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.eclipse.egit.github.core.Reference;
-import org.eclipse.egit.github.core.Tree;
-import org.eclipse.egit.github.core.TreeEntry;
-
-/**
- * {@link Tree} with additional information
- */
-public class FullTree {
-
- /**
- * Entry in a tree
- */
- public static class Entry implements Comparable {
-
- /**
- * Parent folder
- */
- public final Folder parent;
-
- /**
- * Raw tree entry
- */
- public final TreeEntry entry;
-
- /**
- * Name
- */
- public final String name;
-
- private Entry() {
- this.parent = null;
- this.entry = null;
- this.name = null;
- }
-
- private Entry(TreeEntry entry, Folder parent) {
- this.entry = entry;
- this.parent = parent;
- this.name = CommitUtils.getName(entry.getPath());
- }
-
- @Override
- public int compareTo(Entry another) {
- return CASE_INSENSITIVE_ORDER.compare(name, another.name);
- }
- }
-
- /**
- * Folder in a tree
- */
- public static class Folder extends Entry {
-
- /**
- * Sub folders
- */
- public final Map folders = new TreeMap(
- CASE_INSENSITIVE_ORDER);
-
- /**
- * Files
- */
- public final Map files = new TreeMap(
- CASE_INSENSITIVE_ORDER);
-
- private Folder() {
- super();
- }
-
- private Folder(TreeEntry entry, Folder parent) {
- super(entry, parent);
- }
-
- private void addFile(TreeEntry entry, String[] pathSegments, int index) {
- if (index == pathSegments.length - 1) {
- Entry file = new Entry(entry, this);
- files.put(file.name, file);
- } else {
- Folder folder = folders.get(pathSegments[index]);
- if (folder != null)
- folder.addFile(entry, pathSegments, index + 1);
- }
- }
-
- private void addFolder(TreeEntry entry, String[] pathSegments, int index) {
- if (index == pathSegments.length - 1) {
- Folder folder = new Folder(entry, this);
- folders.put(folder.name, folder);
- } else {
- Folder folder = folders.get(pathSegments[index]);
- if (folder != null)
- folder.addFolder(entry, pathSegments, index + 1);
- }
- }
-
- private void add(final TreeEntry entry) {
- String type = entry.getType();
- String path = entry.getPath();
- if (TextUtils.isEmpty(path))
- return;
-
- if (TYPE_BLOB.equals(type)) {
- String[] segments = path.split("/");
- if (segments.length > 1) {
- Folder folder = folders.get(segments[0]);
- if (folder != null)
- folder.addFile(entry, segments, 1);
- } else if (segments.length == 1) {
- Entry file = new Entry(entry, this);
- files.put(file.name, file);
- }
- } else if (TYPE_TREE.equals(type)) {
- String[] segments = path.split("/");
- if (segments.length > 1) {
- Folder folder = folders.get(segments[0]);
- if (folder != null)
- folder.addFolder(entry, segments, 1);
- } else if (segments.length == 1) {
- Folder folder = new Folder(entry, this);
- folders.put(folder.name, folder);
- }
- }
- }
- }
-
- /**
- * Tree
- */
- public final Tree tree;
-
- /**
- * Root folder
- */
- public final Folder root;
-
- /**
- * Reference
- */
- public final Reference reference;
-
- /**
- * Branch where tree is present
- */
- public final String branch;
-
- /**
- * Create tree with branch
- *
- * @param tree
- * @param reference
- */
- public FullTree(final Tree tree, final Reference reference) {
- this.tree = tree;
- this.reference = reference;
- this.branch = RefUtils.getName(reference);
-
- root = new Folder();
- List entries = tree.getTree();
- if (entries != null && !entries.isEmpty())
- for (TreeEntry entry : entries)
- root.add(entry);
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/code/RefreshBlobTask.java b/app/src/main/java/com/github/mobile/core/code/RefreshBlobTask.java
deleted file mode 100644
index a71213f23..000000000
--- a/app/src/main/java/com/github/mobile/core/code/RefreshBlobTask.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.code;
-
-import android.accounts.Account;
-import android.content.Context;
-
-import com.github.mobile.accounts.AuthenticatedUserTask;
-import com.google.inject.Inject;
-
-import org.eclipse.egit.github.core.Blob;
-import org.eclipse.egit.github.core.Repository;
-import org.eclipse.egit.github.core.service.DataService;
-
-/**
- * Task to refresh a blob
- */
-public class RefreshBlobTask extends AuthenticatedUserTask {
-
- private final Repository repository;
-
- private final String blobSha;
-
- @Inject
- private DataService service;
-
- /**
- * @param repository
- * @param blobSha
- * @param context
- */
- public RefreshBlobTask(Repository repository, String blobSha,
- Context context) {
- super(context);
-
- this.repository = repository;
- this.blobSha = blobSha;
- }
-
- @Override
- protected Blob run(Account account) throws Exception {
- return service.getBlob(repository, blobSha);
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/code/RefreshTreeTask.java b/app/src/main/java/com/github/mobile/core/code/RefreshTreeTask.java
deleted file mode 100644
index 723372cfc..000000000
--- a/app/src/main/java/com/github/mobile/core/code/RefreshTreeTask.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.code;
-
-import android.accounts.Account;
-import android.content.Context;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.github.mobile.accounts.AuthenticatedUserTask;
-import com.github.mobile.core.ref.RefUtils;
-import com.google.inject.Inject;
-
-import java.io.IOException;
-
-import org.eclipse.egit.github.core.Commit;
-import org.eclipse.egit.github.core.Reference;
-import org.eclipse.egit.github.core.Repository;
-import org.eclipse.egit.github.core.Tree;
-import org.eclipse.egit.github.core.service.DataService;
-import org.eclipse.egit.github.core.service.RepositoryService;
-
-/**
- * Task to load the tree for a repository's default branch
- */
-public class RefreshTreeTask extends AuthenticatedUserTask {
-
- private static final String TAG = "RefreshTreeTask";
-
- private final Repository repository;
-
- private final Reference reference;
-
- @Inject
- private RepositoryService repoService;
-
- @Inject
- private DataService dataService;
-
- /**
- * Create task to refresh repository's tree
- *
- * @param repository
- * @param reference
- * @param context
- */
- public RefreshTreeTask(final Repository repository,
- final Reference reference, final Context context) {
- super(context);
-
- this.repository = repository;
- this.reference = reference;
- }
-
- private boolean isValidRef(Reference ref) {
- return ref != null && ref.getObject() != null
- && !TextUtils.isEmpty(ref.getObject().getSha());
- }
-
- @Override
- protected FullTree run(Account account) throws Exception {
- Reference ref = reference;
- String branch = RefUtils.getPath(ref);
- if (branch == null) {
- branch = repository.getMasterBranch();
- if (TextUtils.isEmpty(branch)) {
- branch = repoService.getRepository(repository)
- .getMasterBranch();
- if (TextUtils.isEmpty(branch))
- throw new IOException(
- "Repository does not have master branch");
- }
- branch = "heads/" + branch;
- }
-
- if (!isValidRef(ref)) {
- ref = dataService.getReference(repository, branch);
- if (!isValidRef(ref))
- throw new IOException(
- "Reference does not have associated commit SHA-1");
- }
-
- Commit commit = dataService.getCommit(repository, ref.getObject()
- .getSha());
- if (commit == null || commit.getTree() == null
- || TextUtils.isEmpty(commit.getTree().getSha()))
- throw new IOException("Commit does not have associated tree SHA-1");
-
- Tree tree = dataService.getTree(repository, commit.getTree().getSha(),
- true);
- return new FullTree(tree, ref);
- }
-
- @Override
- protected void onException(Exception e) throws RuntimeException {
- super.onException(e);
-
- Log.d(TAG, "Exception loading tree", e);
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/commit/CommitCompareTask.java b/app/src/main/java/com/github/mobile/core/commit/CommitCompareTask.java
deleted file mode 100644
index 933cd672a..000000000
--- a/app/src/main/java/com/github/mobile/core/commit/CommitCompareTask.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.commit;
-
-import android.accounts.Account;
-import android.content.Context;
-import android.util.Log;
-
-import com.github.mobile.accounts.AuthenticatedUserTask;
-import com.google.inject.Inject;
-
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.RepositoryCommitCompare;
-import org.eclipse.egit.github.core.service.CommitService;
-
-/**
- * Task to compare two commits
- */
-public class CommitCompareTask extends
- AuthenticatedUserTask {
-
- private static final String TAG = "CommitCompareTask";
-
- @Inject
- private CommitService service;
-
- private final IRepositoryIdProvider repository;
-
- private final String base;
-
- private final String head;
-
- /**
- * @param context
- * @param repository
- * @param base
- * @param head
- */
- public CommitCompareTask(Context context, IRepositoryIdProvider repository,
- String base, String head) {
- super(context);
-
- this.repository = repository;
- this.base = base;
- this.head = head;
- }
-
- @Override
- protected RepositoryCommitCompare run(Account account) throws Exception {
- return service.compare(repository, base, head);
- }
-
- @Override
- protected void onException(Exception e) throws RuntimeException {
- super.onException(e);
-
- Log.d(TAG, "Exception loading commit compare", e);
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/commit/CommitMatch.java b/app/src/main/java/com/github/mobile/core/commit/CommitMatch.java
deleted file mode 100644
index 4a4dfe995..000000000
--- a/app/src/main/java/com/github/mobile/core/commit/CommitMatch.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.commit;
-
-import org.eclipse.egit.github.core.Repository;
-
-/**
- * Match for a commit in a repository
- */
-public class CommitMatch {
-
- /**
- * Repository of commit
- */
- public final Repository repository;
-
- /**
- * SHA-1 of commit
- */
- public final String commit;
-
- /**
- * Create match
- *
- * @param repository
- * @param commit
- */
- public CommitMatch(final Repository repository, final String commit) {
- this.repository = repository;
- this.commit = commit;
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/commit/CommitPager.java b/app/src/main/java/com/github/mobile/core/commit/CommitPager.java
deleted file mode 100644
index f50ef9847..000000000
--- a/app/src/main/java/com/github/mobile/core/commit/CommitPager.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.commit;
-
-import com.github.mobile.core.ResourcePager;
-
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.RepositoryCommit;
-
-/**
- * Pager over commits
- */
-public abstract class CommitPager extends ResourcePager {
-
- private final IRepositoryIdProvider repository;
-
- private final CommitStore store;
-
- /**
- * Create pager
- *
- * @param repository
- * @param store
- */
- public CommitPager(final IRepositoryIdProvider repository,
- final CommitStore store) {
- this.repository = repository;
- this.store = store;
- }
-
- @Override
- protected Object getId(final RepositoryCommit resource) {
- return resource.getSha();
- }
-
- @Override
- protected RepositoryCommit register(final RepositoryCommit resource) {
- return store.addCommit(repository, resource);
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/commit/CommitStore.java b/app/src/main/java/com/github/mobile/core/commit/CommitStore.java
deleted file mode 100644
index 35372db29..000000000
--- a/app/src/main/java/com/github/mobile/core/commit/CommitStore.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.commit;
-
-import com.github.mobile.core.ItemStore;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.RepositoryCommit;
-import org.eclipse.egit.github.core.service.CommitService;
-
-/**
- * Store of commits
- */
-public class CommitStore extends ItemStore {
-
- private final Map> commits = new HashMap>();
-
- private final CommitService service;
-
- /**
- * Create commit store
- *
- * @param service
- */
- public CommitStore(final CommitService service) {
- this.service = service;
- }
-
- /**
- * Get commit
- *
- * @param repo
- * @param id
- * @return commit or null if not in store
- */
- public RepositoryCommit getCommit(final IRepositoryIdProvider repo,
- final String id) {
- final ItemReferences repoCommits = commits.get(repo
- .generateId());
- return repoCommits != null ? repoCommits.get(id) : null;
- }
-
- /**
- * Add commit to store
- *
- * @param repo
- * @param commit
- * @return commit
- */
- public RepositoryCommit addCommit(IRepositoryIdProvider repo,
- RepositoryCommit commit) {
- RepositoryCommit current = getCommit(repo, commit.getSha());
- if (current != null) {
- current.setAuthor(commit.getAuthor());
- current.setCommit(commit.getCommit());
- current.setCommitter(commit.getCommitter());
- current.setFiles(commit.getFiles());
- current.setParents(commit.getParents());
- current.setSha(commit.getSha());
- current.setStats(commit.getStats());
- current.setUrl(commit.getUrl());
- return current;
- } else {
- String repoId = repo.generateId();
- ItemReferences repoCommits = commits.get(repoId);
- if (repoCommits == null) {
- repoCommits = new ItemReferences();
- commits.put(repoId, repoCommits);
- }
- repoCommits.put(commit.getSha(), commit);
- return commit;
- }
- }
-
- /**
- * Refresh commit
- *
- * @param repo
- * @param id
- * @return refreshed commit
- * @throws IOException
- */
- public RepositoryCommit refreshCommit(final IRepositoryIdProvider repo,
- final String id) throws IOException {
- return addCommit(repo, service.getCommit(repo, id));
- }
-}
diff --git a/app/src/main/java/com/github/mobile/core/commit/CommitUriMatcher.java b/app/src/main/java/com/github/mobile/core/commit/CommitUriMatcher.java
deleted file mode 100644
index 389b6253b..000000000
--- a/app/src/main/java/com/github/mobile/core/commit/CommitUriMatcher.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2012 GitHub Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.mobile.core.commit;
-
-import android.net.Uri;
-import android.text.TextUtils;
-
-import com.github.mobile.core.repo.RepositoryUtils;
-
-import java.util.List;
-
-import org.eclipse.egit.github.core.Repository;
-import org.eclipse.egit.github.core.User;
-
-/**
- * Parses a {@link CommitMatch} from a {@link Uri}
- */
-public class CommitUriMatcher {
-
- /**
- * Attempt to parse a {@link CommitMatch} from the given {@link Uri}
- *
- * @param uri
- * @return {@link CommitMatch} or null if unparseable
- */
- public static CommitMatch getCommit(Uri uri) {
- List