use of com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK 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();
}
Aggregations