Skip to content

Commit

Permalink
Match subversion repositories based on UUIDs instead of paths
Browse files Browse the repository at this point in the history
This allows a number of case which we previously did not support

- different URL schemes between RB and Eclipse
- different username component between RB and Eclipse
- different paths between RB and Eclipse ( not all start at root )

Fixes #90: Svn repository mismatch because of different usernames
  • Loading branch information
rombert committed Jan 13, 2013
1 parent 3bf4bad commit 6bc9880
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
Expand Up @@ -238,6 +238,16 @@ protected PagedResult<Repository> doLoadInternal(int start, int maxResults, IPro

return loader.doLoad();
}

private void loadRepositoryInfo(Repository repository, IProgressMonitor monitor) throws ReviewboardException {

ReviewboardQueryBuilder queryBuilder = new ReviewboardQueryBuilder()
.descend(PATH_REPOSITORIES, repository.getId()).descend(PATH_INFO);

Map<String, String> repositoryInfo = reviewboardReader.readRepositoryInfo(httpClient.executeGet(queryBuilder.createQuery(), monitor));

repository.setRepositoryInfo(repositoryInfo);
}

private List<User> getUsers(IProgressMonitor monitor) throws ReviewboardException {

Expand Down Expand Up @@ -416,11 +426,19 @@ public void updateRepositoryData(boolean force, IProgressMonitor monitor) throws
// repositories with small data sets will not need very accurate progress reporting anyway
clientData.setUsers(getUsers(Policy.subMonitorFor(monitor, 90)));

clientData.setGroups(getReviewGroups(Policy.subMonitorFor(monitor, 5)));
clientData.setGroups(getReviewGroups(Policy.subMonitorFor(monitor, 4)));

clientData.setRepositories(getRepositories(Policy.subMonitorFor(monitor, 4)));
List<Repository> repositories = getRepositories(Policy.subMonitorFor(monitor, 4));

IProgressMonitor repositoryInfoMonitor = Policy.subMonitorFor(monitor,1);

for ( Repository repository : repositories )
if ( repository.getTool() == RepositoryType.Subversion)
loadRepositoryInfo(repository, repositoryInfoMonitor);

clientData.setRepositories(repositories);

clientData.setTimeZone(getTimeZone(Policy.subMonitorFor(monitor, 1)));
clientData.setTimeZone(getTimeZone(repositoryInfoMonitor));

clientData.lastupdate = new Date().getTime();
} finally {
Expand Down
Expand Up @@ -58,6 +58,7 @@

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
* Class for converting Review Board API call responses (JSON format) to Java objects.
Expand Down Expand Up @@ -284,6 +285,29 @@ public PagedResult<Repository> readRepositories(String source) throws Reviewboar
throw new ReviewboardException(e.getMessage(), e);
}
}

public Map<String, String> readRepositoryInfo(String source) throws ReviewboardException {

Map<String, String> repositoryInfo = Maps.newHashMap();

try {
JSONObject rootObject = checkedGetJSonRootObject(source);
JSONObject info = rootObject.getJSONObject("info");


for ( Iterator<?> keyIterator = info.keys(); keyIterator.hasNext(); ) {
String key = (String) keyIterator.next();
String value = info.getString(key);

repositoryInfo.put(key, value);
}

return repositoryInfo;
} catch (JSONException e) {
throw new ReviewboardException(e.getMessage(), e);
}

}

