Skip to content

Commit

Permalink
🐛 Handle cases when copyright and license are at top of file (#451)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Dec 14, 2023
1 parent 60e7f61 commit 65cd4f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (p *javaServiceClient) findPom() string {
} else {
depPath = p.config.DependencyPath
}
if filepath.IsAbs(depPath) {
return depPath
}
f, err := filepath.Abs(filepath.Join(p.config.Location, depPath))
if err != nil {
return ""
Expand Down Expand Up @@ -124,6 +127,10 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
path = location
}
pom, err := gopom.Parse(path)
if err != nil {
p.log.Error(err, "Analyzing POM")
return nil, err
}
p.log.V(10).Info("Analyzing POM",
"POM", fmt.Sprintf("%s:%s:%s", pomCoordinate(pom.GroupID), pomCoordinate(pom.ArtifactID), pomCoordinate(pom.Version)),
"error", err)
Expand Down
14 changes: 12 additions & 2 deletions provider/internal/java/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ func (p *javaServiceClient) getURI(refURI string) (string, uri.URI, error) {
scanner := bufio.NewScanner(file)
name := ""
for scanner.Scan() {
if strings.Contains(scanner.Text(), "package") {
if strings.Contains(scanner.Text(), "package") &&
// here we have to handle the work package in license's/copyrights.
// Ignoring everyting that looks like a java doc comment.
!strings.Contains(scanner.Text(), "//") && !strings.Contains(scanner.Text(), "/*") &&
!strings.HasPrefix(strings.TrimSpace(scanner.Text()), "*") {

name = strings.ReplaceAll(scanner.Text(), "package ", "")
name = strings.ReplaceAll(name, ";", "")
break
Expand Down Expand Up @@ -298,7 +303,12 @@ func (p *javaServiceClient) getURI(refURI string) (string, uri.URI, error) {
n := ""
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.Contains(scanner.Text(), "package") {
if strings.Contains(scanner.Text(), "package") &&
// here we have to handle the work package in license's/copyrights.
// Ignoring everyting that looks like a java doc comment.
!strings.Contains(scanner.Text(), "//") && !strings.Contains(scanner.Text(), "/*") &&
!strings.HasPrefix(strings.TrimSpace(scanner.Text()), "*") {

n = strings.ReplaceAll(scanner.Text(), "package ", "")
n = strings.ReplaceAll(n, ";", "")
break
Expand Down

0 comments on commit 65cd4f5

Please sign in to comment.