Skip to content

Commit d683b7d

Browse files
committed
add get-repos-type Message
1 parent a4eaffc commit d683b7d

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Currently supported message types:
139139
* **delete** – removes project(s) and its repositores from the configuration.
140140
Also deletes its data under data root (but not the source code).
141141
* **indexed** – mark the project(s) as indexed so it becomes visible in the UI
142+
* **get-repos** – get list of repositories in the form of relative paths to source root for given project(s)
143+
* **get-repos-type** – get repository type(s) for given project(s)
142144

143145
## 4. OpenGrok install
144146

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import java.io.IOException;
2727
import java.nio.file.Paths;
2828
import java.util.ArrayList;
29+
import java.util.Arrays;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Set;
3233
import java.util.TreeSet;
3334
import java.util.logging.Level;
3435
import java.util.logging.Logger;
35-
import java.util.stream.Collector;
3636
import java.util.stream.Collectors;
3737
import org.opensolaris.opengrok.configuration.Group;
3838
import org.opensolaris.opengrok.configuration.Project;
@@ -44,7 +44,6 @@
4444
import org.opensolaris.opengrok.index.IndexDatabase;
4545
import org.opensolaris.opengrok.logger.LoggerFactory;
4646
import org.opensolaris.opengrok.util.IOUtils;
47-
import org.opensolaris.opengrok.web.ProjectHelper;
4847

4948

5049
/**
@@ -275,6 +274,24 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
275274
}
276275

277276
return repos.stream().collect(Collectors.joining("\n")).getBytes();
277+
case "get-repos-type":
278+
Set<String> types = new TreeSet<>();
279+
280+
for (String projectName : getTags()) {
281+
Project project;
282+
if ((project = env.getProjects().get(projectName)) == null) {
283+
continue;
284+
}
285+
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().
286+
get(project);
287+
if (infos != null) {
288+
types.addAll(infos.stream().
289+
map(ri -> ri.getType()).
290+
collect(Collectors.toList()));
291+
}
292+
}
293+
294+
return types.stream().collect(Collectors.joining("\n")).getBytes();
278295
}
279296

280297
return ("command \"" + getText() + "\" for projects " +
@@ -289,22 +306,20 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
289306
@Override
290307
public void validate() throws Exception {
291308
String command = getText();
309+
Set<String> allowedText = new TreeSet<>(Arrays.asList("add", "delete",
310+
"list", "list-indexed", "indexed", "get-repos",
311+
"get-repos-type"));
292312

293313
// Text field carries the command.
294314
if (command == null) {
295315
throw new Exception("The message must contain a text - \"add\", \"delete\" or \"indexed\"");
296316
}
297-
if (command.compareTo("add") != 0 &&
298-
command.compareTo("delete") != 0 &&
299-
command.compareTo("list") != 0 &&
300-
command.compareTo("list-indexed") != 0 &&
301-
command.compareTo("get-repos") != 0 &&
302-
command.compareTo("indexed") != 0) {
317+
if (!allowedText.contains(command)) {
303318
throw new Exception("The message must contain either 'add', " +
304319
"'delete', 'indexed', 'list', 'list-indexed' or 'get-repos' text");
305320
}
306321

307-
if (!command.contains("list") && getTags().isEmpty()) {
322+
if (!command.startsWith("list") && getTags().isEmpty()) {
308323
throw new Exception("The message must contain a tag (project name(s))");
309324
}
310325

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,11 @@ public void testGetRepos() throws Exception {
424424

425425
// test
426426
Assert.assertEquals("/mercurial\n/mercurial/closed", out);
427+
428+
// Test the types. There should be only one type for project with
429+
// multiple nested Mercurial repositories.
430+
m.setText("get-repos-type");
431+
out = new String(m.apply(env));
432+
Assert.assertEquals("Mercurial", out);
427433
}
428434
}

tools/Messages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Usage()
7676
echo " - \"list\" - list all projects (both indexed and not indexed)"
7777
echo " - \"list-indexed\" - list indexed projects"
7878
echo " - \"get-repos\" - get list of repositories in the form of relative paths to source root for given project(s)"
79+
echo " - \"get-repos-type\" - get repository type(s) for given project(s)"
7980
echo " normal:"
8081
echo " - assign a <text> to the main page or a project"
8182
echo " - can be more precise with <tags> (for specific project)"

0 commit comments

Comments
 (0)