forked from clearlydefined/crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmavenExtract.js
More file actions
71 lines (62 loc) · 2.67 KB
/
Copy pathmavenExtract.js
File metadata and controls
71 lines (62 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license.
// SPDX-License-Identifier: MIT
const AbstractClearlyDefinedProcessor = require('./abstractClearlyDefinedProcessor')
const sourceDiscovery = require('../../lib/sourceDiscovery')
const SourceSpec = require('../../lib/sourceSpec')
const { get, merge } = require('lodash')
class MavenExtract extends AbstractClearlyDefinedProcessor {
constructor(options, sourceFinder) {
super(options)
this.sourceFinder = sourceFinder
}
get toolVersion() {
return '1.3.1'
}
canHandle(request) {
const spec = this.toSpec(request)
return request.type === 'maven' && spec && spec.type === 'maven'
}
// Coming in here we expect the request.document to have id, location and metadata properties.
// Do interesting processing...
async handle(request) {
// skip all the hard work if we are just traversing.
if (this.isProcessing(request)) {
await super.handle(request)
const spec = this.toSpec(request)
const manifest = { summary: request.document.summary, poms: request.document.poms }
await this._createDocument(request, spec, manifest, request.document.releaseDate)
}
this.addLocalToolTasks(request)
if (request.document.sourceInfo) {
const sourceSpec = SourceSpec.fromObject(request.document.sourceInfo)
this.linkAndQueue(request, 'source', sourceSpec.toEntitySpec())
}
return request
}
_discoverCandidateSourceLocations(manifest) {
const candidateUrls = []
candidateUrls.push(get(manifest, 'summary.scm.0.url.0'))
return candidateUrls.filter(e => e)
}
async _discoverSource(spec, manifest) {
const manifestCandidates = this._discoverCandidateSourceLocations(manifest)
// TODO lookup source discovery in a set of services that have their own configuration
const githubSource = await this.sourceFinder(spec.revision, manifestCandidates, {
githubToken: this.options.githubToken,
logger: this.logger
})
if (githubSource) return githubSource
// didn't find any source in GitHub so make up a sources url to try if the registry thinks there is source
// Need to confirm the expectations here.
const result = SourceSpec.fromObject(spec)
result.type = 'sourcearchive'
return result
}
async _createDocument(request, spec, manifest, releaseDate) {
request.document = merge(this.clone(request.document), { manifest, releaseDate })
// Add source info
const sourceInfo = await this._discoverSource(spec, manifest)
if (sourceInfo) request.document.sourceInfo = sourceInfo
}
}
module.exports = (options, sourceFinder) => new MavenExtract(options, sourceFinder || sourceDiscovery)