Adding repository browsers to the SCM is useful if there are web based repository browsers that can display more information about the change set or the SCM in general. Examples of repository browsers are FishEye, viewvc and sventon.
SCM implementation
Class changes
SCMRepositoryBrowser
Create a class, that extends RepositoryBrowser<ChangeLogSet.Entry>
for your SCM that will act as the base class for each repository browser implementation. The abstract method is getChangeSetLink()
that returns an URL. But if your repository browser can show other information, such as difference of a file between change sets or the file itself, then you should add abstract methods in your repository browser class.
SCM class
Add a field for storing the repository browser.
public class TeamFoundationServerScm extends SCM { private TeamFoundationServerRepositoryBrowser repositoryBrowser; .... @Override public TeamFoundationServerRepositoryBrowser getBrowser() { return repositoryBrowser; } }
SCM Descriptor changes
The configuration of the SCM class must also be updated to support the new repository browser. The constructor must set the repository browser responsible for the SCM and the newInstance()
method must be overridden to retrieve which repository browser to use.
public static class DescriptorImpl extends SCMDescriptor<TeamFoundationServerScm> { protected DescriptorImpl() { super(TeamFoundationServerScm.class, TeamFoundationServerRepositoryBrowser.class); load(); } .... @Override public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException { TeamFoundationServerScm scm = (TeamFoundationServerScm) super.newInstance(req, formData); scm.repositoryBrowser = RepositoryBrowsers.createInstance( TeamFoundationServerRepositoryBrowser.class, req, formData, "browser"); return scm; } }
Jelly files
SCM/config.jelly
Add the following section to the config.jelly
that is used for configuring the SCM.
<j:jelly> .... <t:listScmBrowsers name="tfs.browser" /> </j:jelly>
ChangeLogSet/index.jelly
The index jelly for the ChangeLogSet
must be updated to include the links to the repository browser.
<j:jelly ...> <j:set var="browser" value="${it.build.parent.scm.effectiveBrowser}"/> ... <div class="changeset-message"> <b> ${%Version} <a href="${browser.getChangeSetLink(cs)}">${cs.version}</a> by <a href="${rootURL}/${cs.author.url}/">${cs.user}</a> <j:if test="${cs.domain!=null}"> @${cs.domain} </j:if>: </b><br/> ${cs.msgAnnotated} </div> ...
Adding a repository browser
Adding a repository browser to the SCM, is simple by adding two files, the class extending the RepositoryBrowser
class and the jelly file for configuring it.
CodePlexTfsBrowser
public class CodePlexTfsBrowser extends TeamFoundationServerRepositoryBrowser { public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); public final URL url; @DataBoundConstructor public CodePlexTfsBrowser(URL url) { this.url = normalizeToEndWithSlash(url); } public Descriptor<RepositoryBrowser<?>> getDescriptor() { return DESCRIPTOR; } @Override public URL getChangeSetLink(ChangeSet changeSet) throws IOException { return new URL(url, "?SourcePath=&changeSetId=" + changeSet.getVersion()); } public static class DescriptorImpl extends Descriptor<RepositoryBrowser<?>> { protected DescriptorImpl() { super(CodePlexTfsBrowser.class); } @Override public String getDisplayName() { return "CodePlex"; } } }
config.jelly
The repository browser must be configured with the base URL, so it can be used when determining the URL to link the change set to. The jelly files goes into src/main/resources/hudson/plugins/[SCM]/browsers/CodePlexTfsBrowser
folder.
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> <f:entry title="URL" help="/help/scm-browsers/codeplex-tfs/url.html"> <f:textbox name="codeplex.tfs.url" value="${browser.url}"/> </f:entry> </j:jelly>