Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit 9e21af9

Browse files
committed
modified SourceForge auto-population to allow sf.net URL hosts, and
"/p/project-name" style API identification strings. Signed-off-by: Neal Ensor <[email protected]>
1 parent cf6265d commit 9e21af9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main/java/gov/osti/connectors/SourceForge.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SourceForge implements ConnectorInterface {
3030
// the logger implementation
3131
private static final Logger log = LoggerFactory.getLogger(SourceForge.class);
3232
// pattern to match for PROJECT NAME
33-
private static final Pattern PROJECT_NAME_PATTERN = Pattern.compile("/projects/(.*)$");
33+
private static final Pattern PROJECT_NAME_PATTERN = Pattern.compile("/(?:p|projects)/([a-zA-Z0-9_-]+).*$");
3434

3535
/**
3636
* initialize this Connector
@@ -46,6 +46,8 @@ public void init() throws IOException {
4646
*
4747
* Assumes it contains "sourceforge.net" and the PATH contains the
4848
* "project/project-name" value.
49+
* SF might also be of the form: sourceforge.net/p/project-name or sf.net/p/project-name
50+
* for example.
4951
*
5052
* @param url the URL to process
5153
* @return the PROJECT NAME if possible, or null if not
@@ -58,7 +60,8 @@ protected static String getProjectNameFromUrl(String url) {
5860

5961
// protection against bad URL input
6062
if (null!=uri.getHost()) {
61-
if (uri.getHost().contains("sourceforge.net")) {
63+
if (uri.getHost().contains("sourceforge.net") ||
64+
uri.getHost().contains("sf.net")) {
6265
// assume SourceForge path is formed by "/projects/project-name"
6366
if (null==uri.getPath())
6467
return null;

src/test/java/gov/osti/connectors/SourceForgeTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public void tearDown() {
3636
}
3737

3838
/**
39-
* Test of getProjectNameFromUrl method, of class SourceForge.
39+
* Test extraction of the project name from various SOURCEFORGE repository URLs.
4040
*/
4141
@Test
4242
public void testGetProjectNameFromUrl() {
43+
// these aren't recognized
4344
String[] badvalues = {
4445
"/projects/url",
4546
"sourceforge.com/projects/me",
@@ -52,8 +53,13 @@ public void testGetProjectNameFromUrl() {
5253
assertNull ("Found acceptable: " + value, SourceForge.getProjectNameFromUrl(value));
5354
}
5455

56+
assertEquals("arpa project name wrong", "arpa_project_x", SourceForge.getProjectNameFromUrl("https://svn.code.sf.net/p/arpa_project_x/code/trunk"));
57+
58+
assertEquals("wrong niceproject", "niceproject", SourceForge.getProjectNameFromUrl("http://svn.code.sf.net/p/niceproject/code"));
59+
assertEquals("Not ats", "ats-automatedtestingsystem", SourceForge.getProjectNameFromUrl("https://svn.code.sf.net/p/ats-automatedtestingsystem/code/"));
60+
5561
assertEquals("Matcher failed", "doecode", SourceForge.getProjectNameFromUrl("https://sourceforge.net/projects/doecode"));
56-
assertEquals("Matcher failed", "doecode/", SourceForge.getProjectNameFromUrl("http://sourceforge.net/projects/doecode/"));
62+
assertEquals("Matcher failed", "doecode", SourceForge.getProjectNameFromUrl("http://sourceforge.net/projects/doecode/"));
5763
}
5864

5965
}

0 commit comments

Comments
 (0)