Skip to content

Commit d395f30

Browse files
authored
Merge pull request #33 from fkz/module
Use correct url to download artifacts by also checking urls in .module
2 parents 72f04b4 + 88bed92 commit d395f30

5 files changed

Lines changed: 214 additions & 12 deletions

File tree

buildGradleApplication/mkM2Repository.nix

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,38 @@
3636
"python ${./parse.py} ${verificationXmlFile} ${builtins.toString (builtins.map lib.escapeShellArg repositories)}> $out"
3737
))
3838
);
39-
mkDep = depSpec: {
40-
inherit (depSpec) urls path name hash component;
39+
mkDep = depSpec: let
40+
# Gradle module metadata may specify a different url suffix than the artifact name
41+
urlSuffixFallback = depSpec.name;
42+
urlSuffix =
43+
if (depSpec.module == null)
44+
then urlSuffixFallback
45+
else let
46+
module = fetchArtifact {
47+
urls = lib.map (prefix: "${prefix}/${depSpec.module.name}") depSpec.url_prefixes;
48+
inherit (depSpec.module) hash name;
49+
};
50+
moduleMetadata = builtins.fromJSON (builtins.readFile module);
51+
variantFiles = lib.flatten (lib.map (variant: variant.files or []) (moduleMetadata.variants or []));
52+
matchingVariantFiles =
53+
builtins.filter (
54+
file: (file.${depSpec.hash_algo} or null) == depSpec.hash_value && file.name == depSpec.name
55+
)
56+
variantFiles;
57+
firstMatchingVariantFile = builtins.head matchingVariantFiles;
58+
in
59+
if matchingVariantFiles == []
60+
then urlSuffixFallback
61+
else if builtins.all (f: f.url == firstMatchingVariantFile.url) matchingVariantFiles
62+
then firstMatchingVariantFile.url
63+
else throw "Found multiple matching urls with name ${depSpec.name} and hash ${depSpec.hash} in ${module}: ${builtins.toString (lib.map (f: f.url) matchingVariantFiles)}";
64+
urls = lib.map (prefix: "${prefix}/${urlSuffix}") depSpec.url_prefixes;
65+
in {
66+
inherit urls urlSuffix;
67+
inherit (depSpec) path name hash component;
4168
jar = fetchArtifact {
42-
inherit (depSpec) urls hash name;
69+
inherit urls;
70+
inherit (depSpec) hash name;
4371
};
4472
};
4573
dependencies = builtins.map mkDep depSpecs;
@@ -50,6 +78,6 @@
5078
{}
5179
(
5280
"mkdir $out"
53-
+ lib.concatMapStringsSep "\n" (dep: "mkdir -p $out/${dep.path}\nln -s ${builtins.toString dep.jar} $out/${dep.path}/${dep.name}") dependencies
81+
+ lib.concatMapStringsSep "\n" (dep: "mkdir -p $out/${dep.path}\nln -s ${builtins.toString dep.jar} $out/${dep.path}/${dep.urlSuffix}") dependencies
5482
);
5583
in {inherit dependencies m2Repository;}

buildGradleApplication/parse.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class Artifact:
1515
name: str
1616
hash: object
1717
component: object
18+
module: object
19+
20+
@dataclass
21+
class Module:
22+
name: str
23+
hash: object
24+
1825

1926
@dataclass
2027
class Hash:
@@ -32,15 +39,23 @@ def main():
3239
for artifact in artifacts:
3340
path = f"{artifact.component.group.replace('.', '/')}/{artifact.component.name}/{artifact.component.version}"
3441
output = {
35-
"urls": [f"{maven_repo}/{path}/{artifact.name}" for maven_repo in maven_repos],
42+
"url_prefixes": [f"{maven_repo}/{path}" for maven_repo in maven_repos],
3643
"path": path,
3744
"name": artifact.name,
45+
"module": {
46+
"name": artifact.module.name,
47+
"hash": toSri(artifact.module.hash.algo, artifact.module.hash.value),
48+
"hash_algo": artifact.module.hash.algo,
49+
"hash_value": artifact.module.hash.value,
50+
} if artifact.module is not None else None,
3851
"component": {
3952
"group": artifact.component.group,
4053
"name": artifact.component.name,
4154
"version": artifact.component.version,
4255
},
43-
"hash": toSri(artifact.hash.algo, artifact.hash.value)
56+
"hash": toSri(artifact.hash.algo, artifact.hash.value),
57+
"hash_algo": artifact.hash.algo,
58+
"hash_value": artifact.hash.value,
4459
}
4560
outputs.append(output)
4661
print(json.dumps(outputs))
@@ -66,6 +81,7 @@ def parse(xml_file):
6681
version = component_elem.get("version")
6782
component_obj = Component(group=group, name=name, version=version)
6883

84+
component_artifacts = []
6985
for artifact_elem in component_elem.findall("default:artifact", namespaces):
7086
artifact_name = artifact_elem.get("name")
7187
hash_obj=None
@@ -75,9 +91,22 @@ def parse(xml_file):
7591
value = elem.get("value")
7692
hash_obj = Hash(algo=algo, value=value)
7793

78-
artifact_obj = Artifact(name=artifact_name, hash=hash_obj, component=component_obj)
79-
artifacts.append(artifact_obj)
94+
artifact_obj = Artifact(name=artifact_name, hash=hash_obj, component=component_obj, module=None)
95+
component_artifacts.append(artifact_obj)
96+
97+
# keep reference to Gradle module metadata if it exist
98+
module_name = f"{name}-{version}.module"
99+
module_artifact = next(
100+
(artifact for artifact in component_artifacts if artifact.name == module_name),
101+
None,
102+
)
103+
if module_artifact is not None:
104+
module = Module(name=module_artifact.name, hash=module_artifact.hash)
105+
for artifact in component_artifacts:
106+
if artifact is not module_artifact:
107+
artifact.module = module
80108

109+
artifacts.extend(component_artifacts)
81110
return artifacts
82111

83112

examples/funky-dependencies/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ version = System.getenv("APP_VERSION") ?: "dirty"
1616

1717
dependencies {
1818
implementation(kotlin("stdlib-jdk8"))
19+
20+
// Dependency with artifact that does not follow the maven default convention
21+
// https://github.com/raphiz/buildGradleApplication/issues/30
22+
implementation("com.github.ajalt.clikt:clikt:5.0.1")
1923

2024
// implicitly requires kotlinx-serialization-core-metadata-x.y.z.jar which is not uploaded to m2
2125
// `kotlinx-serialization-core-metadata-x.y.z.jar` must hence be filtered from the verification-metadata.xml

examples/funky-dependencies/gradle/verification-metadata.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,125 @@
1111
</trusted-artifacts>
1212
</configuration>
1313
<components>
14+
<component group="com.github.ajalt.clikt" name="clikt" version="5.0.1">
15+
<artifact name="clikt-5.0.1.module">
16+
<sha256 value="aa797c4cd8b1cf33ac5e26ace5920d2facf7272c55823ce1ab23e2c2679ca62d" origin="Generated by Gradle" />
17+
</artifact>
18+
<artifact name="clikt-mordant-metadata.jar">
19+
<sha256 value="51d5423a7310b3bd47dfe870d64bd0cc922030ca2e0c2c209439da1ed5081e8e" origin="Generated by Gradle" />
20+
</artifact>
21+
</component>
22+
<component group="com.github.ajalt.clikt" name="clikt-core" version="5.0.1">
23+
<artifact name="clikt-core-5.0.1.module">
24+
<sha256 value="2a30d8c905eb72939961be972c5402ff31fe1da33ab14705504f595bf1c54852" origin="Generated by Gradle" />
25+
</artifact>
26+
<artifact name="clikt-metadata.jar">
27+
<sha256 value="270825c82ed9b2b8eb61ce8907b0c3752cb172cf2e59d06ad6a6ae4ff2366382" origin="Generated by Gradle" />
28+
</artifact>
29+
</component>
30+
<component group="com.github.ajalt.clikt" name="clikt-core-jvm" version="5.0.1">
31+
<artifact name="clikt-core-jvm-5.0.1.module">
32+
<sha256 value="b1881d7d8ff72fb2688cb4883470fbca84bcf8810cb69ec3050b49dbe1ca597f" origin="Generated by Gradle" />
33+
</artifact>
34+
<artifact name="clikt-jvm.jar">
35+
<sha256 value="e8c4370db06c69fa4806983b0c0a86eba91c1a5faddb6df315578fd8f3b735b7" origin="Generated by Gradle" />
36+
</artifact>
37+
</component>
38+
<component group="com.github.ajalt.clikt" name="clikt-jvm" version="5.0.1">
39+
<artifact name="clikt-jvm-5.0.1.module">
40+
<sha256 value="814208a734a65bf1d4492690fba1d7a3fb1992c72da39f97558bf3cda38cf724" origin="Generated by Gradle" />
41+
</artifact>
42+
<artifact name="clikt-mordant-jvm.jar">
43+
<sha256 value="ec387fe21884a880bc887dd144d928a95c30d33697e880dbc8f4a4e305a35fb7" origin="Generated by Gradle" />
44+
</artifact>
45+
</component>
46+
<component group="com.github.ajalt.colormath" name="colormath" version="3.6.0">
47+
<artifact name="colormath-3.6.0.module">
48+
<sha256 value="6907aa497adb9af63812c75366389ced3e6bb8bee80e7b239adb4c53673f8884" origin="Generated by Gradle" />
49+
</artifact>
50+
<artifact name="colormath-metadata.jar">
51+
<sha256 value="e3da31d04a895e535f5d08764ccf5f38341c42bf7d68da96ea1f0009f72599d6" origin="Generated by Gradle" />
52+
</artifact>
53+
</component>
54+
<component group="com.github.ajalt.colormath" name="colormath-jvm" version="3.6.0">
55+
<artifact name="colormath-jvm-3.6.0.module">
56+
<sha256 value="3fa76730f989e0284df182fcec85620d9b48ae3221398841ac6caf88462f62f8" origin="Generated by Gradle" />
57+
</artifact>
58+
<artifact name="colormath-jvm.jar">
59+
<sha256 value="59f741adfe62053066782d8b1a45afd06685a4bc64b33277e54876b993ed885c" origin="Generated by Gradle" />
60+
</artifact>
61+
</component>
62+
<component group="com.github.ajalt.mordant" name="mordant" version="3.0.0">
63+
<artifact name="mordant-3.0.0.module">
64+
<sha256 value="4088daf83a3c362fdae2598582fa86972fa97b5c4f028826ed1bcefa42e454d3" origin="Generated by Gradle" />
65+
</artifact>
66+
<artifact name="mordant-omnibus-metadata.jar">
67+
<sha256 value="090984d202692ffef447e88dfe2c63693a5de29670da0831b863bc284da147e2" origin="Generated by Gradle" />
68+
</artifact>
69+
</component>
70+
<component group="com.github.ajalt.mordant" name="mordant-core" version="3.0.0">
71+
<artifact name="mordant-core-3.0.0.module">
72+
<sha256 value="329f19e65d7c6cc2f094eb9d647adc8ac511d8c0eac4c418b4cd3dd8a2bc8048" origin="Generated by Gradle" />
73+
</artifact>
74+
<artifact name="mordant-metadata.jar">
75+
<sha256 value="73f5179d8e94f85114475f19968d165944594e6b338db71c8b0bfdb0951eeb3e" origin="Generated by Gradle" />
76+
</artifact>
77+
</component>
78+
<component group="com.github.ajalt.mordant" name="mordant-core-jvm" version="3.0.0">
79+
<artifact name="mordant-core-jvm-3.0.0.module">
80+
<sha256 value="23e06598fef929d81cdfed30a584243f4775e3c3371e09001ad27bab788cb719" origin="Generated by Gradle" />
81+
</artifact>
82+
<artifact name="mordant-jvm.jar">
83+
<sha256 value="9cf9b46d1f49f2d6cf2635462b29dc59e0c29b1fb2f085b3312888bbe9c7cd31" origin="Generated by Gradle" />
84+
</artifact>
85+
</component>
86+
<component group="com.github.ajalt.mordant" name="mordant-jvm" version="3.0.0">
87+
<artifact name="mordant-jvm-3.0.0.module">
88+
<sha256 value="9f5124881335284c00545731cf5970793cffa05e4953d90cd92a9a865e19786d" origin="Generated by Gradle" />
89+
</artifact>
90+
<artifact name="mordant-omnibus-jvm.jar">
91+
<sha256 value="9ed3b976fcccc78da746d49866fa8ebb8f10530a93c544ea0420259a607dd95e" origin="Generated by Gradle" />
92+
</artifact>
93+
</component>
94+
<component group="com.github.ajalt.mordant" name="mordant-jvm-ffm" version="3.0.0">
95+
<artifact name="mordant-jvm-ffm-3.0.0.module">
96+
<sha256 value="6cf8061ba22c47ce6d03cd68534d36f0bab8385c7bb6548c10f4a97ddbeffa18" origin="Generated by Gradle" />
97+
</artifact>
98+
</component>
99+
<component group="com.github.ajalt.mordant" name="mordant-jvm-ffm-jvm" version="3.0.0">
100+
<artifact name="mordant-jvm-ffm-jvm-3.0.0.module">
101+
<sha256 value="a0501bc9a742047d37dc0605804187e1ee6f973302ddbaf47562939cd0478e07" origin="Generated by Gradle" />
102+
</artifact>
103+
<artifact name="mordant-jvm-ffm-jvm.jar">
104+
<sha256 value="0fdb6002add727daebad1974df8f37d38c45a70445ebe48350173a81b1c72350" origin="Generated by Gradle" />
105+
</artifact>
106+
</component>
107+
<component group="com.github.ajalt.mordant" name="mordant-jvm-graal-ffi" version="3.0.0">
108+
<artifact name="mordant-jvm-graal-ffi-3.0.0.module">
109+
<sha256 value="0dd382b927e40b393c9fa16de190e16ec850f88258e2293c24a85ca7bf47a0ed" origin="Generated by Gradle" />
110+
</artifact>
111+
</component>
112+
<component group="com.github.ajalt.mordant" name="mordant-jvm-graal-ffi-jvm" version="3.0.0">
113+
<artifact name="mordant-jvm-graal-ffi-jvm-3.0.0.module">
114+
<sha256 value="6adb0ab3b5be302bc618882b51eae0212437691798460043ce5e7e5b63ba5f83" origin="Generated by Gradle" />
115+
</artifact>
116+
<artifact name="mordant-jvm-graal-ffi-jvm.jar">
117+
<sha256 value="9c26068c57fa9b2decc24206719d2e5c30d0ff38f2fa774f32e4f92eb0565b50" origin="Generated by Gradle" />
118+
</artifact>
119+
</component>
120+
<component group="com.github.ajalt.mordant" name="mordant-jvm-jna" version="3.0.0">
121+
<artifact name="mordant-jvm-jna-3.0.0.module">
122+
<sha256 value="b863d15a565799756ed0c46bd8a6052f8fca5c48609e81922967167215da0500" origin="Generated by Gradle" />
123+
</artifact>
124+
</component>
125+
<component group="com.github.ajalt.mordant" name="mordant-jvm-jna-jvm" version="3.0.0">
126+
<artifact name="mordant-jvm-jna-jvm-3.0.0.module">
127+
<sha256 value="52dcdaab23879bd04a5632894f1d8d9f385eaf92265b7d032735d408074e7001" origin="Generated by Gradle" />
128+
</artifact>
129+
<artifact name="mordant-jvm-jna-jvm.jar">
130+
<sha256 value="e5fae304714b8c5a2bb52dee7783c601b1bff6fc204738e27ed430d385b96dec" origin="Generated by Gradle" />
131+
</artifact>
132+
</component>
14133
<component group="com.google.code.gson" name="gson" version="2.8.9">
15134
<artifact name="gson-2.8.9.jar">
16135
<sha256 value="d3999291855de495c94c743761b8ab5176cfeabe281a5ab0d8e8d45326fd703e" origin="Generated by Gradle" />
@@ -24,6 +143,14 @@
24143
<sha256 value="b16e026e63427c1972ad0fc68703ec379b1576e411ba49c32fa9a31ab0bbcffb" origin="Generated by Gradle" />
25144
</artifact>
26145
</component>
146+
<component group="net.java.dev.jna" name="jna" version="5.14.0">
147+
<artifact name="jna-5.14.0.jar">
148+
<sha256 value="34ed1e1f27fa896bca50dbc4e99cf3732967cec387a7a0d5e3486c09673fe8c6" origin="Generated by Gradle" />
149+
</artifact>
150+
<artifact name="jna-5.14.0.pom">
151+
<sha256 value="e04e25951501df25adc7b1dcdb6c53373c94897b84d3e14921292763ee07ae3d" origin="Generated by Gradle" />
152+
</artifact>
153+
</component>
27154
<component group="org.apiguardian" name="apiguardian-api" version="1.1.2">
28155
<artifact name="apiguardian-api-1.1.2.jar">
29156
<sha256 value="b509448ac506d607319f182537f0b35d71007582ec741832a1f111e5b5b70b38" origin="Generated by Gradle" />
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
import kotlin.random.Random;
1+
import com.github.ajalt.clikt.core.CliktCommand
2+
import com.github.ajalt.clikt.core.main
3+
import com.github.ajalt.clikt.parameters.options.default
4+
import com.github.ajalt.clikt.parameters.options.help
5+
import com.github.ajalt.clikt.parameters.options.option
6+
import com.github.ajalt.clikt.parameters.options.prompt
7+
import com.github.ajalt.clikt.parameters.types.int
28

3-
fun main() {
4-
println("Hello Kotlin - funky dependencies!")
5-
println(Random.nextInt(2))
9+
class Hello : CliktCommand() {
10+
val count: Int by option().int().default(1).help("Number of greetings")
11+
val name: String by option().prompt("Your name").help("The person to greet")
12+
13+
override fun run() {
14+
repeat(count) {
15+
echo("Hello $name!")
16+
}
17+
}
618
}
19+
20+
fun main(args: Array<String>) = Hello().main(args)

0 commit comments

Comments
 (0)