Skip to content

Commit 7dc0367

Browse files
committed
Read maven relocation information instead of assuming extensions with the same artifact id have a relationship
1 parent 1e7382b commit 7dc0367

File tree

13 files changed

+307
-142
lines changed

13 files changed

+307
-142
lines changed

gatsby-node.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
getStream,
77
} = require("./src/components/util/pretty-platform")
88
const { sortableName } = require("./src/components/util/sortable-name")
9-
const { extensionSlug } = require("./src/components/util/extension-slugger")
9+
const { extensionSlug, extensionSlugFromCoordinates } = require("./src/components/util/extension-slugger")
1010
const { generateMavenInfo } = require("./src/maven/maven-info")
1111
const { createRemoteFileNode } = require("gatsby-source-filesystem")
1212
const { rewriteGuideUrl } = require("./src/components/util/guide-url-rewriter")
@@ -137,37 +137,45 @@ exports.sourceNodes = async ({
137137

138138
// Look for extensions which are not the same, but which have the same artifact id
139139
// (artifactId is just the 'a' part of the gav, artifact is the whole gav string)
140+
141+
const relocation = node.metadata.maven?.relocation
142+
node.isSuperseded = false
143+
144+
if (relocation) {
145+
node.duplicates = [{
146+
artifactId: relocation.artifactId,
147+
groupId: relocation.groupId,
148+
slug: extensionSlugFromCoordinates(relocation),
149+
relationship: "newer",
150+
differentId: relocation.artifactId !== node.metadata.maven?.artifactId ? relocation.artifactId : relocation.groupId,
151+
differenceReason: relocation.artifactId !== node.metadata?.maven?.artifactId ? "artifact id" : "group id"
152+
}]
153+
154+
node.isSuperseded = true
155+
}
156+
157+
// Look for things that mark this extension as a duplicate
140158
const duplicates = extensions.filter(
141159
ext =>
142-
ext.metadata.maven?.artifactId === node.metadata.maven?.artifactId &&
143-
ext.artifact !== node.artifact
160+
ext.metadata.maven?.relocation?.artifactId === node.metadata.maven?.artifactId &&
161+
ext.metadata.maven?.relocation?.groupId === node.metadata.maven?.groupId
144162
)
145-
if (duplicates && duplicates.length > 0) {
163+
if (duplicates) {
146164
const condensedDuplicates = duplicates.map(dupe => {
147-
// If we're missing a timestamp because we couldn't get it from maven, all we can do is describe the versions as 'different' from each other.
148-
const relationship =
149-
dupe.metadata.maven.timestamp && extension.metadata.maven.timestamp
150-
? dupe.metadata.maven.timestamp > extension.metadata.maven.timestamp
151-
? "newer"
152-
: "older"
153-
: "different"
165+
// It's possible both might be different, but we've never seen it, so in that case just mention the different artifact id
154166

155167
return {
156168
artifact: dupe.artifact,
157-
groupId: dupe.metadata.maven.groupId,
169+
artifactId: dupe.metadata.maven?.artifactId,
170+
groupId: dupe.metadata.maven?.groupId,
158171
slug: extensionSlug(dupe.artifact),
159-
timestamp: dupe.metadata.maven.timestamp,
160-
relationship,
172+
relationship: "older",
173+
differentId: dupe.metadata.maven?.artifactId !== node.metadata.maven?.artifactId ? dupe.metadata.maven?.artifactId : dupe.metadata.maven?.groupId,
174+
differenceReason: dupe.metadata.maven?.artifactId !== node.metadata?.maven?.artifactId ? "artifact id" : "group id"
161175
}
162176
})
163-
node.duplicates = condensedDuplicates
177+
node.duplicates = node.duplicates ? [...condensedDuplicates, ...node.duplicates] : condensedDuplicates
164178

165-
if (
166-
condensedDuplicates &&
167-
condensedDuplicates.find(dupe => dupe.relationship === "newer")
168-
) {
169-
node.isSuperseded = true
170-
}
171179
}
172180

173181
return createNode(node)
@@ -305,6 +313,11 @@ exports.createSchemaCustomization = ({ actions }) => {
305313
url: String
306314
version: String
307315
timestamp: String
316+
relocation: RelocationInfo
317+
}
318+
319+
type RelocationInfo {
320+
artifactId: String
308321
}
309322
310323
`)

gatsby-node.test.js

Lines changed: 46 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ const resolvedMavenUrl = "http://reallygoodurl.mvn"
1313
const { generateMavenInfo } = require("./src/maven/maven-info")
1414
jest.mock("./src/maven/maven-info")
1515

16+
const dataCatRelocation = {
17+
artifactId: "quarkus-micrometer-registry-datadog",
18+
groupId: "io.quarkiverse.micrometer.registry"
19+
}
20+
1621
generateMavenInfo.mockImplementation(artifactId => {
1722
const coordinates = parse(artifactId)
1823
// This is totally unscientific and arbitrary, but it's reproducible
1924
coordinates.timestamp = artifactId.length
2025
coordinates.url = resolvedMavenUrl
26+
27+
// Special case the datacat artifact by doing some hardcoding
28+
if (artifactId.includes("datacat")) {
29+
coordinates.relocation = dataCatRelocation
30+
}
31+
2132
return coordinates
2233
})
2334

@@ -433,7 +444,7 @@ describe("the main gatsby entrypoint", () => {
433444
})
434445
})
435446

436-
describe("for an extension with an other extension sharing the artifact id", () => {
447+
describe("for an extension with a relocation to another extension", () => {
437448
const extension = {
438449
artifact:
439450
"io.quarkiverse.micrometer.registry:quarkus-micrometer-registry-datadog::jar:2.12.0",
@@ -443,10 +454,10 @@ describe("the main gatsby entrypoint", () => {
443454
}
444455
const olderExtension = {
445456
artifact:
446-
"io.quarkelsewhere:quarkus-micrometer-registry-datadog::jar:3.12.0",
457+
"io.quarkelsewhere:quarkus-micrometer-registry-datacat::jar:3.12.0",
447458
origins: [
448459
"io.quarkus.platform:quarkus-bom-quarkus-platform-descriptor:3.0.0.Alpha3:json:3.0.0.Alpha3",
449-
],
460+
]
450461
}
451462

452463
// A cut down version of what the registry returns us, with just the relevant bits
@@ -473,27 +484,28 @@ describe("the main gatsby entrypoint", () => {
473484
expect(createNodeId).toHaveBeenCalledTimes(2)
474485
})
475486

476-
it("adds a link to the older extension from the new one", () => {
487+
it("adds a link to the newer extension from the older one", () => {
477488
expect(createNode).toHaveBeenCalledWith(
478489
expect.objectContaining({
479490
artifact: extension.artifact,
480491
duplicates: [
481492
expect.objectContaining({
482493
groupId: "io.quarkelsewhere",
483-
slug: "io.quarkelsewhere/quarkus-micrometer-registry-datadog",
494+
slug: "io.quarkelsewhere/quarkus-micrometer-registry-datacat",
484495
}),
485496
],
486497
})
487498
)
488499
})
489500

490-
it("adds a link to the newer extension from the old one", () => {
501+
it("adds a link to the older extension from the new one", () => {
491502
expect(createNode).toHaveBeenCalledWith(
492503
expect.objectContaining({
493504
artifact: olderExtension.artifact,
494505
duplicates: [
495506
expect.objectContaining({
496507
groupId: "io.quarkiverse.micrometer.registry",
508+
slug: "io.quarkiverse.micrometer.registry/quarkus-micrometer-registry-datadog",
497509
}),
498510
],
499511
})
@@ -507,7 +519,20 @@ describe("the main gatsby entrypoint", () => {
507519
duplicates: [
508520
expect.objectContaining({
509521
relationship: "older",
510-
timestamp: 65,
522+
}),
523+
],
524+
})
525+
)
526+
})
527+
528+
it("adds data to the older one explaining what is different", () => {
529+
expect(createNode).toHaveBeenCalledWith(
530+
expect.objectContaining({
531+
artifact: extension.artifact,
532+
duplicates: [
533+
expect.objectContaining({
534+
differenceReason: "artifact id",
535+
differentId: "quarkus-micrometer-registry-datacat"
511536
}),
512537
],
513538
})
@@ -521,7 +546,20 @@ describe("the main gatsby entrypoint", () => {
521546
duplicates: [
522547
expect.objectContaining({
523548
relationship: "newer",
524-
timestamp: 82,
549+
}),
550+
],
551+
})
552+
)
553+
})
554+
555+
it("adds data to the newer one explaining what is different", () => {
556+
expect(createNode).toHaveBeenCalledWith(
557+
expect.objectContaining({
558+
artifact: olderExtension.artifact,
559+
duplicates: [
560+
expect.objectContaining({
561+
differenceReason: "artifact id",
562+
differentId: "quarkus-micrometer-registry-datadog"
525563
}),
526564
],
527565
})
@@ -545,100 +583,5 @@ describe("the main gatsby entrypoint", () => {
545583
})
546584
)
547585
})
548-
549-
describe("when maven conks out and does not give a timestamp", () => {
550-
beforeAll(async () => {
551-
// Clear any history from the parent beforeAll()
552-
jest.clearAllMocks()
553-
554-
generateMavenInfo.mockImplementation(artifactId => {
555-
const coordinates = parse(artifactId)
556-
// This is totally unscientific and arbitrary, but it's reproducible
557-
coordinates.timestamp = undefined
558-
coordinates.url = resolvedMavenUrl
559-
return coordinates
560-
})
561-
562-
axios.get = jest.fn().mockReturnValue({
563-
data: {
564-
extensions: [extension, olderExtension],
565-
platforms: currentPlatforms.platforms,
566-
},
567-
})
568-
569-
await sourceNodes({ actions, createNodeId, createContentDigest })
570-
})
571-
572-
it("adds a link to the older extension from the new one", () => {
573-
expect(createNode).toHaveBeenCalledWith(
574-
expect.objectContaining({
575-
artifact: extension.artifact,
576-
duplicates: [
577-
expect.objectContaining({
578-
groupId: "io.quarkelsewhere",
579-
slug: "io.quarkelsewhere/quarkus-micrometer-registry-datadog",
580-
}),
581-
],
582-
})
583-
)
584-
})
585-
586-
it("does not mark the new extension as superseded", () => {
587-
expect(createNode).not.toHaveBeenCalledWith(
588-
expect.objectContaining({
589-
artifact: extension.artifact,
590-
isSuperseded: true,
591-
})
592-
)
593-
})
594-
595-
it("adds a link to the newer extension from the old one", () => {
596-
expect(createNode).toHaveBeenCalledWith(
597-
expect.objectContaining({
598-
artifact: olderExtension.artifact,
599-
duplicates: [
600-
expect.objectContaining({
601-
groupId: "io.quarkiverse.micrometer.registry",
602-
}),
603-
],
604-
})
605-
)
606-
})
607-
608-
it("does not mark the older extension as superseded", () => {
609-
expect(createNode).not.toHaveBeenCalledWith(
610-
expect.objectContaining({
611-
artifact: olderExtension.artifact,
612-
isSuperseded: true,
613-
})
614-
)
615-
})
616-
617-
it("marks the older duplicate as just different", () => {
618-
expect(createNode).toHaveBeenCalledWith(
619-
expect.objectContaining({
620-
artifact: extension.artifact,
621-
duplicates: [
622-
expect.objectContaining({
623-
relationship: "different",
624-
}),
625-
],
626-
})
627-
)
628-
})
629-
630-
it("marks the newer duplicate as just different", () => {
631-
expect(createNode).toHaveBeenCalledWith(
632-
expect.objectContaining({
633-
artifact: olderExtension.artifact,
634-
duplicates: [
635-
expect.objectContaining({
636-
relationship: "different",
637-
}),
638-
],
639-
})
640-
)
641-
})
642-
})
643586
})
644587
})

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"tmp-promise": "^3.0.3",
5555
"url-exist": "^2.0.0",
5656
"values.js": "^2.1.1",
57+
"xml2js": "^0.6.2",
5758
"yaml-jest": "^1.2.0"
5859
},
5960
"devDependencies": {

plugins/github-enricher/sponsorFinder.realdata.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ describe.skip("real data contributor information", () => {
1818

1919
it("correctly counts contributors for iron jacamar", async () => {
2020
const answer = await getContributors("quarkiverse", "quarkus-ironjacamar")
21-
console.log("answer", answer)
2221
// This expectation will change over time, obviously
2322
expect(answer).toEqual(expect.arrayContaining([{
2423
"contributions": 145,

src/components/extensions-list.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("extension list", () => {
9090
})
9191

9292
it("displays a brief message about how many extensions there are", async () => {
93-
// The superceded extension should not be counted
93+
// The superseded extension should not be counted
9494
const num = extensions.length - 1
9595
expect(screen.getByText(`Showing ${num} extensions`)).toBeTruthy()
9696
})

src/components/util/extension-slugger.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ const extensionSlug = gav => {
1212
let string
1313
if (gav.includes(":")) {
1414
const coordinates = parse(gav)
15-
// slugs can have slashes in them, so use folders to group extensions in the same group
16-
// slugify strips slashes, so slugify before adding the slashes
17-
string =
18-
slugifyPart(coordinates.groupId) +
19-
"/" +
20-
slugifyPart(coordinates.artifactId)
15+
string = extensionSlugFromCoordinates(coordinates)
2116
} else {
2217
string = slugifyPart(gav)
2318
}
24-
2519
return string
2620
}
2721
}
28-
module.exports = { extensionSlug }
22+
23+
const extensionSlugFromCoordinates = coordinates => {
24+
25+
// slugs can have slashes in them, so use folders to group extensions in the same group
26+
// slugify strips slashes, so slugify before adding the slashes
27+
return slugifyPart(coordinates.groupId) + "/" + slugifyPart(coordinates.artifactId)
28+
29+
}
30+
31+
module.exports = { extensionSlug, extensionSlugFromCoordinates }

0 commit comments

Comments
 (0)