Skip to content

Commit 3ee9402

Browse files
authored
fix: support internal project dependencies (#304)
Follow on from #299 Sometimes artifacts have no file to hash. For example, a reference to another project `implementation project(':utilities')`. In this case hash the childId and assume the dependency is internal.
1 parent 77ef7ec commit 3ee9402

28 files changed

+1101
-7
lines changed

lib/init.gradle

+14-3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ def hash(File file) {
116116
return md.digest().encodeHex().toString()
117117
}
118118

119+
def hashString(String str) {
120+
def md = java.security.MessageDigest.getInstance('SHA-1')
121+
return md.digest(str.bytes).encodeHex().toString()
122+
}
123+
119124
def loadGraph(Iterable deps, GradleGraph graph, parentId, currentChain) {
120125
deps.each { dep ->
121126
dep.each { d ->
@@ -145,15 +150,21 @@ def loadSha1MapGraph(Iterable deps, GradleGraph graph, parentId, currentChain, s
145150
def moduleArtifacts = d.getModuleArtifacts()
146151
moduleArtifacts.each { a ->
147152
def childName = "${d.moduleGroup}:${d.moduleName}"
153+
def childId = "${childName}:${a.type}"
154+
if (a.classifier) childId += ":${a.classifier}"
155+
childId += "@${d.moduleVersion}"
148156
def sha1Hash = ""
149157
try {
150158
sha1Hash = hash(a.getFile())
151-
def childId = "${childName}:${a.type}"
152-
if (a.classifier) childId += ":${a.classifier}"
153-
childId += "@${d.moduleVersion}"
154159
sha1Map.setCoordinate(sha1Hash, childId);
155160
} catch (Exception e) {
161+
// sometimes artifacts have no file to hash
162+
// for example, a reference to another project
163+
// implementation project(':utilities')
164+
// in this case hash the childId
156165
debugLog("Failed to hash artifact ${a.id}, error=${e}")
166+
sha1Hash = hashString(childId)
167+
sha1Map.setCoordinate(sha1Hash, childId);
157168
}
158169
if (sha1Hash && !graph.nodes.get(sha1Hash)) {
159170
def childDependency = ['name': childName, 'version': d.moduleVersion]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
10+
# Binary files should be left untouched
11+
*.jar binary
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
id 'buildlogic.java-application-conventions'
7+
}
8+
9+
dependencies {
10+
implementation 'org.apache.commons:commons-text'
11+
implementation project(':utilities')
12+
}
13+
14+
application {
15+
// Define the main class for the application.
16+
mainClass = 'org.example.app.App'
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
{
2+
"schemaVersion": "1.2.0",
3+
"pkgManager": {
4+
"name": "gradle"
5+
},
6+
"pkgs": [
7+
{
8+
"id": "app@unspecified",
9+
"info": {
10+
"name": "app",
11+
"version": "unspecified"
12+
}
13+
},
14+
{
15+
"id": "org.apache.commons:[email protected]",
16+
"info": {
17+
"name": "org.apache.commons:commons-text",
18+
"version": "1.12.0"
19+
}
20+
},
21+
{
22+
"id": "init-gradle:utilities@unspecified",
23+
"info": {
24+
"name": "init-gradle:utilities",
25+
"version": "unspecified"
26+
}
27+
},
28+
{
29+
"id": "org.junit.jupiter:[email protected]",
30+
"info": {
31+
"name": "org.junit.jupiter:junit-jupiter",
32+
"version": "5.11.3"
33+
}
34+
},
35+
{
36+
"id": "org.junit.platform:[email protected]",
37+
"info": {
38+
"name": "org.junit.platform:junit-platform-launcher",
39+
"version": "1.11.3"
40+
}
41+
},
42+
{
43+
"id": "org.apache.commons:[email protected]",
44+
"info": {
45+
"name": "org.apache.commons:commons-lang3",
46+
"version": "3.14.0"
47+
}
48+
},
49+
{
50+
"id": "init-gradle:list@unspecified",
51+
"info": {
52+
"name": "init-gradle:list",
53+
"version": "unspecified"
54+
}
55+
},
56+
{
57+
"id": "org.junit.jupiter:[email protected]",
58+
"info": {
59+
"name": "org.junit.jupiter:junit-jupiter-params",
60+
"version": "5.11.3"
61+
}
62+
},
63+
{
64+
"id": "org.junit.jupiter:[email protected]",
65+
"info": {
66+
"name": "org.junit.jupiter:junit-jupiter-api",
67+
"version": "5.11.3"
68+
}
69+
},
70+
{
71+
"id": "org.junit.platform:[email protected]",
72+
"info": {
73+
"name": "org.junit.platform:junit-platform-engine",
74+
"version": "1.11.3"
75+
}
76+
},
77+
{
78+
"id": "org.apiguardian:[email protected]",
79+
"info": {
80+
"name": "org.apiguardian:apiguardian-api",
81+
"version": "1.1.2"
82+
}
83+
},
84+
{
85+
"id": "org.junit.platform:[email protected]",
86+
"info": {
87+
"name": "org.junit.platform:junit-platform-commons",
88+
"version": "1.11.3"
89+
}
90+
},
91+
{
92+
"id": "org.opentest4j:[email protected]",
93+
"info": {
94+
"name": "org.opentest4j:opentest4j",
95+
"version": "1.3.0"
96+
}
97+
}
98+
],
99+
"graph": {
100+
"rootNodeId": "root-node",
101+
"nodes": [
102+
{
103+
"nodeId": "root-node",
104+
"pkgId": "app@unspecified",
105+
"deps": [
106+
{
107+
"nodeId": "org.apache.commons:commons-text:[email protected]"
108+
},
109+
{
110+
"nodeId": "init-gradle:utilities:java-classes-directory@unspecified"
111+
},
112+
{
113+
"nodeId": "init-gradle:utilities:jar@unspecified"
114+
},
115+
{
116+
"nodeId": "org.junit.jupiter:junit-jupiter:[email protected]"
117+
},
118+
{
119+
"nodeId": "org.junit.platform:junit-platform-launcher:[email protected]"
120+
}
121+
]
122+
},
123+
{
124+
"nodeId": "org.apache.commons:commons-text:[email protected]",
125+
"pkgId": "org.apache.commons:[email protected]",
126+
"deps": [
127+
{
128+
"nodeId": "org.apache.commons:commons-lang3:[email protected]"
129+
}
130+
]
131+
},
132+
{
133+
"nodeId": "init-gradle:utilities:java-classes-directory@unspecified",
134+
"pkgId": "init-gradle:utilities@unspecified",
135+
"deps": [
136+
{
137+
"nodeId": "init-gradle:list:java-classes-directory@unspecified"
138+
}
139+
]
140+
},
141+
{
142+
"nodeId": "init-gradle:utilities:jar@unspecified",
143+
"pkgId": "init-gradle:utilities@unspecified",
144+
"deps": [
145+
{
146+
"nodeId": "init-gradle:list:jar@unspecified"
147+
}
148+
]
149+
},
150+
{
151+
"nodeId": "org.junit.jupiter:junit-jupiter:[email protected]",
152+
"pkgId": "org.junit.jupiter:[email protected]",
153+
"deps": [
154+
{
155+
"nodeId": "org.junit.jupiter:junit-jupiter-params:[email protected]"
156+
},
157+
{
158+
"nodeId": "org.junit.jupiter:junit-jupiter-api:[email protected]"
159+
}
160+
]
161+
},
162+
{
163+
"nodeId": "org.junit.platform:junit-platform-launcher:[email protected]",
164+
"pkgId": "org.junit.platform:[email protected]",
165+
"deps": [
166+
{
167+
"nodeId": "org.junit.platform:junit-platform-engine:[email protected]"
168+
}
169+
]
170+
},
171+
{
172+
"nodeId": "org.apache.commons:commons-lang3:[email protected]",
173+
"pkgId": "org.apache.commons:[email protected]",
174+
"deps": []
175+
},
176+
{
177+
"nodeId": "init-gradle:list:java-classes-directory@unspecified",
178+
"pkgId": "init-gradle:list@unspecified",
179+
"deps": []
180+
},
181+
{
182+
"nodeId": "init-gradle:list:jar@unspecified",
183+
"pkgId": "init-gradle:list@unspecified",
184+
"deps": []
185+
},
186+
{
187+
"nodeId": "org.junit.jupiter:junit-jupiter-params:[email protected]",
188+
"pkgId": "org.junit.jupiter:[email protected]",
189+
"deps": [
190+
{
191+
"nodeId": "org.junit.jupiter:junit-jupiter-api:[email protected]:pruned"
192+
},
193+
{
194+
"nodeId": "org.apiguardian:apiguardian-api:[email protected]"
195+
}
196+
]
197+
},
198+
{
199+
"nodeId": "org.junit.jupiter:junit-jupiter-api:[email protected]",
200+
"pkgId": "org.junit.jupiter:[email protected]",
201+
"deps": [
202+
{
203+
"nodeId": "org.junit.platform:junit-platform-commons:[email protected]"
204+
},
205+
{
206+
"nodeId": "org.apiguardian:apiguardian-api:[email protected]:pruned"
207+
},
208+
{
209+
"nodeId": "org.opentest4j:opentest4j:[email protected]"
210+
}
211+
]
212+
},
213+
{
214+
"nodeId": "org.junit.platform:junit-platform-engine:[email protected]",
215+
"pkgId": "org.junit.platform:[email protected]",
216+
"deps": [
217+
{
218+
"nodeId": "org.junit.platform:junit-platform-commons:[email protected]:pruned"
219+
},
220+
{
221+
"nodeId": "org.opentest4j:opentest4j:[email protected]:pruned"
222+
}
223+
]
224+
},
225+
{
226+
"nodeId": "org.junit.jupiter:junit-jupiter-api:[email protected]:pruned",
227+
"pkgId": "org.junit.jupiter:[email protected]",
228+
"deps": [],
229+
"info": {
230+
"labels": {
231+
"pruned": "true"
232+
}
233+
}
234+
},
235+
{
236+
"nodeId": "org.apiguardian:apiguardian-api:[email protected]",
237+
"pkgId": "org.apiguardian:[email protected]",
238+
"deps": []
239+
},
240+
{
241+
"nodeId": "org.junit.platform:junit-platform-commons:[email protected]",
242+
"pkgId": "org.junit.platform:[email protected]",
243+
"deps": [
244+
{
245+
"nodeId": "org.apiguardian:apiguardian-api:[email protected]:pruned"
246+
}
247+
]
248+
},
249+
{
250+
"nodeId": "org.apiguardian:apiguardian-api:[email protected]:pruned",
251+
"pkgId": "org.apiguardian:[email protected]",
252+
"deps": [],
253+
"info": {
254+
"labels": {
255+
"pruned": "true"
256+
}
257+
}
258+
},
259+
{
260+
"nodeId": "org.opentest4j:opentest4j:[email protected]",
261+
"pkgId": "org.opentest4j:[email protected]",
262+
"deps": []
263+
},
264+
{
265+
"nodeId": "org.junit.platform:junit-platform-commons:[email protected]:pruned",
266+
"pkgId": "org.junit.platform:[email protected]",
267+
"deps": [],
268+
"info": {
269+
"labels": {
270+
"pruned": "true"
271+
}
272+
}
273+
},
274+
{
275+
"nodeId": "org.opentest4j:opentest4j:[email protected]:pruned",
276+
"pkgId": "org.opentest4j:[email protected]",
277+
"deps": [],
278+
"info": {
279+
"labels": {
280+
"pruned": "true"
281+
}
282+
}
283+
}
284+
]
285+
}
286+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package org.example.app;
5+
6+
import org.example.list.LinkedList;
7+
8+
import static org.example.utilities.StringUtils.join;
9+
import static org.example.utilities.StringUtils.split;
10+
import static org.example.app.MessageUtils.getMessage;
11+
12+
import org.apache.commons.text.WordUtils;
13+
14+
public class App {
15+
public static void main(String[] args) {
16+
LinkedList tokens;
17+
tokens = split(getMessage());
18+
String result = join(tokens);
19+
System.out.println(WordUtils.capitalize(result));
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package org.example.app;
5+
6+
class MessageUtils {
7+
public static String getMessage() {
8+
return "Hello World!";
9+
}
10+
}

0 commit comments

Comments
 (0)