Skip to content

Commit aef8e04

Browse files
committed
add get-repos Message
1 parent 7470afa commit aef8e04

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/org/opensolaris/opengrok/configuration/messages/ProjectMessage.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
257257
case "list-indexed":
258258
return (env.getProjectList().stream().filter(p -> p.isIndexed()).
259259
map(p -> p.getName()).collect(Collectors.joining("\n")).getBytes());
260+
case "get-repos":
261+
List<String> repos = new ArrayList<>();
262+
263+
for (String projectName : getTags()) {
264+
Project project;
265+
if ((project = env.getProjects().get(projectName)) == null) {
266+
continue;
267+
}
268+
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().
269+
get(project);
270+
if (infos != null) {
271+
repos.addAll(infos.stream().
272+
map(ri -> ri.getDirectoryNameRelative()).
273+
collect(Collectors.toList()));
274+
}
275+
}
276+
277+
return repos.stream().collect(Collectors.joining("\n")).getBytes();
260278
}
261279

262280
return ("command \"" + getText() + "\" for projects " +
@@ -280,8 +298,10 @@ public void validate() throws Exception {
280298
command.compareTo("delete") != 0 &&
281299
command.compareTo("list") != 0 &&
282300
command.compareTo("list-indexed") != 0 &&
301+
command.compareTo("get-repos") != 0 &&
283302
command.compareTo("indexed") != 0) {
284-
throw new Exception("The message must contain either 'add', 'delete' or 'indexed' text");
303+
throw new Exception("The message must contain either 'add', " +
304+
"'delete', 'indexed', 'list', 'list-indexed' or 'get-repos' text");
285305
}
286306

287307
if (!command.contains("list") && getTags().isEmpty()) {

test/org/opensolaris/opengrok/configuration/messages/ProjectMessageTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,31 @@ public void testList() throws Exception {
391391
Assert.assertTrue(out.contains("mercurial"));
392392
Assert.assertFalse(out.contains("git"));
393393
}
394+
395+
@Test
396+
public void testGetRepos() throws Exception {
397+
// Create subrepository.
398+
File mercurialRoot = new File(repository.getSourceRoot() + File.separator + "mercurial");
399+
MercurialRepositoryTest.runHgCommand(mercurialRoot,
400+
"clone", mercurialRoot.getAbsolutePath(),
401+
mercurialRoot.getAbsolutePath() + File.separator + "closed");
402+
403+
// Add a project
404+
Message m = new ProjectMessage();
405+
m.setText("add");
406+
m.addTag("mercurial");
407+
m.apply(env);
408+
409+
// Get repositories of the project.
410+
m.setText("get-repos");
411+
String out = new String(m.apply(env));
412+
413+
// Perform cleanup of the subrepository in order not to interefere
414+
// with other tests.
415+
removeRecursive(new File(mercurialRoot.getAbsolutePath() +
416+
File.separator + "closed").toPath());
417+
418+
// test
419+
Assert.assertEquals("/mercurial\n/mercurial/closed", out);
420+
}
394421
}

0 commit comments

Comments
 (0)