This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 79caa809a chore(deps): home made Set to replace 
github.com/scylladb/go-set
79caa809a is described below

commit 79caa809a1b7455b398a89a7743358580e8b3669
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Jun 6 16:56:02 2023 +0200

    chore(deps): home made Set to replace github.com/scylladb/go-set
    
    Ref #4326
---
 go.mod                    |  1 -
 go.sum                    |  4 --
 pkg/metadata/metadata.go  |  7 ++--
 pkg/trait/dependencies.go |  5 +--
 pkg/trait/jvm.go          |  5 +--
 pkg/trait/jvm_test.go     | 10 +++--
 pkg/trait/util.go         |  9 ++---
 pkg/util/sets/set.go      | 93 +++++++++++++++++++++++++++++++++++++++++++++++
 pkg/util/sets/set_test.go | 60 ++++++++++++++++++++++++++++++
 pkg/util/source/types.go  | 15 ++++----
 pkg/util/util.go          |  5 +--
 11 files changed, 181 insertions(+), 33 deletions(-)

diff --git a/go.mod b/go.mod
index dc258f262..0c09a8c7f 100644
--- a/go.mod
+++ b/go.mod
@@ -29,7 +29,6 @@ require (
        github.com/prometheus/common v0.44.0
        github.com/redhat-developer/service-binding-operator v1.3.4
        github.com/rs/xid v1.5.0
-       github.com/scylladb/go-set v1.0.2
        github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
        github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
        github.com/sirupsen/logrus v1.9.3
diff --git a/go.sum b/go.sum
index b89f265cb..713404a37 100644
--- a/go.sum
+++ b/go.sum
@@ -204,8 +204,6 @@ github.com/evanphx/json-patch/v5 v5.6.0/go.mod 
h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
 github.com/fatih/color v1.7.0/go.mod 
h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
 github.com/fatih/color v1.9.0/go.mod 
h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
 github.com/fatih/color v1.12.0/go.mod 
h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
-github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA=
-github.com/fatih/set v0.2.1/go.mod 
h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
 github.com/felixge/httpsnoop v1.0.1/go.mod 
h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
 github.com/flowstack/go-jsonschema v0.1.1/go.mod 
h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
 github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod 
h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
@@ -625,8 +623,6 @@ github.com/rs/xid v1.5.0/go.mod 
h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
 github.com/russross/blackfriday/v2 v2.0.1/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod 
h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
-github.com/scylladb/go-set v1.0.2 
h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE=
-github.com/scylladb/go-set v1.0.2/go.mod 
h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod 
h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 
h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
 github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod 
h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go
index d5a4a824f..5d5479529 100644
--- a/pkg/metadata/metadata.go
+++ b/pkg/metadata/metadata.go
@@ -18,10 +18,9 @@ limitations under the License.
 package metadata
 
 import (
-       "github.com/scylladb/go-set/strset"
-
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        "github.com/apache/camel-k/v2/pkg/util/camel"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
        src "github.com/apache/camel-k/v2/pkg/util/source"
 )
 
@@ -57,8 +56,8 @@ func merge(m1 src.Metadata, m2 src.Metadata) src.Metadata {
        return src.Metadata{
                FromURIs:             f,
                ToURIs:               t,
-               Dependencies:         strset.Union(m1.Dependencies, 
m2.Dependencies),
-               RequiredCapabilities: strset.Union(m1.RequiredCapabilities, 
m2.RequiredCapabilities),
+               Dependencies:         sets.Union(m1.Dependencies, 
m2.Dependencies),
+               RequiredCapabilities: sets.Union(m1.RequiredCapabilities, 
m2.RequiredCapabilities),
                ExposesHTTPServices:  m1.ExposesHTTPServices || 
m2.ExposesHTTPServices,
                PassiveEndpoints:     m1.PassiveEndpoints && 
m2.PassiveEndpoints,
        }
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 09197877c..30dd6f691 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -18,8 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "github.com/scylladb/go-set/strset"
-
        "k8s.io/utils/pointer"
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
@@ -28,6 +26,7 @@ import (
        "github.com/apache/camel-k/v2/pkg/util"
        "github.com/apache/camel-k/v2/pkg/util/camel"
        "github.com/apache/camel-k/v2/pkg/util/kubernetes"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
 )
 
 type dependenciesTrait struct {
@@ -54,7 +53,7 @@ func (t *dependenciesTrait) Apply(e *Environment) error {
                e.Integration.Status.Dependencies = make([]string, 0)
        }
 
-       dependencies := strset.New()
+       dependencies := sets.NewSet()
 
        if e.Integration.Spec.Dependencies != nil {
                if err := camel.ValidateDependenciesE(e.CamelCatalog, 
e.Integration.Spec.Dependencies); err != nil {
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 811bb70e2..7dd081f19 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -24,8 +24,6 @@ import (
        "sort"
        "strings"
 
-       "github.com/scylladb/go-set/strset"
-
        corev1 "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/api/resource"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -39,6 +37,7 @@ import (
        "github.com/apache/camel-k/v2/pkg/util"
        "github.com/apache/camel-k/v2/pkg/util/camel"
        "github.com/apache/camel-k/v2/pkg/util/envvar"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
 )
 
 type jvmTrait struct {
@@ -96,7 +95,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
                return fmt.Errorf("unable to find integration kit for 
integration %s", e.Integration.Name)
        }
 
-       classpath := strset.New()
+       classpath := sets.NewSet()
 
        classpath.Add("./resources")
        classpath.Add(filepath.ToSlash(camel.ConfigResourcesMountPath))
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 9467c509d..36dcf349a 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -24,7 +24,6 @@ import (
        "strings"
        "testing"
 
-       "github.com/scylladb/go-set/strset"
        "github.com/stretchr/testify/assert"
 
        appsv1 "k8s.io/api/apps/v1"
@@ -38,6 +37,7 @@ import (
        "github.com/apache/camel-k/v2/pkg/builder"
        "github.com/apache/camel-k/v2/pkg/util/camel"
        "github.com/apache/camel-k/v2/pkg/util/kubernetes"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
        "github.com/apache/camel-k/v2/pkg/util/test"
 )
 
@@ -109,7 +109,9 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
 
        assert.Nil(t, err)
 
-       cp := strset.New("./resources", crMountPath, rdMountPath, 
"/mount/path").List()
+       s := sets.NewSet()
+       s.Add("./resources", crMountPath, rdMountPath, "/mount/path")
+       cp := s.List()
        sort.Strings(cp)
 
        assert.Equal(t, []string{
@@ -141,7 +143,9 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
 
        assert.Nil(t, err)
 
-       cp := strset.New("./resources", crMountPath, rdMountPath, 
"/mount/path").List()
+       st := sets.NewSet()
+       st.Add("./resources", crMountPath, rdMountPath, "/mount/path")
+       cp := st.List()
        sort.Strings(cp)
 
        assert.Equal(t, []string{
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 0de30bf82..0f5f89de1 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -27,8 +27,6 @@ import (
        "sort"
        "strings"
 
-       "github.com/scylladb/go-set/strset"
-
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -41,6 +39,7 @@ import (
        "github.com/apache/camel-k/v2/pkg/util/camel"
        "github.com/apache/camel-k/v2/pkg/util/kubernetes"
        "github.com/apache/camel-k/v2/pkg/util/property"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
        "github.com/apache/camel-k/v2/pkg/util/uri"
 )
 
@@ -86,7 +85,7 @@ func getIntegrationKit(ctx context.Context, c client.Client, 
integration *v1.Int
 }
 
 func collectConfigurationValues(configurationType string, configurable 
...v1.Configurable) []string {
-       result := strset.New()
+       result := sets.NewSet()
 
        for _, c := range configurable {
                c := c
@@ -209,8 +208,8 @@ func filterTransferableAnnotations(annotations 
map[string]string) map[string]str
 }
 
 // ExtractSourceDependencies extracts dependencies from source.
-func ExtractSourceDependencies(source v1.SourceSpec, catalog 
*camel.RuntimeCatalog) (*strset.Set, error) {
-       dependencies := strset.New()
+func ExtractSourceDependencies(source v1.SourceSpec, catalog 
*camel.RuntimeCatalog) (*sets.Set, error) {
+       dependencies := sets.NewSet()
 
        // Add auto-detected dependencies
        meta, err := metadata.Extract(catalog, source)
diff --git a/pkg/util/sets/set.go b/pkg/util/sets/set.go
new file mode 100644
index 000000000..707ebddab
--- /dev/null
+++ b/pkg/util/sets/set.go
@@ -0,0 +1,93 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package sets
+
+// Set is a very basic implementation for a Set data structure.
+type Set struct {
+       keys map[string]bool
+}
+
+// NewSet creates an empty Set.
+func NewSet() *Set {
+       return &Set{
+               keys: make(map[string]bool),
+       }
+}
+
+// Union creates a Set from the union of two.
+func Union(s1, s2 *Set) *Set {
+       items1 := s1.List()
+       items2 := s2.List()
+
+       unionSet := NewSet()
+       unionSet.Add(items1...)
+       unionSet.Add(items2...)
+
+       return unionSet
+}
+
+// List returns the list of items of the Set.
+func (s *Set) List() []string {
+       keys := make([]string, len(s.keys))
+
+       i := 0
+       for k := range s.keys {
+               keys[i] = k
+               i++
+       }
+
+       return keys
+}
+
+// Add items to the Set.
+func (s *Set) Add(items ...string) {
+       for _, i := range items {
+               s.keys[i] = true
+       }
+}
+
+// Merge with items from another set.
+func (s *Set) Merge(another *Set) {
+       s.Add(another.List()...)
+}
+
+// Each traverses the items in the Set, calling the provided function for each
+// Set member. Traversal will continue until all items in the Set have been
+// visited, or if the closure returns false.
+func (s *Set) Each(f func(item string) bool) {
+       for item := range s.keys {
+               if !f(item) {
+                       break
+               }
+       }
+}
+
+// Has returns true if it contains the item.
+func (s *Set) Has(item string) bool {
+       return s.keys[item]
+}
+
+// IsEmpty returns true if the set has no items.
+func (s *Set) IsEmpty() bool {
+       return s.keys == nil || len(s.keys) == 0
+}
+
+// Size returns the number if items in the Set.
+func (s *Set) Size() int {
+       return len(s.keys)
+}
diff --git a/pkg/util/sets/set_test.go b/pkg/util/sets/set_test.go
new file mode 100644
index 000000000..ea0996da8
--- /dev/null
+++ b/pkg/util/sets/set_test.go
@@ -0,0 +1,60 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package sets
+
+import (
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestSet(t *testing.T) {
+       s := NewSet()
+       assert.True(t, s.IsEmpty())
+       s.Add("hello")
+       assert.False(t, s.IsEmpty())
+       assert.Equal(t, 1, s.Size())
+       s.Add("hello another")
+       assert.Equal(t, 2, s.Size())
+       s.Add("hello")
+       assert.Equal(t, 2, s.Size())
+
+       s2 := NewSet()
+       s2.Add("hello")
+       s2.Add("ciao")
+       assert.Equal(t, 2, s2.Size())
+
+       s3 := Union(s, s2)
+       assert.Equal(t, 3, s3.Size())
+       assert.Contains(t, s3.List(), "hello", "ciao", "hello another")
+       assert.True(t, s3.Has("ciao"))
+       assert.False(t, s3.Has("bye"))
+
+       s.Merge(s2)
+       assert.Equal(t, 3, s.Size())
+       assert.Contains(t, s.List(), "hello", "ciao", "hello another")
+
+       processedList := make([]string, 0)
+
+       s.Each(func(item string) bool {
+               processedList = append(processedList, "processed:"+item)
+               return true
+       })
+
+       assert.Contains(t, processedList, "processed:hello", "processed:ciao", 
"processed:hello another")
+}
diff --git a/pkg/util/source/types.go b/pkg/util/source/types.go
index 3c8304d63..c37460d12 100644
--- a/pkg/util/source/types.go
+++ b/pkg/util/source/types.go
@@ -18,7 +18,7 @@ limitations under the License.
 package source
 
 import (
-       "github.com/scylladb/go-set/strset"
+       "github.com/apache/camel-k/v2/pkg/util/sets"
 )
 
 // Metadata represents metadata for Integration source.
@@ -28,7 +28,7 @@ type Metadata struct {
        // All end URIs of defined routes
        ToURIs []string
        // All inferred dependencies required to run the integration
-       Dependencies *strset.Set
+       Dependencies *sets.Set
        // ExposesHTTPServices indicates if a route defined by the source is 
exposed
        // through HTTP
        ExposesHTTPServices bool
@@ -36,9 +36,8 @@ type Metadata struct {
        // are activated from external calls, including HTTP (useful to 
determine if the
        // integration can scale to 0)
        PassiveEndpoints bool
-       // RequiredCapabilities lists the capabilities required by the 
integration
-       // to run
-       RequiredCapabilities *strset.Set
+       // RequiredCapabilities lists the capabilities required by the 
integration to run
+       RequiredCapabilities *sets.Set
        // All kamelets
        Kamelets []string
 }
@@ -48,15 +47,17 @@ func NewMetadata() Metadata {
        return Metadata{
                FromURIs:             make([]string, 0),
                ToURIs:               make([]string, 0),
-               Dependencies:         strset.New(),
-               RequiredCapabilities: strset.New(),
+               Dependencies:         sets.NewSet(),
+               RequiredCapabilities: sets.NewSet(),
        }
 }
 
+// AddRequiredCapability -- .
 func (m *Metadata) AddRequiredCapability(capability string) {
        m.RequiredCapabilities.Add(capability)
 }
 
+// AddDependency -- .
 func (m *Metadata) AddDependency(dependency string) {
        m.Dependencies.Add(dependency)
 }
diff --git a/pkg/util/util.go b/pkg/util/util.go
index e0bede95f..2d91ee22d 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -35,11 +35,10 @@ import (
        "strings"
        "time"
 
+       "github.com/apache/camel-k/v2/pkg/util/sets"
        "go.uber.org/multierr"
 
        yaml2 "gopkg.in/yaml.v2"
-
-       "github.com/scylladb/go-set/strset"
 )
 
 // Directories and file names:
@@ -334,7 +333,7 @@ func WriteFileWithBytesMarshallerContent(basePath string, 
filePath string, conte
 }
 
 func FindAllDistinctStringSubmatch(data string, regexps ...*regexp.Regexp) 
[]string {
-       submatchs := strset.New()
+       submatchs := sets.NewSet()
 
        for _, reg := range regexps {
                hits := reg.FindAllStringSubmatch(data, -1)

Reply via email to