github / codeql

CodeQL: the libraries and queries that power security researchers around the world, as well as code scanning in GitHub Advanced Security
https://codeql.github.com
MIT License
7.51k stars 1.49k forks source link

Why is it that when CodeQL generates a database, some source code is not analyzed? #13710

Open KingXS opened 1 year ago

KingXS commented 1 year ago

When I add the CodeQL-generated source code analysis database (referred to as "jeecgdb source archive") to the workspace in VS Code for viewing, I notice that some source code files are missing in the generated database structure. What could be the reason for this situation?

The missing file is:/Users/fqy/Desktop/CodeAudit/JAVA/jeecg-boot-3.5.0/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java,In the generated database file, none of the files under the "api" directory have been included.

smowton commented 1 year ago

This is because those files use Lombok, and Lombok is only supported via workarounds at the moment. Seamless Lombok support is coming soon, but until then you can work around this by running delombok before building the project.

For jeecg-boot, I was able to do this using the Maven delombok plugin:

  1. Add the following to the <plugins> block of the root pom.xml file:
    <plugin>
      <groupId>org.projectlombok</groupId>   
      <artifactId>lombok-maven-plugin</artifactId>
      <version>1.18.20.0</version>  
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>delombok</goal>
          </goals>
        </execution>            
      </executions>
          <dependencies> 
      <dependency>
        <!-- Note I force using the latest Lombok, because 1.18.20 has a bug that breaks delombok for this project -->
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.28</version>
      </dependency>
     </dependencies>
    </plugin>
  1. Move src/main/java directories to src/main/lombok -- this means they will be put through delombok before compilation: for d in $(find . | grep src/main/java$); do mv $d ${d/java/lombok}; done

  2. Extract with CodeQL: codeql database create -l java codeql-db -- CodeQL will now see the delombok'd "plain" Java that it understands.