github / github/codeql

General issue with setup

未关闭
#15,240 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

Hello,
I am currently walking through setting up CodeQL. For simplicity I am using the java example and query from this [link](https://codeql.github.com/docs/codeql-language-guides/basic-query-for-java-code/).

```
public class TestJava {
void myJavaFun(String s) {
boolean b = s.equals("");
}
}
```
```
from MethodAccess ma
where
ma.getMethod().hasName("equals") and
ma.getArgument(0).(StringLiteral).getValue() = ""
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
```
Just so that I can get my environment setup. In addition, I am using Maven and VSCode. I have both the VSCode extension and the CLI installed. However, I am running into a few issues.

1) The first is getting the database created. I am first building with Maven to get the .class files. After that I am creating a database from these files. I tried doing these two steps in sperate commands,

```
mvn clean
codeql database create codeql_project --command="mvn install --file ../../../pom.xml" --language=java --overwrite --source-root=target/classes/snippets/
```
However, this causes this error
> CodeQL detected code written in , but not any written in Java/Kotlin. This can occur if the specified build commands failed to compile or process any code.
> - Confirm that there is some source code for the specified language in the project.
> - For codebases written in Go, JavaScript, TypeScript, and Python, do not specify
an explicit --command.
> - For other languages, the --command must specify a "clean" build which compiles
all the source code files without reusing existing build artefacts.
It seems like Java falls in the "Other" category.

Due to this, I am trying both steps in one command.
```
codeql database create codeql_project --command="mvn clean install --file ../../../pom.xml" --language=java --overwrite --source-root=target/classes/snippets/
```
The issue with this is that Maven will delete the target dir during the clean phase, which then causes issues with the source-root.

Currently, the only way I have been able to get a working database is by not specifiying the source-root with this command.
```
codeql database create codeql_project --language=java --command="mvn clean install --file pom.xml"
```
However, I don't feel confident that this is correctly working.

2) In addition I am getting a lot of type errors. Circling back to using the query above. I am getting
> Failed to run query: ERROR: Could not resolve type MethodAccess (C:\Users\Kyler-Laptop\Downloads\Demo1\Demo\codeql_queries\SimpleQuery.ql:1,6-18)
ERROR: Could not resolve type StringLiteral (C:\Users\Kyler-Laptop\Downloads\Demo1\Demo\codeql_queries\SimpleQuery.ql:4,22-35)

This is what originally made me think my database create command might be incorrect.

Any suggestions would be greatly appreciated.
Thank you

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。