feat(manager/sbt): support proxy registries (#27276)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
This commit is contained in:
Lakshmipriya Sivakumar 2024-02-27 15:28:20 -05:00 committed by GitHub
parent 7e7124ef93
commit 5de12e7f09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 219 additions and 96 deletions

View file

@ -8,9 +8,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -18,9 +16,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "com.example:foo", "depName": "com.example:foo",
"packageName": "com.example:foo_2.13.0-RC5", "packageName": "com.example:foo_2.13.0-RC5",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
{ {
"currentValue": "1.2.3", "currentValue": "1.2.3",
@ -28,9 +24,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"depName": "com.abc:abc", "depName": "com.abc:abc",
"groupName": "abcVersion", "groupName": "abcVersion",
"packageName": "com.abc:abc", "packageName": "com.abc:abc",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"variableName": "abcVersion", "variableName": "abcVersion",
}, },
], ],
@ -46,9 +40,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -56,9 +48,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "com.example:foo", "depName": "com.example:foo",
"packageName": "com.example:foo_2.13.0-RC5", "packageName": "com.example:foo_2.13.0-RC5",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
{ {
"currentValue": "1.2.3", "currentValue": "1.2.3",
@ -66,9 +56,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"depName": "com.abc:abc", "depName": "com.abc:abc",
"groupName": "abcVersion", "groupName": "abcVersion",
"packageName": "com.abc:abc", "packageName": "com.abc:abc",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"variableName": "abcVersion", "variableName": "abcVersion",
}, },
{ {
@ -77,9 +65,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"depName": "com.abc:abc-a", "depName": "com.abc:abc-a",
"groupName": "abcVersion", "groupName": "abcVersion",
"packageName": "com.abc:abc-a", "packageName": "com.abc:abc-a",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"variableName": "abcVersion", "variableName": "abcVersion",
}, },
{ {
@ -88,9 +74,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"depName": "com.abc:abc-b", "depName": "com.abc:abc-b",
"groupName": "abcVersion", "groupName": "abcVersion",
"packageName": "com.abc:abc-b", "packageName": "com.abc:abc-b",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"variableName": "abcVersion", "variableName": "abcVersion",
}, },
{ {
@ -99,9 +83,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extract deps from nati
"depName": "com.abc:abc-c", "depName": "com.abc:abc-c",
"groupName": "abcVersion", "groupName": "abcVersion",
"packageName": "com.abc:abc-c", "packageName": "com.abc:abc-c",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"variableName": "abcVersion", "variableName": "abcVersion",
}, },
], ],
@ -118,7 +100,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -133,7 +114,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:foo", "depName": "org.example:foo",
"packageName": "org.example:foo", "packageName": "org.example:foo",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -147,7 +127,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.9.10", "packageName": "org.example:bar_2.9.10",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -161,7 +140,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:baz", "depName": "org.example:baz",
"packageName": "org.example:baz_2.9.10", "packageName": "org.example:baz_2.9.10",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -175,7 +153,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:qux", "depName": "org.example:qux",
"packageName": "org.example:qux", "packageName": "org.example:qux",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -190,7 +167,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depType": "sources", "depType": "sources",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -204,7 +180,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:quux", "depName": "org.example:quux",
"packageName": "org.example:quux", "packageName": "org.example:quux",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -219,7 +194,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depType": "test", "depType": "test",
"packageName": "org.example:quuz_2.9.10", "packageName": "org.example:quuz_2.9.10",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -234,7 +208,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depType": "test", "depType": "test",
"packageName": "org.example:abc_2.9.10", "packageName": "org.example:abc_2.9.10",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -249,7 +222,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depType": "Provided", "depType": "Provided",
"packageName": "org.example:corge", "packageName": "org.example:corge",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -265,7 +237,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"groupName": "versionExample", "groupName": "versionExample",
"packageName": "org.example:grault", "packageName": "org.example:grault",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -281,13 +252,11 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depType": "plugin", "depType": "plugin",
"packageName": "org.example:waldo", "packageName": "org.example:waldo",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
"https://example.com/repos/4/", "https://example.com/repos/4/",
"https://example.com/repos/5/", "https://example.com/repos/5/",
"https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases",
], ],
}, },
{ {
@ -296,7 +265,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
"depName": "org.example:fred", "depName": "org.example:fred",
"packageName": "org.example:fred", "packageName": "org.example:fred",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -318,7 +286,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -333,7 +300,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "org.example:foo", "depName": "org.example:foo",
"packageName": "org.example:foo", "packageName": "org.example:foo",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -347,7 +313,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.12", "packageName": "org.example:bar_2.12",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -361,7 +326,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "org.example:baz", "depName": "org.example:baz",
"packageName": "org.example:baz_2.12", "packageName": "org.example:baz_2.12",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -375,7 +339,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "org.example:qux", "depName": "org.example:qux",
"packageName": "org.example:qux", "packageName": "org.example:qux",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -389,7 +352,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depName": "org.example:quux", "depName": "org.example:quux",
"packageName": "org.example:quux", "packageName": "org.example:quux",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -404,7 +366,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depType": "test", "depType": "test",
"packageName": "org.example:quuz_2.12", "packageName": "org.example:quuz_2.12",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -419,7 +380,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depType": "Provided", "depType": "Provided",
"packageName": "org.example:corge", "packageName": "org.example:corge",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -435,7 +395,6 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"groupName": "versionExample", "groupName": "versionExample",
"packageName": "org.example:grault", "packageName": "org.example:grault",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
@ -451,13 +410,11 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"depType": "plugin", "depType": "plugin",
"packageName": "org.example:waldo", "packageName": "org.example:waldo",
"registryUrls": [ "registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://example.com/repos/1/", "https://example.com/repos/1/",
"https://example.com/repos/2/", "https://example.com/repos/2/",
"https://example.com/repos/3/", "https://example.com/repos/3/",
"https://example.com/repos/4/", "https://example.com/repos/4/",
"https://example.com/repos/5/", "https://example.com/repos/5/",
"https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases",
], ],
}, },
], ],
@ -473,9 +430,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -483,9 +438,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.12", "packageName": "org.example:bar_2.12",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
], ],
"packageFileVersion": undefined, "packageFileVersion": undefined,
@ -500,9 +453,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -510,9 +461,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.12", "packageName": "org.example:bar_2.12",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
], ],
"packageFileVersion": undefined, "packageFileVersion": undefined,
@ -527,9 +476,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -537,9 +484,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.12", "packageName": "org.example:bar_2.12",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
], ],
"packageFileVersion": undefined, "packageFileVersion": undefined,
@ -554,9 +499,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "maven", "datasource": "maven",
"depName": "scala", "depName": "scala",
"packageName": "org.scala-lang:scala-library", "packageName": "org.scala-lang:scala-library",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
"separateMinorPatch": true, "separateMinorPatch": true,
}, },
{ {
@ -564,9 +507,7 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps when sca
"datasource": "sbt-package", "datasource": "sbt-package",
"depName": "org.example:bar", "depName": "org.example:bar",
"packageName": "org.example:bar_2.12", "packageName": "org.example:bar_2.12",
"registryUrls": [ "registryUrls": [],
"https://repo.maven.apache.org/maven2",
],
}, },
], ],
"packageFileVersion": undefined, "packageFileVersion": undefined,

