Skip to content

Commit 0d37128

Browse files
author
Vladimir Kotal
committed
use Paths.get() when querying repositories
fixes #2558
1 parent 1accaf7 commit 0d37128

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

apiary.apib

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,19 @@ will be used for repository paths.
192192

193193
### return type of the repository [GET]
194194

195-
The repository path is relative to source root, starting with slash.
196-
Repository type is separated from the repository path with a colon.
195+
The repository path is relative to source root.
196+
197+
In the response the repository type is separated from the repository path
198+
with a colon. If the type cannot be determined "N/A" is returned.
197199

198200
+ Response 200 (text/plain)
199201
+ Body
200202

201203
/opengrok-master:git
202204

203205
+ Parameters
204-
+ repository - repository for which to return type
206+
+ repository - repository path with native path separators (of the machine
207+
running the service) starting with path separator for which to return type
205208

206209
## Search [/search{?full,def,symbol,path,hist,type,projects,maxresults,start}]
207210

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/RepositoriesController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public class RepositoriesController {
3939
@GET
4040
@Path("/type")
4141
@Produces(MediaType.TEXT_PLAIN)
42-
public String getType(@QueryParam("repository") final String repository) {
42+
public String getType(@QueryParam("repository") final String repositoryPath) {
4343
for (RepositoryInfo ri : env.getRepositories()) {
44-
if (ri.getDirectoryNameRelative().equals(repository)) {
45-
return repository + ":" + ri.getType();
44+
if (ri.getDirectoryNameRelative().equals(repositoryPath)) {
45+
return repositoryPath + ":" + ri.getType();
4646
}
4747
}
48-
return repository + ":N/A";
48+
return repositoryPath + ":N/A";
4949
}
5050

5151
}

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/RepositoriesControllerTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import javax.ws.rs.core.Application;
4343
import java.io.File;
44+
import java.nio.file.Paths;
4445
import java.util.ArrayList;
4546
import java.util.concurrent.ConcurrentHashMap;
4647

@@ -88,10 +89,13 @@ public void tearDown() throws Exception {
8889
}
8990

9091
@Test
91-
public void testGetRepositoryType() throws Exception {
92-
assertEquals("/totally-nonexistent-repository:N/A",
93-
getRepoType("/totally-nonexistent-repository"));
92+
public void testGetRepositoryTypeOfNonExistenRepository() throws Exception {
93+
assertEquals(Paths.get("/totally-nonexistent-repository").toString() + ":N/A",
94+
getRepoType(Paths.get("/totally-nonexistent-repository").toString()));
95+
}
9496

97+
@Test
98+
public void testGetRepositoryType() throws Exception {
9599
// Create subrepository.
96100
File mercurialRoot = new File(repository.getSourceRoot() + File.separator + "mercurial");
97101
MercurialRepositoryTest.runHgCommand(mercurialRoot,
@@ -111,11 +115,12 @@ public void testGetRepositoryType() throws Exception {
111115
new ArrayList<>(), // don't zap cache
112116
false); // don't list repos
113117

114-
assertEquals("/mercurial:Mercurial", getRepoType("/mercurial"));
115-
116-
assertEquals("/mercurial/closed:Mercurial", getRepoType("/mercurial/closed"));
117-
118-
assertEquals("/git:git", getRepoType("/git"));
118+
assertEquals(Paths.get("/mercurial").toString() + ":Mercurial",
119+
getRepoType(Paths.get("/mercurial").toString()));
120+
assertEquals(Paths.get("/mercurial/closed").toString() + ":Mercurial",
121+
getRepoType(Paths.get("/mercurial/closed").toString()));
122+
assertEquals(Paths.get("/git").toString() + ":git",
123+
getRepoType(Paths.get("/git").toString()));
119124
}
120125

121126
private String getRepoType(final String repository) {

0 commit comments

Comments
 (0)