Skip to content

Commit 269c0ed

Browse files
vladakVladimir Kotal
authored andcommitted
add new project Messages to list projects
1 parent a1acdb2 commit 269c0ed

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ public Map<String,Project> getProjects() {
438438
}
439439

440440
/**
441-
* Get descriptions of all projects.
441+
* Get names of all projects.
442442
*
443-
* @return a list containing descriptions of all projects.
443+
* @return a list containing names of all projects.
444444
*/
445-
public List<String> getProjectDescriptions() {
445+
public List<String> getProjectNames() {
446446
return getProjectList().stream().
447447
map(Project::getName).collect(Collectors.toList());
448448
}
@@ -2013,7 +2013,7 @@ public void refreshSearcherManagerMap() {
20132013
for (Map.Entry<String, SearcherManager> entry : searcherManagerMap.entrySet()) {
20142014
// If a project is gone, close the corresponding SearcherManager
20152015
// so that it cannot produce new IndexSearcher objects.
2016-
if (!getProjectDescriptions().contains(entry.getKey())) {
2016+
if (!getProjectNames().contains(entry.getKey())) {
20172017
try {
20182018
LOGGER.log(Level.FINE,
20192019
"closing SearcherManager for project" + entry.getKey());

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Map;
3131
import java.util.logging.Level;
3232
import java.util.logging.Logger;
33+
import java.util.stream.Collector;
3334
import java.util.stream.Collectors;
3435
import org.opensolaris.opengrok.configuration.Project;
3536
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
@@ -234,6 +235,11 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
234235

235236
env.refreshDateForLastIndexRun();
236237
break;
238+
case "list":
239+
return (env.getProjectNames().stream().collect(Collectors.joining("\n")).getBytes());
240+
case "list-indexed":
241+
return (env.getProjectList().stream().filter(p -> p.isIndexed()).
242+
map(p -> p.getName()).collect(Collectors.joining("\n")).getBytes());
237243
}
238244

239245
return ("command \"" + getText() + "\" for projects " +
@@ -247,21 +253,24 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
247253
*/
248254
@Override
249255
public void validate() throws Exception {
250-
if (getTags().isEmpty()) {
251-
throw new Exception("The message must contain a tag (project name(s))");
252-
}
253-
254256
String command = getText();
257+
255258
// Text field carries the command.
256259
if (command == null) {
257260
throw new Exception("The message must contain a text - \"add\", \"delete\" or \"indexed\"");
258261
}
259262
if (command.compareTo("add") != 0 &&
260263
command.compareTo("delete") != 0 &&
264+
command.compareTo("list") != 0 &&
265+
command.compareTo("list-indexed") != 0 &&
261266
command.compareTo("indexed") != 0) {
262267
throw new Exception("The message must contain either 'add', 'delete' or 'indexed' text");
263268
}
264269

270+
if (!command.contains("list") && getTags().isEmpty()) {
271+
throw new Exception("The message must contain a tag (project name(s))");
272+
}
273+
265274
super.validate();
266275
}
267276
}

test/org/opensolaris/opengrok/configuration/ProjectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void testGetProjectDescriptions() {
128128
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
129129
env.setProjects(projects);
130130

131-
List<String> descs = env.getProjectDescriptions();
131+
List<String> descs = env.getProjectNames();
132132
assertTrue(descs.contains("foo"));
133133
assertTrue(descs.contains("bar"));
134134
assertFalse(descs.contains("foobar"));

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
import java.util.TreeSet;
3030
import java.util.concurrent.ConcurrentHashMap;
3131
import org.junit.After;
32-
import org.junit.AfterClass;
3332
import org.junit.Assert;
3433
import static org.junit.Assert.assertTrue;
3534
import org.junit.Assume;
3635
import org.junit.Before;
37-
import org.junit.BeforeClass;
3836
import org.junit.Test;
3937
import org.opensolaris.opengrok.configuration.Project;
4038
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
@@ -311,4 +309,33 @@ public void testIndexed() throws Exception {
311309
Assert.assertTrue("current version should be refreshed",
312310
ri.getCurrentVersion().contains("c78fa757c524"));
313311
}
312+
313+
@Test
314+
public void testList() throws Exception {
315+
// Add a project
316+
Message m = new ProjectMessage();
317+
m.setText("add");
318+
m.addTag("mercurial");
319+
m.apply(env);
320+
321+
// Mark it as indexed.
322+
m.setText("indexed");
323+
m.apply(env);
324+
325+
// Add another project.
326+
m.setText("add");
327+
m.addTag("git");
328+
m.apply(env);
329+
330+
m.setTags(new TreeSet<String>());
331+
m.setText("list");
332+
String out = new String(m.apply(env));
333+
Assert.assertTrue(out.contains("mercurial"));
334+
Assert.assertTrue(out.contains("git"));
335+
336+
m.setText("list-indexed");
337+
out = new String(m.apply(env));
338+
Assert.assertTrue(out.contains("mercurial"));
339+
Assert.assertFalse(out.contains("git"));
340+
}
314341
}

tools/Messages

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ Usage()
6666
echo " - \"auth\" tag requires \"reload\" text and"
6767
echo " reloads all authorization plugins."
6868
echo " project:"
69-
echo " - project names to be added are specified as <tags>"
69+
echo " - project names to be added/deleted/indexed are specified as <tags>"
7070
echo " - command is specified in message <text>:"
7171
echo " - \"add\" - adds project(s) and its repositories to the configuration."
7272
echo " If the project already exists, refresh list of its repositories."
7373
echo " - \"delete\" - removes project(s) and its repositores from the configuration"
7474
echo " Also deletes its data under data root (but not the source code)."
7575
echo " - \"indexed\" - mark the project(s) as indexed so it becomes visible in the UI"
76+
echo " - \"list\" - list all projects (both indexed and not indexed)"
77+
echo " - \"list-indexed\" - list indexed projects"
7678
echo " normal:"
7779
echo " - assign a <text> to the main page or a project"
7880
echo " - can be more precise with <tags> (for specific project)"

0 commit comments

Comments
 (0)