Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for long paths on Windows #236

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fun Project.setupServerProject(
packagesToFix: Provider<List<String>?>,
reobfMappings: Provider<RegularFile>,
): ServerTasks? {
testPathLength(layout)

if (!projectDir.exists()) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,38 @@ fun FileCollection.toJarClassProviderRoots(): List<ClassProviderRoot> = files.as
.map { p -> ClassProviderRoot.fromJar(p) }
.toList()

// Longest path as of 1.20.4
private const val longestPath: String =
"paperweight/mc-dev-sources/data/minecraft/datapacks/update_1_21/data/minecraft/advancements/" +
"recipes/building_blocks/waxed_weathered_chiseled_copper_from_waxed_weathered_cut_copper_stonecutting.json"

fun testPathLength(projectLayout: ProjectLayout) {
if (System.getProperty("os.name").lowercase().contains("win")) {
val tmpProjDir = projectLayout.projectDirectory.path.resolveSibling(
projectLayout.projectDirectory.path.name + "_"
)
val cache = tmpProjDir.resolve(".gradle/$CACHE_PATH")
val testFile = cache.resolve(longestPath)

try {
testFile.parent.createDirectories()
testFile.writeText("test")
} catch (e: Exception) {
throw PaperweightException(
"""The directory this project is cloned in is too nested. Possible solutions:
1) Move the project to a less nested directory (i.e. C:\Paper)
2) Enable long paths in Windows and Git:
Windows documentation: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
Git command: git config --global core.longpaths true
3) Clone and build the project in WSL (this will also improve build speed)""",
e
)
} finally {
tmpProjDir.deleteRecursive()
}
}
}

private fun javaVersion(): Int {
val version = System.getProperty("java.specification.version")
val parts = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
Expand Down
Loading