-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Maven] Support for maven central snapshots #10997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
9f708f1
to
4b400ac
Compare
looking forward to this! |
{ name: 'groupId', example: 'com.google.guava' }, | ||
{ name: 'artifactId', example: 'guava' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace this with an example that works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "problem" with an example here is, that thery remove snapshots after a 90 days.
See https://central.sonatype.org/publish/publish-portal-snapshots/
Specifically, -SNAPSHOT releases are cleaned up after a period of time (currently 90 days). We believe that this should be sufficient, as projects under active development will be pushing new versions of the same -SNAPSHOT component with some frequency.
So even if we go with an SNAPSHOT release today, it might break in 90 days 🫠
So we might need an really active project to have some kind of a stable example...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sure. But if you look at the example used in the service tests, it does actually exist
https://central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/maven-metadata.xml
the versions might expire over time, but the repo is there
https://central.sonatype.com/repository/maven-snapshots/com/google/guava/guava/maven-metadata.xml
is never going to return anything.
OK, so we've got 2 things going on here. First lets take the last updated badge. This one should be fairly simple to land. import Joi from 'joi'
import { pathParams, BaseXmlService } from '../index.js'
import { parseDate, renderDateBadge } from '../date.js'
import { nonNegativeInteger } from '../validators.js'
const updateResponseSchema = Joi.object({
metadata: Joi.object({
versioning: Joi.object({
lastUpdated: nonNegativeInteger,
}).required(),
}).required(),
}).required()
class MavenCentralLastUpdateBase extends BaseXmlService {
static category = 'activity'
static defaultBadgeData = { label: 'last updated' }
async handle({ groupId, artifactId }) {
const { metadata } = await this.fetch({
groupId,
artifactId,
schema: updateResponseSchema,
})
const date = parseDate(
String(metadata.versioning.lastUpdated),
'YYYYMMDDHHmmss',
)
return renderDateBadge(date)
}
static encodeParams({ groupId, artifactId }) {
return {
group: encodeURIComponent(groupId).replace(/\./g, '/'),
artifact: encodeURIComponent(artifactId),
}
}
}
class MavenCentralLastUpdate extends MavenCentralLastUpdateBase {
static route = {
base: 'maven-central/last-update',
pattern: ':groupId/:artifactId',
}
static openApi = {
'/maven-central/last-update/{groupId}/{artifactId}': {
get: {
summary: 'Maven Central Last Update',
parameters: pathParams(
{ name: 'groupId', example: 'com.google.guava' },
{ name: 'artifactId', example: 'guava' },
),
},
},
}
async fetch({ groupId, artifactId, schema }) {
const { group, artifact } = this.constructor.encodeParams({
groupId,
artifactId,
})
return this._requestXml({
schema,
url: `https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml`,
httpErrors: { 404: 'artifact not found' },
})
}
}
class MavenCentralSnapshotsLastUpdate extends MavenCentralLastUpdateBase {
static route = {
base: 'maven-central-snapshots/last-update',
pattern: ':groupId/:artifactId',
}
static openApi = {
'/maven-central-snapshots/last-update/{groupId}/{artifactId}': {
get: {
summary: 'Maven Central Snapshots Last Update',
parameters: pathParams(
{ name: 'groupId', example: 'me.mrdoc.minecraft' },
{ name: 'artifactId', example: 'dlibcustomextensions' },
),
},
},
}
async fetch({ groupId, artifactId, schema }) {
const { group, artifact } = this.constructor.encodeParams({
groupId,
artifactId,
})
return this._requestXml({
schema,
url: `https://central.sonatype.com/repository/maven-snapshots/${group}/${artifact}/maven-metadata.xml`,
httpErrors: { 404: 'artifact not found' },
})
}
}
export default [MavenCentralLastUpdate, MavenCentralSnapshotsLastUpdate] (that can all go in one file) |
queryParam({ | ||
name: 'versionPrefix', | ||
example: '29', | ||
description: 'Filter only versions with this prefix.', | ||
}), | ||
queryParam({ | ||
name: 'versionSuffix', | ||
example: '-android', | ||
description: 'Filter only versions with this suffix.', | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Secondly, lets look at the version badge.
This isn't really your fault, but the maven central version badge has a long-standing issue. #6188
I think it is likely we will remove the versionPrefix
and versionSuffix
params (see #6188 (comment) )
If we are going to add a specific route for this (although you can already make badges for this service anyway e.g: https://img.shields.io/maven-metadata/v.svg?label=maven-central-snapshots&metadataUrl=https%3A//central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/maven-metadata.xml as the routes are just redirectors for the more general maven-metadata route), then I think we should not expose the versionPrefix
and versionSuffix
params on the documentation page. Lets not encourage users to start using a feature that is likely to disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused with the URL you posted here.
Right know, version 1.0.0-SNAPSHOT is released.
See https://central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/maven-metadata.xml
However, if I open the URL, it gives me 0.0.3-SNAPSHOT
back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathParam({ name: 'groupId', example: 'com.google.guava' }), | ||
pathParam({ name: 'artifactId', example: 'guava' }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also replace this with an example that works
Hey guys, what is the progress on that? 😇 |
maven central remove old snapshots then this test can cause issues if try to check a removed version
3127d77
to
732efea
Compare
not sure if wait to the PR for the order of versions based in how this can change how need handle all here for refactor |
This PR close #10894 making a replicate of the current services for maven-central but for the snapshots feature added recently.