"Fossies" - the Fresh Open Source Software Archive 
Member "gradle-8.1.1/build-logic/binary-compatibility/src/main/kotlin/gradlebuild/binarycompatibility/AbstractAcceptedApiChangesMaintenanceTask.kt" (20 Apr 2023, 2363 Bytes) of package /linux/misc/gradle-8.1.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Kotlin source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "AbstractAcceptedApiChangesMaintenanceTask.kt":
8.0.2_vs_8.1.0.
1 /*
2 * Copyright 2022 the original author or authors.
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 gradlebuild.binarycompatibility
18
19 import com.google.common.annotations.VisibleForTesting
20 import com.google.gson.Gson
21 import org.gradle.api.DefaultTask
22 import org.gradle.api.file.RegularFileProperty
23 import org.gradle.api.tasks.CacheableTask
24 import org.gradle.api.tasks.InputFile
25 import org.gradle.api.tasks.PathSensitive
26 import org.gradle.api.tasks.PathSensitivity
27
28
29 /**
30 * Abstract base class for [Task][org.gradle.api.Task]s that verify and manipulate the given accepted API changes file.
31 */
32 @CacheableTask
33 abstract class AbstractAcceptedApiChangesMaintenanceTask : DefaultTask() {
34 @get:InputFile
35 @get:PathSensitive(PathSensitivity.NONE)
36 abstract val apiChangesFile: RegularFileProperty
37
38 protected
39 fun loadChanges(): List<AcceptedApiChange> {
40 val jsonString = apiChangesFile.get().asFile.readText()
41 val json = Gson().fromJson(jsonString, AcceptedApiChanges::class.java)
42 return json.acceptedApiChanges!!
43 }
44
45 /**
46 * Sorts the given list of [AcceptedApiChange]s by type and member.
47 * <p>
48 * This sort ought to remain consistent with the sort used by the [EnrichedReportRenderer].
49 */
50 @Suppress("KDocUnresolvedReference")
51 protected
52 fun sortChanges(originalChanges: List<AcceptedApiChange>) = originalChanges.toMutableList().sortedBy { it.type + '#' + it.member }
53
54 @VisibleForTesting
55 data class AcceptedApiChange(
56 val type: String?,
57 val member: String?,
58 val acceptation: String?,
59 val changes: List<String>?
60 ) {
61 override fun toString(): String = "Type: '$type', Member: '$member'"
62 }
63
64 @VisibleForTesting
65 data class AcceptedApiChanges(
66 val acceptedApiChanges: List<AcceptedApiChange>?
67 )
68 }