# HG changeset patch # User Mirko Friedenhagen # Date 1252527466 -7200 # Branch mirkos # Node ID 7cde4de505b019cc60b6eb9ad6f41e01f147d480 # Parent 77242184270d7b670edbe70d7119b973a4a80a8f Added browsers for codeDOTgoogleDOTcom and bitbucketDOTorg. Outstanding is better support for validation of URLs in the UI. This version should retain backward compability with older versions of the plugin. This changeset is against revision r20468 of https://hudson.dev.java.net/svn/hudson/trunk/hudson/plugins/mercurial. diff -r 77242184270d -r 7cde4de505b0 src/main/java/hudson/plugins/mercurial/MercurialSCM.java --- a/src/main/java/hudson/plugins/mercurial/MercurialSCM.java Wed Aug 05 19:41:28 2009 +0200 +++ b/src/main/java/hudson/plugins/mercurial/MercurialSCM.java Wed Sep 09 22:17:46 2009 +0200 @@ -1,34 +1,55 @@ package hudson.plugins.mercurial; -import hudson.*; +import hudson.AbortException; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.Proc; +import hudson.Util; import hudson.FilePath.FileCallable; -import hudson.model.*; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.BuildListener; +import hudson.model.Computer; +import hudson.model.Hudson; +import hudson.model.TaskListener; +import hudson.plugins.mercurial.browser.HgBrowser; import hudson.plugins.mercurial.browser.HgWeb; import hudson.remoting.VirtualChannel; import hudson.scm.ChangeLogParser; -import hudson.scm.RepositoryBrowsers; +import hudson.scm.RepositoryBrowser; import hudson.scm.SCM; import hudson.scm.SCMDescriptor; import hudson.util.ArgumentListBuilder; import hudson.util.ForkOutputStream; import hudson.util.VersionNumber; -import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.framework.io.WriterOutputStream; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.Serializable; import java.net.MalformedURLException; +import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.Arrays; +import java.util.logging.Level; import java.util.logging.Logger; -import java.util.logging.Level; +import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.regex.Matcher; import net.sf.json.JSONObject; + +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.framework.io.ByteBuffer; +import org.kohsuke.stapler.framework.io.WriterOutputStream; /** * Mercurial SCM. @@ -62,10 +83,10 @@ private final boolean clean; - private HgWeb browser; + private HgBrowser browser; @DataBoundConstructor - public MercurialSCM(String installation, String source, String branch, String modules, HgWeb browser, boolean clean) { + public MercurialSCM(String installation, String source, String branch, String modules, HgBrowser browser, boolean clean) { this.installation = installation; this.source = source; this.modules = Util.fixNull(modules); @@ -116,7 +137,7 @@ } @Override - public HgWeb getBrowser() { + public HgBrowser getBrowser() { if (browser == null) { try { return new HgWeb(source); // #2406 @@ -442,10 +463,14 @@ private transient String version; public DescriptorImpl() { - super(MercurialSCM.class, HgWeb.class); + super(HgBrowser.class); load(); } + protected DescriptorImpl(Class clazz, Class repositoryBrowser) { + super(clazz,repositoryBrowser); + } + public String getDisplayName() { return "Mercurial"; } @@ -460,9 +485,7 @@ @Override public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException { - MercurialSCM scm = req.bindJSON(MercurialSCM.class,formData); - scm.browser = RepositoryBrowsers.createInstance(HgWeb.class,req,formData,"browser"); - return scm; + return super.newInstance(req, formData); } @Override diff -r 77242184270d -r 7cde4de505b0 src/main/java/hudson/plugins/mercurial/browser/BitBucket.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/hudson/plugins/mercurial/browser/BitBucket.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,77 @@ +package hudson.plugins.mercurial.browser; + +import hudson.Extension; +import hudson.model.Descriptor; +import hudson.plugins.mercurial.MercurialChangeSet; +import hudson.plugins.mercurial.MercurialSCM; +import hudson.scm.RepositoryBrowser; + +import java.io.IOException; +import java.net.URL; +import java.net.MalformedURLException; +import java.util.logging.Logger; + +import net.sf.json.JSONObject; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; + +/** + * Mercurial web interface served using a BitBucket repository. + */ +public class BitBucket extends HgBrowser { + + private transient MercurialChangeSet current; + + @DataBoundConstructor + public BitBucket(String url) throws MalformedURLException { + super(url); + } + + /** + * {@inheritDoc} + */ + @Override + public URL getChangeSetLink(MercurialChangeSet changeSet) + throws IOException { + current = changeSet; + return new URL(getUrl(), "changeset/" + changeSet.getShortNode() + "/"); + } + + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link BitBucket#getChangeSetLink(MercurialChangeSet)} to know + * the current {@link MercurialChangeSet}.

