use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.
the class TknCli method findTaskUsages.
@Override
public List<RefUsage> findTaskUsages(String kind, String resource) throws IOException {
String jsonPathExpr = "jsonpath=\\\"{range .items[*]}{@.metadata.name}|{range .spec.tasks[*]}{.taskRef.kind},{.taskRef.name}|{end}{end}\\\"";
String result = ExecHelper.execute(command, envVars, "pipeline", "ls", "-n", getNamespace(), "-o", jsonPathExpr);
String[] resultSplitted = result.replace("\"", "").split("\\|");
List<RefUsage> usages = new ArrayList<>();
String pipeline = "";
for (String item : resultSplitted) {
if (!item.contains(",")) {
pipeline = item;
continue;
}
String[] kindName = item.split(",");
if (kindName.length == 2 && kindName[0].equalsIgnoreCase(kind) && kindName[1].equalsIgnoreCase(resource) && !pipeline.isEmpty()) {
String finalPipeline = pipeline;
Optional<RefUsage> refUsage = usages.stream().filter(ref -> ref.getKind().equals(KIND_PIPELINE) && ref.getName().equals(finalPipeline)).findFirst();
if (refUsage.isPresent()) {
refUsage.get().incremetOccurrence();
} else {
usages.add(new RefUsage(getNamespace(), pipeline, KIND_PIPELINE));
}
}
}
return usages;
}
use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.
the class FindTaskRefAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
TelemetryMessageBuilder.ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_MISC + "find task references").property(PROP_RESOURCE_KIND, KIND_TASK);
ParentableNode element = getElement(selected);
ExecHelper.submit(() -> {
try {
List<RefUsage> usages = tkncli.findTaskUsages(KIND_TASK, element.getName());
UIHelper.executeInUI(() -> FindTaskRefPanelBuilder.instance().build(anActionEvent.getProject(), KIND_TASK, element.getName(), usages));
telemetry.send();
} catch (IOException e) {
telemetry.error(anonymizeResource(null, element.getNamespace(), e.getMessage())).send();
logger.warn(e.getLocalizedMessage(), e);
}
});
}
use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.
the class FindClusterTaskRefAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
ParentableNode element = getElement(selected);
ExecHelper.submit(() -> {
try {
List<RefUsage> usages = tkncli.findTaskUsages(KIND_CLUSTERTASK, element.getName());
UIHelper.executeInUI(() -> FindTaskRefPanelBuilder.instance().build(anActionEvent.getProject(), KIND_CLUSTERTASK, element.getName(), usages));
} catch (IOException e) {
logger.warn(e.getLocalizedMessage(), e);
}
});
}
Aggregations