Permalink
Browse files

MODE-1286 Added more tests for the Git connector

Added several more tests for the Git connector, and changed how the
"git:history" and "git:tree" references are being created so that they
now use the commit ID rather than the tag/branch name.
  • Loading branch information...
1 parent 733e438 commit 85b135ae9112fb075018544b8f8166a87a331371 @rhauch rhauch committed Dec 5, 2012
@@ -78,8 +78,9 @@ public Document execute( Repository repository,
// Construct the references to other nodes in this source ...
ObjectId objId = commit.getId();
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchName, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchName, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
} finally {
walker.dispose();
}
@@ -113,7 +113,7 @@ public Document execute( Repository repository,
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
writer.addProperty(GitLexicon.MESSAGE, commit.getFullMessage().trim());// removes trailing whitespace
writer.addProperty(GitLexicon.PARENTS, GitCommitDetails.referencesToCommits(commit.getParents(), values));
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchOrTagOrCommitId, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
// Compute the difference between the commit and it's parent(s), and generate the diff/patch file ...
List<DiffEntry> differences = computeDifferences(commit, walker, repository);
@@ -91,6 +91,7 @@
*/
public class GitConnector extends ReadOnlyConnector implements Pageable {
+ public static final boolean DEFAULT_INCLUDE_MIME_TYPE = false;
public static final String DEFAULT_REMOTE_NAME = "origin";
private static final String GIT_DIRECTORY_NAME = ".git";
@@ -103,11 +104,18 @@
private String directoryPath;
/**
- * The string value representing the name of the remote that serves as the primary remote repository. By default this is
- * "origin". This is set via reflection and is required for this connector.
+ * The optional string value representing the name of the remote that serves as the primary remote repository. By default this
+ * is "origin". This is set via reflection.
*/
private String remoteName = DEFAULT_REMOTE_NAME;
+ /**
+ * The optional boolean value specifying whether the connector should set the "jcr:mimeType" property on the "jcr:content"
+ * child node under each "git:file" node. By default this is '{@value GitConnector#DEFAULT_INCLUDE_MIME_TYPE}'. This is set
+ * via reflection.
+ */
+ private boolean includeMimeType = DEFAULT_INCLUDE_MIME_TYPE;
+
private Repository repository;
private Git git;
private Map<String, GitFunction> functions;
@@ -189,6 +197,10 @@ protected DocumentWriter newDocumentWriter( String id ) {
return super.newDocument(id);
}
+ protected boolean includeMimeType() {
+ return includeMimeType;
+ }
+
@Override
public void shutdown() {
repository = null;
@@ -208,8 +208,7 @@ protected void addCommitsAsChildren( Git git,
}
if (actual == pageSize) {
// We wrote the maximum number of commits, so there's (probably) another page ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(spec.getId(), commitId, pageSize, totalNumberOfChildren);
+ writer.addPage(spec.getId(), commitId, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
}
}
@@ -252,8 +251,7 @@ protected void addCommitsAsPageOfChildren( Git git,
if (actual == pageSize) {
assert commitId != null;
// We wrote the maximum number of commits, so there's (probably) another page ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(pageKey.getParentId(), commitId, pageSize, totalNumberOfChildren);
+ writer.addPage(pageKey.getParentId(), commitId, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
}
} finally {
walker.dispose();
@@ -89,40 +89,40 @@ public Document execute( Repository repository,
// Generate the child references to the (latest) commits on this branch/tag ...
String branchOrTagNameOrObjectId = spec.parameter(0);
- ObjectId objId = repository.resolve(branchOrTagNameOrObjectId);
+ ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagNameOrObjectId);
RevWalk walker = new RevWalk(repository);
try {
RevCommit commit = walker.parseCommit(objId);
LogCommand command = git.log();
command.add(commit.getId());
command.setMaxCount(pageSize);
for (RevCommit rev : command.call()) {
- String commitId = rev.getId().toString();
+ String commitId = rev.getId().getName();
writer.addChild(spec.childId(commitId), commitId);
}
// Handle paging ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(spec.getParentId(), pageSize, pageSize, totalNumberOfChildren);
+ writer.addPage(spec.getParentId(), pageSize, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
} finally {
walker.dispose();
}
} else if (spec.parameterCount() == 2) {
// This is a specific commit in the history, via "/commits/{branchOrTagNameOrObjectId}/{objectId}"
+ writer.setPrimaryType(GitLexicon.COMMIT);
+
// so we need to show the commit information ...
RevWalk walker = new RevWalk(repository);
try {
- String branchOrTagOrObjectId = spec.parameter(1);
- ObjectId objId = repository.resolve(branchOrTagOrObjectId);
+ String commitId = spec.parameter(1);
+ ObjectId objId = repository.resolve(commitId);
RevCommit commit = walker.parseCommit(objId);
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
writer.addProperty(GitLexicon.AUTHOR, commit.getAuthorIdent().getName());
writer.addProperty(GitLexicon.COMMITTER, commit.getCommitterIdent().getName());
writer.addProperty(GitLexicon.COMMITTED, values.dateFrom(commit.getCommitTime()));
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
- writer.addProperty(GitLexicon.MESSAGE, commit.getFullMessage().trim());
- writer.addProperty(GitLexicon.PARENTS, GitCommitDetails.referencesToCommits(commit.getParents(), values));
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchOrTagOrObjectId, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
// And there are no children
} finally {
walker.dispose();
@@ -162,9 +162,8 @@ public Document execute( Repository repository,
}
// Handle paging ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
int nextOffset = offset + pageSize;
- writer.addPage(pageKey.getParentId(), nextOffset, pageSize, totalNumberOfChildren);
+ writer.addPage(pageKey.getParentId(), nextOffset, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
} finally {
walker.dispose();
}
@@ -49,6 +49,7 @@
public static final Name TREES = new BasicName(Namespace.URI, "trees");
public static final Name FOLDER = new BasicName(Namespace.URI, "folder");
public static final Name FILE = new BasicName(Namespace.URI, "file");
+ public static final Name RESOURCE = new BasicName(Namespace.URI, "resource");
public static final Name DETAILS = new BasicName(Namespace.URI, "details");
public static final Name DETAILED_COMMIT = new BasicName(Namespace.URI, "detailedCommit");
@@ -64,4 +65,5 @@
public static final Name HISTORY = new BasicName(Namespace.URI, "history");
public static final Name DIFF = new BasicName(Namespace.URI, "diff");
public static final Name TREE = new BasicName(Namespace.URI, "tree");
+ public static final Name DETAIL = new BasicName(Namespace.URI, "detail");
}
@@ -77,8 +77,9 @@ public Document execute( Repository repository,
// Construct the references to other nodes in this source ...
ObjectId objId = commit.getId();
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, tagName, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, tagName, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
} finally {
walker.dispose();
}
@@ -24,6 +24,7 @@
package org.modeshape.connector.git;
import java.io.IOException;
+import javax.jcr.RepositoryException;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
@@ -35,7 +36,6 @@
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.infinispan.schematic.document.Document;
import org.modeshape.jcr.JcrLexicon;
-import org.modeshape.jcr.JcrNtLexicon;
import org.modeshape.jcr.api.value.DateTime;
import org.modeshape.jcr.federation.spi.DocumentWriter;
import org.modeshape.jcr.federation.spi.PageKey;
@@ -106,6 +106,7 @@ public Document execute( Repository repository,
writer.addProperty(GitLexicon.COMMITTED, committed);
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchOrTagOrObjectId, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
// Add the top-level children of the directory ...
addInformationForPath(repository, git, writer, commit, "", spec, values);
@@ -190,7 +191,7 @@ protected void addInformationForPath( Repository repository,
String committer = folderCommit.getCommitterIdent().getName();
String author = folderCommit.getAuthorIdent().getName();
DateTime committed = values.dateFrom(folderCommit.getCommitTime());
- writer.setPrimaryType(JcrNtLexicon.FOLDER);
+ writer.setPrimaryType(GitLexicon.FOLDER);
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, folderCommit.getId().name());
@@ -217,7 +218,7 @@ protected void addInformationForPath( Repository repository,
String author = fileCommit.getAuthorIdent().getName();
DateTime committed = values.dateFrom(fileCommit.getCommitTime());
if (isContentNode) {
- writer.setPrimaryType(JcrNtLexicon.RESOURCE);
+ writer.setPrimaryType(GitLexicon.RESOURCE);
writer.addProperty(JcrLexicon.LAST_MODIFIED, committed);
writer.addProperty(JcrLexicon.LAST_MODIFIED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
@@ -241,8 +242,19 @@ protected void addInformationForPath( Repository repository,
}
}
writer.addProperty(JcrLexicon.DATA, value);
+ if (connector.includeMimeType()) {
+ try {
+ String filename = spec.parameter(spec.parameterCount() - 1); // the last is 'jcr:content'
+ String mimeType = value.getMimeType(filename);
+ if (mimeType != null) writer.addProperty(JcrLexicon.MIMETYPE, mimeType);
+ } catch (RepositoryException e) {
+ // do nothing
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
} else {
- writer.setPrimaryType(JcrNtLexicon.FILE);
+ writer.setPrimaryType(GitLexicon.FILE);
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
@@ -39,13 +39,16 @@
- git:objectId (string) mandatory protected
[git:navigable] mixin
-- git:tree (reference) mandatory protected
+- git:tree (reference) mandatory protected < 'git:folder'
[git:historical] mixin
-- git:history (reference) mandatory protected
+- git:history (reference) mandatory protected < 'git:commit'
+
+[git:detailed] mixin
+- git:detail (reference) mandatory protected < 'git:detailedCommit'
// Represents a branch or tag or commit ...
-[git:reference] > git:referenceable, git:navigable, git:historical abstract
+[git:reference] > git:referenceable, git:navigable, git:historical, git:detailed abstract
[git:committed] > git:referenceable mixin
- git:author (string) mandatory protected
@@ -54,17 +57,18 @@
- git:title (string) mandatory protected
[git:root]
++ tree (git:trees) abort protected primary // the 'tree' subgraph is considered primary
+ branches (git:branches) abort protected
+ tags (git:tags) abort protected
+ commits (git:commits) abort protected
-+ trees (git:trees) abort protected
+ commit (git:details) abort protected
//------------------------------------------------------------------------------
// The content with the branch and tag information
//------------------------------------------------------------------------------
[git:branches]
++ master (git:branch) abort protected primary // the 'master' branch is considered primary if it exists
+ * (git:branch) abort protected
[git:branch] > git:reference
@@ -84,9 +88,7 @@
[git:object]
+ * (git:commit) = git:commit abort protected
-[git:commit] > git:committed
-- git:message (string) mandatory protected
-- git:parents (reference) multiple mandatory protected
+[git:commit] > git:committed, git:navigable, git:detailed
//------------------------------------------------------------------------------
// The content showing the details of each commit
@@ -96,18 +98,24 @@
+ * (git:detailedCommit) abort protected
[git:detailedCommit] > git:commit
+- git:message (string) mandatory protected
+- git:parents (reference) multiple mandatory protected < 'git:detailedCommit'
+- git:diff (string) mandatory protected
//------------------------------------------------------------------------------
// The content with the folder and file structure of a particular object
//------------------------------------------------------------------------------
[git:trees]
++ master (git:folder) abort protected primary // the 'master' tree is considered primary if it exists
+ * (git:folder) abort protected
[git:folder] > nt:folder, git:committed, git:historical
+ * (nt:hierarchyNode,git:committed)
[git:file] > nt:file, git:committed
+[git:resource] > nt:resource, git:committed
+
Oops, something went wrong.

0 comments on commit 85b135a

Please sign in to comment.