Search in sources :

Example 1 with KIND_TASK

use of com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK in project intellij-tekton by redhat-developer.

the class SingleInputInTaskCompletionProvider method getLookupsPipeline.

private List<LookupElementBuilder> getLookupsPipeline(CompletionParameters parameters) {
    Project project = parameters.getEditor().getProject();
    String currentInputType = parameters.getPosition().getParent().getParent().getParent().getParent().getParent().getParent().getNode().getFirstChildNode().getText();
    JsonNode currentTaskNode = getCurrentTaskRefNameInPipeline(parameters, parameters.getPosition());
    Tkn tkn = TreeHelper.getTkn(project);
    String ns = parameters.getOriginalFile().getVirtualFile().getUserData(NAMESPACE);
    try {
        JsonNode taskRef = currentTaskNode.get("taskRef");
        if (taskRef == null) {
            return Collections.emptyList();
        }
        String nameTask = taskRef.has("name") ? taskRef.get("name").asText("") : "";
        if (nameTask.isEmpty()) {
            return Collections.emptyList();
        }
        String kind = taskRef.has("kind") ? taskRef.get("kind").asText(KIND_TASK) : KIND_TASK;
        Optional<Task> task = Optional.empty();
        Optional<ClusterTask> cTask = Optional.empty();
        if (kind.equalsIgnoreCase(KIND_TASK)) {
            task = tkn.getTasks(ns).stream().filter(t -> t.getMetadata().getName().equalsIgnoreCase(nameTask)).findFirst();
        } else if (kind.equalsIgnoreCase(KIND_CLUSTERTASK)) {
            cTask = tkn.getClusterTasks().stream().filter(t -> t.getMetadata().getName().equalsIgnoreCase(nameTask)).findFirst();
        }
        TaskSpec spec = task.isPresent() ? task.get().getSpec() : cTask.isPresent() ? cTask.get().getSpec() : null;
        if (spec != null) {
            switch(currentInputType.toLowerCase()) {
                case "params":
                    {
                        return getParamsLookups(spec, currentTaskNode);
                    }
                case "inputs":
                    {
                        return getInputResourcesLookups(spec, currentTaskNode);
                    }
                case "outputs":
                    {
                        return getOutputResourcesLookups(spec, currentTaskNode);
                    }
                case "workspaces":
                    {
                        return getWorkspacesLookups(spec, currentTaskNode);
                    }
            }
        }
    } catch (IOException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }
    return Collections.emptyList();
}
Also used : YAMLHelper(com.redhat.devtools.intellij.common.utils.YAMLHelper) TreeHelper(com.redhat.devtools.intellij.tektoncd.utils.TreeHelper) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) LoggerFactory(org.slf4j.LoggerFactory) KIND_TASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK) ArrayList(java.util.ArrayList) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) NAMESPACE(com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE) ProcessingContext(com.intellij.util.ProcessingContext) TaskSpec(io.fabric8.tekton.pipeline.v1beta1.TaskSpec) Logger(org.slf4j.Logger) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) KIND_CLUSTERTASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK) IOException(java.io.IOException) TextRange(com.intellij.openapi.util.TextRange) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) List(java.util.List) Optional(java.util.Optional) ConfigurationModelFactory(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModelFactory) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Task(io.fabric8.tekton.pipeline.v1beta1.Task) Project(com.intellij.openapi.project.Project) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) Task(io.fabric8.tekton.pipeline.v1beta1.Task) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) TaskSpec(io.fabric8.tekton.pipeline.v1beta1.TaskSpec) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 ProcessingContext (com.intellij.util.ProcessingContext)1 YAMLHelper (com.redhat.devtools.intellij.common.utils.YAMLHelper)1 KIND_CLUSTERTASK (com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK)1 KIND_TASK (com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK)1 NAMESPACE (com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE)1 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)1 TreeHelper (com.redhat.devtools.intellij.tektoncd.utils.TreeHelper)1 ConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel)1 ConfigurationModelFactory (com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModelFactory)1 ClusterTask (io.fabric8.tekton.pipeline.v1beta1.ClusterTask)1 Task (io.fabric8.tekton.pipeline.v1beta1.Task)1 TaskSpec (io.fabric8.tekton.pipeline.v1beta1.TaskSpec)1 IOException (java.io.IOException)1