mirror of https://github.com/sbt/sbt.git
Remove unused methods in lmcoursier.credentials (#123)
This commit is contained in:
parent
6bc9c7c01b
commit
43d24c9609
|
|
@ -2,10 +2,7 @@ package lmcoursier.credentials
|
|||
|
||||
import java.io.File
|
||||
|
||||
abstract class Credentials extends Serializable {
|
||||
// calling this may incur I/O
|
||||
def get(): Seq[DirectCredentials]
|
||||
}
|
||||
abstract class Credentials extends Serializable
|
||||
|
||||
object Credentials {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package lmcoursier.credentials
|
||||
|
||||
import java.net.URI
|
||||
|
||||
final class DirectCredentials private(
|
||||
val host: String,
|
||||
val username: String,
|
||||
|
|
@ -52,32 +50,6 @@ final class DirectCredentials private(
|
|||
copy(matchHost = matchHost)
|
||||
def withHttpsOnly(httpsOnly: Boolean): DirectCredentials =
|
||||
copy(httpsOnly = httpsOnly)
|
||||
|
||||
def autoMatches(url: String, realm0: Option[String]): Boolean =
|
||||
matchHost && {
|
||||
val uri = new URI(url)
|
||||
val schemeOpt = Option(uri.getScheme)
|
||||
val hostOpt = Option(uri.getHost)
|
||||
((schemeOpt.contains("http") && !httpsOnly) || schemeOpt.contains("https")) &&
|
||||
hostOpt.contains(host) &&
|
||||
realm.forall(realm0.contains)
|
||||
}
|
||||
|
||||
def matches(url: String, user: String): Boolean = {
|
||||
val uri = new URI(url)
|
||||
val schemeOpt = Option(uri.getScheme)
|
||||
val hostOpt = Option(uri.getHost)
|
||||
val userInfoOpt = Option(uri.getUserInfo)
|
||||
// !matchHost && // ?
|
||||
userInfoOpt.isEmpty &&
|
||||
((schemeOpt.contains("http") && !httpsOnly) || schemeOpt.contains("https")) &&
|
||||
hostOpt.contains(host) &&
|
||||
user == username
|
||||
}
|
||||
|
||||
def get(): Seq[DirectCredentials] =
|
||||
Seq(this)
|
||||
|
||||
}
|
||||
object DirectCredentials {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
package lmcoursier.credentials
|
||||
|
||||
import java.io.{File, FileInputStream}
|
||||
import java.util.Properties
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
final class FileCredentials private(
|
||||
val path: String,
|
||||
val optional: Boolean
|
||||
|
|
@ -31,59 +26,6 @@ final class FileCredentials private(
|
|||
def withOptional(optional: Boolean): FileCredentials = {
|
||||
copy(optional = optional)
|
||||
}
|
||||
|
||||
def get(): Seq[DirectCredentials] = {
|
||||
|
||||
val f = new File(path)
|
||||
|
||||
if (f.isFile) {
|
||||
|
||||
val props = new Properties
|
||||
|
||||
var fis: FileInputStream = null
|
||||
try {
|
||||
fis = new FileInputStream(f)
|
||||
props.load(fis)
|
||||
} finally {
|
||||
if (fis != null)
|
||||
fis.close()
|
||||
}
|
||||
|
||||
val userProps = props
|
||||
.propertyNames()
|
||||
.asScala
|
||||
.map(_.asInstanceOf[String])
|
||||
.filter(_.endsWith(".username"))
|
||||
.toVector
|
||||
|
||||
userProps.map { userProp =>
|
||||
val prefix = userProp.stripSuffix(".username")
|
||||
|
||||
val user = props.getProperty(userProp)
|
||||
val password = Option(props.getProperty(s"$prefix.password")).getOrElse {
|
||||
throw new Exception(s"Property $prefix.password not found in $path")
|
||||
}
|
||||
|
||||
val host = Option(props.getProperty(s"$prefix.host")).getOrElse {
|
||||
throw new Exception(s"Property $prefix.host not found in $path")
|
||||
}
|
||||
|
||||
val realmOpt = Option(props.getProperty(s"$prefix.realm")) // filter if empty?
|
||||
|
||||
val matchHost = Option(props.getProperty(s"$prefix.auto")).fold(false)(_.toBoolean)
|
||||
val httpsOnly = Option(props.getProperty(s"$prefix.https-only")).fold(true)(_.toBoolean)
|
||||
|
||||
DirectCredentials(host, user, password)
|
||||
.withRealm(realmOpt)
|
||||
.withMatchHost(matchHost)
|
||||
.withHttpsOnly(httpsOnly)
|
||||
}
|
||||
|
||||
} else if (optional)
|
||||
Nil
|
||||
else
|
||||
throw new Exception(s"Credential file $path not found")
|
||||
}
|
||||
}
|
||||
object FileCredentials {
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,12 @@ object Mima {
|
|||
import com.typesafe.tools.mima.core._
|
||||
|
||||
Seq(
|
||||
// Methods that shouldn't have been there
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.FileCredentials.get"),
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.DirectCredentials.matches"),
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.DirectCredentials.get"),
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.DirectCredentials.autoMatches"),
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.Credentials.get"),
|
||||
// Removed unused method, shouldn't have been there in the first place
|
||||
ProblemFilters.exclude[DirectMissingMethodProblem]("lmcoursier.credentials.DirectCredentials.authentication"),
|
||||
// ignore shaded and internal stuff related errors
|
||||
|
|
|
|||
Loading…
Reference in New Issue