Skip to content

Commit

Permalink
Added TFSTeamProjectCollection field and initializing in constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdagenais committed Oct 4, 2013
1 parent cc25487 commit 6efa14d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/hudson/plugins/tfs/model/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.httpclient.Credentials;
import com.microsoft.tfs.core.httpclient.DefaultNTCredentials;
import com.microsoft.tfs.core.httpclient.UsernamePasswordCredentials;
import com.microsoft.tfs.core.util.CredentialsUtils;
import com.microsoft.tfs.core.util.URIUtils;

public class Server implements ServerConfigurationProvider {

private final String url;
Expand All @@ -17,12 +25,33 @@ public class Server implements ServerConfigurationProvider {
private Workspaces workspaces;
private Map<String, Project> projects = new HashMap<String, Project>();
private final TfTool tool;
private final TFSTeamProjectCollection tpc;

public Server(TfTool tool, String url, String username, String password) {
this.tool = tool;
this.url = url;
this.userName = username;
this.userPassword = password;
final URI uri = URIUtils.newURI(url);

Credentials credentials = null;
// In case no user name is provided and the current platform supports
// default credentials, use default credentials
if ((username == null || username.length() == 0) && CredentialsUtils.supportsDefaultCredentials()) {
credentials = new DefaultNTCredentials();
}
else if (username != null && password != null) {
credentials = new UsernamePasswordCredentials(username, password);
}

if (credentials != null) {
// TODO: TFSTeamProjectCollection implements Closeable
// and should be disposed as soon as no longer needed.
this.tpc = new TFSTeamProjectCollection(uri, credentials);
}
else {
this.tpc = null;
}
}

Server(String url) {
Expand All @@ -36,6 +65,11 @@ public Project getProject(String projectPath) {
return projects.get(projectPath);
}

public TFSTeamProjectCollection getTeamProjectCollection()
{
return this.tpc;
}

public Workspaces getWorkspaces() {
if (workspaces == null) {
workspaces = new Workspaces(this);
Expand Down

0 comments on commit 6efa14d

Please sign in to comment.