nicolaferraro closed pull request #119: Groovy regression URL: https://github.com/apache/camel-k/pull/119
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/Gopkg.lock b/Gopkg.lock index 0975b14..4c8e50f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -492,14 +492,6 @@ revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" version = "v0.9.1" -[[projects]] - branch = "v1" - digest = "1:52ffb9db0286de37253a5098607cfbcfcdc94e51e8c226da120513df82adab0c" - name = "gopkg.in/yaml.v1" - packages = ["."] - pruneopts = "NUT" - revision = "9f9df34309c04878acc86042b16630b0f696e1de" - [[projects]] digest = "1:7c95b35057a0ff2e19f707173cc1a947fa43a6eb5c4d300d196ece0334046082" name = "gopkg.in/yaml.v2" @@ -741,7 +733,6 @@ "github.com/spf13/cobra", "github.com/stoewer/go-strcase", "github.com/stretchr/testify/assert", - "gopkg.in/yaml.v1", "gopkg.in/yaml.v2", "k8s.io/api/apps/v1", "k8s.io/api/core/v1", diff --git a/pkg/client/cmd/completion_bash.go b/pkg/client/cmd/completion_bash.go index a109e36..c689f8e 100644 --- a/pkg/client/cmd/completion_bash.go +++ b/pkg/client/cmd/completion_bash.go @@ -66,6 +66,11 @@ __kamel_dependency_type() { esac } +__kamel_languages() { + local type_list="js groovy java xml" + COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") ) +} + __kamel_kubectl_get_configmap() { local template local kubectl_out @@ -183,6 +188,13 @@ func configureKnownBashCompletions(command *cobra.Command) { cobra.BashCompCustom: {"__kamel_kubectl_get_user_integrationcontexts"}, }, ) + configureBashAnnotationForFlag( + command, + "language", + map[string][]string{ + cobra.BashCompCustom: {"__kamel_languages"}, + }, + ) } func configureBashAnnotationForFlag(command *cobra.Command, flagName string, annotations map[string][]string) { diff --git a/pkg/client/cmd/run.go b/pkg/client/cmd/run.go index 37d06bb..ca4e52f 100644 --- a/pkg/client/cmd/run.go +++ b/pkg/client/cmd/run.go @@ -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" @@ -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", diff --git a/pkg/stub/action/integration/build.go b/pkg/stub/action/integration/build.go index 5978365..4dcf728 100644 --- a/pkg/stub/action/integration/build.go +++ b/pkg/stub/action/integration/build.go @@ -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" @@ -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 diff --git a/pkg/stub/action/integration/util.go b/pkg/stub/action/integration/util.go index 8c69f69..33c3787 100644 --- a/pkg/stub/action/integration/util.go +++ b/pkg/stub/action/integration/util.go @@ -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" @@ -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 } } @@ -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 := "" diff --git a/pkg/util/util.go b/pkg/util/util.go new file mode 100644 index 0000000..c2a2631 --- /dev/null +++ b/pkg/util/util.go @@ -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 +} ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services