+ */ + @Override + public URL getFileLink(String path) throws MalformedURLException { + // http://bitbucket.org/mfriedenhagen/hudson-mercurial/src/d736d15e5389/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java + return new URL(getUrl(), "src/" + current.getShortNode() + "/" + path); + } + + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link BitBucket#getChangeSetLink(MercurialChangeSet)} to know + * the current {@link MercurialChangeSet}.

+ */ + @Override + public URL getDiffLink(String path) throws MalformedURLException { + // http://bitbucket.org/mfriedenhagen/hudson-mercurial/changeset/d736d15e5389/#chg-src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java + return new URL(getUrl(), "changeset/" + current.getShortNode() + "/#chg-" + path); + } + + + @Extension + public static class DescriptorImpl extends Descriptor> { + public String getDisplayName() { + return "bitbucket"; + } + + public @Override BitBucket newInstance(StaplerRequest req, JSONObject json) throws FormException { + return req.bindParameters(BitBucket.class,"bitbucket."); + } + } + + private static final long serialVersionUID = 1L; +} diff -r 77242184270d -r 7cde4de505b0 src/main/java/hudson/plugins/mercurial/browser/GoogleCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/hudson/plugins/mercurial/browser/GoogleCode.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,86 @@ +package hudson.plugins.mercurial.browser; + +import hudson.Extension; +import hudson.model.Descriptor; +import hudson.plugins.mercurial.MercurialChangeSet; +import hudson.scm.RepositoryBrowser; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.MalformedURLException; +import java.net.URLEncoder; + +import net.sf.json.JSONObject; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; + +/** + * Mercurial web interface served using a Google code repository. + */ +public class GoogleCode extends HgBrowser { + + private transient MercurialChangeSet current; + + @DataBoundConstructor + public GoogleCode(String url) throws MalformedURLException { + super(url); + if (!this.getUrl().toExternalForm().endsWith("/source/")) { + throw new MalformedURLException("GoogleCode browser URL (currently: " + url + ") must end with '/source/'"); + } + } + + /** + * {@inheritDoc} + */ + @Override + public URL getChangeSetLink(MercurialChangeSet changeSet) + throws IOException { + current = changeSet; + //E.g.: http://code.google.com/p/jmemcache-daemon/source/detail?r=eb1b7d8338ccaf6d54420bc98f52d00563d3cb40 + return new URL(getUrl(), "detail?r=" + changeSet.getNode()); + } + + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link GoogleCode#getChangeSetLink(MercurialChangeSet)} to know the current + * {@link MercurialChangeSet}.

+ */ + @Override + public URL getFileLink(String path) throws MalformedURLException { + //http://code.google.com/p/jmemcache-daemon/source/browse/core/src/main/java/com/thimbleware/jmemcached/Cache.java?spec=svn8365b0a208d3d5f07a014d05b878ed8c88e72ddf&r=8365b0a208d3d5f07a014d05b878ed8c88e72ddf + //E.g.: http://code.google.com/p/jmemcache-daemon/source/browse/test/src/test/java/com/thimbleware/jmemcached/test/AvailablePortFinder.java?r=2634a09900cb4dbc1dea714ac0a5db6ddf882321 + return new URL(getUrl(), "browse/" + path + "?spec=svn"+ current.getNode() + "&r=" + current.getNode()); + } + + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link GoogleCode#getChangeSetLink(MercurialChangeSet)} to know the current + * {@link MercurialChangeSet}.

+ */ + @Override + public URL getDiffLink(String path) throws MalformedURLException { + //E.g: http://code.google.com/p/jmemcache-daemon/source/diff?spec=svn8365b0a208d3d5f07a014d05b878ed8c88e72ddf&old=eb1b7d8338ccaf6d54420bc98f52d00563d3cb40&r=8365b0a208d3d5f07a014d05b878ed8c88e72ddf&format=unidiff&path=%2Fcore%2Fsrc%2Fmain%2Fjava%2Fcom%2Fthimbleware%2Fjmemcached%2FCache.java + try { + // We don't specify the old revision, but google seems to clever enough to take the predecessor as default. + return new URL(getUrl(), "diff?spec=svn"+ current.getNode() + "&r=" + current.getNode() + "&format=unidiff&path=%2F" + URLEncoder.encode(path, "UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("JDK broken?", e); + } + } + + @Extension + public static class DescriptorImpl extends Descriptor> { + public String getDisplayName() { + return "googlecode"; + } + + public @Override GoogleCode newInstance(StaplerRequest req, JSONObject json) throws FormException { + return req.bindParameters(GoogleCode.class,"googlecode."); + } + } + + private static final long serialVersionUID = 1L; +} diff -r 77242184270d -r 7cde4de505b0 src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,71 @@ +package hudson.plugins.mercurial.browser; + +import hudson.plugins.mercurial.MercurialChangeSet; +import hudson.scm.RepositoryBrowser; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * Parent class, as there is more than one browser. + * {@link HgBrowser#resolveObject()} will return the old default {@link HgWeb}. + */ +public class HgBrowser extends RepositoryBrowser { + + private final URL url; + + private static final long serialVersionUID = 1L; + + + /** + * {@inheritDoc} + */ + @Override + public URL getChangeSetLink(MercurialChangeSet changeset) throws IOException { + throw new UnsupportedOperationException("Method is not implemented for HgBrowser"); + } + + /** + * Returns a link to a specific revision of a file. + * + * @param path to a file. + * @return URL pointing to a specific revision of the file. + * + * @throws MalformedURLException + */ + public URL getFileLink(String path) throws MalformedURLException { + throw new UnsupportedOperationException("Method is not implemented for HgBrowser"); + } + + /** + * Returns a link to a diff for a file. + * + * @param path to a file. + * @return URL pointing to a specific revision of the file. + * + * @throws MalformedURLException + */ + public URL getDiffLink(String path) throws MalformedURLException { + throw new UnsupportedOperationException("Method is not implemented for HgBrowser"); + } + + @DataBoundConstructor + public HgBrowser(String url) throws MalformedURLException { + this.url = normalizeToEndWithSlash(new URL(url)); + } + + public URL getUrl() { + return url; + } + + public Object resolveObject() { + try { + return new HgWeb(url.toExternalForm()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } +} diff -r 77242184270d -r 7cde4de505b0 src/main/java/hudson/plugins/mercurial/browser/HgWeb.java --- a/src/main/java/hudson/plugins/mercurial/browser/HgWeb.java Wed Aug 05 19:41:28 2009 +0200 +++ b/src/main/java/hudson/plugins/mercurial/browser/HgWeb.java Wed Sep 09 22:17:46 2009 +0200 @@ -17,31 +17,49 @@ * Mercurial web interface served using the standalone server * or hgweb CGI scripts. */ -public class HgWeb extends RepositoryBrowser{ - private final URL url; - +public class HgWeb extends HgBrowser { + + private transient MercurialChangeSet current; + @DataBoundConstructor public HgWeb(String url) throws MalformedURLException { - if(!url.endsWith("/")) - url += '/'; - this.url = new URL(url); - - // TODO finish: - // add verification of url + super(url); } - public URL getUrl() { - return url; - } - - + /** + * {@inheritDoc} + */ @Override public URL getChangeSetLink(MercurialChangeSet changeSet) throws IOException { - // TODO: consider verifying the repository connection to tip at configuration time? - return new URL(url, "rev/" + changeSet.getShortNode()); + current = changeSet; + return new URL(getUrl(), "rev/" + changeSet.getShortNode()); } + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link HgWeb#getChangeSetLink(MercurialChangeSet)} to know the current + * {@link MercurialChangeSet}.

+ */ + @Override + public URL getFileLink(String path) throws MalformedURLException { + // http://hg.friedenhagen.net/index.cgi/mercurial-hudson/file/d736d15e5389/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java + return new URL(getUrl(), "file/" + current.getShortNode() + "/" + path); + } + + /** + * {@inheritDoc} + * + *

Must be preceded by a call to {@link HgWeb#getChangeSetLink(MercurialChangeSet)} to know the current + * {@link MercurialChangeSet}.

+ */ + @Override + public URL getDiffLink(String path) throws MalformedURLException { + // http://hg.friedenhagen.net/index.cgi/mercurial-hudson/diff/d736d15e5389/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java + return new URL(getUrl(), "diff/" + current.getShortNode() + "/" + path); + } + @Extension public static class DescriptorImpl extends Descriptor> { public String getDisplayName() { diff -r 77242184270d -r 7cde4de505b0 src/main/resources/hudson/plugins/mercurial/MercurialChangeSetList/index.jelly --- a/src/main/resources/hudson/plugins/mercurial/MercurialChangeSetList/index.jelly Wed Aug 05 19:41:28 2009 +0200 +++ b/src/main/resources/hudson/plugins/mercurial/MercurialChangeSetList/index.jelly Wed Sep 09 22:17:46 2009 +0200 @@ -31,7 +31,19 @@ - ${p} + + + ${p} + + + ${p} + + + + (diff) + + + diff -r 77242184270d -r 7cde4de505b0 src/main/resources/hudson/plugins/mercurial/browser/BitBucket/config.jelly --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/hudson/plugins/mercurial/browser/BitBucket/config.jelly Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff -r 77242184270d -r 7cde4de505b0 src/main/resources/hudson/plugins/mercurial/browser/GoogleCode/config.jelly --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/hudson/plugins/mercurial/browser/GoogleCode/config.jelly Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff -r 77242184270d -r 7cde4de505b0 src/main/resources/index.jelly --- a/src/main/resources/index.jelly Wed Aug 05 19:41:28 2009 +0200 +++ b/src/main/resources/index.jelly Wed Sep 09 22:17:46 2009 +0200 @@ -1,4 +1,4 @@
This plugin integrates Mercurial SCM to Hudson. - It includes repository browsing support for hg serve/hgweb. + It includes repository browsing support for hg serve/hgweb, google code and bitbucket.
\ No newline at end of file diff -r 77242184270d -r 7cde4de505b0 src/main/webapp/bitbucket.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/bitbucket.html Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,3 @@ +
+ Specify the root URL serving this repository (such as this.) +
\ No newline at end of file diff -r 77242184270d -r 7cde4de505b0 src/main/webapp/googlecode.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/googlecode.html Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,3 @@ +
+ Specify the root URL serving this repository (such as this.) +
\ No newline at end of file diff -r 77242184270d -r 7cde4de505b0 src/test/java/hudson/plugins/mercurial/browser/BitBucketTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/hudson/plugins/mercurial/browser/BitBucketTest.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,45 @@ +/* + * BitBucketTest.java 07.09.2009 + */ +package hudson.plugins.mercurial.browser; + +import static org.junit.Assert.assertEquals; +import hudson.plugins.mercurial.MercurialChangeSet; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.junit.Before; +import org.junit.Test; + +public class BitBucketTest { + + private static final String REPO_URL = "http://www.example.org/hg/repos"; + private final BitBucket browser; + private final MercurialChangeSet changeSet = new MercurialChangeSet(); + + public BitBucketTest() throws MalformedURLException { + browser = new BitBucket(REPO_URL); + changeSet.setNode("6704efde87541766fadba17f66d04b926cd4d343"); + } + + @Test + public void testGetChangeSetLinkMercurialChangeSet() throws IOException { + assertEquals(REPO_URL+ "/changeset/6704efde8754/", browser.getChangeSetLink(changeSet).toExternalForm()); + } + + @Test + public void testGetFileLink() throws IOException { + final String expected = REPO_URL + "/src/6704efde8754/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getFileLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + + @Test + public void testGetDiffLink() throws IOException { + final String expected = REPO_URL + "/changeset/6704efde8754/#chg-src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getDiffLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + +} diff -r 77242184270d -r 7cde4de505b0 src/test/java/hudson/plugins/mercurial/browser/GoogleCodeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/hudson/plugins/mercurial/browser/GoogleCodeTest.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,54 @@ +package hudson.plugins.mercurial.browser; + +import static org.junit.Assert.*; + +import hudson.plugins.mercurial.MercurialChangeSet; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.junit.Test; + +public class GoogleCodeTest { + + private static final String REPO_URL = "http://code.google.com/p/PROJECTNAME/source"; + private final GoogleCode browser; + private final MercurialChangeSet changeSet; + + public GoogleCodeTest() throws MalformedURLException { + browser = new GoogleCode(REPO_URL); + changeSet = new MercurialChangeSet(); + changeSet.setNode("6704efde87541766fadba17f66d04b926cd4d343"); + } + + @Test + public void testGetChangeSetLinkMercurialChangeSet() throws IOException { + final String expected = REPO_URL+"/detail?r=6704efde87541766fadba17f66d04b926cd4d343"; + assertEquals(expected, browser.getChangeSetLink(changeSet).toExternalForm()); + } + + @Test + public void testGetFileLink() throws IOException { + //http://code.google.com/p/jmemcache-daemon/source/browse/test/src/test/java/com/thimbleware/jmemcached/test/BasicCacheTest.java?r=2634a09900cb4dbc1dea714ac0a5db6ddf882321 + final String expected = REPO_URL + "/browse/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java?spec=svn6704efde87541766fadba17f66d04b926cd4d343&r=6704efde87541766fadba17f66d04b926cd4d343"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getFileLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + + @Test + public void testGetDiffLink() throws IOException { + final String expected = REPO_URL + "/diff?spec=svn6704efde87541766fadba17f66d04b926cd4d343&r=6704efde87541766fadba17f66d04b926cd4d343&format=unidiff&path=%2Fsrc%2Fmain%2Fjava%2Fhudson%2Fplugins%2Fmercurial%2Fbrowser%2FHgBrowser.java"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getDiffLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + + @Test + public void testGoogleCode() throws MalformedURLException { + assertEquals(REPO_URL +"/", browser.getUrl().toExternalForm()); + } + + @Test(expected=MalformedURLException.class) + public void testGoogleCodeMustEndWithSource() throws MalformedURLException { + new GoogleCode("http://code.google.com/p/PROJECTNAME"); + } +} diff -r 77242184270d -r 7cde4de505b0 src/test/java/hudson/plugins/mercurial/browser/HgBrowserTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/hudson/plugins/mercurial/browser/HgBrowserTest.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,37 @@ +package hudson.plugins.mercurial.browser; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.junit.Test; + +public class HgBrowserTest { + + @Test(expected=UnsupportedOperationException.class) + public final void testGetChangeSetLinkMercurialChangeSet() throws MalformedURLException, IOException { + new HgBrowser("http://abc/").getChangeSetLink(null); + } + + @Test(expected=UnsupportedOperationException.class) + public final void getFileLink() throws IOException { + new HgBrowser("http://abc/").getFileLink(""); + } + + @Test(expected=UnsupportedOperationException.class) + public final void testgetDiffLink() throws IOException { + new HgBrowser("http://abc/").getDiffLink(""); + } + @Test + public final void testGetUrl() throws MalformedURLException { + assertEquals("http://abc/", new HgBrowser("http://abc").getUrl().toExternalForm()); + } + + @Test + public final void testResolveObject() throws MalformedURLException { + final Object browser = new HgBrowser("http://abc").resolveObject(); + assertEquals(HgWeb.class, browser.getClass()); + } + +} diff -r 77242184270d -r 7cde4de505b0 src/test/java/hudson/plugins/mercurial/browser/HgWebTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/hudson/plugins/mercurial/browser/HgWebTest.java Wed Sep 09 22:17:46 2009 +0200 @@ -0,0 +1,42 @@ +package hudson.plugins.mercurial.browser; + +import static org.junit.Assert.assertEquals; +import hudson.plugins.mercurial.MercurialChangeSet; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.junit.Test; + +public class HgWebTest { + + private static final String REPO_URL = "http://hg.friedenhagen.net/index.cgi/mercurial-hudson"; + private final HgWeb browser; + private MercurialChangeSet changeSet = new MercurialChangeSet(); + + public HgWebTest() throws MalformedURLException { + browser = new HgWeb(REPO_URL); + changeSet.setNode("6704efde87541766fadba17f66d04b926cd4d343"); + } + + @Test + public void testGetChangeSetLinkMercurialChangeSet() throws IOException { + final String expected = REPO_URL + "/rev/6704efde8754"; + assertEquals(expected, browser.getChangeSetLink(changeSet).toExternalForm()); + } + + @Test + public void testGetFileLink() throws IOException { + final String expected = REPO_URL + "/file/6704efde8754/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getFileLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + + @Test + public void testGetDiffLink() throws IOException { + final String expected = REPO_URL + "/diff/6704efde8754/src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java"; + browser.getChangeSetLink(changeSet); + assertEquals(expected, browser.getDiffLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java").toExternalForm()); + } + +}