Skip to content

Commit

Permalink
fix(analyze-command): Properly close PackageManagers after they have …
Browse files Browse the repository at this point in the history
…retrieved all dependencies.

Signed-off-by: Thomas Neidhart <[email protected]>
  • Loading branch information
netomi committed Dec 1, 2023
1 parent 5af7043 commit 2e145e9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
8 changes: 7 additions & 1 deletion analyzer/src/main/kotlin/PackageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.ossreviewtoolkit.analyzer

import java.io.Closeable
import java.io.File
import java.nio.file.FileSystems
import java.nio.file.Path
Expand Down Expand Up @@ -62,7 +63,7 @@ abstract class PackageManager(
val analysisRoot: File,
val analyzerConfig: AnalyzerConfiguration,
val repoConfig: RepositoryConfiguration
) {
) : Closeable {
companion object {
private val PACKAGE_MANAGER_DIRECTORIES = setOf(
// Ignore intermediate build system directories.
Expand Down Expand Up @@ -361,6 +362,11 @@ abstract class PackageManager(
}
}
}

/**
* [PackageManager] implementations should override this method if they need to clean resources.
*/
override fun close() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.
}

/**
Expand Down
4 changes: 4 additions & 0 deletions plugins/commands/analyzer/src/main/kotlin/AnalyzerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,9 @@ class AnalyzerCommand : OrtCommand(
val issues = analyzerRun.result.getAllIssues().flatMap { it.value }
SeverityStatsPrinter(terminal, resolutionProvider).stats(issues)
.print().conclude(ortConfig.severeIssueThreshold, 2)

for (packageManager in info.managedFiles.keys) {
packageManager.close()
}
}
}
4 changes: 4 additions & 0 deletions plugins/package-managers/gradle/src/main/kotlin/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,8 @@ class Gradle(
}
}
}

override fun close() {
maven.close()
}
}
4 changes: 4 additions & 0 deletions plugins/package-managers/maven/src/main/kotlin/Maven.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class Maven(
) = Maven(type, analysisRoot, analyzerConfig, repoConfig)
}

override fun close() {
mvn.close()
}

private inner class LocalProjectWorkspaceReader : WorkspaceReader {
private val workspaceRepository = WorkspaceRepository()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.ossreviewtoolkit.plugins.packagemanagers.maven.utils

import java.io.Closeable
import java.io.File
import java.net.URI

Expand Down Expand Up @@ -108,7 +109,7 @@ fun Artifact.identifier() = "$groupId:$artifactId:$version"
private val File?.safePath: String
get() = this?.invariantSeparatorsPath ?: "<unknown file>"

class MavenSupport(private val workspaceReader: WorkspaceReader) {
class MavenSupport(private val workspaceReader: WorkspaceReader) : Closeable {
companion object {
private val PACKAGING_TYPES = setOf(
// Core packaging types, see https://maven.apache.org/pom.html#packaging.
Expand Down Expand Up @@ -814,6 +815,10 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
legacySupport.session = null
}
}

override fun close() {
remoteArtifactCache.close()
}

Check warning on line 821 in plugins/package-managers/maven/src/main/kotlin/utils/MavenSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/maven/src/main/kotlin/utils/MavenSupport.kt#L820-L821

Added lines #L820 - L821 were not covered by tests
}

/**
Expand Down
7 changes: 6 additions & 1 deletion utils/common/src/main/kotlin/DiskCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.utils.common

import com.jakewharton.disklrucache.DiskLruCache

import java.io.Closeable
import java.io.File
import java.io.IOException

Expand All @@ -46,7 +47,7 @@ class DiskCache(
* Duration in seconds that cache entries are valid.
*/
private val maxCacheEntryAgeInSeconds: Long
) {
) : Closeable {
companion object {
const val INDEX_FULL_KEY = 0
const val INDEX_TIMESTAMP = 1
Expand Down Expand Up @@ -144,4 +145,8 @@ class DiskCache(
}

private fun currentTimeInSeconds() = System.currentTimeMillis() / 1000L

override fun close() {
diskLruCache.close()
}
}

0 comments on commit 2e145e9

Please sign in to comment.