2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.logging.ref.slf4j.analysis;
24 import java.util.List;
26 import org.apache.commons.lang3.StringUtils;
27 import org.testng.Assert;
30 * A simple, recursive text-only report writer for the call graph.
32 public class CallGraphReportWriter {
34 /** The analyzer which does the work. */
35 final CallGraphAnalyzer mAnalyzer;
37 /** Short report, for validation. */
38 final StringBuilder mShortReport = new StringBuilder();
40 /** Longer report, for human eyes. */
41 final StringBuilder mLongReport = new StringBuilder();
45 * @param analyzer initialized analyzer.
47 public CallGraphReportWriter(final CallGraphAnalyzer analyzer) {
49 this.mAnalyzer = analyzer;
51 Assert.assertTrue(analyzer.getEntries().size() > 0);
52 final LogEntry e0 = analyzer.findEntryPoint();
53 Assert.assertNotNull(e0);
55 this.mLongReport.append(e0.toShortString()).append("\n");
56 this.mShortReport.append(StringUtils.substringAfter(e0.getLogger(), ".Component")).append("\n");
63 * Recursively analyze.
64 * @param invoker entry point.
65 * @param depth recursive depth, for handbrake.
67 private void report(final LogEntry invoker, final int depth) {
70 throw new AssertionError("Recursion ad infinitum");
73 final List<LogEntry> invokes0 = this.mAnalyzer.findInvokes(invoker);
74 for (final LogEntry invoke0 : invokes0) {
76 final LogEntry invoked0 = this.mAnalyzer.findInvocation(invoke0);
78 Assert.assertNotNull(invoked0);
80 final String indent = StringUtils.repeat(' ', depth * 4);
81 this.mLongReport.append(indent).append(invoked0.toShortString()).append('\n');
82 this.mShortReport.append(indent).append(StringUtils.substringAfter(invoked0.getLogger(), ".Component")).append('\n');
84 report(invoked0, depth + 1);
90 * @return short report, for validation.
92 public String getShortReport() {
93 return this.mShortReport.toString();
98 * @return long report, for printing out.
100 public String getLongReport() {
101 return this.mLongReport.toString();
108 public String toString() {
109 return this.getLongReport();