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
/**
@@ -275,6 +274,24 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
275
274
}
276
275
277
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 ();
278
295
}
279
296
280
297
return ("command \" " + getText () + "\" for projects " +
@@ -289,22 +306,20 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
289
306
@ Override
290
307
public void validate () throws Exception {
291
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" ));
292
312
293
313
// Text field carries the command.
294
314
if (command == null ) {
295
315
throw new Exception ("The message must contain a text - \" add\" , \" delete\" or \" indexed\" " );
296
316
}
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 )) {
303
318
throw new Exception ("The message must contain either 'add', " +
304
319
"'delete', 'indexed', 'list', 'list-indexed' or 'get-repos' text" );
305
320
}
306
321
307
- if (!command .contains ("list" ) && getTags ().isEmpty ()) {
322
+ if (!command .startsWith ("list" ) && getTags ().isEmpty ()) {
308
323
throw new Exception ("The message must contain a tag (project name(s))" );
309
324
}
310
325
0 commit comments