Search in sources :

Example 1 with ConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel in project intellij-tekton by redhat-developer.

the class YAMLBuilder method createRunInternal.

public static ObjectNode createRunInternal(String kind, ConfigurationModel model, boolean toDebug) {
    ObjectNode rootNode = YAML_MAPPER.createObjectNode();
    rootNode.put("apiVersion", "tekton.dev/v1beta1");
    rootNode.put("kind", kind);
    ObjectNode metadataNode = YAML_MAPPER.createObjectNode();
    metadataNode.put("generateName", model.getName() + "-");
    rootNode.set("metadata", metadataNode);
    ObjectNode spec = YAML_MAPPER.createObjectNode();
    if (model instanceof ActionToRunModel) {
        ActionToRunModel actionModel = (ActionToRunModel) model;
        if (kind.equalsIgnoreCase(KIND_PIPELINERUN)) {
            spec = createPipelineRunSpec(actionModel);
        } else {
            spec = createTaskRunSpec(actionModel.getResource().getName(), actionModel.getParams(), actionModel.getInputResources(), actionModel.getOutputResources(), actionModel.getWorkspaces(), actionModel.getServiceAccount().isEmpty() ? null : actionModel.getServiceAccount(), toDebug);
        }
    } else if (model instanceof TaskConfigurationModel) {
        Map<String, Workspace> workspaces = new HashMap<>();
        ((TaskConfigurationModel) model).getWorkspaces().stream().forEach(workspace -> {
            workspace.setKind(Workspace.Kind.EMPTYDIR);
            workspaces.put(workspace.getName(), workspace);
        });
        spec = createTaskRunSpec(model.getName(), ((TaskConfigurationModel) model).getParams(), ((TaskConfigurationModel) model).getInputResources(), ((TaskConfigurationModel) model).getOutputResources(), workspaces, "", toDebug);
    }
    rootNode.set("spec", spec);
    return rootNode;
}
Also used : WRITE_DOC_START_MARKER(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) YAMLHelper(com.redhat.devtools.intellij.common.utils.YAMLHelper) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Output(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Output) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) HashMap(java.util.HashMap) KIND_PIPELINERUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINERUN) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) List(java.util.List) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) KIND_PVC(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PVC) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) JsonNode(com.fasterxml.jackson.databind.JsonNode) KIND_PIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) HashMap(java.util.HashMap) Map(java.util.Map) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel)

Example 2 with ConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel in project intellij-tekton by redhat-developer.

the class StartResourceModel method adaptsToRun.

public void adaptsToRun(String configuration) {
    ConfigurationModel model = ConfigurationModelFactory.getModel(configuration);
    if (!(model instanceof RunConfigurationModel))
        return;
    // update params/input resources
    this.resource.getParams().forEach(input -> {
        // for each input, update its defaultValue/Value with the value taken from the *run model
        if (((RunConfigurationModel) model).getParameters().containsKey(input.name())) {
            String value = ((RunConfigurationModel) model).getParameters().get(input.name());
            input.setDefaultValue(value);
        }
    });
    this.resource.getInputResources().forEach(input -> {
        // for each input, update its defaultValue/Value with the value taken from the *run model
        String value = null;
        if (model instanceof PipelineRunConfigurationModel) {
            if (((PipelineRunConfigurationModel) model).getResources().containsKey(input.name())) {
                value = ((PipelineRunConfigurationModel) model).getResources().get(input.name());
            }
        } else {
            if (((TaskRunConfigurationModel) model).getInputResources().containsKey(input.name())) {
                value = ((TaskRunConfigurationModel) model).getInputResources().get(input.name());
            }
        }
        if (value != null) {
            input.setValue(value);
        }
    });
    // update output resource if its a taskrun
    if (model instanceof TaskRunConfigurationModel) {
        this.resource.getOutputResources().stream().forEach(output -> {
            if (((TaskRunConfigurationModel) model).getOutputResources().containsKey(output.name())) {
                output.setValue(((TaskRunConfigurationModel) model).getOutputResources().get(output.name()));
            }
        });
    }
    // update workspaces
    this.workspaces.keySet().forEach(workspaceName -> {
        if (((RunConfigurationModel) model).getWorkspacesValues().containsKey(workspaceName)) {
            this.workspaces.put(workspaceName, ((RunConfigurationModel) model).getWorkspacesValues().get(workspaceName));
        }
    });
    // update serviceAccount/taskServiceAccount
    String sa = ((RunConfigurationModel) model).getServiceAccountName();
    if (sa != null) {
        this.globalServiceAccount = sa;
    }
    this.taskServiceAccountNames.keySet().forEach(task -> {
        if (((RunConfigurationModel) model).getTaskServiceAccountNames().containsKey(task)) {
            this.taskServiceAccountNames.put(task, ((RunConfigurationModel) model).getTaskServiceAccountNames().get(task));
        }
    });
}
Also used : PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel) PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) RunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel) PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) RunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel)

