This is an automated email from the ASF dual-hosted git repository. hepin pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-pekko-persistence-r2dbc.git
commit 308a50b6de2f0fe06c2549b86da64d74eaa2ce49 Author: Matthew de Detrich <[email protected]> AuthorDate: Tue Apr 11 20:42:55 2023 +0200 Add CopyrightHeader to deal with Apache license headers --- build.sbt | 4 -- project/CopyrightHeader.scala | 105 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 29aeaae..a4adfe5 100644 --- a/build.sbt +++ b/build.sbt @@ -37,7 +37,6 @@ def common: Seq[Setting[_]] = sonatypeProfileName := "org.apache.pekko", // Setting javac options in common allows IntelliJ IDEA to import them automatically Compile / javacOptions ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8"), - headerLicense := Some(HeaderLicense.Custom("""Copyright (C) 2021 Lightbend Inc. <https://www.lightbend.com>""")), Test / logBuffered := false, Test / parallelExecution := false, // show full stack traces and test case durations @@ -74,14 +73,12 @@ lazy val core = (project in file("core")) .settings(common) .settings(name := "pekko-persistence-r2dbc", libraryDependencies ++= Dependencies.core) .settings(MetaInfLicenseNoticeCopy.settings) - .enablePlugins(AutomateHeaderPlugin) lazy val projection = (project in file("projection")) .dependsOn(core) .settings(common) .settings(name := "pekko-projection-r2dbc", libraryDependencies ++= Dependencies.projection) .settings(MetaInfLicenseNoticeCopy.settings) - .enablePlugins(AutomateHeaderPlugin) lazy val migration = (project in file("migration")) .settings(common) @@ -101,7 +98,6 @@ lazy val migration = (project in file("migration")) "-Dlogback.configurationFile=logback-main.xml" :: "-Xms1G" :: "-Xmx1G" :: "-XX:MaxDirectMemorySize=256M" :: pekkoProperties }) .dependsOn(core % "compile->compile;test->test") - .enablePlugins(AutomateHeaderPlugin) lazy val docs = project .in(file("docs")) diff --git a/project/CopyrightHeader.scala b/project/CopyrightHeader.scala new file mode 100644 index 0000000..ae52015 --- /dev/null +++ b/project/CopyrightHeader.scala @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * license agreements; and to You under the Apache License, version 2.0: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * This file is part of the Apache Pekko project, derived from Akka. + */ + +import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._ +import de.heikoseeberger.sbtheader.{ CommentCreator, HeaderPlugin, NewLine } +import org.apache.commons.lang3.StringUtils +import sbt.Keys._ +import sbt._ + +trait CopyrightHeader extends AutoPlugin { + + override def requires: Plugins = HeaderPlugin + + override def trigger: PluginTrigger = allRequirements + + protected def headerMappingSettings: Seq[Def.Setting[_]] = + Seq(Compile, Test, IntegrationTest).flatMap { config => + inConfig(config)( + Seq( + headerLicense := Some(HeaderLicense.Custom(apacheHeader)), + headerMappings := headerMappings.value ++ Map( + HeaderFileType.scala -> cStyleComment, + HeaderFileType.java -> cStyleComment, + HeaderFileType.conf -> hashLineComment, + HeaderFileType("template") -> cStyleComment))) + } + + override def projectSettings: Seq[Def.Setting[_]] = + Def.settings(headerMappingSettings, additional) ++ Defaults.itSettings ++ + headerSettings(IntegrationTest) + + def additional: Seq[Def.Setting[_]] = + Def.settings(Compile / compile := { + (Compile / headerCreate).value + (Compile / compile).value + }, + Test / compile := { + (Test / headerCreate).value + (Test / compile).value + }) + + def apacheHeader: String = + """Licensed to the Apache Software Foundation (ASF) under one or more + |license agreements; and to You under the Apache License, version 2.0: + | + | https://www.apache.org/licenses/LICENSE-2.0 + | + |This file is part of the Apache Pekko project, derived from Akka. + |""".stripMargin + + val apacheSpdxHeader: String = "SPDX-License-Identifier: Apache-2.0" + + val cStyleComment = HeaderCommentStyle.cStyleBlockComment.copy(commentCreator = new CommentCreator() { + + override def apply(text: String, existingText: Option[String]): String = { + val formatted = existingText match { + case Some(currentText) if isValidCopyrightAnnotated(currentText) => + currentText + case Some(currentText) if isLightbendCopyrighted(currentText) => + HeaderCommentStyle.cStyleBlockComment.commentCreator(text, existingText) + NewLine * 2 + currentText + case Some(currentText) => + throw new IllegalStateException(s"Unable to detect copyright for header:[${currentText}]") + case None => + HeaderCommentStyle.cStyleBlockComment.commentCreator(text, existingText) + } + formatted.trim + } + }) + + 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 = { + val formatted = existingText match { + case Some(currentText) if isApacheCopyrighted(currentText) => + currentText + case Some(currentText) => + HeaderCommentStyle.hashLineComment.commentCreator(apacheSpdxHeader, existingText) + NewLine * 2 + currentText + case None => + HeaderCommentStyle.hashLineComment.commentCreator(apacheSpdxHeader, existingText) + } + formatted.trim + } + }) + + private def isApacheCopyrighted(text: String): Boolean = + StringUtils.containsIgnoreCase(text, "licensed to the apache software foundation (asf)") || + StringUtils.containsIgnoreCase(text, "www.apache.org/licenses/license-2.0") || + StringUtils.contains(text, "Apache-2.0") + + private def isLightbendCopyrighted(text: String): Boolean = + StringUtils.containsIgnoreCase(text, "lightbend inc.") + + private def isValidCopyrightAnnotated(text: String): Boolean = { + isApacheCopyrighted(text) + } +} + +object CopyrightHeader extends CopyrightHeader --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
