-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Java source code (#251)
* Added support for Java source code * Added option to disable source parser * Updated GSQL client URL
- Loading branch information
1 parent
2e0f4da
commit c95c8ec
Showing
8 changed files
with
130 additions
and
14 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
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
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,7 @@ | ||
public class Bar { | ||
|
||
public static int test(int a) { | ||
return a + 1; | ||
} | ||
|
||
} |
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,7 @@ | ||
public class Foo { | ||
|
||
public static void main(String[] args) { | ||
Bar.test(2); | ||
} | ||
|
||
} |
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
63 changes: 63 additions & 0 deletions
63
src/test/scala/com/github/plume/oss/SourceSupportTests.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,63 @@ | ||
package com.github.plume.oss | ||
|
||
import com.github.plume.oss.drivers.OverflowDbDriver | ||
import io.shiftleft.codepropertygraph.generated.{Cpg, NodeTypes, PropertyNames} | ||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import org.slf4j.LoggerFactory | ||
|
||
import java.io.File | ||
import java.nio.file.{Files, Paths} | ||
|
||
class SourceSupportTests extends AnyWordSpec with Matchers with BeforeAndAfterAll { | ||
|
||
private val logger = LoggerFactory.getLogger(classOf[SourceSupportTests]) | ||
|
||
private def getTestResource(dir: String): File = { | ||
val resourceURL = getClass.getResource(dir) | ||
if (resourceURL == null) throw new NullPointerException("Unable to obtain test resource") | ||
new File(resourceURL.getFile) | ||
} | ||
|
||
private val foo: File = getTestResource("/source_support/Foo.java") | ||
private val bar: File = getTestResource("/source_support/Bar.java") | ||
|
||
private var driver = new OverflowDbDriver() | ||
private var cpg: Option[Cpg] = None | ||
private val storage = Some("./cpg_test.odb") | ||
private val sandboxDir: File = Files.createTempDirectory("plume").toFile | ||
|
||
override def beforeAll(): Unit = { | ||
Paths.get(storage.get).toFile.delete() | ||
driver.clear() | ||
driver.close() | ||
driver = new OverflowDbDriver(storage) | ||
cpg = Some(new Jimple2Cpg().createCpg(foo.getParent, driver = driver)) | ||
sandboxDir.listFiles().foreach(_.delete()) | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
driver.clear() | ||
driver.close() | ||
Paths.get(storage.get).toFile.delete() | ||
driver.cacheConfig.dataFlowCacheFile match { | ||
case Some(jsonFile) => new File(jsonFile.toFile.getAbsolutePath + ".lz4").delete() | ||
case None => | ||
} | ||
} | ||
|
||
"should accept Java source files" in { | ||
val List(barM, fooM) = driver | ||
.propertyFromNodes(NodeTypes.TYPE_DECL, PropertyNames.NAME, PropertyNames.FULL_NAME, PropertyNames.IS_EXTERNAL) | ||
.filter(!_.getOrElse(PropertyNames.IS_EXTERNAL, true).toString.toBoolean) | ||
.sortWith { case (x, y) => | ||
x(PropertyNames.FULL_NAME).toString < y(PropertyNames.FULL_NAME).toString | ||
} | ||
fooM.get(PropertyNames.FULL_NAME) shouldBe Some("Foo") | ||
barM.get(PropertyNames.FULL_NAME) shouldBe Some("Bar") | ||
fooM.get(PropertyNames.IS_EXTERNAL) shouldBe Some(false) | ||
barM.get(PropertyNames.IS_EXTERNAL) shouldBe Some(false) | ||
} | ||
|
||
} |