@@ -24,7 +24,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2424import { readdirSync } from "fs" ;
2525import { join , relative , resolve } from "path" ;
2626
27- import type { AttachmentFactory } from "../factories/fromPath .node" ;
27+ import type * as Factories from "../factories/index .node" ;
2828import { NamedLicense } from "../models/license" ;
2929
3030
@@ -34,21 +34,23 @@ import {NamedLicense} from "../models/license";
3434 */
3535export class LicenseEvidenceBuilder {
3636
37- readonly #afac: AttachmentFactory
37+ readonly #attachmentFactory: Factories . FromPath . AttachmentFactory
3838
39- constructor ( afac : AttachmentFactory ) {
40- this . #afac = afac
39+ constructor ( attachmentFactory : LicenseEvidenceBuilder [ 'attachmentFactory' ] ) {
40+ this . #attachmentFactory = attachmentFactory
4141 }
4242
43- readonly #LICENSE_FILENAME_PATTERN = / ^ (?: U N ) ? L I C E N [ C S ] E | .\. L I C E N [ C S ] E $ | ^ N O T I C E $ / i
43+ get attachmentFactory ( ) : Factories . FromPath . AttachmentFactory {
44+ return this . #attachmentFactory
45+ }
4446
4547 /**
46- * Return a license on success, returns undefined if it appears to bes no known text file.
48+ * Return a license on success.
49+ * Returns undefined if it appears to bes no known text file.
4750 * Throws error, if license attachment content could not be fetched.
4851 *
4952 * @param file - path to file
50- * @param relativeFrom - path the file shall be relative to
51- * @returns {@link NamedLicense } on success
53+ * @param relativeFrom - path the file shall be relative from
5254 */
5355 public fromFile ( file : string , relativeFrom : string | undefined = undefined ) : NamedLicense | undefined {
5456 let name
@@ -59,19 +61,23 @@ export class LicenseEvidenceBuilder {
5961 file = resolve ( relativeFrom , file )
6062 name = `file: ${ relative ( relativeFrom , file ) } `
6163 }
62- const text = this . #afac . fromTextFile ( file )
64+ const text = this . #attachmentFactory . fromTextFile ( file )
6365 if ( text === undefined ) {
6466 return undefined
6567 }
6668 return new NamedLicense ( name , { text} )
6769 }
6870
71+ readonly #LICENSE_FILENAME_PATTERN = / ^ (?: U N ) ? L I C E N [ C S ] E | .\. L I C E N [ C S ] E $ | ^ N O T I C E $ / i
72+
6973 /**
70- * Returns a generator for license evidences.
71- * Throws error, if dir content could not be inspected.
74+ * Returns a generator for license evidences in a directory.
75+ * Throws error, if directory content could not be inspected.
76+ *
77+ * Unreadable files will be omitted.
7278 *
7379 * @param dir - path to inspect
74- * @param relativeFrom - path the dir and files shall be relative to
80+ * @param relativeFrom - path the dir and files shall be relative from
7581 */
7682 public * fromDir ( dir : string , relativeFrom : string | undefined = undefined ) : Generator < NamedLicense > {
7783 if ( relativeFrom !== undefined ) {
0 commit comments