mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 21:47:42 -05:00
Fix #755
This commit is contained in:
@@ -272,7 +272,7 @@ public final class CompileConfiguration {
|
||||
private static Path getLockFile(Project project) {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final Path cacheDirectory = extension.getFiles().getUserCache().toPath();
|
||||
final String pathHash = Checksum.toHex(project.getProjectDir().getAbsolutePath().getBytes(StandardCharsets.UTF_8)).substring(0, 16);
|
||||
final String pathHash = Checksum.projectHash(project);
|
||||
return cacheDirectory.resolve("." + pathHash + ".lock");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ package net.fabricmc.loom.util;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.common.io.Files;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.logging.Logging;
|
||||
|
||||
@@ -81,4 +83,9 @@ public class Checksum {
|
||||
public static String toHex(byte[] bytes) {
|
||||
return BaseEncoding.base16().lowerCase().encode(bytes);
|
||||
}
|
||||
|
||||
public static String projectHash(Project project) {
|
||||
String str = project.getProjectDir().getAbsolutePath() + ":" + project.getPath();
|
||||
return toHex(str.getBytes(StandardCharsets.UTF_8)).substring(0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.test.unit
|
||||
|
||||
import net.fabricmc.loom.util.Checksum
|
||||
import org.gradle.api.Project
|
||||
import spock.lang.Specification
|
||||
|
||||
class ChecksumTest extends Specification {
|
||||
def "project hash"() {
|
||||
given:
|
||||
def project = Mock(Project)
|
||||
project.getPath() >> path
|
||||
project.getProjectDir() >> new File(dir)
|
||||
|
||||
when:
|
||||
def hash = Checksum.projectHash(project)
|
||||
|
||||
then:
|
||||
hash == expected
|
||||
|
||||
where:
|
||||
path | dir | expected
|
||||
":" | "C://mod" | "2f55736572732f6d"
|
||||
":sub" | "/Users/test/Documents/modding/fabric-loom" | "2f55736572732f74"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user