NIFI-11460 Switched to JLine 3.23.0 FileNameCompleter

Removed project StandardFileNameCompleter no longer required as of JLine 3.23.0 which incorporated JLine Pull Request 817

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #7175.
This commit is contained in:
exceptionfactory 2023-04-17 10:32:14 -05:00 committed by Pierre Villard
parent 88587f5c02
commit 946064b1c4
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
2 changed files with 2 additions and 117 deletions

View File

@ -21,7 +21,7 @@ import org.apache.nifi.toolkit.cli.api.CommandGroup;
import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
import org.apache.nifi.toolkit.cli.impl.command.session.SessionCommandGroup;
import org.apache.nifi.toolkit.cli.impl.session.SessionVariable;
import org.apache.nifi.toolkit.cli.impl.util.StandardFileNameCompleter;
import org.jline.builtins.Completers;
import org.jline.reader.Candidate;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
@ -77,7 +77,7 @@ public class CLICompleter implements Completer {
*/
private final Map<String, List<String>> commandOptionsMap;
private final Completer fileNameCompleter = new StandardFileNameCompleter();
private final Completer fileNameCompleter = new Completers.FileNameCompleter();
/**
* Initializes the completer based on the top-level commands and command groups.

View File

@ -1,115 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.toolkit.cli.impl.util;
import org.jline.builtins.Completers;
import org.jline.builtins.Styles;
import org.jline.reader.Candidate;
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
import org.jline.utils.StyleResolver;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
/**
* Standard File Name Completer overriding references to Styles.lsStyle() to avoid parsing issues with LS_COLORS
*/
public class StandardFileNameCompleter extends Completers.FileNameCompleter {
private static final String STANDARD_LS_COLORS = "di=1;91:ex=1;92:ln=1;96:fi=";
private static final String HOME_DIRECTORY_ALIAS = "~";
private static final String EMPTY = "";
private static final StyleResolver STYLE_RESOLVER = Styles.style(STANDARD_LS_COLORS);
/**
* Complete file names based on JLine 3.22.0 without calling Styles.lsStyle()
*
* @param reader Line Reader
* @param commandLine Parsed Command
* @param candidates Candidates to be populated
*/
@Override
public void complete(final LineReader reader, final ParsedLine commandLine, final List<Candidate> candidates) {
assert commandLine != null;
assert candidates != null;
final String buffer = commandLine.word().substring(0, commandLine.wordCursor());
final Path current;
final String curBuf;
final String sep = getSeparator(reader.isSet(LineReader.Option.USE_FORWARD_SLASH));
final int lastSep = buffer.lastIndexOf(sep);
try {
if (lastSep >= 0) {
curBuf = buffer.substring(0, lastSep + 1);
if (curBuf.startsWith(HOME_DIRECTORY_ALIAS)) {
if (curBuf.startsWith(HOME_DIRECTORY_ALIAS + sep)) {
current = getUserHome().resolve(curBuf.substring(2));
} else {
current = getUserHome().getParent().resolve(curBuf.substring(1));
}
} else {
current = getUserDir().resolve(curBuf);
}
} else {
curBuf = EMPTY;
current = getUserDir();
}
try (final DirectoryStream<Path> directory = Files.newDirectoryStream(current, this::accept)) {
directory.forEach(path -> {
final String value = curBuf + path.getFileName().toString();
if (Files.isDirectory(path)) {
candidates.add(
new Candidate(
value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : EMPTY),
getDisplay(reader.getTerminal(), path, STYLE_RESOLVER, sep),
null,
null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null,
null,
false
)
);
} else {
candidates.add(
new Candidate(
value,
getDisplay(reader.getTerminal(), path, STYLE_RESOLVER, sep),
null,
null,
null,
null,
true
)
);
}
});
} catch (final IOException e) {
// Ignore
}
} catch (final Exception e) {
// Ignore
}
}
}