Skip to content

feat: add switch to add license text to BOM result#427

Closed
CompartMSL wants to merge 2 commits intoCycloneDX:mainfrom
CompartMSL:feature/addLicTexts
Closed

feat: add switch to add license text to BOM result#427
CompartMSL wants to merge 2 commits intoCycloneDX:mainfrom
CompartMSL:feature/addLicTexts

Conversation

@CompartMSL
Copy link

@CompartMSL CompartMSL commented Jan 10, 2023

fixes #256

@CompartMSL CompartMSL requested a review from a team as a code owner January 10, 2023 17:24
@CompartMSL CompartMSL closed this Jan 11, 2023
@CompartMSL CompartMSL deleted the feature/addLicTexts branch January 11, 2023 06:51
@CompartMSL CompartMSL restored the feature/addLicTexts branch January 11, 2023 06:52
@CompartMSL CompartMSL reopened this Jan 11, 2023
@jkowalleck
Copy link
Member

jkowalleck commented Jan 11, 2023

❌ Please add proper tests.

PS: this is already ongoing

Signed-off-by: Matthias Schiebel <msl@compart.com>
@CompartMSL CompartMSL force-pushed the feature/addLicTexts branch 2 times, most recently from 217a4c8 to b53631e Compare January 16, 2023 12:39
@jkowalleck
Copy link
Member

jkowalleck commented Jan 19, 2023

Based on the proposed implementation, the new switch --add-license-text contradicts the existing switch --package-lock-only.

The --package-lock-only (options.packageLockOnly) should have priority - meaning if options.packageLockOnly is true, then options.addLicenseText should be set to false regardless of the user's input. (see how options.packageLockOnly is handled in src/cli.ts)

@CompartMSL, how do you see this?

@CompartMSL
Copy link
Author

Based on the proposed implementation, the new switch --add-license-text contradicts the existing switch --package-lock-only.

The --package-lock-only (options.packageLockOnly) should have priority - meaning if options.packageLockOnly is true, then options.addLicenseText should be set to false regardless of the user's input. (see how options.packageLockOnly is handled in src/cli.ts)

@CompartMSL, how do you see this?

You are right.
After the implementation of this change I recognized, after the run of the tests, that the chosen test approach for --add-license-texts is disturbed by this change. The files in tests_data\sbom_demo-results\add-license-text\ shows not the wanted effect anymore.
Currently, I see the need to search another test approach and have no idea where to start.

@jkowalleck jkowalleck changed the title FEAT: Option to add license text to BOM output (#256) feat: Option to add license text to BOM output (#256) Jan 23, 2023
@jkowalleck jkowalleck changed the title feat: Option to add license text to BOM output (#256) feat: add switch to add license text to BOM result Jan 23, 2023
@jkowalleck
Copy link
Member

@CompartMSL re #427 (comment)

Ignore the tests for a while, and just take care of the needed implementation details.
Maybe just revert the tests you added, for a while. I will assist setting up a test, as soon as the desired feature is shaped properly.

if (pkgPath.length < 1) {
return licenseFilenamesWType
}
const typicalFilenames = ['LICENSE', 'License', 'license', 'LICENCE', 'Licence', 'licence', 'NOTICE', 'Notice', 'notice']
Copy link
Member

@jkowalleck jkowalleck Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the list/implementation to be case-insensitive.
I'd suggest having only lowercased entries in the list.
I'd suggest using a scandir-like behavior where all files are lowercased before they are compared against the list of known files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the other way first to get a list of all files and match case-insensitive. Maybe there is later an idea to handle multiple files

@jkowalleck jkowalleck marked this pull request as draft January 24, 2023 13:46
@jkowalleck
Copy link
Member

converted PR to "draft", since the implementation is not final, yet.

@CompartMSL CompartMSL force-pushed the feature/addLicTexts branch 2 times, most recently from d0c1d1c to 2efa5b7 Compare January 25, 2023 08:38
Signed-off-by: Matthias Schiebel <msl@compart.com>

import { Enums, Models } from '@cyclonedx/cyclonedx-library'
import * as fs from 'fs'
import * as minimatch from 'minimatch'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ where does this come from?

myConsole
).buildFromProjectDir(projectDir, process)

if (options.addLicenseText) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do this after everything is set?
I'd suggest putting the code in the existing BomBuilder.makeComponent()

@jkowalleck
Copy link
Member

jkowalleck commented Jan 25, 2023

@CompartMSL I find the proposed current implementation disturbing, as it does not stick to chosen design principles and architecture of this project.

my suggestion: write the needed function and usage in the builders.ts file.

  • Add the option whether to add the license texts to existing BomBuilderOptions and act based on it in the exiting BomBuilder. This option could be called shouldAddLicenseTexts.
  • Create a new class there, that has a method that returns or updates needed structures based on a given directory path.
  • inject your own builder into BomBuilder - like BomBuilder.componentBuilder.
    It could be called LicensBuilder and be available internally as this.licensBuilder.
  • hook into the existing BomBuilder.makeComponent() and call needed methods like
    const component = this.componentBuilder.makeComponent(data, type)
    // ...
    if (!this.packageLockOnly && this.shouldAddLicenseTexts && data.path) {
      this.licensBuilder.addTexts(component.licenses, data.path)
    }
    // ...
    return component

* @param {Models.DisjunctiveLicense} license
* @param {string} installPath
*/
function addLicTextBasedOnLicenseFiles (license: Models.DisjunctiveLicense, installPath: string): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license text detection is not completely solved.

Therefore, the result shall be an evidence, rather than n license attachment.

@jkowalleck jkowalleck added the enhancement New feature or request label Jun 8, 2023
cuhland added a commit to cuhland/cyclonedx-node-npm that referenced this pull request Dec 9, 2024
As suggested in CycloneDX#427 (comment)

Signed-off-by: Christoph Uhland <42832096+cuhland@users.noreply.github.com>
@cuhland
Copy link
Contributor

cuhland commented Dec 9, 2024

I want to support this feature and created a branch which took these commits here, rebased them on top of current main and did soome refactoring regarding the code structure.
@jkowalleck Is there a chance that this feature can be part of the next release?

@jkowalleck
Copy link
Member

jkowalleck commented Dec 9, 2024

I want to support this feature and created a branch which took these commits here, rebased them on top of current main and did soome refactoring regarding the code structure. @jkowalleck Is there a chance that this feature can be part of the next release?

I do not see a good to merge the current state of this very PR.

If you have a maintained version of it, feel free to open a competing pull-request.

Since this feature is nothing new, there is no need to reinvent the wheel. It is expected to simply copy existing art.
Please be aware of existing art:

just in case: Please keep the scope of your PR, don't mix unrelated changes into a feature-PR

@jkowalleck
Copy link
Member

Superseded by #1243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: Option to add license text to SBOM result

3 participants