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

add feature: support resolving pom.xml for maven #50

Merged
merged 9 commits into from Aug 3, 2021

Conversation

MoGuGuai-hzr
Copy link
Contributor

Solution: copy, using mvn dependency:copy-dependencies, all dependencies and transitive dependencies, and then resolve license from the jar files.

Known disadvantages:

  • depends on maven
  • replication of the jar files needs to read and write the disk

@kezhenxu94 kezhenxu94 self-requested a review July 25, 2021 23:16
@kezhenxu94 kezhenxu94 added this to the 0.2.0 milestone Jul 25, 2021
Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

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

One question, this PR is only including dependency resolving, but not checking the dependencies license compatible, right?

pkg/deps/maven_test.go Show resolved Hide resolved
@kezhenxu94
Copy link
Member

One question, this PR is only including dependency resolving, but not checking the dependencies license compatible, right?

All the dependencies licenses resolvers including Go, NPM don’t check license compatibility now, they just resolve the licenses for human’s reference. Checking license compatibility is out of the scope of this PR and will be discussed after the main resolvers (Java, NodeJS, Golang) can correctly resolve the licenses first.

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

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

This and #48 should be very similar PR, but why do the changes have so many differences?

  1. Resolvers is not changed here.
  2. .licensserc.yaml is not changed in Add support for resolving npm dependencies' licenses #48

.licenserc.yaml Outdated Show resolved Hide resolved
pkg/deps/maven.go Show resolved Hide resolved
Comment on lines 21 to 27
var err error
_, err = exec.Command("mvn", "--version").Output()
if err != nil {
return
}

Resolvers = append(Resolvers, new(MavenPomResolver))
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 this is not a good condition to check whether we should add the resolver:

  • mvn version is not enough to determine whether maven resolver can be use, maven wrapper is also widely used in some projects.
  • We should log some warning / error logs when users' environment don't have maven installed, instead of failing silently.

My suggestion is

  • just add the resolver to
    var Resolvers = []Resolver{
    new(GoModResolver),
    new(NpmResolver),
    }
  • check whether mvnw exists in the same directory as pom.xml first, if yes, use mvnw, otherwise, use mvn
  • run the needed command (mvn copy-dependencies), if it failed, we also fail the command and print some logs

