Skip to content

Commit

Permalink
db and bf CLI options are not honored, close #1323
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Landelle committed Jul 31, 2013
1 parent 268bce0 commit 2b89363
Showing 1 changed file with 15 additions and 11 deletions.
Expand Up @@ -60,21 +60,25 @@ object GatlingFiles {
}
}

def validateResource(filePath: Path, defaultFolder: String): Validation[Resource] = {
val defaultPath = defaultFolder / filePath
val classPathResource = Option(getClass.getClassLoader.getResource(defaultPath.toString.replace('\\', '/'))).map { url =>
url.getProtocol match {
case "file" => FileResource(url.getFile.toFile)
case "jar" => ClassPathResource(url, filePath.extension)
case _ => throw new UnsupportedOperationException
def validateResource(filePath: Path, defaultFolder: Path, defaultPackage: String): Validation[Resource] = {
val path = defaultFolder / filePath
val resource = if (path.exists) {
Some(FileResource(path.toFile))
} else {
val classpathPath = defaultPackage / filePath
Option(getClass.getClassLoader.getResource(classpathPath.toString.replace('\\', '/'))).map { url =>
url.getProtocol match {
case "file" => FileResource(url.getFile.toFile)
case "jar" => ClassPathResource(url, filePath.extension)
case _ => throw new UnsupportedOperationException
}
}
}

val resource = classPathResource.orElse(filePath.ifFile(path => FileResource(path.toFile)))
resource.map(_.success).getOrElse(s"file $filePath doesn't exist".failure)
}

def requestBodyResource(filePath: Path) = requestBodyFileMemo.getOrElseUpdate(filePath, validateResource(filePath, "request-bodies"))
def requestBodyResource(filePath: Path) = requestBodyFileMemo.getOrElseUpdate(filePath, validateResource(filePath, requestBodiesDirectory, "request-bodies"))

def feederResource(filePath: Path) = feederFileMemo.getOrElseUpdate(filePath, validateResource(filePath, "data"))
}
def feederResource(filePath: Path) = feederFileMemo.getOrElseUpdate(filePath, validateResource(filePath, dataDirectory, "data"))
}

0 comments on commit 2b89363

Please sign in to comment.