-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from joernio/andrei/securibench-downloader
[Dataset] Added downloader for `Securibench-Micro`
- Loading branch information
Showing
5 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ jobs: | |
- name: Rename | ||
run: | | ||
mv workspace/ichnaea.zip ichnaea.zip | ||
mv workspace/securibench-micro-JAVA_BYTECODE.zip securibench-micro-JAVA_BYTECODE.zip | ||
mv workspace/securibench-micro-JAVA_SRC.zip securibench-micro-JAVA_SRC.zip | ||
- name: Set next release version | ||
id: taggerFinal | ||
uses: anothrNick/[email protected] | ||
|
@@ -53,4 +55,6 @@ jobs: | |
with: | ||
tag_name: ${{ steps.taggerDryRun.outputs.new_tag }} | ||
files: | | ||
ichnaea.zip | ||
ichnaea.zip | ||
securibench-micro-JAVA_BYTECODE.zip | ||
securibench-micro-JAVA_SRC.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/scala/io/joern/benchmarks/datasets/runner/SecuribenchMicroDownloader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.joern.benchmarks.datasets.runner | ||
|
||
import better.files.File | ||
import io.joern.benchmarks.* | ||
import io.joern.benchmarks.datasets.JavaCpgTypes | ||
import io.joern.x2cpg.utils.ExternalCommand | ||
import org.slf4j.LoggerFactory | ||
|
||
import java.net.{URI, URL} | ||
import scala.util.{Failure, Success, Try} | ||
|
||
class SecuribenchMicroDownloader(datasetDir: File, cpgCreatorType: JavaCpgTypes.Value) | ||
extends DatasetDownloader(datasetDir) | ||
with SingleFileDownloader { | ||
|
||
private val logger = LoggerFactory.getLogger(getClass) | ||
|
||
override val benchmarkName = s"Securibench Micro v1.08" | ||
|
||
override protected val benchmarkUrl: URL = URI( | ||
"https://github.com/too4words/securibench-micro/archive/6a5a724.zip" | ||
).toURL | ||
override protected val benchmarkFileName: String = "securibench-micro-6a5a72488ea830d99f9464fc1f0562c4f864214b" | ||
override protected val benchmarkBaseDir: File = datasetDir / benchmarkFileName | ||
|
||
private val apacheJdo = URI("https://repo1.maven.org/maven2/javax/jdo/jdo-api/3.1/jdo-api-3.1.jar").toURL | ||
|
||
override def initialize(): Try[File] = Try { | ||
downloadBenchmarkAndUnarchive(CompressionTypes.ZIP) | ||
downloadFile(apacheJdo, benchmarkBaseDir / "lib" / "jdo-api-3.1.jar") | ||
if ( | ||
cpgCreatorType == JavaCpgTypes.JAVA_BYTECODE && (benchmarkBaseDir / "classes") | ||
.walk() | ||
.count(_.`extension`.contains(".class")) < 1 | ||
) { | ||
val sourceFiles = (benchmarkBaseDir / "src") | ||
.walk() | ||
.filter(f => f.isRegularFile && f.`extension`.contains(".java")) | ||
.map(f => f.pathAsString.stripPrefix(s"${benchmarkBaseDir.pathAsString}${java.io.File.separator}")) | ||
.mkString(" ") | ||
val command = | ||
Seq( | ||
"javac", | ||
"-cp", | ||
"'.:lib/cos.jar:lib/j2ee.jar:lib/java2html.jar:lib/jdo-api-3.1.jar;'", | ||
"-d", | ||
"classes", | ||
sourceFiles | ||
).mkString(" ") | ||
ExternalCommand.run(command, benchmarkBaseDir.pathAsString) match { | ||
case Failure(exception) => | ||
logger.error(s"Exception encountered while compiling source code with: '$command'") | ||
throw exception | ||
case Success(_) => logger.info(s"Successfully compiled $benchmarkName") | ||
} | ||
} | ||
|
||
compressBenchmark( | ||
benchmarkBaseDir, | ||
Option(File(s"${datasetDir.pathAsString}/securibench-micro-${cpgCreatorType.toString}.zip")) | ||
) | ||
} | ||
|
||
override def run(): Unit = { | ||
initialize() match { | ||
case Failure(exception) => | ||
logger.error(s"Unable to initialize benchmark '$getClass'", exception) | ||
case Success(benchmarkDir) => | ||
} | ||
} | ||
} |