mirror of https://github.com/sbt/sbt.git
refined auto project ID to prepend 'root-' if initial character is numeric
This commit is contained in:
parent
b8ff4ca3d5
commit
7992997ac1
|
|
@ -163,19 +163,20 @@ object Project extends ProjectExtra
|
||||||
|
|
||||||
/** Returns None if `id` is a valid Project ID or Some containing the parser error message if it is not.*/
|
/** Returns None if `id` is a valid Project ID or Some containing the parser error message if it is not.*/
|
||||||
def validProjectID(id: String): Option[String] = DefaultParsers.parse(id, DefaultParsers.ID).left.toOption
|
def validProjectID(id: String): Option[String] = DefaultParsers.parse(id, DefaultParsers.ID).left.toOption
|
||||||
|
private[this] def validProjectIDStart(id: String): Boolean = DefaultParsers.parse(id, DefaultParsers.IDStart).isRight
|
||||||
|
|
||||||
/** Constructs a valid Project ID based on `id` and returns it in Right or returns the error message in Left if one cannot be constructed.*/
|
/** Constructs a valid Project ID based on `id` and returns it in Right or returns the error message in Left if one cannot be constructed.*/
|
||||||
def normalizeProjectID(id: String): Either[String, String] =
|
def normalizeProjectID(id: String): Either[String, String] =
|
||||||
{
|
{
|
||||||
// TODO: better attempt
|
val attempt = normalizeBase(id)
|
||||||
val attempt = id.toLowerCase.replaceAll("""\W+""", "-")
|
val refined = if(!validProjectIDStart(attempt.substring(0, 1)) ) "root-" + attempt else attempt
|
||||||
validProjectID(attempt).toLeft(attempt)
|
validProjectID(refined).toLeft(refined)
|
||||||
}
|
}
|
||||||
|
private[this] def normalizeBase(s: String) = s.toLowerCase.replaceAll("""\W+""", "-")
|
||||||
|
|
||||||
/** Normalize a String so that it is suitable for use as a dependency management module identifier.
|
/** Normalize a String so that it is suitable for use as a dependency management module identifier.
|
||||||
* This is a best effort implementation, since valid characters are not documented or consistent.*/
|
* This is a best effort implementation, since valid characters are not documented or consistent.*/
|
||||||
def normalizeModuleID(id: String): String = id.toLowerCase.replaceAll("""\W+""", "-")
|
def normalizeModuleID(id: String): String = normalizeBase(id)
|
||||||
|
|
||||||
def resolved(id: String, base: File, aggregate: => Seq[ProjectRef], dependencies: => Seq[ResolvedClasspathDependency], delegates: => Seq[ProjectRef],
|
def resolved(id: String, base: File, aggregate: => Seq[ProjectRef], dependencies: => Seq[ResolvedClasspathDependency], delegates: => Seq[ProjectRef],
|
||||||
settings: Seq[Def.Setting[_]], configurations: Seq[Configuration], auto: AddSettings): ResolvedProject =
|
settings: Seq[Def.Setting[_]], configurations: Seq[Configuration], auto: AddSettings): ResolvedProject =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue