Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of gradle api #88

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
jvm: ['21', '22']
jvm: ['21', '22', '23']
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win_compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.8','3.9','3.10','3.11','3.12']
python-version: ['3.10','3.11','3.12']
with-science: ["--download", "--download --with-science"]
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "chen"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "2.1.6"
ThisBuild / version := "2.1.7"
ThisBuild / scalaVersion := "3.5.0"

val cpgVersion = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"downloadUrl": "https://github.com/AppThreat/chen",
"issueTracker": "https://github.com/AppThreat/chen/issues",
"name": "chen",
"version": "2.1.6",
"version": "2.1.7",
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
"applicationCategory": "code-analysis",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "2.1.6" %}
{% set version = "2.1.7" %}

package:
name: chen
Expand Down
1 change: 0 additions & 1 deletion platform/frontends/javasrc2cpg/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dependsOn(Projects.dataflowengineoss, Projects.x2cpg % "compile->compile;test->t
libraryDependencies ++= Seq(
"io.appthreat" %% "cpg2" % Versions.cpg,
"com.github.javaparser" % "javaparser-symbol-solver-core" % "3.26.2",
"org.gradle" % "gradle-tooling-api" % Versions.gradleTooling,
"org.scalatest" %% "scalatest" % Versions.scalatest % Test,
"org.projectlombok" % "lombok" % "1.18.34",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TSTypesTest extends AbstractPassTest {
args.name shouldBe "args"
args.code shouldBe "...args"
args.isVariadic shouldBe true
args.typeFullName shouldBe Defines.Any
args.typeFullName shouldBe "Array<any>"
}

"have return types for arrow functions" in AstFixture("const foo = () => 42;", tsTypes = true) { cpg =>
Expand Down Expand Up @@ -138,7 +138,7 @@ class TSTypesTest extends AbstractPassTest {
inside(cpg.identifier.l) { case List(x) =>
x.name shouldBe "x"
x.code shouldBe "x"
x.typeFullName shouldBe Defines.String // we can actually follow type intrinsics
x.typeFullName shouldBe "ModifiedNickName"
}
}

Expand Down
1 change: 0 additions & 1 deletion platform/frontends/x2cpg/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % Versions.circe,
"io.circe" %% "circe-generic" % Versions.circe,
"io.circe" %% "circe-parser" % Versions.circe,
"org.gradle" % "gradle-tooling-api" % Versions.gradleTooling % Optional,
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.appthreat.x2cpg.utils.dependency
import better.files.File
import io.appthreat.x2cpg.utils.ExternalCommand
import io.appthreat.x2cpg.utils.dependency.GradleConfigKeys.GradleConfigKey
import org.slf4j.LoggerFactory

import java.nio.file.Path
import scala.util.{Failure, Success}
Expand All @@ -17,10 +16,7 @@ case class DependencyResolverParams(
)

object DependencyResolver:
private val logger = LoggerFactory.getLogger(getClass)
private val defaultGradleProjectName = "app"
private val defaultGradleConfigurationName = "compileClasspath"
private val MaxSearchDepth: Int = 4
private val MaxSearchDepth: Int = 4

def getCoordinates(
projectDir: Path,
Expand All @@ -31,9 +27,8 @@ object DependencyResolver:
// TODO: implement
None
else if isGradleBuildFile(buildFile) then
getCoordinatesForGradleProject(buildFile.getParent, defaultGradleConfigurationName)
Nil
else
logger.debug(s"Found unsupported build file $buildFile")
Nil
}.flatten

Expand All @@ -49,16 +44,10 @@ object DependencyResolver:
) match
case Success(lines) => lines
case Failure(exception) =>
logger.debug(
s"Could not retrieve dependencies for Gradle project at path `$projectDir`\n" +
exception.getMessage
)
Seq()

val coordinates = MavenCoordinates.fromGradleOutput(lines)
logger.debug("Got {} Maven coordinates", coordinates.size)
Some(coordinates)
end getCoordinatesForGradleProject

def getDependencies(
projectDir: Path,
Expand All @@ -68,35 +57,13 @@ object DependencyResolver:
if isMavenBuildFile(buildFile) then
MavenDependencies.get(buildFile.getParent)
else if isGradleBuildFile(buildFile) then
getDepsForGradleProject(params, buildFile.getParent)
Nil
else
logger.debug(s"Found unsupported build file $buildFile")
Nil
}.flatten

Option.when(dependencies.nonEmpty)(dependencies)

private def getDepsForGradleProject(
params: DependencyResolverParams,
projectDir: Path
): Option[collection.Seq[String]] =
logger.debug("resolving Gradle dependencies at {}", projectDir)
val gradleProjectName =
params.forGradle.getOrElse(GradleConfigKeys.ProjectName, defaultGradleProjectName)
val gradleConfiguration =
params.forGradle.getOrElse(
GradleConfigKeys.ConfigurationName,
defaultGradleConfigurationName
)
GradleDependencies.get(projectDir, gradleProjectName, gradleConfiguration) match
case Some(deps) => Some(deps)
case None =>
logger.debug(
s"Could not download Gradle dependencies for project at path `$projectDir`"
)
None
end getDepsForGradleProject

private def isGradleBuildFile(file: File): Boolean =
val pathString = file.pathAsString
pathString.endsWith(".gradle") || pathString.endsWith(".gradle.kts")
Expand All @@ -106,7 +73,6 @@ object DependencyResolver:

private def findSupportedBuildFiles(currentDir: File, depth: Int = 0): List[Path] =
if depth >= MaxSearchDepth then
logger.debug("findSupportedBuildFiles reached max depth before finding build files")
Nil
else
val (childDirectories, childFiles) = currentDir.children.partition(_.isDirectory)
Expand Down
Loading
Loading