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