Skip to content

Commit

Permalink
getBriefHistory now uses TFS Java SDK so that polling does not requir…
Browse files Browse the repository at this point in the history
…e any TFS client installation
  • Loading branch information
albanf committed Jan 27, 2014
1 parent 84b4346 commit 3d45ad2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
55 changes: 29 additions & 26 deletions src/main/java/hudson/plugins/tfs/model/Project.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hudson.plugins.tfs.model;

import com.microsoft.tfs.core.clients.versioncontrol.specs.version.ChangesetVersionSpec;
import com.microsoft.tfs.core.clients.versioncontrol.specs.version.VersionSpec;
import hudson.model.User;
import hudson.plugins.tfs.commands.BriefHistoryCommand;
import hudson.plugins.tfs.commands.GetFilesToWorkFolderCommand;
Expand Down Expand Up @@ -66,21 +68,20 @@ public String getProjectPath() {
}
return result;
}

/**
* Returns a list of change sets containing modified items.
* @param fromTimestamp the timestamp to get history from
* @param toTimestamp the timestamp to get history to
* Returns a list of changes using TFS Java SDK
* @param fromVersion the version to get the history from
* @param toVersion the version to get the history to
* @param includeFileDetails whether or not to include details of modified items
* @return a list of change sets
*/
public List<ChangeSet> getDetailedHistory(Calendar fromTimestamp, Calendar toTimestamp) throws IOException, InterruptedException, ParseException {
private List<ChangeSet> getVCCHistory(VersionSpec fromVersion, VersionSpec toVersion, boolean includeFileDetails) {
final TFSTeamProjectCollection tpc = server.getTeamProjectCollection();
final IIdentityManagementService ims = new IdentityManagementService(tpc);
final UserLookup userLookup = new TfsUserLookup(ims);
final VersionControlClient vcc = tpc.getVersionControlClient();
try {
final DateVersionSpec fromVersion = new DateVersionSpec(fromTimestamp);
final DateVersionSpec toVersion = new DateVersionSpec(toTimestamp);
final Changeset[] serverChangesets = vcc.queryHistory(
projectPath,
fromVersion,
Expand All @@ -90,17 +91,17 @@ public List<ChangeSet> getDetailedHistory(Calendar fromTimestamp, Calendar toTim
fromVersion,
toVersion,
Integer.MAX_VALUE,
true /* includeFileDetails */,
includeFileDetails /* includeFileDetails */,
true /* slotMode */,
false /* includeDownloadInfo */,
false /* sortAscending */
);
);
final List<ChangeSet> result = new ArrayList<ChangeSet>();
if (serverChangesets != null) {
for (final Changeset serverChangeset : serverChangesets) {
final ChangeSet changeSet = convertServerChangeset(serverChangeset, userLookup);
result.add(changeSet);
}
}
}
return result;
}
Expand All @@ -109,21 +110,28 @@ public List<ChangeSet> getDetailedHistory(Calendar fromTimestamp, Calendar toTim
}
}

/**
* Returns a list of change sets containing modified items.
* @param fromTimestamp the timestamp to get history from
* @param toTimestamp the timestamp to get history to
* @return a list of change sets
*/
public List<ChangeSet> getDetailedHistory(Calendar fromTimestamp, Calendar toTimestamp) throws IOException, InterruptedException, ParseException {
final DateVersionSpec fromVersion = new DateVersionSpec(fromTimestamp);
final DateVersionSpec toVersion = new DateVersionSpec(toTimestamp);
return getVCCHistory(fromVersion, toVersion, true);
}

/**
* Returns a list of change sets not containing the modified items.
* @param fromTimestamp the timestamp to get history from
* @param toTimestamp the timestamp to get history to
* @return a list of change sets
*/
public List<ChangeSet> getBriefHistory(Calendar fromTimestamp, Calendar toTimestamp) throws IOException, InterruptedException, ParseException {
BriefHistoryCommand command = new BriefHistoryCommand(server, projectPath, fromTimestamp, toTimestamp);
Reader reader = null;
try {
reader = server.execute(command.getArguments());
return command.parse(reader);
} finally {
IOUtils.closeQuietly(reader);
}
final DateVersionSpec fromVersion = new DateVersionSpec(fromTimestamp);
final DateVersionSpec toVersion = new DateVersionSpec(toTimestamp);
return getVCCHistory(fromVersion, toVersion, false);
}

/**
Expand All @@ -133,14 +141,9 @@ public List<ChangeSet> getBriefHistory(Calendar fromTimestamp, Calendar toTimest
* @return a list of change sets
*/
public List<ChangeSet> getBriefHistory(int fromChangeset, Calendar toTimestamp) throws IOException, InterruptedException, ParseException {
BriefHistoryCommand command = new BriefHistoryCommand(server, projectPath, fromChangeset, toTimestamp);
Reader reader = null;
try {
reader = server.execute(command.getArguments());
return command.parse(reader);
} finally {
IOUtils.closeQuietly(reader);
}
final ChangesetVersionSpec fromVersion = new ChangesetVersionSpec(fromChangeset);
final VersionSpec toVersion = new DateVersionSpec(toTimestamp);
return getVCCHistory(fromVersion, toVersion, false);
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/test/java/hudson/plugins/tfs/model/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,7 @@ public void assertConvertServerChangeset() throws Exception {
assertEquals("The item action was incorrect", "add", item.getAction());

}

@Test
public void assertGetBriefHistory() throws Exception {
Server server = mock(Server.class);
when(server.execute(isA(MaskedArgumentListBuilder.class))).thenReturn(new StringReader(
"Changeset User Date Comment\n" +
"--------- -------------- -------------------- ----------------------------------------------------------------------------\n" +
"\n" +
"12495 SND\\redsolo_cp 2008-jun-27 13:21:25 changed and created one\n"));
Project project = new Project(server, "$/serverpath");
List<ChangeSet> list = project.getBriefHistory(Util.getCalendar(2008, 06, 01), Util.getCalendar(2008, 07, 01));
assertNotNull("The returned list was null", list);
assertEquals("The number of change sets in list was incorrect", 1, list.size());
verify(server).execute(isA(MaskedArgumentListBuilder.class));
}

@Test
public void assertGetBriefHistoryClosesReader() throws Exception {
Reader spy = spy(new StringReader(""));
Server server = mock(Server.class);
when(server.execute(isA(MaskedArgumentListBuilder.class))).thenReturn(spy);
new Project(server, "$/serverpath").getBriefHistory(Util.getCalendar(2008, 06, 01), Util.getCalendar(2008, 07, 01));

verify(spy).close();
}

@Test
public void assertGetFiles() throws Exception {
Server server = mock(Server.class);
Expand Down

0 comments on commit 3d45ad2

Please sign in to comment.