mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-11 19:14:11 +00:00
Poplar
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.api.artifacts.component.ComponentIdentifier;
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -15,6 +17,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
@@ -27,6 +30,27 @@ public final class NativeRuntimeArtifacts {
|
||||
private NativeRuntimeArtifacts() {
|
||||
}
|
||||
|
||||
public static Map<String, File> publishedArtifacts(Map<ComponentIdentifier, File> resolved,
|
||||
List<String> modules, String version) {
|
||||
Map<String, File> artifacts = new TreeMap<>();
|
||||
for (Map.Entry<ComponentIdentifier, File> entry : resolved.entrySet()) {
|
||||
if (!(entry.getKey() instanceof ModuleComponentIdentifier component)
|
||||
|| !GROUP.equals(component.getGroup()) || !version.equals(component.getVersion())
|
||||
|| !modules.contains(component.getModule())) {
|
||||
throw new GradleException("Native runtime providers must resolve to published coordinates at "
|
||||
+ version + ": " + entry.getKey().getDisplayName());
|
||||
}
|
||||
if (artifacts.put(component.getModule(), entry.getValue()) != null) {
|
||||
throw new GradleException("Duplicate native runtime provider: " + component.getModule());
|
||||
}
|
||||
}
|
||||
if (!artifacts.keySet().equals(new TreeSet<>(modules))) {
|
||||
throw new GradleException("Published native runtime providers differ: " + artifacts.keySet()
|
||||
+ "; expected " + modules);
|
||||
}
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
public static void generate(Map<String, File> artifacts, String version, File output, File rules) throws IOException {
|
||||
List<String> manifest = new ArrayList<>();
|
||||
manifest.add("modules=" + String.join(",", artifacts.keySet()));
|
||||
|
||||
@@ -1,20 +1,66 @@
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.api.artifacts.ModuleIdentifier;
|
||||
import org.gradle.api.artifacts.component.ComponentIdentifier;
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
|
||||
import org.junit.Test;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class NativeRuntimeArtifactsTest {
|
||||
@Test
|
||||
public void acceptsOnlyRequestedPublishedCoordinates() {
|
||||
File common = new File("common.jar");
|
||||
File provider = new File("provider.jar");
|
||||
Map<ComponentIdentifier, File> resolved = Map.of(
|
||||
module("native-common", "revision"), common,
|
||||
module("native-v26_2_R1", "revision"), provider);
|
||||
assertEquals(Map.of("native-common", common, "native-v26_2_R1", provider),
|
||||
NativeRuntimeArtifacts.publishedArtifacts(resolved,
|
||||
List.of("native-common", "native-v26_2_R1"), "revision"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsCompositeProjectArtifacts() {
|
||||
ComponentIdentifier project = () -> "project :VolmLib:native-common";
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.publishedArtifacts(
|
||||
Map.of(project, new File("native-common-local-SNAPSHOT.jar")), List.of("native-common"), "revision"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsUnexpectedCoordinates() {
|
||||
List<ComponentIdentifier> invalid = List.of(
|
||||
new PublishedModule("other.group", "native-common", "revision"),
|
||||
module("native-common", "other-revision"),
|
||||
module("native-v26_3_R1", "revision"));
|
||||
for (ComponentIdentifier component : invalid) {
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.publishedArtifacts(
|
||||
Map.of(component, new File("provider.jar")), List.of("native-common"), "revision"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsMissingProviders() {
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.publishedArtifacts(
|
||||
Map.of(module("native-common", "revision"), new File("common.jar")),
|
||||
List.of("native-common", "native-v26_2_R1"), "revision"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordsExactDependenciesAndRetainsSharedProviderReferences() throws Exception {
|
||||
Path directory = Files.createTempDirectory("native-artifacts");
|
||||
@@ -31,6 +77,14 @@ public class NativeRuntimeArtifactsTest {
|
||||
File rules = directory.resolve("keep.pro").toFile();
|
||||
NativeRuntimeArtifacts.generate(Map.of("native-common", provider, "native-v26_2_R1", provider),
|
||||
"revision", directory.toFile(), rules);
|
||||
Properties manifest = new Properties();
|
||||
try (Reader reader = Files.newBufferedReader(directory.resolve(NativeRuntimeArtifacts.MANIFEST))) {
|
||||
manifest.load(reader);
|
||||
}
|
||||
String digest = HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256")
|
||||
.digest(Files.readAllBytes(provider.toPath())));
|
||||
assertEquals(digest, manifest.getProperty("native-common.sha256"));
|
||||
assertEquals(digest, manifest.getProperty("native-v26_2_R1.sha256"));
|
||||
assertTrue(Files.readString(rules.toPath()).contains("-keep class art.arcane.volmlib.util.collection.KList { *; }"));
|
||||
File plugin = directory.resolve("plugin.jar").toFile();
|
||||
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(plugin.toPath()))) {
|
||||
@@ -42,4 +96,41 @@ public class NativeRuntimeArtifactsTest {
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verify(plugin, List.of("v26_3_R1"), "revision"));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verify(plugin, List.of("v26_2_R1"), "other"));
|
||||
}
|
||||
|
||||
private static ModuleComponentIdentifier module(String module, String version) {
|
||||
return new PublishedModule("com.github.VolmitSoftware.VolmLib", module, version);
|
||||
}
|
||||
|
||||
private record PublishedModule(String group, String module, String version)
|
||||
implements ModuleComponentIdentifier, ModuleIdentifier {
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleIdentifier getModuleIdentifier() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return group + ":" + module + ":" + version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user