Search in sources :

Example 1 with PipelineConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel 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 2 with PipelineConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel 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 3 with PipelineConfigurationModel

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

the class GeneralCompletionProvider method getLookupsPipeline.

/**
 * Get lookups for the opened pipeline configuration
 *
 * @param parameters
 * @param model the model built by the configuration
 * @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> getLookupsPipeline(CompletionParameters parameters, ConfigurationModel model, String prefix, String completionPrefix, int insertOffset) {
    List<LookupElementBuilder> lookups = new ArrayList<>();
    // get lookups for params
    lookups.addAll(getParamLookups(((PipelineConfigurationModel) model).getParams(), prefix, completionPrefix, insertOffset));
    // get lookups for tasks result
    String headPrefix_8 = prefix.length() > 8 ? prefix.substring(0, 8) : prefix;
    if ("$(tasks.".contains(headPrefix_8)) {
        String namespace = model.getNamespace();
        if (Strings.isNullOrEmpty(namespace)) {
            VirtualFile vf = FileDocumentManager.getInstance().getFile(parameters.getEditor().getDocument());
            namespace = vf.getUserData(NAMESPACE);
        }
        lookups.addAll(getTasksInPipelineLookups(parameters, namespace, prefix, completionPrefix, insertOffset));
    }
    return lookups;
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Example 4 with PipelineConfigurationModel

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

the class PipelineConfigurationModelTest method checkPipelineModelWithWorkspaces.

@Test
public void checkPipelineModelWithWorkspaces() throws IOException {
    String configuration = load("pipeline5.yaml");
    PipelineConfigurationModel model = (PipelineConfigurationModel) ConfigurationModelFactory.getModel(configuration);
    assertEquals(model.getName(), "foo");
    assertEquals(model.getNamespace(), "tekton");
    assertEquals(model.getKind(), "Pipeline");
    assertTrue(model.getParams().isEmpty());
    assertTrue(model.getInputResources().isEmpty());
    assertTrue(model.getOutputResources().isEmpty());
    assertTrue(model.getWorkspaces().size() == 2);
    assertEquals(model.getWorkspaces().get(0).getName(), "password-vault");
    assertEquals(model.getWorkspaces().get(1).getName(), "recipe-store");
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 5 with PipelineConfigurationModel

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

the class ResourceInPipelineCompletionProvider method getResourcesLookups.

private List<LookupElementBuilder> getResourcesLookups(CompletionParameters parameters) {
    String configuration = parameters.getEditor().getDocument().getText();
    ConfigurationModel model = ConfigurationModelFactory.getModel(configuration);
    if (model == null || !(model instanceof PipelineConfigurationModel))
        return Collections.emptyList();
    List<LookupElementBuilder> lookups = new ArrayList<>();
    ((PipelineConfigurationModel) model).getInputResources().forEach(resource -> {
        lookups.add(LookupElementBuilder.create(resource.name()).withPresentableText(resource.name()).withLookupString(resource.name()));
    });
    return lookups;
}
Also used : PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) PipelineConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel) ArrayList(java.util.ArrayList) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Aggregations

PipelineConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.resources.PipelineConfigurationModel)11 BaseTest (com.redhat.devtools.intellij.tektoncd.BaseTest)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 ConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel)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 Collections (java.util.Collections)3 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 ASTNode (com.intellij.lang.ASTNode)2 StringHelper (com.redhat.devtools.intellij.common.utils.StringHelper)2 TaskConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1