blob: d04e0872cae72df238cab4029271294f6a3eaa29 [file] [log] [blame]
Ray Milkey95c50872015-04-14 14:32:31 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkey95c50872015-04-14 14:32:31 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.app;
17
18import java.util.Iterator;
19import java.util.List;
20import java.util.Spliterator;
21import java.util.Spliterators;
22import java.util.stream.StreamSupport;
23
Ray Milkey9dcc0e82018-10-01 10:26:53 -070024import org.apache.karaf.shell.api.action.lifecycle.Service;
Ray Milkey95c50872015-04-14 14:32:31 -070025import org.onosproject.app.ApplicationService;
26import org.onosproject.cli.AbstractChoicesCompleter;
27import org.onosproject.core.Application;
28
29import static java.util.stream.Collectors.toList;
30import static org.onosproject.app.ApplicationState.INSTALLED;
31import static org.onosproject.cli.AbstractShellCommand.get;
32
33/**
34 * All installed application name completer.
35 */
Ray Milkey9dcc0e82018-10-01 10:26:53 -070036@Service
Ray Milkey95c50872015-04-14 14:32:31 -070037public class AllApplicationNamesCompleter extends AbstractChoicesCompleter {
38 @Override
39 public List<String> choices() {
40
41 // Fetch the service and return the list of app names
42 ApplicationService service = get(ApplicationService.class);
43 Iterator<Application> it = service.getApplications().iterator();
44
45 // Filter the list of apps, selecting only the installed ones.
46 // Add each app name to the list of choices.
47 return
48 StreamSupport.stream(
49 Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false)
50 .filter(app -> service.getState(app.id()) == INSTALLED)
51 .map(app -> app.id().name())
52 .collect(toList());
53
54 }
55
56}