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

Provide --summary flag to generate the license summary file #103

Merged
merged 7 commits into from
May 7, 2022

Conversation

mrproliu
Copy link
Contributor

@mrproliu mrproliu commented May 6, 2022

Follow apache/skywalking#8992, I have done two things:

  1. Add a new flag --summary to help users generate the license summary file by template file.
  2. Add licenses config under the dependency to declare which license is could not be recognized.

@mrproliu mrproliu added the enhancement New feature or request label May 6, 2022
@mrproliu mrproliu added this to the 0.3.0 milestone May 6, 2022
@mrproliu mrproliu requested review from wu-sheng and kezhenxu94 May 6, 2022 09:28
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
commands/deps_resolve.go Outdated Show resolved Hide resolved
return err
if summaryTplPath != "" {
if outDir == "" {
return fmt.Errorf("please provide the output directory to write the license summary file")
Copy link
Member

Choose a reason for hiding this comment

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

outDir is for -o, I think it's not related to -s, if you do this, users have to use -o if they want to use -s, i.e. they can't use -s without -o.

I thought we can simply generate the LICENSE file in the same directory as LICENSE.tpl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update to split these two flags.

}
_, err = file.WriteString(summary)
if err != nil {
logger.Log.Errorf("failed to write summary file, %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Return the error and handle it from the caller method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -119,7 +125,10 @@ func (resolver *GoModResolver) ResolvePackageLicense(module *packages.Module, re
}
identifier, err := license.Identify(module.Path, string(content))
if err != nil {
return err
if declareLicense == nil {
Copy link
Member

Choose a reason for hiding this comment

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

If the users already declare this license I don't think we need to license.Identify it, this gives the users ability to override the license if we make something wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

LicenseID string // License ID
}

func GenerateDependencyLicenseFilename(result *Result) string {
Copy link
Member

Choose a reason for hiding this comment

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

This method is not used in --summary flag, it's used in --output flag, why put it here (summary.go)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I provide the Location field into the template, It could help for getting generated license file path.

Copy link
Member

Choose a reason for hiding this comment

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

Read my comment https://github.com/apache/skywalking-eyes/pull/103/files#r866676214 , you are coupling 2 flags that they should be able to work independently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rollback to the previous version.

Comment on lines 82 to 85
licenseContent, err := license.GetLicenseContent(head.License.SpdxID)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

head.License.SpdxID is not required so it might be empty, users can use other forms to specify their license, not just SpdxID. You need to take care the case where SpdxID is not set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, If the head.License.SpdxID is not set, should I just throw a new error? or another config could get the license?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, If the head.License.SpdxID is not set, should I just throw a new error? or another config could get the license?

You can use this method to get the license content, but notice only use this as a fallback when the users don't specify spdxID

func (config *ConfigHeader) GetLicenseContent() string {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

commands/deps_resolve.go Outdated Show resolved Hide resolved
@@ -70,6 +86,12 @@ var DepsResolveCommand = &cobra.Command{
}
}

if summaryTpl != nil {
if err := writeSummary(&report); err != nil {
logger.Log.Warnf("write summary file error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

What about

Suggested change
logger.Log.Warnf("write summary file error: %v", err)
return err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better to perform before writing licenses if we need to throw the exception, it could make the command more consistent.

pkg/license/identifier.go Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
Copy link
Member

@kezhenxu94 kezhenxu94 left a comment

Choose a reason for hiding this comment

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

Some nits, generally good to me, thanks!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
{{.LicenseContent }}
{{ range .Groups }}
========================================================================
{{.Name}} licenses
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it'd be more specific if we rename {{.Name}} to something like {{.LicenseSpdxID}} or {{.LicenseName}}? Because there is another {{.Name}} inside the {{.Deps}},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it could be better to rename it to {{.LicenseID}}? WDYT?
Let it same with the {{.LicenseID}} inside the {{.Deps}}. For now, they are the same.

Copy link
Member

Choose a reason for hiding this comment

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

I think it could be better to rename it to {{.LicenseID}}? WDYT?

{{.LicenseID}} is good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

pkg/license/identifier.go Outdated Show resolved Hide resolved
// the license id of the project
var headerContent string
if head.License.SpdxID != "" {
headerContent, _ = license.GetLicenseContent(head.License.SpdxID)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the error can be ignored, if the users specify an unknown SpdxID (by mistake), we should notify that

Copy link
Contributor Author

@mrproliu mrproliu May 7, 2022

Choose a reason for hiding this comment

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

Updated. If GetLicenseContent could not be found, then throw an error.

@kezhenxu94 kezhenxu94 changed the title Provide summary flag to generate the license summary file Provide --summary flag to generate the license summary file May 7, 2022
@kezhenxu94 kezhenxu94 merged commit 78aa037 into apache:main May 7, 2022
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.

2 participants