Skip to content
Permalink
Browse files

Merge pull request #41 from thomedw/path-equal

[FIXED JENKINS-18252] Added ability to recognize non-URL file paths in /notifyCommit
  • Loading branch information...
jglick committed Aug 2, 2013
2 parents fc8a1a7 + 15808c3 commit 9d41ba0b7ad66b6ddefd87711195c0c3e7843124
@@ -273,6 +273,9 @@ static boolean pathEquals(@NonNull String pathURL, @NonNull String pathAsInConfi
if (pathURL.startsWith("file:/") && URI.create(pathURL).equals(new File(pathAsInConfig).toURI())) {
return true;
}
if (pathAsInConfig.startsWith("file:/") && URI.create(pathAsInConfig).equals(new File(pathURL).toURI())) {
return true;
}
return false;
}
}
@@ -16,6 +16,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
@@ -53,22 +54,31 @@ private static int getPort(URI uri) {
int port = uri.getPort();
if ( port < 0 ){
String scheme = uri.getScheme();
if ( scheme.equals("http") ){
if ("http".equals(scheme)){
port = 80;
} else if ( scheme.equals("https") ) {
} else if ("https".equals(scheme)) {
port = 443;
} else if ( scheme.equals("ssh") ) {
} else if ("ssh".equals(scheme)) {
port = 22;
}
}
return port;
}

@Nonnull
private static String getScheme(URI uri) {
String scheme = uri.getScheme();
if (scheme == null) {
return "file";
}
return scheme;
}

static boolean looselyMatches(URI notifyUri, String repository) {
boolean result = false;
try {
URI repositoryUri = new URI(repository);
result = Objects.equal(notifyUri.getScheme(), repositoryUri.getScheme())
result = getScheme(notifyUri).equals(getScheme(repositoryUri))
&& Objects.equal(notifyUri.getHost(), repositoryUri.getHost())
&& getPort(notifyUri) == getPort(repositoryUri)
&& Objects.equal(notifyUri.getPath(), repositoryUri.getPath())
@@ -38,6 +38,9 @@
assertTrue(HgExe.pathEquals("file:/var/hg/stuff", "/var/hg/stuff"));
assertTrue(HgExe.pathEquals("file:///var/hg/stuff", "/var/hg/stuff"));
assertFalse(HgExe.pathEquals("file:/var/hg/stuff", "/var/hg/other"));
assertTrue(HgExe.pathEquals("/var/hg/stuff", "file:/var/hg/stuff"));
assertTrue(HgExe.pathEquals("/var/hg/stuff", "file:///var/hg/stuff"));
assertFalse(HgExe.pathEquals("/var/hg/other", "file:/var/hg/stuff"));
}
}
}
@@ -58,6 +58,12 @@
assertFalse( MercurialStatus.looselyMatches(new URI("http://somehost/path"), "http://somehost/") );
assertFalse( MercurialStatus.looselyMatches(new URI("http://somehost/path"), "http://somehost/path?query=test") );
assertFalse( MercurialStatus.looselyMatches(new URI("http://somehost/path"), "http://somehost:81/path") );
assertTrue( MercurialStatus.looselyMatches(new URI("/var/hg/stuff"), "/var/hg/stuff") );
assertTrue( MercurialStatus.looselyMatches(new URI("file:///var/hg/stuff"), "/var/hg/stuff") );
assertTrue( MercurialStatus.looselyMatches(new URI("file:/var/hg/stuff"), "/var/hg/stuff") );
assertTrue( MercurialStatus.looselyMatches(new URI("/var/hg/stuff"), "file:/var/hg/stuff") );
assertTrue( MercurialStatus.looselyMatches(new URI("/var/hg/stuff"), "file:///var/hg/stuff") );
assertTrue( MercurialStatus.looselyMatches(new URI("file:///var/hg/stuff"), "file:///var/hg/stuff") );
}

}

0 comments on commit 9d41ba0

Please sign in to comment.
You can’t perform that action at this time.