2022-03-03 09:35:26 +00:00
|
|
|
import { logger } from '../../../logger';
|
|
|
|
import { Http } from '../../../util/http';
|
|
|
|
import { regEx } from '../../../util/regex';
|
|
|
|
import { ensureTrailingSlash } from '../../../util/url';
|
2021-01-21 12:11:35 +00:00
|
|
|
import * as ivyVersioning from '../../versioning/ivy';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { compare } from '../../versioning/maven/compare';
|
|
|
|
import { downloadHttpProtocol } from '../maven/util';
|
2022-02-15 05:12:30 +00:00
|
|
|
import { SbtPackageDatasource } from '../sbt-package';
|
|
|
|
import { getLatestVersion, parseIndexDir } from '../sbt-package/util';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type { GetReleasesConfig, ReleaseResult } from '../types';
|
2019-05-30 23:39:07 +00:00
|
|
|
|
2022-02-15 05:12:30 +00:00
|
|
|
export const SBT_PLUGINS_REPO =
|
2022-12-14 19:00:40 +00:00
|
|
|
'https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases';
|
2022-02-15 05:12:30 +00:00
|
|
|
|
2020-04-07 13:41:39 +00:00
|
|
|
export const defaultRegistryUrls = [SBT_PLUGINS_REPO];
|
2022-02-15 05:12:30 +00:00
|
|
|
|
|
|
|
export class SbtPluginDatasource extends SbtPackageDatasource {
|
|
|
|
static override readonly id = 'sbt-plugin';
|
|
|
|
|
|
|
|
override readonly defaultRegistryUrls = defaultRegistryUrls;
|
|
|
|
|
|
|
|
override readonly registryStrategy = 'hunt';
|
|
|
|
|
|
|
|
override readonly defaultVersioning = ivyVersioning.id;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(SbtPluginDatasource.id);
|
|
|
|
this.http = new Http('sbt');
|
|
|
|
}
|
|
|
|
|
|
|
|
async resolvePluginReleases(
|
|
|
|
rootUrl: string,
|
|
|
|
artifact: string,
|
|
|
|
scalaVersion: string
|
|
|
|
): Promise<string[] | null> {
|
|
|
|
const searchRoot = `${rootUrl}/${artifact}`;
|
|
|
|
const parse = (content: string): string[] =>
|
|
|
|
parseIndexDir(content, (x) => !regEx(/^\.+$/).test(x));
|
|
|
|
const { body: indexContent } = await downloadHttpProtocol(
|
|
|
|
this.http,
|
|
|
|
ensureTrailingSlash(searchRoot)
|
2020-04-12 16:09:36 +00:00
|
|
|
);
|
2022-02-15 05:12:30 +00:00
|
|
|
if (indexContent) {
|
|
|
|
const releases: string[] = [];
|
|
|
|
const scalaVersionItems = parse(indexContent);
|
|
|
|
const scalaVersions = scalaVersionItems.map((x) =>
|
|
|
|
x.replace(regEx(/^scala_/), '')
|
2020-01-14 11:22:42 +00:00
|
|
|
);
|
2022-02-15 05:12:30 +00:00
|
|
|
const searchVersions = scalaVersions.includes(scalaVersion)
|
|
|
|
? [scalaVersion]
|
|
|
|
: scalaVersions;
|
|
|
|
for (const searchVersion of searchVersions) {
|
|
|
|
const searchSubRoot = `${searchRoot}/scala_${searchVersion}`;
|
|
|
|
const { body: subRootContent } = await downloadHttpProtocol(
|
|
|
|
this.http,
|
|
|
|
ensureTrailingSlash(searchSubRoot)
|
|
|
|
);
|
|
|
|
if (subRootContent) {
|
|
|
|
const sbtVersionItems = parse(subRootContent);
|
|
|
|
for (const sbtItem of sbtVersionItems) {
|
|
|
|
const releasesRoot = `${searchSubRoot}/${sbtItem}`;
|
|
|
|
const { body: releasesIndexContent } = await downloadHttpProtocol(
|
|
|
|
this.http,
|
|
|
|
ensureTrailingSlash(releasesRoot)
|
|
|
|
);
|
|
|
|
if (releasesIndexContent) {
|
|
|
|
const releasesParsed = parse(releasesIndexContent);
|
|
|
|
releasesParsed.forEach((x) => releases.push(x));
|
|
|
|
}
|
2019-11-24 04:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 05:12:30 +00:00
|
|
|
if (releases.length) {
|
|
|
|
return [...new Set(releases)].sort(compare);
|
|
|
|
}
|
2019-11-24 04:09:13 +00:00
|
|
|
}
|
2022-02-04 19:50:14 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:12:30 +00:00
|
|
|
override async getReleases({
|
2022-03-03 15:08:43 +00:00
|
|
|
packageName,
|
2022-02-15 05:12:30 +00:00
|
|
|
registryUrl,
|
|
|
|
}: GetReleasesConfig): Promise<ReleaseResult | null> {
|
|
|
|
// istanbul ignore if
|
|
|
|
if (!registryUrl) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-03 15:08:43 +00:00
|
|
|
const [groupId, artifactId] = packageName.split(':');
|
2022-02-15 05:12:30 +00:00
|
|
|
const groupIdSplit = groupId.split('.');
|
|
|
|
const artifactIdSplit = artifactId.split('_');
|
|
|
|
const [artifact, scalaVersion] = artifactIdSplit;
|
2020-07-17 08:14:50 +00:00
|
|
|
|
2022-02-15 05:12:30 +00:00
|
|
|
const repoRoot = ensureTrailingSlash(registryUrl);
|
|
|
|
const searchRoots: string[] = [];
|
|
|
|
// Optimize lookup order
|
|
|
|
searchRoots.push(`${repoRoot}${groupIdSplit.join('.')}`);
|
|
|
|
searchRoots.push(`${repoRoot}${groupIdSplit.join('/')}`);
|
|
|
|
|
|
|
|
for (let idx = 0; idx < searchRoots.length; idx += 1) {
|
|
|
|
const searchRoot = searchRoots[idx];
|
|
|
|
let versions = await this.resolvePluginReleases(
|
2020-07-17 08:14:50 +00:00
|
|
|
searchRoot,
|
|
|
|
artifact,
|
|
|
|
scalaVersion
|
|
|
|
);
|
2022-02-15 05:12:30 +00:00
|
|
|
let urls = {};
|
|
|
|
|
|
|
|
if (!versions?.length) {
|
|
|
|
const artifactSubdirs = await this.getArtifactSubdirs(
|
|
|
|
searchRoot,
|
|
|
|
artifact,
|
|
|
|
scalaVersion
|
|
|
|
);
|
|
|
|
versions = await this.getPackageReleases(searchRoot, artifactSubdirs);
|
|
|
|
const latestVersion = getLatestVersion(versions);
|
|
|
|
urls = await this.getUrls(searchRoot, artifactSubdirs, latestVersion);
|
|
|
|
}
|
2019-05-30 23:39:07 +00:00
|
|
|
|
2022-02-15 05:12:30 +00:00
|
|
|
const dependencyUrl = `${searchRoot}/${artifact}`;
|
2019-06-10 15:48:26 +00:00
|
|
|
|
2022-08-08 11:45:27 +00:00
|
|
|
logger.trace({ dependency: packageName, versions }, `Package versions`);
|
2022-02-15 05:12:30 +00:00
|
|
|
if (versions) {
|
|
|
|
return {
|
|
|
|
...urls,
|
|
|
|
dependencyUrl,
|
|
|
|
releases: versions.map((v) => ({ version: v })),
|
|
|
|
};
|
|
|
|
}
|
2019-05-30 23:39:07 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 05:12:30 +00:00
|
|
|
logger.debug(
|
2022-03-03 15:08:43 +00:00
|
|
|
`No versions found for ${packageName} in ${searchRoots.length} repositories`
|
2022-02-15 05:12:30 +00:00
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
2019-05-30 23:39:07 +00:00
|
|
|
}
|