Skip to content

Commit

Permalink
Add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Jan 11, 2024
1 parent 0a830ae commit 32933c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ public class DefaultExternalModuleLinkResolver(
} else true
}?.first ?: return null

val modulePath = context.configuration.outputDir.absolutePath
val modulePathParts = modulePath.split(File.separator)
// relativization [fileContext] path over output path (or `fileContext.relativeTo(outputPath)`)
// e.g. outputPath = `/a/b/`
// fileContext = `/a/c/d/index.html`
// will be transformed to `../../b`+ validLink
val outputPath = context.configuration.outputDir.absolutePath


val outputPathParts = outputPath.split(File.separator)
val contextPathParts = fileContext.absolutePath.split(File.separator)
val commonPathElements = modulePathParts.zip(contextPathParts)
val commonPathElements = outputPathParts.zip(contextPathParts)
.takeWhile { (a, b) -> a == b }.count()

return (List(contextPathParts.size - commonPathElements - 1) { ".." } + modulePathParts.drop(commonPathElements))
return (List(contextPathParts.size - commonPathElements - 1) { ".." } + outputPathParts.drop(commonPathElements))
.joinToString("/") + validLink.removePrefix("file:")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.test.Test
import kotlin.test.assertTrue

/**
* The test check the first case (short-term solution) of #3368:
* The test checks the first case (short-term solution) of #3368:
* a situation where 2 (or more) local modules have the same package name.
*
* It does not check links for external modules, only for local ones.
Expand Down

0 comments on commit 32933c7

Please sign in to comment.