Filtering tab tabs in input tasks

I am currently implementing the SBT plugin for Gatling . One of its functions is to open the last generated report on a new browser tab from SBT. Since each run may have a different “simulation identifier” (basically a simple line), I would like to suggest that tabs on simulation identifiers end.

Example:

Launching the Gatling SBT plugin will create several folders (named simulationId + report generation date) in target/gatling, for example mysim-20140204234534, myothersim-20140203124534and yetanothersim-20140204234534.

Make a call lastReport. If someone starts typing lastReport my, I want to filter out the completion tab to offer only mysimand myothersim.

Getting a simulation ID is a breeze, but how can the parser help filter out sentences so that it offers only the existing simulation ID?

To summarize, I would like to do what testOnlyto do in some way: I only want to offer things that make sense in my context.

Thanks in advance for your answers,

Pierre

Edit: Since I got a little stuck after my last attempts, here is the code for my inputTask, it has the current state:

package io.gatling.sbt

import sbt._
import sbt.complete.{ DefaultParsers, Parser }

import io.gatling.sbt.Utils._

object GatlingTasks {

val lastReport = inputKey[Unit]("Open last report in browser")

val allSimulationIds = taskKey[Set[String]]("List of simulation ids found in reports folder")

val allReports = taskKey[List[Report]]("List of all reports by simulation id and timestamp")

def findAllReports(reportsFolder: File): List[Report] = {
    val allDirectories = (reportsFolder ** DirectoryFilter.&&(new PatternFilter(reportFolderRegex.pattern))).get
    allDirectories.map(file => (file, reportFolderRegex.findFirstMatchIn(file.getPath).get)).map {
        case (file, regexMatch) => Report(file, regexMatch.group(1), regexMatch.group(2))
    }.toList
}

def findAllSimulationIds(allReports: Seq[Report]): Set[String] = allReports.map(_.simulationId).distinct.toSet

def openLastReport(allReports: List[Report], allSimulationIds: Set[String]): Unit = {
    def simulationIdParser(allSimulationIds: Set[String]): Parser[Option[String]] =
        DefaultParsers.ID.examples(allSimulationIds, check = true).?

    def filterReportsIfSimulationIdSelected(allReports: List[Report], simulationId: Option[String]): List[Report] =
        simulationId match {
            case Some(id) => allReports.filter(_.simulationId == id)
            case None => allReports
        }

    Def.inputTaskDyn {
        val selectedSimulationId = simulationIdParser(allSimulationIds).parsed
        val filteredReports = filterReportsIfSimulationIdSelected(allReports, selectedSimulationId)
        val reportsSortedByDate = filteredReports.sorted.map(_.path)
        Def.task(reportsSortedByDate.headOption.foreach(file => openInBrowser((file / "index.html").toURI)))
    }
}

}

Of course, it openReportis called using the results of allReportsand allSimulationIds. I think I'm close to a functioning input task, but I still missed something ...

+3
source share
1 answer
  • Def.inputTaskDyn InputTask[T] . InputKey, lastReport. openLastReport Unit, , openLastReport , , . :

    def openLastReport(...): InputTask[...] = ...
    
    lastReport := openLastReport(...).evaluated
    

    ( openLastReport ​​ :=)

  • , , inputTaskDyn, inputTask. inputTaskDyn, . inputTask Def.task.

+1

All Articles