Skip to content

Commit 86269d8

Browse files
committed
refactor(gradle): Inline the code from gradle-model
Stop sharing the model between the legacy `Gradle` package manager and `GradleInspector`, to prepare for changing the representation of the dependency tree structure to fix an issue with `GradleInspector`. With a shared model also `Gradle` would need to be aligned, which would result in a (too) large commit, quite a bit of development effort and not least impose the risk of introducing new bugs into `Gradle`. It is planned to remove `Gradle` once `GradleInspector` covers all its features, which is why it does not make sense to put much effort into `Gradle` anymore. So, decouple the implementations entirely to reflect these priorities. Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent 2eb8d83 commit 86269d8

4 files changed

Lines changed: 118 additions & 3 deletions

File tree

plugins/package-managers/gradle/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
implementation(libs.maven.core)
3131
implementation(libs.maven.resolver.api)
3232
implementation(projects.downloader)
33-
implementation(projects.plugins.packageManagers.gradleModel)
3433
implementation(projects.plugins.packageManagers.mavenPackageManager)
3534
implementation(projects.utils.commonUtils)
3635
implementation(projects.utils.ortUtils)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2021 The ORT Project Copyright Holders <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>
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+
* https://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+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.plugins.packagemanagers.gradle
21+
22+
import OrtComponent
23+
24+
/**
25+
* The type of this Gradle dependency. In case of a project, it is [projectType]. Otherwise it is "Maven" unless there
26+
* is no POM, then it is "Unknown".
27+
*/
28+
internal fun OrtComponent.getIdentifierType(projectType: String) =
29+
when {
30+
isProjectDependency -> projectType
31+
pomFile != null -> "Maven"
32+
else -> "Unknown"
33+
}
34+
35+
/**
36+
* A flag to indicate whether this Gradle dependency refers to a project, or to a package.
37+
*/
38+
internal val OrtComponent.isProjectDependency: Boolean
39+
get() = localPath != null

plugins/package-managers/gradle/src/main/kotlin/GradleDependencyHandler.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import org.ossreviewtoolkit.model.PackageLinkage
3434
import org.ossreviewtoolkit.model.Severity
3535
import org.ossreviewtoolkit.model.createAndLogIssue
3636
import org.ossreviewtoolkit.model.utils.DependencyHandler
37-
import org.ossreviewtoolkit.plugins.packagemanagers.gradlemodel.getIdentifierType
38-
import org.ossreviewtoolkit.plugins.packagemanagers.gradlemodel.isProjectDependency
3937
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.MavenSupport
4038
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.identifier
4139
import org.ossreviewtoolkit.utils.common.collectMessages
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2017 The ORT Project Copyright Holders <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>
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+
* https://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+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
// As it is not possible to declare a package in "init.gradle" also no package is declared here.
21+
22+
// The following interfaces have to match those in "plugins/package-managers/gradle/src/main/resources/init.gradle"
23+
// because they are used to deserialize the model produced there.
24+
25+
internal interface OrtDependencyTreeModel {
26+
val group: String
27+
val name: String
28+
val version: String
29+
val configurations: List<OrtConfiguration>
30+
val repositories: List<OrtRepository>
31+
val errors: List<String>
32+
val warnings: List<String>
33+
}
34+
35+
internal interface OrtConfiguration {
36+
val name: String
37+
val dependencies: List<OrtComponent>
38+
}
39+
40+
internal interface OrtComponentIdentifier {
41+
val groupId: String
42+
val artifactId: String
43+
val version: String
44+
}
45+
46+
internal interface OrtComponent {
47+
val componentId: OrtComponentIdentifier
48+
val classifier: String
49+
val extension: String
50+
val variants: Map<String, Map<String, String>>
51+
val dependencies: List<OrtComponent>
52+
val error: String?
53+
val warning: String?
54+
val pomFile: String?
55+
val mavenModel: OrtMavenModel?
56+
val localPath: String?
57+
}
58+
59+
internal interface OrtMavenModel {
60+
val licenses: Set<String>
61+
val authors: Set<String>
62+
val description: String?
63+
val homepageUrl: String?
64+
val vcs: OrtVcsModel?
65+
}
66+
67+
internal interface OrtVcsModel {
68+
val connection: String
69+
val tag: String
70+
val browsableUrl: String
71+
}
72+
73+
internal interface OrtRepository {
74+
val url: String
75+
val username: String?
76+
val password: String?
77+
val headerName: String?
78+
val headerValue: String?
79+
}

0 commit comments

Comments
 (0)