From b7d3e78dbb10fa2271a9b4678fe7212a3f320b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0est=C3=A1k=20V=C3=ADt?= Date: Mon, 21 Nov 2016 13:30:13 +0100 Subject: [PATCH] Error messages refactoring --- .../DependencyCheckReportsProcessor.scala | 20 +++++++++++++------ app/controllers/warnings.scala | 9 +++++++++ app/views/warnings/projectFailures.scala.html | 8 ++++++++ .../resultsWithErrorMessages.scala.html | 7 ++----- 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 app/views/warnings/projectFailures.scala.html diff --git a/app/controllers/DependencyCheckReportsProcessor.scala b/app/controllers/DependencyCheckReportsProcessor.scala index 64c8bcf..216efa0 100644 --- a/app/controllers/DependencyCheckReportsProcessor.scala +++ b/app/controllers/DependencyCheckReportsProcessor.scala @@ -5,6 +5,7 @@ import com.google.inject.Inject import com.google.inject.name.Named import com.ysoft.odc.Checks._ import com.ysoft.odc._ +import com.ysoft.odc.statistics.FailedProjects import org.joda.time.DateTimeConstants import play.api.Logger import play.api.i18n.{I18nSupport, MessagesApi} @@ -40,6 +41,7 @@ final class DependencyCheckReportsProcessor @Inject() ( } } + private def buildLink(reportInfo: ReportInfo): String = s"$server/browse/${reportInfo.projectId}" def processResults( resultsFuture: Future[(Map[String, (Build, ArtifactItem, ArtifactFile)], Map[String, Throwable])], @@ -47,7 +49,7 @@ final class DependencyCheckReportsProcessor @Inject() ( )(implicit requestHeader: DefaultRequest, snoozesInfo: SnoozesInfo, executionContext: ExecutionContext) = try{ for((successfulResults, failedResults) <- resultsFuture) yield{ val reportResult = dependencyCheckReportsParser.parseReports(successfulResults, failedResults) - import reportResult.{allDependencies, failedAnalysises, flatReports, groupedDependencies, vulnerableDependencies} + import reportResult.{allDependencies, failedAnalysises, flatReports, groupedDependencies, vulnerableDependencies, projectsReportInfo} val now = DateTime.now val oldReportThreshold = now - 1.day val cveTimestampThreshold = now - (if(now.dayOfWeek().get == DateTimeConstants.MONDAY) 4.days else 2.days ) @@ -73,12 +75,18 @@ final class DependencyCheckReportsProcessor @Inject() ( ) val unknownIdentifierTypes = allDependencies.flatMap(_._1.identifiers.map(_.identifierType)).toSet -- Set("maven", "cpe") + val logChecks = Seq[(String => Boolean, ProjectWarningBuilder)]( + ( + log => log.lines.exists(l => (l.toLowerCase startsWith "error") || (l.toLowerCase contains "[error]")), + ProjectWarningBuilder("results-with-error-messages", views.html.warnings.resultsWithErrorMessages(), WarningSeverity.Error) + ) + ) + val logWarnings: Seq[Warning] = logChecks.flatMap{case (logCheck, warningBuilder) => + val resultsWithErrorMessages = successfulResults.filter{case (k, (_, _, log)) => logCheck(log.dataString)} + if(resultsWithErrorMessages.nonEmpty) Some(warningBuilder.forProjects(new FailedProjects(resultsWithErrorMessages.keys.map(projectsReportInfo.reportIdToReportInfo).toSet), buildLink)) else None + } val extraWarnings = Seq[Option[Warning]]( if(unknownIdentifierTypes.size > 0) Some(IdentifiedWarning("unknown-identifier-types", views.html.warnings.unknownIdentifierType(unknownIdentifierTypes), WarningSeverity.Info)) else None, - { - val resultsWithErrorMessages = successfulResults.filter{case (k, (_, _, log)) => log.dataString.lines.exists(l => (l.toLowerCase startsWith "error") || (l.toLowerCase contains "[error]"))} - if(resultsWithErrorMessages.nonEmpty) Some(IdentifiedWarning("results-with-error-messages", views.html.warnings.resultsWithErrorMessages(resultsWithErrorMessages.values.map{case (build, _, _) => build}.toSeq, server), WarningSeverity.Error)) else None - }, if(failedResults.isEmpty) None else Some(IdentifiedWarning("failed-results", views.html.warnings.failedResults(failedResults), WarningSeverity.Error)), if(requiredVersions.isEmpty) None else Some(IdentifiedWarning("required-versions", views.html.warnings.textWarning("You have manually requested results for some older version."), WarningSeverity.Warning)), if(failedAnalysises.isEmpty) None else Some(IdentifiedWarning("failed-analysises", views.html.warnings.textWarning(s"Some reports failed to parse: ${failedAnalysises.keySet}"), WarningSeverity.Error)) @@ -86,7 +94,7 @@ final class DependencyCheckReportsProcessor @Inject() ( val scanWarnings = ScanChecks.flatMap(_(flatReports)) val groupedDependenciesWarnings = GroupedDependenciesChecks.flatMap(_(groupedDependencies)) - val allWarnings = scanWarnings ++ groupedDependenciesWarnings ++ extraWarnings + val allWarnings = scanWarnings ++ groupedDependenciesWarnings ++ logWarnings ++ extraWarnings // TODO: log analysis // TODO: related dependencies diff --git a/app/controllers/warnings.scala b/app/controllers/warnings.scala index 671f90b..1f8b13b 100644 --- a/app/controllers/warnings.scala +++ b/app/controllers/warnings.scala @@ -1,5 +1,6 @@ package controllers +import com.ysoft.odc.statistics.FailedProjects import controllers.WarningSeverity.WarningSeverity import play.twirl.api.Html @@ -21,4 +22,12 @@ sealed abstract class Warning { final case class IdentifiedWarning(id: String, html: Html, severity: WarningSeverity) extends Warning{ def optimize = copy(html = Html(html.body)) +} + +final case class ProjectWarningBuilder(id: String, html: Html, severity: WarningSeverity){ + def forProjects(projects: FailedProjects, buildLink: ReportInfo => String): IdentifiedWarning = IdentifiedWarning( + id, + views.html.warnings.projectFailures(html, projects, buildLink), + severity + ) } \ No newline at end of file diff --git a/app/views/warnings/projectFailures.scala.html b/app/views/warnings/projectFailures.scala.html new file mode 100644 index 0000000..2e59c6c --- /dev/null +++ b/app/views/warnings/projectFailures.scala.html @@ -0,0 +1,8 @@ +@import com.ysoft.odc.statistics.FailedProjects +@(message: Html, failedReports: FailedProjects, buildLink: ReportInfo => String) +@message + \ No newline at end of file diff --git a/app/views/warnings/resultsWithErrorMessages.scala.html b/app/views/warnings/resultsWithErrorMessages.scala.html index efb93b0..b3b86fd 100644 --- a/app/views/warnings/resultsWithErrorMessages.scala.html +++ b/app/views/warnings/resultsWithErrorMessages.scala.html @@ -1,5 +1,2 @@ -@(reportsWithErrorMessages: Seq[Build], urlBase: String) -Following projects seem to contain some error messages in their logs: -@for(build <- reportsWithErrorMessages.toSeq.sortBy(_.projectName)){ -
  • @secureLink(build.resultLink(urlBase)){@build.projectName}
  • -} +@() +Following projects seem to contain some error messages in their logs: \ No newline at end of file