Comment on lines 40 to 43
err := CheckMVN()
if err != nil {
logger.Log.Errorln("an error occurred when checking maven tool:", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's invoke this in maven resolver manually instead of in init method, so that when users don't need to resolve pom.xml files won't see these logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have moved it~

@kezhenxu94
Copy link
Member

kezhenxu94 commented Jul 27, 2021

Screen Shot 2021-07-27 at 12 01 04

So many changed files / lines 😱

@MoGuGuai-hzr
Copy link
Contributor Author

Screen Shot 2021-07-27 at 12 01 04

So many changed files / lines 😱

It may be caused by the CR/LF, now it is fixed.

Comment on lines 88 to 110
err := resolver.CheckMVN()
if err != nil {
logger.Log.Errorln("an error occurred when checking maven tool:", err)
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

Please bear in mind, CanResolve will be invoked for every kind of projects, not just maven projects, so if I just want to resolve Go project or NPM project, this error logs look weird to me. Note that I'm not saying we should not log this error, instead, we should only check mvn right before when we need to run mvn command, (in the Resolve method), CanResolve is only used to filter the resolver according to the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get it~

Comment on lines 83 to 100
if err := os.Chdir(dir); err != nil {
logger.Log.Errorf("an error occurred when entering dir <%s> to parser file <%s>:%v\n", dir, base, err)
return false
}
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 this part should be moved into CheckMVN function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok~

_, err = exec.Command("./mvnw", "--version").Output()
if err == nil {
resolver.maven = "./mvnw"
logger.Log.Debugln("use mvnw")
Copy link
Member

Choose a reason for hiding this comment

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

mvnw is found, will use mvnw by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this mean to modify the log message?

Copy link
Member

Choose a reason for hiding this comment

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

does this mean to modify the log message?

Uh yes, sorry, didn't make it clear 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is my fault, I didn't understand it well😅

@MoGuGuai-hzr
Copy link
Contributor Author

added some patterns describing the possible locations of license, but does not work for some jar packages

Copy link
Contributor Author

@MoGuGuai-hzr MoGuGuai-hzr left a comment

Choose a reason for hiding this comment

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

should i crawl the original webpage or judge directly from the url to identify the license

@kezhenxu94
Copy link
Member

should i crawl the original webpage or judge directly from the url to identify the license

We can consider this later, we don't need to do all in one PR (which is hard to review and cost too long to finish), we can deliver minimal yet complete features step by step, in this PR I think it's OK to only support the "standard" dependencies that have a LICENSE file in their .jar, so let's polish this part instead of keep adding new things in this PR

@MoGuGuai-hzr
Copy link
Contributor Author

should i crawl the original webpage or judge directly from the url to identify the license

We can consider this later, we don't need to do all in one PR (which is hard to review and cost too long to finish), we can deliver minimal yet complete features step by step, in this PR I think it's OK to only support the "standard" dependencies that have a LICENSE file in their .jar, so let's polish this part instead of keep adding new things in this PR

ok~, i will do it

return fmt.Errorf("neither found mvnw nor mvn")
}

logger.Log.Debugln("mvnw is not found, will use mvn by default")
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed / correct now,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i have removed it

}

func (resolver *MavenPomResolver) DownloadDeps() error {
cmd := exec.Command(resolver.maven, "process-resources") // #nosec G204
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be problematic in multi-modules maven project, can you try this feature in our main repo http://github.com/apache/skywalking ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as you said in discussion, the failure may be caused by submodules. so i resolve it using maven command install -DskipTests to install possible need dependencies, and it may take some time.

@wu-sheng
Copy link
Member

wu-sheng commented Aug 3, 2021

Just a reminder, I am not sure whether this could be fixed easily. Maven includes a plugin called shaded, which would not include the dependency jar, but package it inside another package during the install. You could try this case.

@MoGuGuai-hzr
Copy link
Contributor Author

Just a reminder, I am not sure whether this could be fixed easily. Maven includes a plugin called shaded, which would not include the dependency jar, but package it inside another package during the install. You could try this case.

thanks for your help, and i am using install command attempting to resolve the incompatibility

@wu-sheng
Copy link
Member

wu-sheng commented Aug 3, 2021

Just a reminder, I am not sure whether this could be fixed easily. Maven includes a plugin called shaded, which would not include the dependency jar, but package it inside another package during the install. You could try this case.

thanks for your help, and i am using install command attempting to resolve the incompatibility

My point is, the module using this plugin, may escape from your dependency check. You should check the case.

@MoGuGuai-hzr
Copy link
Contributor Author

Just a reminder, I am not sure whether this could be fixed easily. Maven includes a plugin called shaded, which would not include the dependency jar, but package it inside another package during the install. You could try this case.

thanks for your help, and i am using install command attempting to resolve the incompatibility

My point is, the module using this plugin, may escape from your dependency check. You should check the case.

sorry, I didn’t understand it very well. does this mean giving up on resolving these module? since the shaded package will be packaged during the install, can it be solved by installing first?

@wu-sheng
Copy link
Member

wu-sheng commented Aug 3, 2021

orry, I didn’t understand it very well. does this mean giving up on resolving these module? since the shaded package will be packaged during the install, can it be solved by installing first?

I don't know. This is only a reminder, I just recommend you to check.

@MoGuGuai-hzr
Copy link
Contributor Author

orry, I didn’t understand it very well. does this mean giving up on resolving these module? since the shaded package will be packaged during the install, can it be solved by installing first?

I don't know. This is only a reminder, I just recommend you to check.

ok, I've got the information. i will attemp it later

kezhenxu94
kezhenxu94 previously approved these changes Aug 3, 2021
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.

Nice work! This is closing to serve as the 1st version for maven projects, though we may have some corner cases to consider later. 👍🏻

I left some comments, please take a look

Comment on lines 84 to 89
var seemLicense = regexp.MustCompile(`(?i)licen[sc]e|copyright|copying`)

// Seem determine whether the content of the file may be a license file
func Seem(content string) bool {
return seemLicense.MatchString(content)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you reuse possibleLicenseFileName in file golang.go? it may not be a good idea to put possibleLicenseFileName in identifier.go but now let's unify the 2 places, you can move possibleLicenseFileName into identifier.go later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you reuse possibleLicenseFileName in file golang.go? it may not be a good idea to put possibleLicenseFileName in identifier.go but now let's unify the 2 places, you can move possibleLicenseFileName into identifier.go later.

the purpose of Seem function was to simply determine whether one file may be a license base on the input content, not the file name. i remove it from identifier.go now.

pkg/deps/maven_test.go Outdated 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.

Thank you @MoGuGuai-hzr for the great work and patience 🙇🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants