Skip to content
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

refactor(maven): Remove file protocol support from datasource #10191

Merged
merged 10 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions lib/datasource/clojure/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -640,40 +640,3 @@ Array [
},
]
`;

exports[`datasource/clojure/index supports file protocol 1`] = `
Object {
"display": "org.example:package",
"group": "org.example",
"homepage": "https://package.example.org/about",
"name": "package",
"registryUrl": "file:///bar",
"releases": Array [
Object {
"version": "1.0.0",
},
Object {
"version": "1.0.1",
},
Object {
"version": "1.0.2",
},
Object {
"version": "2.0.0",
},
],
}
`;

exports[`datasource/clojure/index supports file protocol 2`] = `
Array [
Array [
"/bar/org/example/package/maven-metadata.xml",
"utf8",
],
Array [
"/bar/org/example/package/2.0.0/package-2.0.0.pom",
"utf8",
],
]
`;
25 changes: 1 addition & 24 deletions lib/datasource/clojure/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import _fs from 'fs-extra';
import upath from 'upath';
import { ReleaseResult, getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, loadFixture, mocked } from '../../../test/util';
import { getName, loadFixture } from '../../../test/util';
import * as hostRules from '../../util/host-rules';
import { id as versioning } from '../../versioning/maven';
import { ClojureDatasource } from '.';

jest.mock('fs-extra');
const fs = mocked(_fs);

const baseUrl = 'https://clojars.org/repo';
const baseUrlCustom = 'https://custom.registry.renovatebot.com';

Expand Down Expand Up @@ -241,23 +237,4 @@ describe(getName(), () => {

expect(sourceUrl).toEqual('https://github.com/example/test');
});

it('supports file protocol', async () => {
fs.exists.mockResolvedValueOnce(false);

fs.exists.mockResolvedValueOnce(true);
fs.readFile.mockResolvedValueOnce(
Buffer.from(loadFixture('metadata.xml', upath.join('..', 'maven')))
);

fs.exists.mockResolvedValueOnce(true);
fs.readFile.mockResolvedValueOnce(
Buffer.from(loadFixture('pom.xml', upath.join('..', 'maven')))
);

const res = await get('org.example:package', 'file:///foo', 'file:///bar');

expect(res).toMatchSnapshot();
expect(fs.readFile.mock.calls).toMatchSnapshot();
});
});
37 changes: 0 additions & 37 deletions lib/datasource/maven/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -810,43 +810,6 @@ Array [
]
`;

exports[`datasource/maven/index supports file protocol 1`] = `
Object {
"display": "org.example:package",
"group": "org.example",
"homepage": "https://package.example.org/about",
"name": "package",
"registryUrl": "file:///bar",
"releases": Array [
Object {
"version": "1.0.0",
},
Object {
"version": "1.0.1",
},
Object {
"version": "1.0.2",
},
Object {
"version": "2.0.0",
},
],
}
`;

exports[`datasource/maven/index supports file protocol 2`] = `
Array [
Array [
"/bar/org/example/package/maven-metadata.xml",
"utf8",
],
Array [
"/bar/org/example/package/2.0.0/package-2.0.0.pom",
"utf8",
],
]
`;

exports[`datasource/maven/index throws EXTERNAL_HOST_ERROR for 50x 1`] = `
Array [
Object {
Expand Down
21 changes: 1 addition & 20 deletions lib/datasource/maven/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import _fs from 'fs-extra';
import { ReleaseResult, getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, loadFixture, mocked } from '../../../test/util';
import { getName, loadFixture } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import * as hostRules from '../../util/host-rules';
import { id as versioning } from '../../versioning/maven';
import { id as datasource } from '.';

jest.mock('fs-extra');
const fs = mocked(_fs);

const baseUrl = 'https://repo.maven.apache.org/maven2';
const baseUrlCustom = 'https://custom.registry.renovatebot.com';

Expand Down Expand Up @@ -309,19 +305,4 @@ describe(getName(), () => {
expect(res).toMatchSnapshot();
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('supports file protocol', async () => {
fs.exists.mockResolvedValueOnce(false);

fs.exists.mockResolvedValueOnce(true);
fs.readFile.mockResolvedValueOnce(Buffer.from(loadFixture('metadata.xml')));

fs.exists.mockResolvedValueOnce(true);
fs.readFile.mockResolvedValueOnce(Buffer.from(loadFixture('pom.xml')));

const res = await get('org.example:package', 'file:///foo', 'file:///bar');

expect(res).toMatchSnapshot();
expect(fs.readFile.mock.calls).toMatchSnapshot();
});
});
16 changes: 2 additions & 14 deletions lib/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ function isValidArtifactsInfo(
return versions.every((v) => info[v] !== undefined);
}

async function getArtifactInfo(
version: string,
artifactUrl: url.URL
): Promise<ArtifactInfoResult> {
const proto = artifactUrl.protocol;
if (proto === 'http:' || proto === 'https:') {
const result = await isHttpResourceExists(artifactUrl);
return [version, result];
}
return [version, true];
}

async function filterMissingArtifacts(
dependency: MavenDependency,
repoUrl: string,
Expand All @@ -130,8 +118,8 @@ async function filterMissingArtifacts(
.filter(([_, artifactUrl]) => Boolean(artifactUrl))
.map(
([version, artifactUrl]) =>
(): Promise<ArtifactInfoResult> =>
getArtifactInfo(version, artifactUrl)
async (): Promise<ArtifactInfoResult> =>
zharinov marked this conversation as resolved.
Show resolved Hide resolved
[version, await isHttpResourceExists(artifactUrl)]
);
const results = await pAll(queue, { concurrency: 5 });
artifactsInfo = results.reduce(
Expand Down
12 changes: 0 additions & 12 deletions lib/datasource/maven/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import url from 'url';
import fs from 'fs-extra';
import { XmlDocument } from 'xmldoc';
import { HOST_DISABLED } from '../../constants/error-messages';
import { logger } from '../../logger';
Expand Down Expand Up @@ -100,14 +99,6 @@ export async function downloadHttpProtocol(
}
}

async function downloadFileProtocol(pkgUrl: url.URL): Promise<string | null> {
const pkgPath = pkgUrl.toString().replace('file://', '');
if (!(await fs.exists(pkgPath))) {
return null;
}
return fs.readFile(pkgPath, 'utf8');
}

export async function isHttpResourceExists(
pkgUrl: url.URL | string,
hostType = id
Expand Down Expand Up @@ -150,9 +141,6 @@ export async function downloadMavenXml(
let rawContent: string;
let authorization: boolean;
switch (pkgUrl.protocol) {
case 'file:':
rawContent = await downloadFileProtocol(pkgUrl);
break;
case 'http:':
case 'https:':
({ authorization, body: rawContent } = await downloadHttpProtocol(
Expand Down