You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by nv...@apache.org on 2023/01/17 13:13:08 UTC

[incubator-pekko-persistence-cassandra] branch main updated: Adds copyright header plugin (#15)

This is an automated email from the ASF dual-hosted git repository.

nvollmar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko-persistence-cassandra.git


The following commit(s) were added to refs/heads/main by this push:
     new bae56ca  Adds copyright header plugin (#15)
bae56ca is described below

commit bae56cae9981e2cc9f6ad4203244858440b96e4e
Author: Nicolas Vollmar <nv...@gmail.com>
AuthorDate: Tue Jan 17 14:13:02 2023 +0100

    Adds copyright header plugin (#15)
---
 .github/workflows/check-build-test.yml |  6 +--
 CONTRIBUTING.md                        |  2 +-
 project/CopyrightHeader.scala          | 93 ++++++++++++++++++++++++++++++++++
 project/plugins.sbt                    |  5 +-
 4 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/check-build-test.yml b/.github/workflows/check-build-test.yml
index c110e06..5768962 100644
--- a/.github/workflows/check-build-test.yml
+++ b/.github/workflows/check-build-test.yml
@@ -11,7 +11,7 @@ on:
 
 jobs:
   style-compile:
-    name: Compile, Code Style
+    name: Check Code Style
     if: github.repository == 'apache/incubator-pekko-persistence-cassandra'
     runs-on: ubuntu-20.04
     env:
@@ -35,8 +35,8 @@ jobs:
       - name: Cache Coursier cache
         uses: coursier/cache-action@v6.3
 
-      - name: "Code style, compile tests"
-        run: sbt "verifyCodeStyle; Test/compile"
+      - name: Compilation and binary-compatibility check
+        run: sbt "verifyCodeStyle; +Test/compile" # todo: add mimaReportBinaryIssues
 
 
   documentation:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3d351a1..56e43f9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -38,7 +38,7 @@ The steps are exactly the same for everyone involved in the project, including t
 1. [Fork the project](https://github.com/apache/incubator-pekko-persistence-cassandra#fork-destination-box) on GitHub. You'll need to create a feature-branch for your work on your fork, as this way you'll be able to submit a pull request against the mainline Pekko.
 1. Create a branch on your fork and work on the feature. For example: `git checkout -b custom-headers-pekko-http`
    - Please make sure to follow the general quality guidelines (specified below) when developing your patch.
-   - Please write additional tests covering your feature and adjust existing ones if needed before submitting your pull request. The `validatePullRequest` sbt task ([explained below](#the-validatepullrequest-task)) may come in handy to verify your changes are correct.
+   - Please write additional tests covering your feature and adjust existing ones if needed before submitting your pull request.
    - Use the `verifyCodeStyle` sbt task to ensure your code is properly formatted and includes the proper copyright headers.
 1. Once your feature is complete, prepare the commit following our [Creating Commits And Writing Commit Messages](#creating-commits-and-writing-commit-messages). For example, a good commit message would be: `Adding compression support for Manifests #22222` (note the reference to the ticket it aimed to resolve).
 1. If it's a new feature or a change of behavior, document it on the [docs](https://github.com/apache/incubator-pekko-persistence-cassandra/tree/main/docs). When the feature touches Scala and Java DSL, document both the Scala and Java APIs.
diff --git a/project/CopyrightHeader.scala b/project/CopyrightHeader.scala
new file mode 100644
index 0000000..3fddd4d
--- /dev/null
+++ b/project/CopyrightHeader.scala
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+/*
+ * Copyright (C) 2018-2022 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
+import de.heikoseeberger.sbtheader.{ CommentCreator, CommentStyle, HeaderPlugin, NewLine }
+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).flatMap { config =>
+      inConfig(config)(
+        Seq(
+          headerLicense := Some(HeaderLicense.Custom(apacheHeader)),
+          headerMappings := headerMappings.value ++ Map(
+            HeaderFileType.scala -> cStyleComment,
+            HeaderFileType.java -> cStyleComment,
+            HeaderFileType("template") -> cStyleComment)))
+    }
+
+  override def projectSettings: Seq[Def.Setting[_]] = Def.settings(headerMappingSettings, additional)
+
+  def additional: Seq[Def.Setting[_]] =
+    Def.settings(Compile / compile := {
+        (Compile / headerCreate).value
+        (Compile / compile).value
+      },
+      Test / compile := {
+        (Test / headerCreate).value
+        (Test / compile).value
+      })
+
+  def headerFor(year: String): String =
+    s"Copyright (C) $year Lightbend Inc. <https://www.lightbend.com>"
+
+  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 cStyleComment: CommentStyle = HeaderCommentStyle.cStyleBlockComment.copy(commentCreator = new CommentCreator() {
+
+    override def apply(text: String, existingText: Option[String]): String = {
+      val formatted = existingText match {
+        case Some(existedText) if isValidCopyRightAnnotated(existedText) =>
+          existedText
+        case Some(existedText) if isOnlyLightbendCopyRightAnnotated(existedText) =>
+          HeaderCommentStyle.cStyleBlockComment.commentCreator(text, existingText) + NewLine * 2 + existedText
+        case Some(existedText) =>
+          throw new IllegalStateException(s"Unable to detect copyright for header:[${existedText}]")
+        case None =>
+          HeaderCommentStyle.cStyleBlockComment.commentCreator(text, existingText)
+      }
+      formatted.trim
+    }
+
+    private def isApacheCopyRighted(text: String): Boolean =
+      text.contains("Licensed to the Apache Software Foundation (ASF)") ||
+      text.contains("www.apache.org/licenses/license-2.0")
+
+    private def isLightbendCopyRighted(text: String): Boolean =
+      text.contains("Lightbend Inc.")
+
+    private def isValidCopyRightAnnotated(text: String): Boolean = {
+      isApacheCopyRighted(text)
+    }
+
+    private def isOnlyLightbendCopyRightAnnotated(text: String): Boolean = {
+      isLightbendCopyRighted(text) && !isApacheCopyRighted(text)
+    }
+  })
+}
+
+object CopyrightHeader extends CopyrightHeader
diff --git a/project/plugins.sbt b/project/plugins.sbt
index c41c91e..c6a61ed 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -1,3 +1,5 @@
+addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
+
 addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.9.0")
 addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
 addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
@@ -11,6 +13,3 @@ addSbtPlugin("com.lightbend.paradox" % "sbt-paradox-dependencies" % "0.2.2")
 addSbtPlugin("com.lightbend.sbt" % "sbt-publish-rsync" % "0.2")
 addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")
 addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
-
-// For example
-addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.0")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org