Skip to content

Commit

Permalink
Regression for groovy routes #118
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Sep 24, 2018
1 parent 3761557 commit 39a7dd2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
9 changes: 0 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/client/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strconv"
"strings"

"github.com/apache/camel-k/pkg/util"

"github.com/apache/camel-k/pkg/util/sync"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -267,6 +269,15 @@ func (o *runCmdOptions) updateIntegrationCode(filename string) (*v1alpha1.Integr
}
}

// special handling for groovy
// TODO: we should define handlers for languages and/or file extensions
if o.Language == "groovy" && !util.StringSliceExists(o.Dependencies, "camel:groovy") {
integration.Spec.Dependencies = append(integration.Spec.Dependencies, "camel:groovy")
}
if o.Language == "" && strings.HasSuffix(filename, ".groovy") {
integration.Spec.Dependencies = append(integration.Spec.Dependencies, "camel:groovy")
}

for _, item := range o.Properties {
integration.Spec.Configuration = append(integration.Spec.Configuration, v1alpha1.ConfigurationSpec{
Type: "property",
Expand Down
4 changes: 3 additions & 1 deletion pkg/stub/action/integration/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package action

import (
"fmt"

"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/digest"

"github.com/rs/xid"
Expand Down Expand Up @@ -60,7 +62,7 @@ func (action *buildAction) Handle(integration *v1alpha1.Integration) error {
// amended to add/remove dependencies

//TODO: this is a very simple check, we may need to provide a deps comparison strategy
if !StringSliceContains(ctx.Spec.Dependencies, integration.Spec.Dependencies) {
if !util.StringSliceContains(ctx.Spec.Dependencies, integration.Spec.Dependencies) {
// We need to re-generate a context or search for a new one that
// satisfies integrations needs so let's remove the association
// with a context
Expand Down
26 changes: 3 additions & 23 deletions pkg/stub/action/integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

"github.com/apache/camel-k/pkg/util"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"k8s.io/api/core/v1"
Expand Down Expand Up @@ -38,7 +40,7 @@ func LookupContextForIntegration(integration *v1alpha1.Integration) (*v1alpha1.I
continue
}

if StringSliceContains(ctx.Spec.Dependencies, integration.Spec.Dependencies) {
if util.StringSliceContains(ctx.Spec.Dependencies, integration.Spec.Dependencies) {
return &ctx, nil
}
}
Expand All @@ -47,28 +49,6 @@ func LookupContextForIntegration(integration *v1alpha1.Integration) (*v1alpha1.I
return nil, nil
}

// StringSliceContains --
func StringSliceContains(slice []string, items []string) bool {
for i := 0; i < len(items); i++ {
if !StringSliceExists(slice, items[i]) {
return false
}
}

return true
}

// StringSliceExists --
func StringSliceExists(slice []string, item string) bool {
for i := 0; i < len(slice); i++ {
if slice[i] == item {
return true
}
}

return false
}

// PropertiesString --
func PropertiesString(m map[string]string) string {
properties := ""
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
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 util

// StringSliceContains --
func StringSliceContains(slice []string, items []string) bool {
for i := 0; i < len(items); i++ {
if !StringSliceExists(slice, items[i]) {
return false
}
}

return true
}

// StringSliceExists --
func StringSliceExists(slice []string, item string) bool {
for i := 0; i < len(slice); i++ {
if slice[i] == item {
return true
}
}

return false
}

0 comments on commit 39a7dd2

Please sign in to comment.