diff --git a/config/cdConfig.js b/config/cdConfig.js index 37346cab..05b5a524 100644 --- a/config/cdConfig.js +++ b/config/cdConfig.js @@ -99,6 +99,7 @@ module.exports = { format: '--json-pp' }, source: {}, + sourcearchive: {}, top: { githubToken } }, store: { diff --git a/providers/index.js b/providers/index.js index e73ac303..451354b2 100644 --- a/providers/index.js +++ b/providers/index.js @@ -48,6 +48,7 @@ module.exports = { scancode: require('./process/scancode'), fossology: require('./process/fossology'), source: require('./process/source').processor, + sourcearchive: require('./process/sourcearchiveExtract'), top: require('./process/top') }, store: { diff --git a/providers/process/sourceExtract.js b/providers/process/sourceExtract.js index 7addffe6..24ad00af 100644 --- a/providers/process/sourceExtract.js +++ b/providers/process/sourceExtract.js @@ -15,7 +15,7 @@ class SourceExtract extends AbstractClearlyDefinedProcessor { canHandle(request) { const spec = this.toSpec(request) - return request.type === 'clearlydefined' && spec && ['git', 'sourcearchive'].includes(spec.type) + return request.type === 'clearlydefined' && spec && ['git'].includes(spec.type) } async handle(request) { diff --git a/providers/process/sourcearchiveExtract.js b/providers/process/sourcearchiveExtract.js new file mode 100644 index 00000000..d9e8a40d --- /dev/null +++ b/providers/process/sourcearchiveExtract.js @@ -0,0 +1,25 @@ +// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. +// SPDX-License-Identifier: MIT + +const AbstractClearlyDefinedProcessor = require('./abstractClearlyDefinedProcessor') +const { merge } = require('lodash') + +class SourceArchiveExtract extends AbstractClearlyDefinedProcessor { + get toolVersion() { + return '1.2.0' + } + + canHandle(request) { + const spec = this.toSpec(request) + return request.type === 'clearlydefined' && spec?.type === 'sourcearchive' + } + + async handle(request) { + await super.handle(request) + const { summary, poms, releaseDate } = request.document + const manifest = { summary, poms } + request.document = merge(this.clone(request.document), { manifest, releaseDate }) + } +} + +module.exports = options => new SourceArchiveExtract(options) diff --git a/test/unit/providers/process/sourceArchiveExtractTests.js b/test/unit/providers/process/sourceArchiveExtractTests.js new file mode 100644 index 00000000..b60fc03d --- /dev/null +++ b/test/unit/providers/process/sourceArchiveExtractTests.js @@ -0,0 +1,52 @@ +// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. +// SPDX-License-Identifier: MIT + +const { expect } = require('chai') +const SourceArchiveExtract = require('../../../../providers/process/sourcearchiveExtract') +const Request = require('../../../../ghcrawler').request + +const pomsArray = [{ pom1: 'pom1' }, { pom2: 'pom2' }] +const summaryObj = { version: '8.1.0' } + +describe('SourceArchiveExtract Tests', () => { + let processor, request + beforeEach(async () => { + ;({ processor, request } = await setup()) + }) + + afterEach(() => { + request.getTrackedCleanups().forEach(cleanup => cleanup()) + }) + + it('verifies the version of the source archive extract', () => { + expect(processor._schemaVersion).to.equal('1.4.0') + }) + + it('handles a source archive request', () => { + expect(processor.canHandle(request)).to.be.true + }) + + it('extracts the release date, summary and poms sections', async () => { + await processor.handle(request) + expect(request.document.manifest.summary).to.be.deep.equal(summaryObj) + expect(request.document.manifest.poms).to.be.deep.equal(pomsArray) + expect(request.document.releaseDate).to.be.equal('2021-08-01T00:00:00.000Z') + }) +}) + +async function setup() { + const processor = SourceArchiveExtract({ logger: {} }) + const request = createRequest() + const dir = processor.createTempDir(request) + request.document.location = dir.name + request.document.summary = { ...summaryObj } + request.document.poms = [...pomsArray] + request.document.releaseDate = '2021-08-01T00:00:00.000Z' + return { processor, request } +} + +function createRequest() { + const request = new Request('clearlydefined', 'cd:/sourcearchive/mavencentral/org.osgi/osgi.annotation/8.1.0') + request.document = { _metadata: { links: {} }, registryData: { manifest: {} } } + return request +} diff --git a/test/unit/providers/process/sourceExtractTests.js b/test/unit/providers/process/sourceExtractTests.js new file mode 100644 index 00000000..11ae94a1 --- /dev/null +++ b/test/unit/providers/process/sourceExtractTests.js @@ -0,0 +1,12 @@ +// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. +// SPDX-License-Identifier: MIT + +const { expect } = require('chai') +const SourceExtract = require('../../../../providers/process/sourceExtract') + +describe('SourceExtract', () => { + it('verifies version of the source extract', () => { + const handler = SourceExtract({}) + expect(handler._schemaVersion).to.equal('1.3.0') + }) +})