-
Notifications
You must be signed in to change notification settings - Fork 314
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
GradleInspector: Ignore artifacts of zero byte size #8305
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,11 @@ private val GRADLE_USER_HOME = Os.env["GRADLE_USER_HOME"]?.let { File(it) } ?: O | |
*/ | ||
const val OPTION_GRADLE_VERSION = "gradleVersion" | ||
|
||
/** | ||
* The sha1 sum for a zero by size file. | ||
*/ | ||
private const val ZERO_BYTES_FILE_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only used in |
||
|
||
/** | ||
* The [Gradle](https://gradle.org/) package manager for Java. | ||
* | ||
|
@@ -350,15 +355,15 @@ private fun Collection<OrtDependency>.toPackageRefs( | |
} | ||
|
||
/** | ||
* Create a [RemoteArtifact] based on the given [pomUrl], [classifier], [extension] and hash [algorithm]. The hash value | ||
* is retrieved remotely. | ||
* Create a [RemoteArtifact] based on the given [pomUrl], [classifier] and [extension]. The hash value is retrieved | ||
* remotely. | ||
*/ | ||
private fun createRemoteArtifact( | ||
private fun GradleInspector.createRemoteArtifact( | ||
pomUrl: String?, | ||
classifier: String? = null, | ||
extension: String? = null, | ||
algorithm: String = "sha1" | ||
extension: String? = null | ||
): RemoteArtifact { | ||
val algorithm = "sha1" | ||
val artifactBaseUrl = pomUrl?.removeSuffix(".pom") ?: return RemoteArtifact.EMPTY | ||
|
||
val artifactUrl = buildString { | ||
|
@@ -371,7 +376,14 @@ private fun createRemoteArtifact( | |
val checksum = okHttpClient.downloadText("$artifactUrl.$algorithm") | ||
.getOrElse { return RemoteArtifact.EMPTY } | ||
|
||
return RemoteArtifact(artifactUrl, parseChecksum(checksum, algorithm)) | ||
// Ignore file with zero byte size, because it cannot be a valid archive. | ||
val hash = parseChecksum(checksum, algorithm).takeUnless { it.value == ZERO_BYTES_FILE_SHA1 } | ||
?: run { | ||
logger.info("Ignoring zero byte size artifact: $artifactUrl.") | ||
return RemoteArtifact.EMPTY | ||
} | ||
|
||
return RemoteArtifact(artifactUrl, hash) | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message nits: