26
26
import java .io .IOException ;
27
27
import java .nio .file .Paths ;
28
28
import java .util .ArrayList ;
29
+ import java .util .Arrays ;
29
30
import java .util .List ;
30
31
import java .util .Map ;
31
32
import java .util .Set ;
32
33
import java .util .TreeSet ;
33
34
import java .util .logging .Level ;
34
35
import java .util .logging .Logger ;
35
- import java .util .stream .Collector ;
36
36
import java .util .stream .Collectors ;
37
37
import org .opensolaris .opengrok .configuration .Group ;
38
38
import org .opensolaris .opengrok .configuration .Project ;
44
44
import org .opensolaris .opengrok .index .IndexDatabase ;
45
45
import org .opensolaris .opengrok .logger .LoggerFactory ;
46
46
import org .opensolaris .opengrok .util .IOUtils ;
47
- import org .opensolaris .opengrok .web .ProjectHelper ;
48
47
49
48
50
49
/**
@@ -257,6 +256,42 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
257
256
case "list-indexed" :
258
257
return (env .getProjectList ().stream ().filter (p -> p .isIndexed ()).
259
258
map (p -> p .getName ()).collect (Collectors .joining ("\n " )).getBytes ());
259
+ case "get-repos" :
260
+ List <String > repos = new ArrayList <>();
261
+
262
+ for (String projectName : getTags ()) {
263
+ Project project ;
264
+ if ((project = env .getProjects ().get (projectName )) == null ) {
265
+ continue ;
266
+ }
267
+ List <RepositoryInfo > infos = env .getProjectRepositoriesMap ().
268
+ get (project );
269
+ if (infos != null ) {
270
+ repos .addAll (infos .stream ().
271
+ map (ri -> ri .getDirectoryNameRelative ()).
272
+ collect (Collectors .toList ()));
273
+ }
274
+ }
275
+
276
+ 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 ();
260
295
}
261
296
262
297
return ("command \" " + getText () + "\" for projects " +
@@ -271,20 +306,20 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
271
306
@ Override
272
307
public void validate () throws Exception {
273
308
String command = getText ();
309
+ Set <String > allowedText = new TreeSet <>(Arrays .asList ("add" , "delete" ,
310
+ "list" , "list-indexed" , "indexed" , "get-repos" ,
311
+ "get-repos-type" ));
274
312
275
313
// Text field carries the command.
276
314
if (command == null ) {
277
315
throw new Exception ("The message must contain a text - \" add\" , \" delete\" or \" indexed\" " );
278
316
}
279
- if (command .compareTo ("add" ) != 0 &&
280
- command .compareTo ("delete" ) != 0 &&
281
- command .compareTo ("list" ) != 0 &&
282
- command .compareTo ("list-indexed" ) != 0 &&
283
- command .compareTo ("indexed" ) != 0 ) {
284
- throw new Exception ("The message must contain either 'add', 'delete' or 'indexed' text" );
317
+ if (!allowedText .contains (command )) {
318
+ throw new Exception ("The message must contain either 'add', " +
319
+ "'delete', 'indexed', 'list', 'list-indexed' or 'get-repos' text" );
285
320
}
286
321
287
- if (!command .contains ("list" ) && getTags ().isEmpty ()) {
322
+ if (!command .startsWith ("list" ) && getTags ().isEmpty ()) {
288
323
throw new Exception ("The message must contain a tag (project name(s))" );
289
324
}
290
325
0 commit comments