Skip to content

Commit beaa3fe

Browse files
committed
WIP: verify license compatibility
1 parent 8b42184 commit beaa3fe

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <[email protected]>
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+
18+
package com.github.vlsi.gradle.license
19+
20+
import com.github.vlsi.gradle.license.api.License
21+
import com.github.vlsi.gradle.license.api.LicenseExpression
22+
import com.github.vlsi.gradle.license.api.SimpleLicense
23+
import com.github.vlsi.gradle.license.api.asExpression
24+
import com.github.vlsi.gradle.license.api.disjunctions
25+
import org.gradle.api.DefaultTask
26+
import org.gradle.api.artifacts.Configuration
27+
import org.gradle.api.model.ObjectFactory
28+
import org.gradle.api.tasks.Input
29+
import org.gradle.api.tasks.InputFiles
30+
import org.gradle.api.tasks.OutputFile
31+
import org.gradle.api.tasks.TaskAction
32+
import org.gradle.kotlin.dsl.mapProperty
33+
import org.gradle.kotlin.dsl.resolver.DefaultResolverEventLogger.outputFile
34+
import org.gradle.kotlin.dsl.setProperty
35+
import javax.inject.Inject
36+
37+
class VerifyLicenseCompatibilityTask @Inject constructor(
38+
objectFactory: ObjectFactory
39+
) : DefaultTask() {
40+
@InputFiles
41+
val metadata = objectFactory.fileCollection()
42+
43+
@Input
44+
val acceptableLicenses = objectFactory.setProperty<LicenseExpression>()
45+
46+
/**
47+
* Outputs `OK` when verification is successful.
48+
*/
49+
@OutputFile
50+
val outputFile = objectFactory.fileProperty()
51+
52+
fun allow(license: License) {
53+
allow(license.asExpression())
54+
}
55+
56+
fun allow(licenseExpression: LicenseExpression) {
57+
acceptableLicenses.add(licenseExpression)
58+
}
59+
60+
@TaskAction
61+
fun run() {
62+
val dependencies = MetadataStore.load(metadata).dependencies
63+
val output = outputFile.get().asFile.apply {
64+
parentFile.mkdirs()
65+
}
66+
67+
val okLicenses = acceptableLicenses.get()
68+
.flatMapTo(mutableSetOf()) { it.disjunctions() }
69+
70+
for ((dependency, license) in dependencies) {
71+
if (license.)
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)