public ReviewRequest readReviewRequest(String source) throws ReviewboardException {

Expand Down
Expand Up @@ -38,6 +38,7 @@
package org.review_board.ereviewboard.core.model;

import java.io.Serializable;
import java.util.Map;


/**
Expand All @@ -47,10 +48,16 @@
*/
public class Repository implements Serializable {

/**
* Property name for the 'uuid' property found for Subversion repositories
*/
public static final String PN_UUID= "uuid";

private int id;
private String name;
private RepositoryType tool;
private String path;
private Map<String, String> repositoryInfo;

/**
* @return the id
Expand Down Expand Up @@ -108,6 +115,14 @@ public void setPath(String path) {
this.path = path;
}

public Map<String, String> getRepositoryInfo() {
return repositoryInfo;
}

public void setRepositoryInfo(Map<String, String> properties) {
this.repositoryInfo = properties;
}

@Override
public String toString() {
return name;
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.tigris.subversion.subclipse.core.resources.LocalResourceStatus;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNInfo;
import org.tigris.subversion.svnclientadapter.SVNClientException;

/**
Expand Down Expand Up @@ -168,6 +169,20 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
Assert.isNotNull(svnProvider, "No " + SVNTeamProvider.class.getSimpleName() + " for " + _project);

ISVNLocalResource projectSvnResource = SVNWorkspaceRoot.getSVNResourceFor(_project);
String localRepositoryUuid;
try {
ISVNInfo info = projectSvnResource.getRepository().getSVNClient().getInfo(projectSvnResource.getUrl());
localRepositoryUuid = info.getUuid();
} catch (SVNException e1) {
throw new InvocationTargetException(e1, "Unable to find uuid for repository at" + projectSvnResource.getRepository().getUrl());
} catch (SVNClientException e1) {
throw new InvocationTargetException(e1, "Unable to find uuid for repository at" + projectSvnResource.getRepository().getUrl());
}

if ( localRepositoryUuid == null ) {
setErrorMessage("No uuid found for local SVN repository, unable to continue");
return;
}

ReviewboardClientManager clientManager = ReviewboardCorePlugin.getDefault().getConnector().getClientManager();
ReviewboardClient rbClient = null;
Expand All @@ -176,7 +191,8 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte

setSvnRepositoryLocation(projectSvnResource.getRepository());

Activator.getDefault().trace(TraceLocation.MAIN, "Local repository is " + getSvnRepositoryLocation().getRepositoryRoot().toString());
Activator.getDefault().trace(TraceLocation.MAIN, "Local repository is " + getSvnRepositoryLocation().getRepositoryRoot().toString() +
", uuid is " + localRepositoryUuid);

List<String> clientUrls = clientManager.getAllClientUrl();
if ( clientUrls.isEmpty() ) {
Expand Down Expand Up @@ -220,7 +236,8 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte

hasSvnRepos = true;

if ( getSvnRepositoryLocation().getRepositoryRoot().toString().equals(repository.getPath()) ) {
if ( localRepositoryUuid.equals(repository.getRepositoryInfo().get(Repository.PN_UUID)) ) {

reviewBoardRepository = repository;
taskRepository = repositoryCandidate;
rbClient = client;
Expand Down
Expand Up @@ -50,6 +50,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import org.junit.Before;
Expand Down Expand Up @@ -187,6 +188,16 @@ public void readRepositories() throws Exception {

assertThat("repositories[1].tool", repositories.get(1).getTool(), is(RepositoryType.ClearCase));
}

@Test
public void readRepositoryInfo() throws Exception {

// http://www.reviewboard.org/docs/manual/1.7/webapi/2.0/resources/repository-info/
Map<String, String> repositoryInfo = reader.readRepositoryInfo(readJsonTestResource("repository_info.json"));

assertThat("repositoryInfo.size", repositoryInfo.size(), is(3));
assertThat("repositoryInfo.uuid", repositoryInfo.get("uuid"), is("5efc13c4-1f27-0410-8691-ff2d1f55687e"));
}

@Test
public void readReviewRequests() throws Exception {
Expand Down
@@ -0,0 +1,8 @@
{
"info": {
"root_url": "http://reviewboard.googlecode.com/svn",
"url": "http://reviewboard.googlecode.com/svn",
"uuid": "5efc13c4-1f27-0410-8691-ff2d1f55687e"
},
"stat": "ok"
}

0 comments on commit 6bc9880

Please sign in to comment.