All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.cli.plugin.PluginCommand Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.cli.plugin;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

import io.quarkus.cli.build.ExecuteUtil;
import io.quarkus.cli.common.OutputOptionMixin;

public interface PluginCommand extends Callable {

    List getCommand();

    List getArguments();

    OutputOptionMixin getOutput();

    void useArguments(List arguments);

    default Path getWorkingDirectory() {
        return Paths.get(System.getProperty("user.dir"));
    }

    default Integer call() throws Exception {
        try {
            List commandWithArgs = new ArrayList<>();
            commandWithArgs.addAll(getCommand());
            commandWithArgs.addAll(getArguments());
            return ExecuteUtil.executeProcess(getOutput(), commandWithArgs.toArray(new String[commandWithArgs.size()]),
                    getWorkingDirectory().toFile());
        } catch (Exception e) {
            e.printStackTrace();
            return getOutput().handleCommandException(e, "Unable to run plugin command: [" + String.join(" ", getCommand())
                    + "] with arguments: [" + String.join(" ", getArguments()) + "]");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy