Skip to content

Commit d22dd7c

Browse files
committed
Let Konsist checks the license header
1 parent 4d3a2d4 commit d22dd7c

File tree

3 files changed

+86
-18
lines changed

3 files changed

+86
-18
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2024 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.element.android.tests.konsist
18+
19+
import com.lemonappdev.konsist.api.Konsist
20+
import com.lemonappdev.konsist.api.verify.assertTrue
21+
import org.junit.Test
22+
23+
class KonsistLicenseTest {
24+
private val publicLicense = """
25+
/\*
26+
(?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd
27+
(?:.*\n)* \*
28+
\* Licensed under the Apache License, Version 2\.0 \(the "License"\);
29+
\* you may not use this file except in compliance with the License\.
30+
\* You may obtain a copy of the License at
31+
\*
32+
\* {5}https?://www\.apache\.org/licenses/LICENSE-2\.0
33+
\*
34+
\* Unless required by applicable law or agreed to in writing, software
35+
\* distributed under the License is distributed on an "AS IS" BASIS,
36+
\* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.
37+
\* See the License for the specific language governing permissions and
38+
\* limitations under the License\.
39+
\*/
40+
""".trimIndent().toRegex()
41+
42+
private val enterpriseLicense = """
43+
/\*
44+
\* © 20\d\d New Vector Limited, Element Software SARL, Element Software Inc\.,
45+
\* and Element Software GmbH \(the "Element Group"\) only make this file available
46+
\* under a proprietary license model\.
47+
\*
48+
\* Without a proprietary license with us, you cannot use this file\. The terms of
49+
\* the proprietary license agreement between you and any member of the Element Group
50+
\* shall always apply to your use of this file\. Unauthorised use, copying, distribution,
51+
\* or modification of this file, via any medium, is strictly prohibited\.
52+
\*
53+
\* For details about the licensing terms, you must either visit our website or contact
54+
\* a member of our sales team\.
55+
\*/
56+
""".trimIndent().toRegex()
57+
58+
@Test
59+
fun `assert that FOSS files have the correct license header`() {
60+
Konsist
61+
.scopeFromProject()
62+
.files
63+
.filter {
64+
it.path.contains("/enterprise/features").not() &&
65+
it.nameWithExtension != "locales.kt" &&
66+
it.name.startsWith("Template ").not()
67+
}
68+
.assertTrue {
69+
publicLicense.containsMatchIn(it.text)
70+
}
71+
}
72+
73+
@Test
74+
fun `assert that Enterprise files have the correct license header`() {
75+
Konsist
76+
.scopeFromProject()
77+
.files
78+
.filter {
79+
it.path.contains("/enterprise/features")
80+
}
81+
.assertTrue {
82+
enterpriseLicense.containsMatchIn(it.text)
83+
}
84+
}
85+
}

tools/detekt/detekt.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ performance:
197197
# Note: all rules for `comments` are disabled by default, but I put them here to be aware of their existence
198198
comments:
199199
AbsentOrWrongFileLicense:
200-
active: true
201-
licenseTemplateFile: 'license.template'
202-
licenseTemplateIsRegex: true
200+
active: false
203201
CommentOverPrivateFunction:
204202
active: false
205203
CommentOverPrivateProperty:

tools/detekt/license.template

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)