Skip to content

Commit 0ed68f7

Browse files
committed
Improvement in algorithm
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
1 parent c73b06a commit 0ed68f7

File tree

1 file changed

+15
-14
lines changed
  • external-providers/java-external-provider/pkg/java_external_provider

1 file changed

+15
-14
lines changed

external-providers/java-external-provider/pkg/java_external_provider/util.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,32 @@ func constructArtifactFromPom(log logr.Logger, jarFile string) (javaArtifact, er
213213
return dep, fmt.Errorf("failed to construct artifact from pom properties")
214214
}
215215

216-
// constructArtifactFromStructure tries to infer if a JAR is a public piece of software based on its internal structure
216+
// constructArtifactFromStructure builds an artifact object out of the JAR internal structure.
217217
func constructArtifactFromStructure(log logr.Logger, jarFile string, depToLabels map[string]*depLabelItem) (javaArtifact, error) {
218-
log.V(10).Info("trying to infer if %s is a public dependency", jarFile)
218+
log.V(10).Info(fmt.Sprintf("trying to infer if %s is a public dependency", jarFile))
219219
groupId, err := inferGroupName(jarFile)
220220
if err != nil {
221221
return javaArtifact{}, err
222222
}
223223
artifact := javaArtifact{GroupId: groupId}
224-
// check against depToLabels. add *?
225-
groupIdRegex := strings.Join([]string{groupId, "*"}, ".")
226-
log.V(10).Info("%s is a public dependency", jarFile)
227-
if depToLabels[groupIdRegex] != nil {
228-
artifact.foundOnline = true
229-
return artifact, nil
230-
} else {
231-
// lets try to remove one segment from the end
232-
groupIdSgmts := strings.Split(groupId, ".")
233-
groupId = strings.Join(groupIdSgmts[:len(groupIdSgmts)-1], ".")
234-
groupIdRegex = strings.Join([]string{groupId, "*"}, ".")
224+
// check the inferred groupId against list of public groups
225+
// if groupId is not found, remove last segment. repeat if not found until no segments are left.
226+
sgmts := strings.Split(groupId, ".")
227+
for len(sgmts) > 0 {
228+
// check against depToLabels. add *
229+
groupIdRegex := strings.Join([]string{groupId, "*"}, ".")
235230
if depToLabels[groupIdRegex] != nil {
231+
log.V(10).Info(fmt.Sprintf("%s is a public dependency", jarFile))
236232
artifact.foundOnline = true
237233
return artifact, nil
234+
} else {
235+
// lets try to remove one segment from the end
236+
sgmts = sgmts[:len(sgmts)-1]
237+
groupId = strings.Join(sgmts, ".")
238+
groupIdRegex = strings.Join([]string{groupId, "*"}, ".")
238239
}
239240
}
240-
log.V(10).Info("could not decide whether %s is public, setting as private", jarFile)
241+
log.V(10).Info(fmt.Sprintf("could not decide whether %s is public, setting as private", jarFile))
241242
return artifact, nil
242243
}
243244

0 commit comments

Comments
 (0)