String () { List<BuildEvent> events = collect(); Map<Object, Integer> levelMap = new HashMap<>(); Map<Object, String> result = new LinkedHashMap<>(); for (BuildEvent event : events) { if (event instanceof FinishEvent) { Integer value = levelMap.get(event.getId()); if (value == null) { fail("Finish event for non-registered start event" + event); } } if (event instanceof FinishEvent && ((FinishEvent)event).getResult() instanceof FailureResult) { result.computeIfPresent(event.getId(), (id, s) -> "error:" + s); } else { int level; if (event.getId() instanceof ExternalSystemTaskId) { level = 0; } else { Integer integer = levelMap.get(event.getParentId()); if (integer == null) { fail("Parent id not registered!" + event); } level = integer + 1; } assertFalse("cannot calculate event level, possible bad parent id", level < 0); if(event instanceof OutputBuildEvent && mySkipOutput){ continue; } result.put(event.getId(), event.getMessage()); levelMap.put(event.getId(), level); } } StringBuilder builder = new StringBuilder(); for (Map.Entry<Object, String> entry : result.entrySet()) { Integer indent = levelMap.get(entry.getKey()); builder.append(StringUtil.repeatSymbol(' ', indent == null ? 0 : indent.intValue())).append(entry.getValue()); if(!entry.getValue().endsWith("\n")) { builder.append("\n"); } } return builder.toString(); }