can only set headerLicense config once (#234)

* can only set headerLicense config once

* Update CopyrightHeader.scala
This commit is contained in:
PJ Fanning 2023-03-06 10:43:02 +01:00 committed by GitHub
parent 0a8b8a572f
commit f9eb8aaebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,20 +34,12 @@ trait CopyrightHeader extends AutoPlugin {
headerMappings := headerMappings.value ++ Map( headerMappings := headerMappings.value ++ Map(
HeaderFileType.scala -> cStyleComment, HeaderFileType.scala -> cStyleComment,
HeaderFileType.java -> cStyleComment, HeaderFileType.java -> cStyleComment,
HeaderFileType.conf -> hashLineComment,
HeaderFileType("template") -> cStyleComment))) HeaderFileType("template") -> cStyleComment)))
} }
private def confHeaderMappingSettings: Seq[Def.Setting[_]] =
Seq(Compile, Test).flatMap { config =>
inConfig(config)(
Seq(
headerLicense := Some(HeaderLicense.Custom(apacheSpdxHeader)),
headerMappings := headerMappings.value ++ Map(
HeaderFileType.conf -> hashLineComment)))
}
override def projectSettings: Seq[Def.Setting[_]] = override def projectSettings: Seq[Def.Setting[_]] =
Def.settings(headerMappingSettings, confHeaderMappingSettings, additional) Def.settings(headerMappingSettings, additional)
def additional: Seq[Def.Setting[_]] = def additional: Seq[Def.Setting[_]] =
Def.settings(Compile / compile := { Def.settings(Compile / compile := {
@ -59,9 +51,6 @@ trait CopyrightHeader extends AutoPlugin {
(Test / compile).value (Test / compile).value
}) })
def headerFor(year: String): String =
s"Copyright (C) $year Lightbend Inc. <https://www.lightbend.com>"
def apacheHeader: String = def apacheHeader: String =
"""Licensed to the Apache Software Foundation (ASF) under one or more """Licensed to the Apache Software Foundation (ASF) under one or more
|license agreements; and to You under the Apache License, version 2.0: |license agreements; and to You under the Apache License, version 2.0:
@ -92,14 +81,15 @@ trait CopyrightHeader extends AutoPlugin {
val hashLineComment = HeaderCommentStyle.hashLineComment.copy(commentCreator = new CommentCreator() { val hashLineComment = HeaderCommentStyle.hashLineComment.copy(commentCreator = new CommentCreator() {
// deliberately hardcode use of apacheSpdxHeader and ignore input text
override def apply(text: String, existingText: Option[String]): String = { override def apply(text: String, existingText: Option[String]): String = {
val formatted = existingText match { val formatted = existingText match {
case Some(currentText) if isApacheCopyrighted(currentText) => case Some(currentText) if isApacheCopyrighted(currentText) =>
currentText currentText
case Some(currentText) => case Some(currentText) =>
HeaderCommentStyle.hashLineComment.commentCreator(text, existingText) + NewLine * 2 + currentText HeaderCommentStyle.hashLineComment.commentCreator(apacheSpdxHeader, existingText) + NewLine * 2 + currentText
case None => case None =>
HeaderCommentStyle.hashLineComment.commentCreator(text, existingText) HeaderCommentStyle.hashLineComment.commentCreator(apacheSpdxHeader, existingText)
} }
formatted.trim formatted.trim
} }