fix(maven): Use fallback maven registry (#5613)

This commit is contained in:
Sergio Zharinov 2020-03-02 12:08:37 +04:00 committed by GitHub
parent 6f46153e09
commit 0691b13819
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 90 additions and 74 deletions

View file

@ -1 +1,5 @@
export const id = 'maven';
export const MAVEN_REPO = 'https://repo.maven.apache.org/maven2';
export const MAVEN_REPO_DEPRECATED = 'https://central.maven.org/maven2';
export const CLOJARS_REPO = 'https://clojars.org/repo';

View file

@ -45,10 +45,10 @@ describe('datasource/maven', () => {
password: 'password',
});
nock.disableNetConnect();
nock('http://central.maven.org')
nock('https://repo.maven.apache.org')
.get('/maven2/mysql/mysql-connector-java/maven-metadata.xml')
.reply(200, MYSQL_MAVEN_METADATA);
nock('http://central.maven.org')
nock('https://repo.maven.apache.org')
.get(
'/maven2/mysql/mysql-connector-java/8.0.12/mysql-connector-java-8.0.12.pom'
)
@ -150,7 +150,7 @@ describe('datasource/maven', () => {
const releases = await maven.getPkgReleases({
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: ['http://central.maven.org/maven2/'],
registryUrls: ['https://repo.maven.apache.org/maven2/'],
});
expect(releases.releases).toEqual(generateReleases(MYSQL_VERSIONS));
});
@ -160,7 +160,7 @@ describe('datasource/maven', () => {
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: [
'http://central.maven.org/maven2/',
'https://repo.maven.apache.org/maven2/',
'http://failed_repo/',
'http://unauthorized_repo/',
'http://dns_error_repo',
@ -185,13 +185,28 @@ describe('datasource/maven', () => {
})
).rejects.toThrow(Error(DATASOURCE_FAILURE));
});
it('should throw registry-failure if default maven repo fails', async () => {
nock('https://repo.maven.apache.org')
.get('/maven2/org/artifact/maven-metadata.xml')
.times(4)
.reply(503);
expect.assertions(1);
await expect(
maven.getPkgReleases({
...config,
lookupName: 'org:artifact',
registryUrls: ['https://repo.maven.apache.org/maven2/'],
})
).rejects.toThrow(Error(DATASOURCE_FAILURE));
});
it('should return all versions of a specific library if a repository fails because invalid protocol', async () => {
const releases = await maven.getPkgReleases({
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: [
'http://central.maven.org/maven2/',
'https://repo.maven.apache.org/maven2/',
'http://failed_repo/',
'ftp://protocol_error_repo',
],
@ -217,7 +232,7 @@ describe('datasource/maven', () => {
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: [
'http://central.maven.org/maven2/',
'https://repo.maven.apache.org/maven2/',
'http://invalid_metadata_repo/maven2/',
],
});
@ -235,7 +250,7 @@ describe('datasource/maven', () => {
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: [
'http://central.maven.org/maven2/',
'https://repo.maven.apache.org/maven2/',
'http://invalid_metadata_repo/maven2/',
],
});
@ -246,7 +261,7 @@ describe('datasource/maven', () => {
const releases = await maven.getPkgReleases({
...config,
lookupName: 'mysql:mysql-connector-java',
registryUrls: ['http://central.maven.org/maven2'],
registryUrls: ['https://repo.maven.apache.org/maven2'],
});
expect(releases).not.toBeNull();
});
@ -256,7 +271,7 @@ describe('datasource/maven', () => {
...config,
lookupName: 'mysql:mysql-connector-java',
});
expect(releases).toBeNull();
expect(releases).not.toBeNull();
});
it('should return null for invalid registryUrls', async () => {
const releases = await maven.getPkgReleases({

View file

@ -7,6 +7,7 @@ import { compare } from '../../versioning/maven/compare';
import mavenVersion from '../../versioning/maven';
import { downloadHttpProtocol } from './util';
import { GetReleasesConfig, ReleaseResult } from '../common';
import { MAVEN_REPO } from './common';
export { id } from './common';
@ -139,18 +140,14 @@ export async function getPkgReleases({
lookupName,
registryUrls,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const versions: string[] = [];
const dependency = getDependencyParts(lookupName);
if (!is.nonEmptyArray(registryUrls)) {
logger.warn(`No repositories defined for ${dependency.display}`);
return null;
}
const repositories = registryUrls.map(repository =>
const registries = is.nonEmptyArray(registryUrls)
? registryUrls
: [MAVEN_REPO];
const repositories = registries.map(repository =>
repository.replace(/\/?$/, '/')
);
logger.debug(
`Found ${repositories.length} repositories for ${dependency.display}`
);
const dependency = getDependencyParts(lookupName);
const versions: string[] = [];
const repoForVersions = {};
for (let i = 0; i < repositories.length; i += 1) {
const repoUrl = repositories[i];

View file

@ -3,12 +3,15 @@ import got from '../../util/got';
import { logger } from '../../logger';
import { DatasourceError } from '../common';
import { id } from './common';
import { id, MAVEN_REPO, MAVEN_REPO_DEPRECATED } from './common';
const getHost = (x: string): string => new url.URL(x).host;
const defaultHosts = [MAVEN_REPO, MAVEN_REPO_DEPRECATED].map(getHost);
function isMavenCentral(pkgUrl: url.URL | string): boolean {
return (
(typeof pkgUrl === 'string' ? pkgUrl : pkgUrl.host) === 'central.maven.org'
);
const host = typeof pkgUrl === 'string' ? pkgUrl : pkgUrl.host;
return defaultHosts.includes(host);
}
function isTemporalError(err: { code: string; statusCode: number }): boolean {

View file

@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import nock from 'nock';
import { getPkgReleases } from '.';
import { DEFAULT_MAVEN_REPO } from '../../manager/maven/extract';
import { MAVEN_REPO } from '../maven/common';
import { parseIndexDir, SBT_PLUGINS_REPO } from '../sbt-plugin/util';
const mavenIndexHtml = fs.readFileSync(
@ -110,7 +110,7 @@ describe('datasource/sbt', () => {
lookupName: 'org.scalatest:scalatest',
registryUrls: [
'https://failed_repo/maven',
DEFAULT_MAVEN_REPO,
MAVEN_REPO,
SBT_PLUGINS_REPO,
],
})
@ -124,7 +124,7 @@ describe('datasource/sbt', () => {
expect(
await getPkgReleases({
lookupName: 'org.scalatest:scalatest_2.12',
registryUrls: [DEFAULT_MAVEN_REPO, SBT_PLUGINS_REPO],
registryUrls: [MAVEN_REPO, SBT_PLUGINS_REPO],
})
).toEqual({
dependencyUrl: 'https://repo.maven.apache.org/maven2/org/scalatest',

View file

@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import nock from 'nock';
import { getPkgReleases } from '.';
import { DEFAULT_MAVEN_REPO } from '../../manager/maven/extract';
import { MAVEN_REPO } from '../maven/common';
import { parseIndexDir, SBT_PLUGINS_REPO } from './util';
const mavenIndexHtml = fs.readFileSync(
@ -114,7 +114,7 @@ describe('datasource/sbt', () => {
expect(
await getPkgReleases({
lookupName: 'org.foundweekends:sbt-bintray',
registryUrls: [DEFAULT_MAVEN_REPO, SBT_PLUGINS_REPO],
registryUrls: [MAVEN_REPO, SBT_PLUGINS_REPO],
})
).toEqual({
dependencyUrl:
@ -127,7 +127,7 @@ describe('datasource/sbt', () => {
expect(
await getPkgReleases({
lookupName: 'org.foundweekends:sbt-bintray_2.12',
registryUrls: [DEFAULT_MAVEN_REPO, SBT_PLUGINS_REPO],
registryUrls: [MAVEN_REPO, SBT_PLUGINS_REPO],
})
).toEqual({
dependencyUrl:

View file

@ -9,7 +9,7 @@ Object {
"depName": "persistent-sorted-set:persistent-sorted-set",
"fileReplacePosition": 53,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -19,7 +19,7 @@ Object {
"depName": "org.clojure:clojure",
"fileReplacePosition": 147,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -29,7 +29,7 @@ Object {
"depName": "org.clojure:clojure",
"fileReplacePosition": 241,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -39,7 +39,7 @@ Object {
"depName": "org.clojure:clojurescript",
"fileReplacePosition": 389,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -49,7 +49,7 @@ Object {
"depName": "org.clojure:tools.namespace",
"fileReplacePosition": 451,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -59,7 +59,7 @@ Object {
"depName": "org.clojure:clojurescript",
"fileReplacePosition": 584,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -69,7 +69,7 @@ Object {
"depName": "lambdaisland:kaocha",
"fileReplacePosition": 644,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -79,7 +79,7 @@ Object {
"depName": "lambdaisland:kaocha-cljs",
"fileReplacePosition": 703,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -89,7 +89,7 @@ Object {
"depName": "cider:cider-nrepl",
"fileReplacePosition": 810,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -99,7 +99,7 @@ Object {
"depName": "nrepl:nrepl",
"fileReplacePosition": 870,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -109,7 +109,7 @@ Object {
"depName": "org.clojure:tools.namespace",
"fileReplacePosition": 929,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},
@ -119,7 +119,7 @@ Object {
"depName": "com.datomic:datomic-free",
"fileReplacePosition": 1141,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
],
},

View file

@ -1,5 +1,5 @@
import { DEFAULT_MAVEN_REPO } from '../maven/extract';
import { expandDepName, DEFAULT_CLOJARS_REPO } from '../leiningen/extract';
import { CLOJARS_REPO, MAVEN_REPO } from '../../datasource/maven/common';
import { expandDepName } from '../leiningen/extract';
import { PackageFile, PackageDependency } from '../common';
import * as datasourceMaven from '../../datasource/maven';
@ -24,7 +24,7 @@ export function extractPackageFile(content: string): PackageFile {
depName: expandDepName(depName),
currentValue,
fileReplacePosition,
registryUrls: [DEFAULT_CLOJARS_REPO, DEFAULT_MAVEN_REPO],
registryUrls: [CLOJARS_REPO, MAVEN_REPO],
});
}

View file

@ -10,7 +10,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 2747,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -25,7 +25,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 2794,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -40,7 +40,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 2862,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -55,7 +55,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 2912,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -70,7 +70,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 3223,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -85,7 +85,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 3272,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -100,7 +100,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 3330,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -115,7 +115,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 11073,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -130,7 +130,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 11139,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -145,7 +145,7 @@ Object {
"depType": "dependencies",
"fileReplacePosition": 11287,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -160,7 +160,7 @@ Object {
"depType": "managed-dependencies",
"fileReplacePosition": 4705,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -175,7 +175,7 @@ Object {
"depType": "managed-dependencies",
"fileReplacePosition": 4754,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -190,7 +190,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 5558,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -205,7 +205,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 5591,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -220,7 +220,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 5630,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -235,7 +235,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 5661,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -250,7 +250,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 5705,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -265,7 +265,7 @@ Object {
"depType": "plugins",
"fileReplacePosition": 11489,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -280,7 +280,7 @@ Object {
"depType": "pom-plugins",
"fileReplacePosition": 26925,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -295,7 +295,7 @@ Object {
"depType": "pom-plugins",
"fileReplacePosition": 27372,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",
@ -310,7 +310,7 @@ Object {
"depType": "pom-plugins",
"fileReplacePosition": 27440,
"registryUrls": Array [
"https://clojars.org/repo/",
"https://clojars.org/repo",
"https://repo.maven.apache.org/maven2",
"https://download.java.net/maven/2",
"https://oss.sonatype.org/content/repositories/releases",

View file

@ -1,9 +1,7 @@
import { DEFAULT_MAVEN_REPO } from '../maven/extract';
import { CLOJARS_REPO, MAVEN_REPO } from '../../datasource/maven/common';
import { PackageDependency, PackageFile } from '../common';
import * as datasourceMaven from '../../datasource/maven';
export const DEFAULT_CLOJARS_REPO = 'https://clojars.org/repo/';
export function trimAtKey(str: string, kwName: string): string | null {
const regex = new RegExp(`:${kwName}(?=\\s)`);
const keyOffset = str.search(regex);
@ -92,7 +90,7 @@ export function extractFromVectors(
}
function extractLeinRepos(content: string): string[] {
const result = [DEFAULT_CLOJARS_REPO, DEFAULT_MAVEN_REPO];
const result = [CLOJARS_REPO, MAVEN_REPO];
const repoContent = trimAtKey(
content.replace(/;;.*(?=[\r\n])/g, ''), // get rid of comments

View file

@ -6,8 +6,7 @@ import { logger } from '../../logger';
import { ExtractConfig, PackageFile, PackageDependency } from '../common';
import { platform } from '../../platform';
import * as datasourceMaven from '../../datasource/maven';
export const DEFAULT_MAVEN_REPO = 'https://repo.maven.apache.org/maven2';
import { MAVEN_REPO } from '../../datasource/maven/common';
export function parsePom(raw: string): XmlDocument | null {
let project: XmlDocument;
@ -53,7 +52,7 @@ function depFromNode(node: XmlElement): PackageDependency | null {
const versionNode = node.descendantWithPath('version');
const fileReplacePosition = versionNode.position;
const datasource = datasourceMaven.id;
const registryUrls = [DEFAULT_MAVEN_REPO];
const registryUrls = [MAVEN_REPO];
return {
datasource,
depName,

View file

@ -1,4 +1,4 @@
import { DEFAULT_MAVEN_REPO } from '../maven/extract';
import { MAVEN_REPO } from '../../datasource/maven/common';
import { PackageFile, PackageDependency } from '../common';
import { get } from '../../versioning';
import * as mavenVersioning from '../../versioning/maven';
@ -283,7 +283,7 @@ export function extractPackageFile(content: string): PackageFile {
const lines = content.split(/\n/);
return lines.reduce(parseSbtLine, {
fileOffset: 0,
registryUrls: [DEFAULT_MAVEN_REPO],
registryUrls: [MAVEN_REPO],
deps: [],
isMultiDeps: false,
scalaVersion: null,