From d22dd7c2f77b5e269f8892fb8c68e38dfc211876 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 15:55:57 +0200 Subject: [PATCH] Let Konsist checks the license header --- .../tests/konsist/KonsistLicenseTest.kt | 85 +++++++++++++++++++ tools/detekt/detekt.yml | 4 +- tools/detekt/license.template | 15 ---- 3 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt delete mode 100644 tools/detekt/license.template diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt new file mode 100644 index 0000000000..e6cbf9ca14 --- /dev/null +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.tests.konsist + +import com.lemonappdev.konsist.api.Konsist +import com.lemonappdev.konsist.api.verify.assertTrue +import org.junit.Test + +class KonsistLicenseTest { + private val publicLicense = """ + /\* + (?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd + (?:.*\n)* \* + \* Licensed under the Apache License, Version 2\.0 \(the "License"\); + \* you may not use this file except in compliance with the License\. + \* You may obtain a copy of the License at + \* + \* {5}https?://www\.apache\.org/licenses/LICENSE-2\.0 + \* + \* Unless required by applicable law or agreed to in writing, software + \* distributed under the License is distributed on an "AS IS" BASIS, + \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. + \* See the License for the specific language governing permissions and + \* limitations under the License\. + \*/ + """.trimIndent().toRegex() + + private val enterpriseLicense = """ + /\* + \* © 20\d\d New Vector Limited, Element Software SARL, Element Software Inc\., + \* and Element Software GmbH \(the "Element Group"\) only make this file available + \* under a proprietary license model\. + \* + \* Without a proprietary license with us, you cannot use this file\. The terms of + \* the proprietary license agreement between you and any member of the Element Group + \* shall always apply to your use of this file\. Unauthorised use, copying, distribution, + \* or modification of this file, via any medium, is strictly prohibited\. + \* + \* For details about the licensing terms, you must either visit our website or contact + \* a member of our sales team\. + \*/ + """.trimIndent().toRegex() + + @Test + fun `assert that FOSS files have the correct license header`() { + Konsist + .scopeFromProject() + .files + .filter { + it.path.contains("/enterprise/features").not() && + it.nameWithExtension != "locales.kt" && + it.name.startsWith("Template ").not() + } + .assertTrue { + publicLicense.containsMatchIn(it.text) + } + } + + @Test + fun `assert that Enterprise files have the correct license header`() { + Konsist + .scopeFromProject() + .files + .filter { + it.path.contains("/enterprise/features") + } + .assertTrue { + enterpriseLicense.containsMatchIn(it.text) + } + } +} diff --git a/tools/detekt/detekt.yml b/tools/detekt/detekt.yml index cffb824ea4..7212a58ce3 100644 --- a/tools/detekt/detekt.yml +++ b/tools/detekt/detekt.yml @@ -197,9 +197,7 @@ performance: # Note: all rules for `comments` are disabled by default, but I put them here to be aware of their existence comments: AbsentOrWrongFileLicense: - active: true - licenseTemplateFile: 'license.template' - licenseTemplateIsRegex: true + active: false CommentOverPrivateFunction: active: false CommentOverPrivateProperty: diff --git a/tools/detekt/license.template b/tools/detekt/license.template deleted file mode 100644 index 08cadc82f9..0000000000 --- a/tools/detekt/license.template +++ /dev/null @@ -1,15 +0,0 @@ -\/\* -(?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd -(?:.*\n)* \* - \* Licensed under the Apache License, Version 2\.0 \(the "License"\); - \* you may not use this file except in compliance with the License\. - \* You may obtain a copy of the License at - \* - \* http(?:s)?:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0 - \* - \* Unless required by applicable law or agreed to in writing, software - \* distributed under the License is distributed on an "AS IS" BASIS, - \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. - \* See the License for the specific language governing permissions and - \* limitations under the License\. - \*\/