View file

@ -1,6 +1,12 @@
import { codeBlock } from 'common-tags'; import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures'; import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile as extract } from '.'; import { fs } from '../../../../test/util';
import {
extractPackageFile as extract,
extractAllPackageFiles,
} from './extract';
jest.mock('../../../util/fs');
const extractPackageFile = (content: string) => extract(content, 'build.sbt'); const extractPackageFile = (content: string) => extract(content, 'build.sbt');
@ -124,7 +130,7 @@ describe('modules/manager/sbt/extract', () => {
datasource: 'sbt-package', datasource: 'sbt-package',
depName: 'org.scalatest:scalatest', depName: 'org.scalatest:scalatest',
packageName: 'org.scalatest:scalatest', packageName: 'org.scalatest:scalatest',
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
}, },
{ {
currentValue: '1.0.11', currentValue: '1.0.11',
@ -133,10 +139,7 @@ describe('modules/manager/sbt/extract', () => {
depType: 'plugin', depType: 'plugin',
groupName: 'sbtReleaseVersion', groupName: 'sbtReleaseVersion',
packageName: 'com.github.gseitz:sbt-release', packageName: 'com.github.gseitz:sbt-release',
registryUrls: [ registryUrls: [],
'https://repo.maven.apache.org/maven2',
'https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases',
],
variableName: 'sbtReleaseVersion', variableName: 'sbtReleaseVersion',
}, },
], ],
@ -297,7 +300,7 @@ describe('modules/manager/sbt/extract', () => {
expect(extractPackageFile(content)).toMatchObject({ expect(extractPackageFile(content)).toMatchObject({
deps: [ deps: [
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
datasource: 'maven', datasource: 'maven',
depName: 'scala', depName: 'scala',
packageName: 'org.scala-lang:scala-library', packageName: 'org.scala-lang:scala-library',
@ -305,14 +308,14 @@ describe('modules/manager/sbt/extract', () => {
separateMinorPatch: true, separateMinorPatch: true,
}, },
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
depName: 'com.typesafe.scala-logging:scala-logging', depName: 'com.typesafe.scala-logging:scala-logging',
packageName: 'com.typesafe.scala-logging:scala-logging_2.13', packageName: 'com.typesafe.scala-logging:scala-logging_2.13',
currentValue: '3.9.4', currentValue: '3.9.4',
datasource: 'sbt-package', datasource: 'sbt-package',
}, },
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
depName: 'ch.qos.logback:logback-classic', depName: 'ch.qos.logback:logback-classic',
packageName: 'ch.qos.logback:logback-classic', packageName: 'ch.qos.logback:logback-classic',
currentValue: '1.2.10', currentValue: '1.2.10',
@ -337,7 +340,7 @@ describe('modules/manager/sbt/extract', () => {
expect(extractPackageFile(content)).toMatchObject({ expect(extractPackageFile(content)).toMatchObject({
deps: [ deps: [
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
datasource: 'maven', datasource: 'maven',
depName: 'scala', depName: 'scala',
packageName: 'org.scala-lang:scala-library', packageName: 'org.scala-lang:scala-library',
@ -345,14 +348,14 @@ describe('modules/manager/sbt/extract', () => {
separateMinorPatch: true, separateMinorPatch: true,
}, },
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
depName: 'com.typesafe.scala-logging:scala-logging', depName: 'com.typesafe.scala-logging:scala-logging',
packageName: 'com.typesafe.scala-logging:scala-logging_2.13', packageName: 'com.typesafe.scala-logging:scala-logging_2.13',
currentValue: '3.9.4', currentValue: '3.9.4',
datasource: 'sbt-package', datasource: 'sbt-package',
}, },
{ {
registryUrls: ['https://repo.maven.apache.org/maven2'], registryUrls: [],
depName: 'ch.qos.logback:logback-classic', depName: 'ch.qos.logback:logback-classic',
packageName: 'ch.qos.logback:logback-classic', packageName: 'ch.qos.logback:logback-classic',
currentValue: '1.2.10', currentValue: '1.2.10',
@ -438,4 +441,120 @@ describe('modules/manager/sbt/extract', () => {
).toBeNull(); ).toBeNull();
}); });
}); });
describe('extractAllPackageFiles()', () => {
it('extracts proxy repositories', async () => {
const repositoryContent = codeBlock`
[repositories]
local
my-maven-repo: http://example.org/repo
my-ivy-repo: https://example.org/ivy-repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-central
`;
fs.readLocalFile
.mockResolvedValueOnce(repositoryContent)
.mockResolvedValueOnce(sbtDependencyFile);
const packages = await extractAllPackageFiles({}, [
'repositories',
'build.sbt',
]);
const expected_packages = [
{
deps: [
{
packageName: 'org.scala-lang:scala-library',
currentValue: '2.13.0-RC5',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
{
packageName: 'com.example:foo_2.13.0-RC5',
currentValue: '0.7.1',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
{
packageName: 'com.abc:abc',
currentValue: '1.2.3',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
{
packageName: 'com.abc:abc-a',
currentValue: '1.2.3',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
{
packageName: 'com.abc:abc-b',
currentValue: '1.2.3',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
{
packageName: 'com.abc:abc-c',
currentValue: '1.2.3',
registryUrls: [
'http://example.org/repo',
'https://example.org/ivy-repo/',
'https://repo1.maven.org/maven2',
],
},
],
},
];
expect(packages).toMatchObject(expected_packages);
});
it('should include default registryUrls if no repositories file is provided', async () => {
fs.readLocalFile.mockResolvedValueOnce(sbt);
const packages = await extractAllPackageFiles({}, ['build.sbt']);
for (const pkg of packages) {
for (const dep of pkg.deps.filter((d) => d.depType === 'plugin')) {
expect(dep.registryUrls).toStrictEqual([
'https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases',
'https://repo1.maven.org/maven2',
'https://example.com/repos/1/',
'https://example.com/repos/2/',
'https://example.com/repos/3/',
'https://example.com/repos/4/',
'https://example.com/repos/5/',
]);
}
}
for (const pkg of packages) {
for (const dep of pkg.deps.filter((d) => d.depType !== 'plugin')) {
expect(dep.registryUrls).toStrictEqual([
'https://repo1.maven.org/maven2',
'https://example.com/repos/1/',
'https://example.com/repos/2/',
'https://example.com/repos/3/',
'https://example.com/repos/4/',
'https://example.com/repos/5/',
]);
}
}
});
it('should return empty packagefiles is no content is provided', async () => {
fs.readLocalFile.mockResolvedValueOnce('');
const packages = await extractAllPackageFiles({}, ['build.sbt']);
expect(packages).toBeEmpty();
});
});
}); });

View file

@ -1,6 +1,7 @@
import { lang, query as q } from 'good-enough-parser'; import { lang, query as q } from 'good-enough-parser';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { regEx } from '../../../util/regex'; import { readLocalFile } from '../../../util/fs';
import { newlineRegex, regEx } from '../../../util/regex';
import { parseUrl } from '../../../util/url'; import { parseUrl } from '../../../util/url';
import { GithubReleasesDatasource } from '../../datasource/github-releases'; import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { MavenDatasource } from '../../datasource/maven'; import { MavenDatasource } from '../../datasource/maven';
@ -12,8 +13,12 @@ import {
import { get } from '../../versioning'; import { get } from '../../versioning';
import * as mavenVersioning from '../../versioning/maven'; import * as mavenVersioning from '../../versioning/maven';
import * as semverVersioning from '../../versioning/semver'; import * as semverVersioning from '../../versioning/semver';
import { REGISTRY_URLS } from '../gradle/parser/common'; import type {
import type { PackageDependency, PackageFileContent } from '../types'; ExtractConfig,
PackageDependency,
PackageFile,
PackageFileContent,
} from '../types';
import { normalizeScalaVersion } from './util'; import { normalizeScalaVersion } from './util';
type Vars = Record<string, string>; type Vars = Record<string, string>;
@ -36,12 +41,18 @@ interface Ctx {
variableName?: string; variableName?: string;
} }
const SBT_MVN_REPO = 'https://repo1.maven.org/maven2';
const scala = lang.createLang('scala'); const scala = lang.createLang('scala');
const sbtVersionRegex = regEx( const sbtVersionRegex = regEx(
'sbt\\.version *= *(?<version>\\d+\\.\\d+\\.\\d+)', 'sbt\\.version *= *(?<version>\\d+\\.\\d+\\.\\d+)',
); );
const sbtProxyUrlRegex = regEx(
/^\s*(?<repoName>\S+):\s+(?<proxy>https?:\/\/[\w./-]+)/,
);
const scalaVersionMatch = q const scalaVersionMatch = q
.sym<Ctx>('scalaVersion') .sym<Ctx>('scalaVersion')
.op(':=') .op(':=')
@ -268,9 +279,6 @@ const addResolverMatch = q.sym<Ctx>('resolvers').alt(
function registryUrlHandler(ctx: Ctx): Ctx { function registryUrlHandler(ctx: Ctx): Ctx {
for (const dep of ctx.deps) { for (const dep of ctx.deps) {
dep.registryUrls = [...ctx.registryUrls]; dep.registryUrls = [...ctx.registryUrls];
if (dep.depType === 'plugin') {
dep.registryUrls.push(SBT_PLUGINS_REPO);
}
} }
return ctx; return ctx;
} }
@ -289,6 +297,23 @@ const query = q.tree<Ctx>({
postHandler: registryUrlHandler, postHandler: registryUrlHandler,
}); });
export function extractProxyUrls(
content: string,
packageFile: string,
): string[] {
const extractedProxyUrls: string[] = [];
logger.debug(`Parsing proxy repository file ${packageFile}`);
for (const line of content.split(newlineRegex)) {
const extraction = sbtProxyUrlRegex.exec(line);
if (extraction?.groups?.proxy) {
extractedProxyUrls.push(extraction.groups.proxy);
} else if (line.trim() === 'maven-central') {
extractedProxyUrls.push(SBT_MVN_REPO);
}
}
return extractedProxyUrls;
}
export function extractPackageFile( export function extractPackageFile(
content: string, content: string,
packageFile: string, packageFile: string,
@ -325,7 +350,7 @@ export function extractPackageFile(
parsedResult = scala.query(content, query, { parsedResult = scala.query(content, query, {
vars: {}, vars: {},
deps: [], deps: [],
registryUrls: [REGISTRY_URLS.mavenCentral], registryUrls: [],
}); });
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
logger.debug({ err, packageFile }, 'Sbt parsing error'); logger.debug({ err, packageFile }, 'Sbt parsing error');
@ -343,3 +368,40 @@ export function extractPackageFile(
return { deps, packageFileVersion }; return { deps, packageFileVersion };
} }
export async function extractAllPackageFiles(
_config: ExtractConfig,
packageFiles: string[],
): Promise<PackageFile[]> {
const packages: PackageFile[] = [];
const proxyUrls: string[] = [];
for (const packageFile of packageFiles) {
const content = await readLocalFile(packageFile, 'utf8');
if (!content) {
logger.debug({ packageFile }, 'packageFile has no content');
continue;
}
if (packageFile === 'repositories') {
const urls = extractProxyUrls(content, packageFile);
proxyUrls.push(...urls);
} else {
const pkg = extractPackageFile(content, packageFile);
if (pkg) {
packages.push({ deps: pkg.deps, packageFile });
}
}
}
for (const pkg of packages) {
for (const dep of pkg.deps) {
if (proxyUrls.length > 0) {
dep.registryUrls!.unshift(...proxyUrls);
} else if (dep.depType === 'plugin') {
dep.registryUrls!.unshift(SBT_PLUGINS_REPO, SBT_MVN_REPO);
} else {
dep.registryUrls!.unshift(SBT_MVN_REPO);
}
}
}
return packages;
}

View file

@ -5,7 +5,7 @@ import { SbtPackageDatasource } from '../../datasource/sbt-package';
import { SbtPluginDatasource } from '../../datasource/sbt-plugin'; import { SbtPluginDatasource } from '../../datasource/sbt-plugin';
import * as ivyVersioning from '../../versioning/ivy'; import * as ivyVersioning from '../../versioning/ivy';
export { extractPackageFile } from './extract'; export { extractAllPackageFiles } from './extract';
export { bumpPackageVersion } from './update'; export { bumpPackageVersion } from './update';
export const supportedDatasources = [ export const supportedDatasources = [
@ -20,6 +20,7 @@ export const defaultConfig = {
'\\.sbt$', '\\.sbt$',
'project/[^/]*\\.scala$', 'project/[^/]*\\.scala$',
'project/build\\.properties$', 'project/build\\.properties$',
'(^|/)repositories$',
], ],
versioning: ivyVersioning.id, versioning: ivyVersioning.id,
}; };