[Gradle, JS] Implement reason and other methods beside version
^KT-41054 fixed
This commit is contained in:
+46
-10
@@ -9,6 +9,7 @@ import org.gradle.api.Action
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.*
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.gradle.api.internal.artifacts.ModuleVersionSelectorStrictSpec
|
||||
import org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint
|
||||
import org.gradle.api.internal.artifacts.dependencies.DependencyConstraintInternal
|
||||
import org.gradle.api.internal.attributes.ImmutableAttributes
|
||||
@@ -20,6 +21,8 @@ class NpmDependencyConstraint(
|
||||
private val version: String
|
||||
) : DependencyConstraintInternal {
|
||||
|
||||
private var reason: String? = null
|
||||
|
||||
private val versionConstraint = DefaultMutableVersionConstraint(version)
|
||||
|
||||
override fun getGroup(): String? = null
|
||||
@@ -28,8 +31,9 @@ class NpmDependencyConstraint(
|
||||
|
||||
override fun getVersion(): String = versionConstraint.version
|
||||
|
||||
override fun matchesStrictly(p0: ModuleVersionIdentifier): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
override fun matchesStrictly(identifier: ModuleVersionIdentifier): Boolean {
|
||||
return ModuleVersionSelectorStrictSpec(this)
|
||||
.isSatisfiedBy(identifier)
|
||||
}
|
||||
|
||||
override fun getModule(): ModuleIdentifier {
|
||||
@@ -44,20 +48,29 @@ class NpmDependencyConstraint(
|
||||
return ImmutableAttributes.EMPTY
|
||||
}
|
||||
|
||||
override fun attributes(p0: Action<in AttributeContainer>): DependencyConstraint {
|
||||
override fun attributes(configureAction: Action<in AttributeContainer>): DependencyConstraint {
|
||||
warnAboutInternalApiUse()
|
||||
return this
|
||||
}
|
||||
|
||||
override fun version(p0: Action<in MutableVersionConstraint>) {
|
||||
TODO("Not yet implemented")
|
||||
private fun warnAboutInternalApiUse() {
|
||||
project.logger.warn(
|
||||
"""Cannot set attributes for NPM constraint '${this.path}:${this.version}"""
|
||||
)
|
||||
}
|
||||
|
||||
override fun version(configureAction: Action<in MutableVersionConstraint>) {
|
||||
configureAction.execute(versionConstraint)
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
nodeJs.npmResolutionManager.putNpmResolution(path, version)
|
||||
}
|
||||
|
||||
override fun getReason(): String? {
|
||||
return null
|
||||
return reason
|
||||
}
|
||||
|
||||
override fun because(p0: String?) {
|
||||
TODO("Not yet implemented")
|
||||
override fun because(reason: String?) {
|
||||
this.reason = reason
|
||||
}
|
||||
|
||||
override fun getVersionConstraint(): VersionConstraint {
|
||||
@@ -66,11 +79,34 @@ class NpmDependencyConstraint(
|
||||
return versionConstraint
|
||||
}
|
||||
|
||||
override fun setForce(p0: Boolean) {
|
||||
|
||||
override fun setForce(force: Boolean) {
|
||||
}
|
||||
|
||||
override fun isForce(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as NpmDependencyConstraint
|
||||
|
||||
if (project != other.project) return false
|
||||
if (path != other.path) return false
|
||||
if (versionConstraint != other.versionConstraint) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = project.hashCode()
|
||||
result = 31 * result + path.hashCode()
|
||||
result = 31 * result + versionConstraint.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "NpmDependencyConstraint(path='$path', versionConstraint=$versionConstraint)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user