Search in sources :

Example 1 with NAMESPACE

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

the class TaskCompletionProvider method getTasksLookups.

private List<LookupElementBuilder> getTasksLookups(Project project, String namespace) {
    Tkn tkn = TreeHelper.getTkn(project);
    List<LookupElementBuilder> lookups = Collections.emptyList();
    try {
        lookups = tkn.getClusterTasks().stream().map(clusterTask -> LookupElementBuilder.create(clusterTask).withPresentableText(clusterTask.getMetadata().getName()).withTailText(" (clusterTask)", true).withLookupStrings(Arrays.asList("clustertask", clusterTask.getMetadata().getName())).withInsertHandler(new TaskAutoInsertHandler())).collect(Collectors.toList());
        lookups.addAll(tkn.getTasks(namespace).stream().map(task -> LookupElementBuilder.create(task).withPresentableText(task.getMetadata().getName()).withLookupString(task.getMetadata().getName()).withInsertHandler(new TaskAutoInsertHandler())).collect(Collectors.toList()));
        lookups.sort(Comparator.comparing(item -> ((HasMetadata) item.getObject()).getMetadata().getName()));
    } catch (IOException e) {
        logger.warn("Error: " + e.getLocalizedMessage(), e);
    }
    return lookups;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) TreeHelper(com.redhat.devtools.intellij.tektoncd.utils.TreeHelper) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) List(java.util.List) CompletionProvider(com.intellij.codeInsight.completion.CompletionProvider) Project(com.intellij.openapi.project.Project) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) NAMESPACE(com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) IOException(java.io.IOException)

Example 2 with NAMESPACE

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

the class VirtualFileHelper method innerOpenVirtualFileInEditor.

public static void innerOpenVirtualFileInEditor(Project project, String namespace, String name, String content, String kind, boolean edit, boolean readOnly, boolean clean) throws IOException {
    Optional<FileEditor> editor = Arrays.stream(FileEditorManager.getInstance(project).getAllEditors()).filter(fileEditor -> fileEditor.getFile().getName().startsWith(name)).findFirst();
    if (!clean) {
        clean = SettingsState.getInstance().displayCleanedYAMLInEditor;
    }
    if (!editor.isPresent()) {
        createAndOpenVirtualFile(project, namespace, name, content, kind, null, readOnly, clean);
    } else {
        Editor openedEditor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, editor.get().getFile()), true);
        if (edit) {
            content = cleanContent(content);
            openedEditor.getDocument().setText(content);
        }
    }
}
Also used : AllowNonProjectEditing(com.redhat.devtools.intellij.common.editor.AllowNonProjectEditing) Arrays(java.util.Arrays) CONTENT(com.redhat.devtools.intellij.common.CommonConstants.CONTENT) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) KIND_PIPELINERUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINERUN) SettingsState(com.redhat.devtools.intellij.tektoncd.settings.SettingsState) CLEANED(com.redhat.devtools.intellij.common.CommonConstants.CLEANED) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TARGET_NODE(com.redhat.devtools.intellij.tektoncd.Constants.TARGET_NODE) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) VirtualFileHelper.createTempFile(com.redhat.devtools.intellij.common.utils.VirtualFileHelper.createTempFile) Project(com.intellij.openapi.project.Project) Optional(java.util.Optional) VirtualFileHelper.cleanContent(com.redhat.devtools.intellij.common.utils.VirtualFileHelper.cleanContent) KIND_TASKRUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASKRUN) PROJECT(com.redhat.devtools.intellij.common.CommonConstants.PROJECT) KIND_PLURAL(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PLURAL) NAMESPACE(com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 3 with NAMESPACE

use of com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE 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

Project (com.intellij.openapi.project.Project)3 NAMESPACE (com.redhat.devtools.intellij.tektoncd.Constants.NAMESPACE)3 IOException (java.io.IOException)3 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 ProcessingContext (com.intellij.util.ProcessingContext)2 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)2 TreeHelper (com.redhat.devtools.intellij.tektoncd.utils.TreeHelper)2 Optional (java.util.Optional)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CompletionProvider (com.intellij.codeInsight.completion.CompletionProvider)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1