Skip to content

Commit 75ecf55

Browse files
committed
Fix labelling problem
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
1 parent d4be7e8 commit 75ecf55

File tree

1 file changed

+20
-9
lines changed
  • external-providers/java-external-provider/pkg/java_external_provider

1 file changed

+20
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error {
695695
if (artifact != javaArtifact{}) {
696696
d.Name = fmt.Sprintf("%s.%s", artifact.GroupId, artifact.ArtifactId)
697697
d.Version = artifact.Version
698-
d.Labels = addDepLabels(w.depToLabels, d.Name)
698+
d.Labels = addDepLabels(w.depToLabels, d.Name, artifact.foundOnline)
699699
d.ResolvedIdentifier = artifact.sha1
700700
// when we can successfully get javaArtifact from a jar
701701
// we added it to the pom and it should be in m2Repo path
@@ -728,7 +728,7 @@ func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error {
728728
if (artifact != javaArtifact{}) {
729729
d.Name = fmt.Sprintf("%s.%s", artifact.GroupId, artifact.ArtifactId)
730730
d.Version = artifact.Version
731-
d.Labels = addDepLabels(w.depToLabels, d.Name)
731+
d.Labels = addDepLabels(w.depToLabels, d.Name, artifact.foundOnline)
732732
d.ResolvedIdentifier = artifact.sha1
733733
// when we can successfully get javaArtifact from a jar
734734
// we added it to the pom and it should be in m2Repo path
@@ -813,7 +813,7 @@ func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) (
813813
if !strings.HasPrefix(fp, "/") {
814814
fp = "/" + fp
815815
}
816-
d.Labels = addDepLabels(p.depToLabels, d.Name)
816+
d.Labels = addDepLabels(p.depToLabels, d.Name, false)
817817
d.FileURIPrefix = fmt.Sprintf("file://%v", filepath.Dir(fp))
818818

819819
if runtime.GOOS == "windows" {
@@ -865,7 +865,9 @@ func resolveDepFilepath(d *provider.Dep, p *javaServiceClient, group string, art
865865
return fp
866866
}
867867

868-
func addDepLabels(depToLabels map[string]*depLabelItem, depName string) []string {
868+
// addDepLabels adds some labels (open-source/internal and java) to the dependencies. The openSource argument can be used
869+
// in cased it was already determined that the dependency is open source by any other means (ie by inferring the groupId)
870+
func addDepLabels(depToLabels map[string]*depLabelItem, depName string, openSource bool) []string {
869871
m := map[string]interface{}{}
870872
for _, d := range depToLabels {
871873
if d.r.Match([]byte(depName)) {
@@ -878,11 +880,20 @@ func addDepLabels(depToLabels map[string]*depLabelItem, depName string) []string
878880
for k := range m {
879881
s = append(s, k)
880882
}
881-
// if open source label is not found, qualify the dep as being internal by default
882-
if _, openSourceLabelFound :=
883-
m[labels.AsString(provider.DepSourceLabel, javaDepSourceOpenSource)]; !openSourceLabelFound {
884-
s = append(s,
885-
labels.AsString(provider.DepSourceLabel, javaDepSourceInternal))
883+
// if open source label is not found and we don't know if it's open source yet, qualify the dep as being internal by default
884+
_, openSourceLabelFound := m[labels.AsString(provider.DepSourceLabel, javaDepSourceOpenSource)]
885+
_, internalSourceLabelFound := m[labels.AsString(provider.DepSourceLabel, javaDepSourceInternal)]
886+
if openSourceLabelFound || openSource {
887+
if !openSourceLabelFound {
888+
s = append(s, labels.AsString(provider.DepSourceLabel, javaDepSourceOpenSource))
889+
}
890+
if internalSourceLabelFound {
891+
delete(m, labels.AsString(provider.DepSourceLabel, javaDepSourceInternal))
892+
}
893+
} else {
894+
if !internalSourceLabelFound {
895+
s = append(s, labels.AsString(provider.DepSourceLabel, javaDepSourceInternal))
896+
}
886897
}
887898
s = append(s, labels.AsString(provider.DepLanguageLabel, "java"))
888899
return s

0 commit comments

Comments
 (0)