Example 3 with ConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel in project intellij-tekton by redhat-developer.

the class FinallyReferencesInspector method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    ConfigurationModel model = getTektonModelFromFile(file);
    if (model == null) {
        return ProblemDescriptor.EMPTY_ARRAY;
    }
    List<PsiElement> errorPsiElements = new ArrayList<>();
    if (model instanceof PipelineConfigurationModel) {
        errorPsiElements = findFinallySectionErrors(file);
    }
    return errorPsiElements.stream().map(item -> manager.createProblemDescriptor(item, item, "No runAfter can be specified in final tasks.", ProblemHighlightType.GENERIC_ERROR, isOnTheFly)).toArray(ProblemDescriptor[]::new);
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) List(java.util.List) InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel in project intellij-tekton by redhat-developer.

the class VariableReferencesInspector method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    ConfigurationModel model = getTektonModelFromFile(file);
    if (model == null) {
        return ProblemDescriptor.EMPTY_ARRAY;
    }
    List<PsiElement> unusedPsiElements = new ArrayList<>();
    if (model instanceof PipelineConfigurationModel) {
        unusedPsiElements = highlightInPipeline(file, (PipelineConfigurationModel) model);
    } else if (model instanceof TaskConfigurationModel) {
        unusedPsiElements = highlightInTask(file, (TaskConfigurationModel) model);
    }
    return unusedPsiElements.stream().map(item -> manager.createProblemDescriptor(item, item, "Variable " + StringHelper.getUnquotedValueFromPsi(item.getContext()) + " is never used", ProblemHighlightType.WEAK_WARNING, isOnTheFly, LocalQuickFix.EMPTY_ARRAY)).toArray(ProblemDescriptor[]::new);
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) Output(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Output) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) List(java.util.List) InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) FileASTNode(com.intellij.lang.FileASTNode) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) StringHelper(com.redhat.devtools.intellij.common.utils.StringHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Collections(java.util.Collections) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) ArrayList(java.util.ArrayList) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel in project intellij-tekton by redhat-developer.

the class GeneralCompletionProvider method getVariablesLookups.

/**
 * Get lookups for all possible variables matching the prefix
 *
 * @param parameters
 * @param prefix the prefix we are really using. E.g the line we are in is "value: test -f $(params." -> the prefix is "$(params."
 * @param completionPrefix the prefix we need to add to the lookup to make it be shown by IJ. E.g the line we are in is "value: test -f $(params." -> the completionPrefix is "test -f $(params."
 * @param insertOffset the position where the lookup has to be copied on
 * @return
 */
private List<LookupElementBuilder> getVariablesLookups(CompletionParameters parameters, String prefix, String completionPrefix, int insertOffset) {
    String configuration = parameters.getEditor().getDocument().getText();
    ConfigurationModel model = ConfigurationModelFactory.getModel(configuration);
    if (model == null)
        return Collections.emptyList();
    return getLookupsByKind(parameters, model, prefix, completionPrefix, insertOffset);
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) ConditionConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.ConditionConfigurationModel) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel)

Aggregations

ConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel)8 PipelineConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 InspectionManager (com.intellij.codeInspection.InspectionManager)3 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)3 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 TaskConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel)3 Collections (java.util.Collections)3 Pattern (java.util.regex.Pattern)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 ASTNode (com.intellij.lang.ASTNode)2 StringHelper (com.redhat.devtools.intellij.common.utils.StringHelper)2 Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)2 Output (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Output)2 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)2 IOException (java.io.IOException)2