Skip to content

Commit

Permalink
Merge pull request #17 from jenkinsci/useTfsSdk
Browse files Browse the repository at this point in the history
Switch to TFS SDK and use it for obtaining detailed changeset info
  • Loading branch information
olivierdagenais committed Oct 23, 2013
2 parents df7be69 + 509c497 commit 9996e24
Show file tree
Hide file tree
Showing 93 changed files with 1,093 additions and 92 deletions.
70 changes: 69 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<version>1.436</version>
</parent>

<artifactId>tfs</artifactId>
Expand All @@ -13,6 +13,37 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Team+Foundation+Server+Plugin</url>
<licenses>
<license><name>MIT license</name><comments>All source code is under the MIT license.</comments></license>
<license>
<name>Microsoft Visual Studio Team Foundation Server 2012 Software Development Kit for Java license terms</name>
<url>http://download.microsoft.com/download/5/9/9/5993F89B-AEF0-4381-9CEE-D3D7BA9EA33B/license.html</url>
</license>
<license>
<name>
Apache Commons Codec, Apache Commons Logging, Apache HttpClient, Apache Commons Lang, Apache log4j,
and Apache ServiceMix are licensed by the Apache Foundation under the Apache License, Version 2.0.
</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
<license>
<name>
The Apache Foundation's Xerces Java Parser project is licensed by the
Apache Foundation under the Apache License, Version 1.1.
</name>
<url>http://www.apache.org/licenses/LICENSE-1.1</url>
</license>
<license>
<name>
The Woodstox XML Processor and the StAX API are licensed by their authors under the Apache License, Version 2.0.
</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url></license>
<license>
<name>This product includes software from the Hypersonic SQL DB http://hsqldb.org/.</name>
<url>http://www.hsqldb.org/web/hsqlLicense.html</url>
</license>
<license>
<name>This product includes software from the Cryptix project http://www.cryptix.org/.</name>
<url>http://cryptix.org/LICENSE.TXT</url>
</license>
</licenses>

<developers>
Expand Down Expand Up @@ -77,6 +108,43 @@
</build>

<dependencies>
<!--
com.microsoft.tfs.sdk includes its dependencies inline, some of which conflict with those of jenkins-core.
We have to repeat dependencies here to make sure they are considered before those inside the TFS SDK.
-->
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-war</artifactId>
<version>1.436</version>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-core</artifactId>
<version>1.436</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>1.436</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>ui-samples-plugin</artifactId>
<version>1.436</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.microsoft.tfs.sdk</groupId>
<artifactId>com.microsoft.tfs.sdk</artifactId>
<version>11.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/com.microsoft.tfs.sdk-11.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
93 changes: 52 additions & 41 deletions src/main/java/hudson/plugins/tfs/TeamFoundationServerScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,47 +154,50 @@ private String substituteBuildParameter(Run<?,?> run, String text) {
@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspaceFilePath, BuildListener listener, File changelogFile) throws IOException, InterruptedException {
Server server = createServer(new TfTool(getDescriptor().getTfExecutable(), launcher, listener, workspaceFilePath), build);
WorkspaceConfiguration workspaceConfiguration = new WorkspaceConfiguration(server.getUrl(), getWorkspaceName(build, Computer.currentComputer()), getProjectPath(build), getLocalPath());

// Check if the configuration has changed
if (build.getPreviousBuild() != null) {
BuildWorkspaceConfiguration nodeConfiguration = new BuildWorkspaceConfigurationRetriever().getLatestForNode(build.getBuiltOn(), build.getPreviousBuild());
if ((nodeConfiguration != null) &&
nodeConfiguration.workspaceExists()
&& (! workspaceConfiguration.equals(nodeConfiguration))) {
listener.getLogger().println("Deleting workspace as the configuration has changed since a build was performed on this computer.");
new RemoveWorkspaceAction(workspaceConfiguration.getWorkspaceName()).remove(server);
nodeConfiguration.setWorkspaceWasRemoved();
nodeConfiguration.save();
}
}

build.addAction(workspaceConfiguration);
CheckoutAction action = new CheckoutAction(workspaceConfiguration.getWorkspaceName(), workspaceConfiguration.getProjectPath(), workspaceConfiguration.getWorkfolder(), isUseUpdate());
try {
List<ChangeSet> list = action.checkout(server, workspaceFilePath, (build.getPreviousBuild() != null ? build.getPreviousBuild().getTimestamp() : null), build.getTimestamp());
ChangeSetWriter writer = new ChangeSetWriter();
writer.write(list, changelogFile);
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
}

try {
setWorkspaceChangesetVersion(null);
String projectPath = workspaceConfiguration.getProjectPath();
Project project = server.getProject(projectPath);
// TODO: even better would be to call this first, then use the changeset when calling checkout
int buildChangeset = project.getRemoteChangesetVersion(build.getTimestamp());
setWorkspaceChangesetVersion(Integer.toString(buildChangeset, 10));
WorkspaceConfiguration workspaceConfiguration = new WorkspaceConfiguration(server.getUrl(), getWorkspaceName(build, Computer.currentComputer()), getProjectPath(build), getLocalPath());

// by adding this action, we prevent calcRevisionsFromBuild() from being called
build.addAction(new TFSRevisionState(buildChangeset, projectPath));
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
// Check if the configuration has changed
if (build.getPreviousBuild() != null) {
BuildWorkspaceConfiguration nodeConfiguration = new BuildWorkspaceConfigurationRetriever().getLatestForNode(build.getBuiltOn(), build.getPreviousBuild());
if ((nodeConfiguration != null) &&
nodeConfiguration.workspaceExists()
&& (! workspaceConfiguration.equals(nodeConfiguration))) {
listener.getLogger().println("Deleting workspace as the configuration has changed since a build was performed on this computer.");
new RemoveWorkspaceAction(workspaceConfiguration.getWorkspaceName()).remove(server);
nodeConfiguration.setWorkspaceWasRemoved();
nodeConfiguration.save();
}
}

build.addAction(workspaceConfiguration);
CheckoutAction action = new CheckoutAction(workspaceConfiguration.getWorkspaceName(), workspaceConfiguration.getProjectPath(), workspaceConfiguration.getWorkfolder(), isUseUpdate());
try {
List<ChangeSet> list = action.checkout(server, workspaceFilePath, (build.getPreviousBuild() != null ? build.getPreviousBuild().getTimestamp() : null), build.getTimestamp());
ChangeSetWriter writer = new ChangeSetWriter();
writer.write(list, changelogFile);
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
}

try {
setWorkspaceChangesetVersion(null);
String projectPath = workspaceConfiguration.getProjectPath();
Project project = server.getProject(projectPath);
// TODO: even better would be to call this first, then use the changeset when calling checkout
int buildChangeset = project.getRemoteChangesetVersion(build.getTimestamp());
setWorkspaceChangesetVersion(Integer.toString(buildChangeset, 10));

// by adding this action, we prevent calcRevisionsFromBuild() from being called
build.addAction(new TFSRevisionState(buildChangeset, projectPath));
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
}
} finally {
server.close();
}

return true;
}

