Skip to content

Commit

Permalink
add get-repos-type Message
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Oct 3, 2017
1 parent a4eaffc commit d683b7d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Currently supported message types:
* **delete** – removes project(s) and its repositores from the configuration.
Also deletes its data under data root (but not the source code).
* **indexed** – mark the project(s) as indexed so it becomes visible in the UI
* **get-repos** – get list of repositories in the form of relative paths to source root for given project(s)
* **get-repos-type** – get repository type(s) for given project(s)

## 4. OpenGrok install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.opensolaris.opengrok.configuration.Group;
import org.opensolaris.opengrok.configuration.Project;
Expand All @@ -44,7 +44,6 @@
import org.opensolaris.opengrok.index.IndexDatabase;
import org.opensolaris.opengrok.logger.LoggerFactory;
import org.opensolaris.opengrok.util.IOUtils;
import org.opensolaris.opengrok.web.ProjectHelper;


/**
Expand Down Expand Up @@ -275,6 +274,24 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
}

return repos.stream().collect(Collectors.joining("\n")).getBytes();
case "get-repos-type":
Set<String> types = new TreeSet<>();

for (String projectName : getTags()) {
Project project;
if ((project = env.getProjects().get(projectName)) == null) {
continue;
}
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().
get(project);
if (infos != null) {
types.addAll(infos.stream().
map(ri -> ri.getType()).
collect(Collectors.toList()));
}
}

return types.stream().collect(Collectors.joining("\n")).getBytes();
}

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

// Text field carries the command.
if (command == null) {
throw new Exception("The message must contain a text - \"add\", \"delete\" or \"indexed\"");
}
if (command.compareTo("add") != 0 &&
command.compareTo("delete") != 0 &&
command.compareTo("list") != 0 &&
command.compareTo("list-indexed") != 0 &&
command.compareTo("get-repos") != 0 &&
command.compareTo("indexed") != 0) {
if (!allowedText.contains(command)) {
throw new Exception("The message must contain either 'add', " +
"'delete', 'indexed', 'list', 'list-indexed' or 'get-repos' text");
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,11 @@ public void testGetRepos() throws Exception {

// test
Assert.assertEquals("/mercurial\n/mercurial/closed", out);

// Test the types. There should be only one type for project with
// multiple nested Mercurial repositories.
m.setText("get-repos-type");
out = new String(m.apply(env));
Assert.assertEquals("Mercurial", out);
}
}
1 change: 1 addition & 0 deletions tools/Messages
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Usage()
echo " - \"list\" - list all projects (both indexed and not indexed)"
echo " - \"list-indexed\" - list indexed projects"
echo " - \"get-repos\" - get list of repositories in the form of relative paths to source root for given project(s)"
echo " - \"get-repos-type\" - get repository type(s) for given project(s)"
echo " normal:"
echo " - assign a <text> to the main page or a project"
echo " - can be more precise with <tags> (for specific project)"
Expand Down

0 comments on commit d683b7d

Please sign in to comment.