use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.
the class FeatureCompleterSupport method complete.
@Override
public int complete(Session session, final CommandLine commandLine, final List<String> candidates) {
List<Candidate> cands = new ArrayList<>();
completeCandidates(session, commandLine, cands);
for (Candidate cand : cands) {
candidates.add(cand.value());
}
return candidates.isEmpty() ? -1 : 0;
}
use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.
the class AggregateCompleter method complete.
@SuppressWarnings({ "unchecked", "rawtypes" })
public int complete(final Session session, final CommandLine commandLine, final List<String> candidates) {
List<Candidate> cands = new ArrayList<>();
completeCandidates(session, commandLine, cands);
for (Candidate cand : cands) {
candidates.add(cand.value());
}
return 0;
}
use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.
the class UriCompleter method maven.
private void maven(Session session, CommandLine commandLine, List<Candidate> candidates) {
String repo = System.getProperty("user.home") + "/.m2/repository";
String buffer = commandLine.getCursorArgument();
String mvn = buffer.substring("mvn:".length(), commandLine.getArgumentPosition());
String rem = "";
try {
String[] parts = mvn.split("/");
if (parts.length == 0 || parts.length == 1 && !mvn.endsWith("/")) {
String known = "";
String group = "";
String[] dirs = parts.length > 0 ? parts[0].split("\\.") : new String[] { "" };
if (parts.length > 0 && parts[0].endsWith(".")) {
for (String dir : dirs) {
known += dir + "/";
group += dir + ".";
}
} else {
for (int i = 0; i < dirs.length - 1; i++) {
known += dirs[i] + "/";
group += dirs[i] + ".";
}
rem = dirs[dirs.length - 1];
}
Path rep = Paths.get(repo);
Path dir = rep.resolve(known);
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + group + name, false));
}
}
}
rem = group + rem;
} else if (parts.length == 1 || parts.length == 2 && !mvn.endsWith("/")) {
rem = parts.length > 1 ? parts[1] : "";
Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/"));
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + parts[0] + "/" + name, false));
}
}
}
} else if (parts.length == 2 || parts.length == 3 && !mvn.endsWith("/")) {
rem = parts.length > 2 ? parts[2] : "";
Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/") + "/" + parts[1]);
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + parts[0] + "/" + parts[1] + "/" + name, true));
}
}
}
}
} catch (Exception e) {
// Ignore
}
}
use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.
the class ArgumentCompleter method complete.
public int complete(Session session, final CommandLine commandLine, final List<String> candidates) {
List<Candidate> cands = new ArrayList<>();
completeCandidates(session, commandLine, cands);
for (Candidate cand : cands) {
candidates.add(cand.value());
}
return 0;
}
use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.
the class CommandsCompleter method complete.
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
List<Candidate> cands = new ArrayList<>();
completeCandidates(session, commandLine, cands);
for (Candidate cand : cands) {
candidates.add(cand.value());
}
return 0;
}
Aggregations