Search in sources :

Example 16 with Tkn

use of com.redhat.devtools.intellij.tektoncd.tkn.Tkn in project intellij-tekton by redhat-developer.

the class TreeHelper method getYAMLAndKindFromNode.

/**
 * Get YAML and Tekton kind from Tekton tree node.
 *
 * @param node the Tekton tree node
 * @return Pair where 'first' is YAML content and 'second' is Tekton kind
 */
public static Pair<String, String> getYAMLAndKindFromNode(ParentableNode<?> node) {
    Pair<String, String> yamlAndKind = null;
    try {
        String namespace = node.getNamespace();
        Tkn tkncli = node.getRoot().getTkn();
        String content = "";
        String kind = "";
        if (node instanceof PipelineNode) {
            content = tkncli.getPipelineYAML(namespace, node.getName());
            kind = KIND_PIPELINES;
        } else if (node instanceof ResourceNode) {
            content = tkncli.getResourceYAML(namespace, node.getName());
            kind = KIND_RESOURCES;
        } else if (node instanceof TaskNode) {
            content = tkncli.getTaskYAML(namespace, node.getName());
            kind = KIND_TASKS;
        } else if (node instanceof ClusterTaskNode) {
            content = tkncli.getClusterTaskYAML(node.getName());
            kind = KIND_CLUSTERTASKS;
        } else if (node instanceof ConditionNode) {
            content = tkncli.getConditionYAML(namespace, node.getName());
            kind = KIND_CONDITIONS;
        } else if (node instanceof TriggerTemplateNode) {
            content = tkncli.getTriggerTemplateYAML(namespace, node.getName());
            kind = KIND_TRIGGERTEMPLATES;
        } else if (node instanceof TriggerBindingNode) {
            content = tkncli.getTriggerBindingYAML(namespace, node.getName());
            kind = KIND_TRIGGERBINDINGS;
        } else if (node instanceof ClusterTriggerBindingNode) {
            content = tkncli.getClusterTriggerBindingYAML(node.getName());
            kind = KIND_CLUSTERTRIGGERBINDINGS;
        } else if (node instanceof EventListenerNode) {
            content = tkncli.getEventListenerYAML(namespace, node.getName());
            kind = KIND_EVENTLISTENERS;
        } else if (node instanceof TaskRunNode) {
            content = tkncli.getTaskRunYAML(namespace, node.getName());
            kind = KIND_TASKRUN;
        } else if (node instanceof PipelineRunNode) {
            content = tkncli.getPipelineRunYAML(namespace, node.getName());
            kind = KIND_PIPELINERUN;
        }
        yamlAndKind = Pair.create(content, kind);
    } catch (IOException e) {
        UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Error"));
    }
    return yamlAndKind;
}
Also used : ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) TriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingNode) TaskNode(com.redhat.devtools.intellij.tektoncd.tree.TaskNode) ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) EventListenerNode(com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode) ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) IOException(java.io.IOException) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) TriggerTemplateNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplateNode) ResourceNode(com.redhat.devtools.intellij.tektoncd.tree.ResourceNode) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) ConditionNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionNode) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)

Example 17 with Tkn

use of com.redhat.devtools.intellij.tektoncd.tkn.Tkn in project intellij-tekton by redhat-developer.

the class ConditionCompletionProvider method getConditionsLookups.

private List<LookupElementBuilder> getConditionsLookups(Project project, String namespace) {
    Tkn tkn = TreeHelper.getTkn(project);
    List<LookupElementBuilder> lookups = Collections.emptyList();
    try {
        lookups = tkn.getConditions(namespace).stream().map(condition -> LookupElementBuilder.create(condition).withPresentableText(condition.getMetadata().getName()).withLookupString(condition.getMetadata().getName()).withInsertHandler(new ConditionAutoInsertHandler())).collect(Collectors.toList());
    } catch (IOException e) {
        logger.warn("Error: " + e.getLocalizedMessage(), e);
    }
    return lookups;
}
Also used : Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) IOException(java.io.IOException)

Example 18 with Tkn

use of com.redhat.devtools.intellij.tektoncd.tkn.Tkn 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)

Example 19 with Tkn

use of com.redhat.devtools.intellij.tektoncd.tkn.Tkn in project intellij-tekton by redhat-developer.

the class TaskReferencesInspector method getTasksOnCluster.

private List<String> getTasksOnCluster(Project project, String namespace) {
    if (project == null) {
        return Collections.emptyList();
    }
    List<String> tasks = new ArrayList<>();
    try {
        Tkn tkn = TreeHelper.getTkn(project);
        if (tkn != null) {
            tkn.getTasks(namespace).forEach(task -> tasks.add(task.getMetadata().getName()));
            tkn.getClusterTasks().forEach(ctask -> tasks.add(ctask.getMetadata().getName()));
        }
    } catch (IOException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }
    return tasks;
}
Also used : Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 20 with Tkn

use of com.redhat.devtools.intellij.tektoncd.tkn.Tkn in project intellij-tekton by redhat-developer.

the class TektonTreeStructure method getConditions.

private Object[] getConditions(ConditionsNode element) {
    List<Object> conditions = new ArrayList<>();
    try {
        Tkn tkn = element.getRoot().getTkn();
        tkn.getConditions(element.getParent().getName()).forEach(condition -> conditions.add(new ConditionNode(element.getRoot(), element, condition)));
    } catch (IOException e) {
        conditions.add(new MessageNode(element.getRoot(), element, "Failed to load conditions"));
    }
    return conditions.toArray(new Object[conditions.size()]);
}
Also used : Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)25 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)13 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)3 Project (com.intellij.openapi.project.Project)3 TreeHelper (com.redhat.devtools.intellij.tektoncd.utils.TreeHelper)3 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 ProcessingContext (com.intellij.util.ProcessingContext)2 KIND_CLUSTERTASK (com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK)2 KIND_TASK (com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK)2 NAMESPACE (com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE)2 ClusterTaskNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode)2 ClusterTriggerBindingNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode)2 ConditionNode (com.redhat.devtools.intellij.tektoncd.tree.ConditionNode)2 EventListenerNode (com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode)2 PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)2 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)2 ResourceNode (com.redhat.devtools.intellij.tektoncd.tree.ResourceNode)2 TaskNode (com.redhat.devtools.intellij.tektoncd.tree.TaskNode)2