All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.ikor.sip.foundation.mvnplugin.ResultsFormatter Maven / Gradle / Ivy

The newest version!
package de.ikor.sip.foundation.mvnplugin;

import de.ikor.sip.foundation.mvnplugin.model.AnalyzeResult;
import de.ikor.sip.foundation.mvnplugin.model.BannedImportRecords;
import de.ikor.sip.foundation.mvnplugin.model.ImportStatement;
import java.util.List;

/** Formats the info about found cross dependencies for presentation purpose. */
class ResultsFormatter {
  /** Formats the info about found cross dependencies for presentation purpose. */
  public String formatMatches(AnalyzeResult analyzeResult) {
    final StringBuilder b = new StringBuilder();

    b.append("SIP connectors cross-dependencies detected. Please decouple connector packages:\n");

    if (analyzeResult.bannedImportsInCompileCode()) {
      b.append("\nDependable connectors in main folder:\n\n");

      final List srcMatchesByGroup = analyzeResult.srcBanMatches();
      formatGroupedMatches(b, srcMatchesByGroup);
    }

    if (analyzeResult.bannedImportsInTestCode()) {
      b.append("\nDependable connectors in test folder:\n\n");
      final List testMatchesByGroup = analyzeResult.testBanMatches();
      formatGroupedMatches(b, testMatchesByGroup);
    }

    return b.toString();
  }

  private void formatGroupedMatches(StringBuilder b, List matches) {
    matches.forEach(
        fileMatch -> {
          b.append("\tin file").append(": ").append(fileMatch.getSourceFile()).append("\n");
          fileMatch.getMatchedImports().forEach(match -> appendMatch(match, b));
        });
  }

  private void appendMatch(ImportStatement match, StringBuilder b) {
    b.append("\t\t")
        .append("Line: ")
        .append(match.getLine())
        .append("\t")
        .append(match.getImportName())
        .append("\n");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy