mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-27 07:55:25 +00:00
Speed up bash completion loading by packaging it as a file in the ZIP distribution #296
This commit is contained in:
@@ -15,15 +15,27 @@
|
||||
*/
|
||||
package org.mvndaemon.mvnd.client;
|
||||
|
||||
import org.mvndaemon.mvnd.common.IoUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Completion {
|
||||
|
||||
public static String getCompletion(String shell) {
|
||||
public static String getCompletion(String shell, DaemonParameters daemonParameters) {
|
||||
if (!"bash".equals(shell)) {
|
||||
throw new IllegalArgumentException("Unexpected --completion value: '" + shell + "'; expected: 'bash'");
|
||||
}
|
||||
return IoUtils.readResource(Completion.class.getClassLoader(), "mvnd-bash-completion.bash");
|
||||
final Path bashCompletionPath = daemonParameters.mvndHome().resolve("bin/mvnd-bash-completion.bash");
|
||||
if (!Files.isRegularFile(bashCompletionPath)) {
|
||||
throw new IllegalStateException("Bash completion file does not exist: " + bashCompletionPath);
|
||||
}
|
||||
try {
|
||||
return new String(Files.readAllBytes(bashCompletionPath), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not read " + bashCompletionPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -136,7 +136,7 @@ public class DefaultClient implements Client {
|
||||
final List<String> args = new ArrayList<>(argv);
|
||||
final String completionShell = Environment.COMPLETION.removeCommandLineOption(args);
|
||||
if (completionShell != null) {
|
||||
output.accept(Message.log(Completion.getCompletion(completionShell)));
|
||||
output.accept(Message.log(Completion.getCompletion(completionShell, parameters)));
|
||||
return DefaultResult.success(argv);
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ import org.mvndaemon.mvnd.common.Environment;
|
||||
import org.mvndaemon.mvnd.common.Environment.OptionOrigin;
|
||||
import org.mvndaemon.mvnd.common.IoUtils;
|
||||
|
||||
public class CompletionGenerator {
|
||||
public class CompletionGeneratorTest {
|
||||
|
||||
@Test
|
||||
void generate() throws IOException {
|
||||
@@ -70,8 +70,7 @@ public class CompletionGenerator {
|
||||
final Path baseDir = Paths.get(System.getProperty("project.basedir", "."));
|
||||
|
||||
final byte[] bytes = template.getBytes(StandardCharsets.UTF_8);
|
||||
Files.write(baseDir.resolve("src/main/resources/mvnd-bash-completion.bash"), bytes);
|
||||
Files.write(baseDir.resolve("target/classes/mvnd-bash-completion.bash"), bytes);
|
||||
Files.write(baseDir.resolve("../dist/src/main/distro/bin/mvnd-bash-completion.bash"), bytes);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user