@Test public void testBrowse() throws Exception { localTmpDir = new File(tmpDir, "localTmpDir-" + timestamp); Properties parameters = new Properties(); parameters.setProperty(GitStorageConnector.REPO_DEST_PROPERTY, localTmpDir.getAbsolutePath()); parameters.setProperty(GitStorageConnector.REPO_PATH_PROPERTY, myGitDir.getAbsolutePath()); connector = new GitStorageConnector(parameters); StorageTree<String> structure = connector.browse(); String tree = structure.printTree(); assertEquals(TREE, tree); }
@Override public StorageTree<String> browse() throws Exception { cloneRepository(); StorageTree<String> storageTree = new StorageTree<String>(); Repository repository = git.getRepository(); Ref head = repository.findRef(Constants.HEAD); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); StorageParent<String> parent = storageTree; int currentDepth = 0; while (treeWalk.next()) { if (treeWalk.getDepth() < currentDepth) { currentDepth = treeWalk.getDepth(); parent = parent.getParent(); } StorageNode<String> child = parent.addChild(treeWalk.getNameString()); if (treeWalk.isSubtree()) { parent = child; treeWalk.enterSubtree(); currentDepth = treeWalk.getDepth(); } } } } return storageTree; }
GitStorageConnector implements StorageConnector { @Override public StorageTree<String> browse() throws Exception { cloneRepository(); StorageTree<String> storageTree = new StorageTree<String>(); Repository repository = git.getRepository(); Ref head = repository.findRef(Constants.HEAD); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); StorageParent<String> parent = storageTree; int currentDepth = 0; while (treeWalk.next()) { if (treeWalk.getDepth() < currentDepth) { currentDepth = treeWalk.getDepth(); parent = parent.getParent(); } StorageNode<String> child = parent.addChild(treeWalk.getNameString()); if (treeWalk.isSubtree()) { parent = child; treeWalk.enterSubtree(); currentDepth = treeWalk.getDepth(); } } } } return storageTree; } }
GitStorageConnector implements StorageConnector { @Override public StorageTree<String> browse() throws Exception { cloneRepository(); StorageTree<String> storageTree = new StorageTree<String>(); Repository repository = git.getRepository(); Ref head = repository.findRef(Constants.HEAD); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); StorageParent<String> parent = storageTree; int currentDepth = 0; while (treeWalk.next()) { if (treeWalk.getDepth() < currentDepth) { currentDepth = treeWalk.getDepth(); parent = parent.getParent(); } StorageNode<String> child = parent.addChild(treeWalk.getNameString()); if (treeWalk.isSubtree()) { parent = child; treeWalk.enterSubtree(); currentDepth = treeWalk.getDepth(); } } } } return storageTree; } GitStorageConnector(Properties parameters); }
GitStorageConnector implements StorageConnector { @Override public StorageTree<String> browse() throws Exception { cloneRepository(); StorageTree<String> storageTree = new StorageTree<String>(); Repository repository = git.getRepository(); Ref head = repository.findRef(Constants.HEAD); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); StorageParent<String> parent = storageTree; int currentDepth = 0; while (treeWalk.next()) { if (treeWalk.getDepth() < currentDepth) { currentDepth = treeWalk.getDepth(); parent = parent.getParent(); } StorageNode<String> child = parent.addChild(treeWalk.getNameString()); if (treeWalk.isSubtree()) { parent = child; treeWalk.enterSubtree(); currentDepth = treeWalk.getDepth(); } } } } return storageTree; } GitStorageConnector(Properties parameters); @Override StorageConnectorId getId(); @Override Set<Descriptor> getDescriptors(); String getPath(); String getBranch(); String getDestination(); String getFilePath(Properties parameters); @Override boolean refresh(); @Override void write(Exportable artifact, UnitOfWork transaction, Properties parameters); @Override InputStream read(Properties parameters); @Override StorageTree<String> browse(); @Override void dispose(); }
GitStorageConnector implements StorageConnector { @Override public StorageTree<String> browse() throws Exception { cloneRepository(); StorageTree<String> storageTree = new StorageTree<String>(); Repository repository = git.getRepository(); Ref head = repository.findRef(Constants.HEAD); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); StorageParent<String> parent = storageTree; int currentDepth = 0; while (treeWalk.next()) { if (treeWalk.getDepth() < currentDepth) { currentDepth = treeWalk.getDepth(); parent = parent.getParent(); } StorageNode<String> child = parent.addChild(treeWalk.getNameString()); if (treeWalk.isSubtree()) { parent = child; treeWalk.enterSubtree(); currentDepth = treeWalk.getDepth(); } } } } return storageTree; } GitStorageConnector(Properties parameters); @Override StorageConnectorId getId(); @Override Set<Descriptor> getDescriptors(); String getPath(); String getBranch(); String getDestination(); String getFilePath(Properties parameters); @Override boolean refresh(); @Override void write(Exportable artifact, UnitOfWork transaction, Properties parameters); @Override InputStream read(Properties parameters); @Override StorageTree<String> browse(); @Override void dispose(); static final String REPO_PATH_PROPERTY; static final String REPO_DEST_PROPERTY; static final String REPO_BRANCH_PROPERTY; static final String REPO_PRIVATE_KEY; static final String REPO_PASSPHRASE; static final String REPO_KNOWN_HOSTS_ID; static final String REPO_USERNAME; static final String REPO_PASSWORD; static final String AUTHOR_NAME_PROPERTY; static final String AUTHOR_EMAIL_PROPERTY; }