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

.scala-fortify_3.5.2.1.1.4.source-code.SessionWriter.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright © 2016-2024 Lightbend, Inc. All rights reserved.
 * No information contained herein may be reproduced or transmitted in any form
 * or by any means without the express written permission of Lightbend, Inc.
 */

package com.lightbend.tools.fortify.plugin

// so we can generate buildid.scasession.increment, with an entry
// for each source file we processed

import java.io.{File, PrintWriter}
import java.text.SimpleDateFormat
import java.util.TimeZone

object SessionWriter {

  case class Entry(sourcePath: File, nstPath: File, lines: Int)

  def formatDate(millis: Long, timeZone: TimeZone = TimeZone.getDefault): String = {
    val format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss.SSSXXX")
    format.setTimeZone(timeZone)
    format.format(millis)
  }

  def escape(s: String): String = s.flatMap {
    case '&' => "&"
    case '<' => "<"
    case c   => c.toString
  }

  def write(
      w: PrintWriter,
      buildId: String,
      session: Seq[Entry],
      encoding: String,
      millis: Long = System.currentTimeMillis(),
      timeZone: TimeZone = TimeZone.getDefault): Unit = {
    w.println(s"""<>""")
    w.println(s"""""")
    val now = formatDate(millis, timeZone)
    w.println(s"""""")
    w.println(s"""  """)
    w.println(s"""  """)
    w.println(s"""  ${escape(buildId)}""")
    w.println(s"""  """)
    for ((Entry(sourcePath, _, lines), index) <- session.zipWithIndex) {
      w.println(s"""    """)
      w.println(s"""      """)
      w.println(s"""        ${sourcePath.length}""")
      w.println(s"""        ${sourcePath.lastModified}""")
      w.println(s"""        ${escape(sourcePath.getCanonicalPath)}""")
      w.println(s"""      """)
      w.println(s"""    """)
    }
    for ((Entry(_, nstPath, lines), index) <- session.zipWithIndex) {
      w.println(s"""    """)
      w.println(s"""      """)
      w.println(s"""        ${escape(nstPath.getCanonicalPath)}""")
      w.println(s"""        """)
      w.println(s"""        """)
      w.println(s"""      """)
      w.println(s"""    """)
    }
    w.println(s"""  """)
    w.println(s"""  """)
    w.println(s"""    """)
    w.println(s"""      """)
    for (n <- 0 until (session.size * 2))
      w.println(s"""        """)
    w.println(s"""      """)
    w.println(s"""    """)
    w.println(s"""  """)
    w.println(s"""  """)
    w.println(s"""  """)
    w.println(s"""  """)
    w.println(s"""""")
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy