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;
}
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));
}
});
}
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);
}
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);
}
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);
}
Aggregations