Expand All @@ -217,6 +220,8 @@ public boolean pollChanges(AbstractProject hudsonProject, Launcher launcher, Fil
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
} finally {
server.close();
}
}
}
Expand Down Expand Up @@ -255,9 +260,13 @@ public boolean processWorkspaceBeforeDeletion(AbstractProject<?, ?> project, Fil
LogTaskListener listener = new LogTaskListener(logger, Level.INFO);
Launcher launcher = node.createLauncher(listener);
Server server = createServer(new TfTool(getDescriptor().getTfExecutable(), launcher, listener, workspace), lastRun);
if (new RemoveWorkspaceAction(configuration.getWorkspaceName()).remove(server)) {
configuration.setWorkspaceWasRemoved();
configuration.save();
try {
if (new RemoveWorkspaceAction(configuration.getWorkspaceName()).remove(server)) {
configuration.setWorkspaceWasRemoved();
configuration.save();
}
} finally {
server.close();
}
}
return true;
Expand Down Expand Up @@ -463,6 +472,8 @@ protected PollingResult compareRemoteRevisionWith(
} catch (ParseException pe) {
listener.fatalError(pe.getMessage());
throw new AbortException();
} finally {
server.close();
}
}
}
58 changes: 43 additions & 15 deletions src/main/java/hudson/plugins/tfs/model/ChangeSet.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,35 @@
@ExportedBean(defaultVisibility=999)
public class ChangeSet extends hudson.scm.ChangeLogSet.Entry {

private User authorUser;
private User checkedInByUser;
private String version;
private String user;
private String userString;
private String domain;
private Date date;
private String comment;
private List<Item> items;
private String checkedInByUser;
private String checkedInByUserString;

public ChangeSet() {
this("", null, "", "");
}

public ChangeSet(String version, Date date, String user, String comment) {
public ChangeSet(String version, Date date, String userString, String comment) {
this.version = version;
this.date = date;
this.comment = comment;
items = new ArrayList<Item>();
setUser(user);
setUser(userString);
}

public ChangeSet(String version, Date date, User author, String comment) {
this.version = version;
this.date = date;
this.authorUser = author;
this.userString = author.getId();
this.comment = comment;
items = new ArrayList<Item>();
}

@Override
Expand All @@ -52,7 +63,10 @@ public ChangeLogSet getParent() {

@Override
public User getAuthor() {
return User.get(user);
if(authorUser == null) {
authorUser = User.get(userString);
}
return authorUser;
}

@Override
Expand All @@ -76,16 +90,16 @@ public String getDomain() {

@Exported
public String getUser() {
return user;
return userString;
}

public void setUser(String user) {
String[] split = user.split("\\\\");
if (split.length == 2) {
this.domain = split[0];
this.user = split[1];
this.userString = split[1];
} else {
this.user = user;
this.userString = user;
this.domain = null;
}
}
Expand All @@ -108,16 +122,30 @@ public void setComment(String comment) {
this.comment = comment;
}

public void setCheckedInBy(String user) {
checkedInByUser = user;
}
public void setCheckedInBy(String checkedInByUserString) {
if (checkedInByUserString != null) {
String[] split = checkedInByUserString.split("\\\\");
if (split.length == 2) {
this.checkedInByUserString = split[1];
} else {
this.checkedInByUserString = checkedInByUserString;
}
}
}

public String getCheckedInBy() {
return checkedInByUser;
}
public String getCheckedInBy() {
return checkedInByUserString;
}

public User getCheckedInByUser() {
return User.get(checkedInByUser);
if (checkedInByUser == null) {
checkedInByUser = User.get(checkedInByUserString);
}
return checkedInByUser;
}

public void setCheckedInByUser(User checkedInBy) {
this.checkedInByUser = checkedInBy;
}

@Exported
Expand Down

0 comments on commit 9996e24

Please sign in to comment.