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

fix hanging python scan (issue #138) #151

Merged
merged 1 commit into from
Mar 14, 2025
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
42 changes: 35 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@
<artifactId>quarkus-config-yaml</artifactId>
</dependency>

<!-- Fixes error with quarkus 3.17 >
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency-->

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
Expand Down Expand Up @@ -135,6 +128,16 @@
<groupId>com.ibm</groupId>
<artifactId>sonar-cryptography-plugin</artifactId>
<version>${sonar.crypto.plugin.version}</version>
<exclusions>
<exclusion>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
Expand Down Expand Up @@ -164,6 +167,12 @@
<artifactId>google-java-format</artifactId>
<version>${google-java-format.version}</version>
</dependency>

<dependency> <!-- Fixes issue #138 -->
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.29.0</version> <!-- Use the latest stable version -->
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -352,6 +361,25 @@
<verbose>false</verbose><!-- = ${cyclonedx.verbose} -->
</configuration>
</plugin>
<!-- Enable to check dependecy conflicts -->
<!--plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<dependencyConvergence/>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin-->
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.ibm.usecases.scanning.services.git.GitService;
import com.ibm.usecases.scanning.services.indexing.JavaIndexService;
import com.ibm.usecases.scanning.services.indexing.ProjectModule;
import com.ibm.usecases.scanning.services.indexing.PythonIndexService;
import com.ibm.usecases.scanning.services.pkg.MavenPackageFinderService;
import com.ibm.usecases.scanning.services.pkg.SetupPackageFinderService;
import com.ibm.usecases.scanning.services.pkg.TomlPackageFinderService;
Expand All @@ -65,6 +66,7 @@
import com.ibm.usecases.scanning.services.resolve.PurlResolver;
import com.ibm.usecases.scanning.services.scan.ScanResultDTO;
import com.ibm.usecases.scanning.services.scan.java.JavaScannerService;
import com.ibm.usecases.scanning.services.scan.python.PythonScannerService;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.io.File;
Expand Down Expand Up @@ -292,11 +294,11 @@ private void handleIndexModulesCommand(@Nonnull IndexModulesCommand command) thr
javaIndexService.index(scanAggregate.getPackageFolder());
this.index.put(Language.JAVA, javaIndex);
// python
// final PythonIndexService pythonIndexService =
// new PythonIndexService(this.progressDispatcher, dir);
// final List<ProjectModule> pythonIndex =
// pythonIndexService.index(scanAggregate.getPackageFolder());
// this.index.put(Language.PYTHON, pythonIndex);
final PythonIndexService pythonIndexService =
new PythonIndexService(this.progressDispatcher, dir);
final List<ProjectModule> pythonIndex =
pythonIndexService.index(scanAggregate.getPackageFolder());
this.index.put(Language.PYTHON, pythonIndex);
// continue with scan
this.commandBus.send(new ScanCommand(command.id()));
} catch (Exception e) {
Expand Down Expand Up @@ -372,43 +374,43 @@ private void handleScanCommand(@Nonnull ScanCommand command)
javaScanResultDTO.cbom()));
}

// // python
// final PythonScannerService pythonScannerService =
// new PythonScannerService(
// this.progressDispatcher,
// Optional.ofNullable(this.projectDirectory)
// .orElseThrow(NoProjectDirectoryProvided::new));
// final ScanResultDTO pythonScanResultDTO =
// pythonScannerService.scan(
// gitUrl,
// scanAggregate.getRevision(),
// commit,
// scanAggregate.getPackageFolder().orElse(null),
// Optional.ofNullable(this.index)
// .map(i -> i.get(Language.PYTHON))
// .orElseThrow(NoIndexForProject::new));
// // update statistics
// numberOfScannedLine += pythonScanResultDTO.numberOfScannedLine();
// numberOfScannedFiles += pythonScanResultDTO.numberOfScannedFiles();
// python
final PythonScannerService pythonScannerService =
new PythonScannerService(
this.progressDispatcher,
Optional.ofNullable(this.projectDirectory)
.orElseThrow(NoProjectDirectoryProvided::new));
final ScanResultDTO pythonScanResultDTO =
pythonScannerService.scan(
gitUrl,
scanAggregate.getRevision(),
commit,
scanAggregate.getPackageFolder().orElse(null),
Optional.ofNullable(this.index)
.map(i -> i.get(Language.PYTHON))
.orElseThrow(NoIndexForProject::new));
// update statistics
numberOfScannedLine += pythonScanResultDTO.numberOfScannedLine();
numberOfScannedFiles += pythonScanResultDTO.numberOfScannedFiles();

// if (pythonScanResultDTO.cbom() != null) {
// // update statistics
// if (cbom != null) {
// cbom.merge(pythonScanResultDTO.cbom());
// } else {
// cbom = pythonScanResultDTO.cbom();
// }
if (pythonScanResultDTO.cbom() != null) {
// update statistics
if (cbom != null) {
cbom.merge(pythonScanResultDTO.cbom());
} else {
cbom = pythonScanResultDTO.cbom();
}

// scanAggregate.reportScanResults(
// new LanguageScan(
// Language.PYTHON,
// new ScanMetadata(
// pythonScanResultDTO.startTime(),
// pythonScanResultDTO.endTime(),
// pythonScanResultDTO.numberOfScannedLine(),
// pythonScanResultDTO.numberOfScannedFiles()),
// pythonScanResultDTO.cbom()));
// }
scanAggregate.reportScanResults(
new LanguageScan(
Language.PYTHON,
new ScanMetadata(
pythonScanResultDTO.startTime(),
pythonScanResultDTO.endTime(),
pythonScanResultDTO.numberOfScannedLine(),
pythonScanResultDTO.numberOfScannedFiles()),
pythonScanResultDTO.cbom()));
}

// publish scan finished and save state
scanAggregate.scanFinished();
Expand All @@ -435,10 +437,9 @@ private void handleScanCommand(@Nonnull ScanCommand command)
.toString()));
this.progressDispatcher.send(
new ProgressMessage(ProgressMessageType.LABEL, "Finished"));
} catch (Exception e) {
} catch (Exception | NoSuchMethodError e) { // catch NoSuchMethodError: see issue #138
this.progressDispatcher.send(
new ProgressMessage(ProgressMessageType.ERROR, e.getMessage()));
this.compensate(command.id());
throw e;
} finally {
this.compensate(command.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public PythonScannerService(
throws ClientDisconnected {
final PythonCheck visitor = new PythonDetectionCollectionRule(this);

LOGGER.info("Start scanning {} python projects", index.size());

long scanTimeStart = System.currentTimeMillis();
int counter = 1;
int numberOfScannedLines = 0;
Expand All @@ -73,7 +75,6 @@ public PythonScannerService(
ProgressMessageType.LABEL, "Scanning project " + projectStr));

for (InputFile inputFile : project.inputFileList()) {
LOGGER.info("Scanning file: {}", inputFile.filename());
final PythonScannableFile pythonScannableFile = new PythonScannableFile(inputFile);
final FileInput parsedFile = pythonScannableFile.parse();
final PythonVisitorContext context =
Expand Down
Loading