Skip to content

Commit fd9c2cd

Browse files
committed
refactor(analyzer): Extend and use ModuleInfo.toId() for projects
The function previously was used only for packages. Well, it was also used for the assingment of `projectId`, but that value hasn't been used for the project in the returned result. Signed-off-by: Frank Viernau <[email protected]>
1 parent 0a97f62 commit fd9c2cd

File tree

1 file changed

+22
-12
lines changed
  • analyzer/src/main/kotlin/managers

1 file changed

+22
-12
lines changed

analyzer/src/main/kotlin/managers/GoMod.kt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ class GoMod(
142142
return listOf(
143143
ProjectAnalyzerResult(
144144
project = Project(
145-
id = Identifier(
146-
type = managerName,
147-
namespace = "",
148-
name = projectId.name,
149-
version = projectVcs.revision
150-
),
145+
id = projectId,
151146
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
152147
authors = emptySet(), // Go mod doesn't support author information.
153148
declaredLicenses = emptySet(), // Go mod doesn't support declared licenses.
@@ -222,12 +217,27 @@ class GoMod(
222217
}
223218

224219
private fun ModuleInfo.toId(): Identifier =
225-
Identifier(
226-
type = managerName.takeIf { main } ?: "Go",
227-
namespace = "",
228-
name = path,
229-
version = normalizeModuleVersion(version)
230-
)
220+
if (version.isBlank()) {
221+
// If the version is blank, it is a project in ORT speak.
222+
check(main) { "Found a local module dependency which is not supported." }
223+
224+
checkNotNull(dir) { "For projects, the directory is expected to not be null." }
225+
226+
Identifier(
227+
type = managerName,
228+
namespace = "",
229+
name = path,
230+
version = processProjectVcs(File(dir)).revision
231+
)
232+
} else {
233+
// If the version is not blank, it is a package in ORT speak.
234+
Identifier(
235+
type = "Go",
236+
namespace = "",
237+
name = path,
238+
version = normalizeModuleVersion(version)
239+
)
240+
}
231241

232242
/**
233243
* Return the list of all modules contained in the dependency tree with resolved versions and the 'replace'

0 commit comments

Comments
 (0)