@@ -32,7 +32,8 @@ object CopyrightHeader extends AutoPlugin {
3232 )
3333
3434 val CurrentYear = java.time.Year .now.getValue.toString
35- val CopyrightPattern = " (?s).* Copyright \\ ([Cc]\\ ) (\\ d{4}(-\\ d{4})?) (Lightbend|Typesafe) Inc.*" .r
35+ val CopyrightPattern = " Copyright \\ ([Cc]\\ ) (\\ d{4}(-\\ d{4})?) (Lightbend|Typesafe) Inc. <.*>" .r
36+ val CopyrightHeaderPattern = s " (?s).* ${CopyrightPattern }.* " .r
3637
3738 def headerFor (year : String ): String =
3839 s " Copyright (C) $year Lightbend Inc. <https://www.lightbend.com> "
@@ -41,17 +42,22 @@ object CopyrightHeader extends AutoPlugin {
4142 import HeaderCommentStyle .cStyleBlockComment .commentCreator
4243
4344 def updateLightbendHeader (header : String ): String = header match {
44- case CopyrightPattern (years, null , _) =>
45- if (years != CurrentYear ) commentCreator(headerFor(years + " -" + CurrentYear ))
46- else commentCreator(headerFor(years))
47- case CopyrightPattern (years, endYears, _) => commentCreator(headerFor(years.replace(endYears, " -" + CurrentYear )))
48- case _ => header.trim
45+ case CopyrightHeaderPattern (years, null , _) =>
46+ if (years != CurrentYear )
47+ CopyrightPattern .replaceFirstIn(header, headerFor(years + " -" + CurrentYear ))
48+ else
49+ CopyrightPattern .replaceFirstIn(header, headerFor(years))
50+ case CopyrightHeaderPattern (years, endYears, _) =>
51+ CopyrightPattern .replaceFirstIn(header, headerFor(years.replace(endYears, " -" + CurrentYear )))
52+ case _ =>
53+ header
4954 }
5055
5156 override def apply (text : String , existingText : Option [String ]): String = {
5257 existingText
5358 .map(updateLightbendHeader)
5459 .getOrElse(commentCreator(text, existingText))
60+ .trim
5561 }
5662 })
5763}
0 commit comments