From 6b78cc793c97e76b0a895c253bb6a56e68955361 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Sun, 10 Mar 2019 20:00:09 +0100 Subject: [PATCH] camel-k --runtime-version is not honoured for all runtimes #538 --- pkg/builder/builder_steps.go | 17 ---- pkg/builder/builder_steps_test.go | 61 +++++++++++++ pkg/builder/builder_utils.go | 21 +++++ pkg/builder/springboot/generator.go | 15 ---- pkg/builder/springboot/generator_test.go | 90 +++++++++++++++++++ .../integrationplatform/initialize.go | 2 +- 6 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 pkg/builder/springboot/generator_test.go diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go index 6fcd31744b..f12470db34 100644 --- a/pkg/builder/builder_steps.go +++ b/pkg/builder/builder_steps.go @@ -47,23 +47,6 @@ func GenerateProject(ctx *Context) error { ctx.Project = p - // - // Repositories - // - - ctx.Project.Repositories = make([]maven.Repository, 0, len(ctx.Request.Repositories)) - ctx.Project.PluginRepositories = make([]maven.Repository, 0, len(ctx.Request.Repositories)) - - for i, r := range ctx.Request.Repositories { - repo := maven.NewRepository(r) - if repo.ID == "" { - repo.ID = fmt.Sprintf("repo-%03d", i) - } - - ctx.Project.Repositories = append(ctx.Project.Repositories, repo) - ctx.Project.PluginRepositories = append(ctx.Project.PluginRepositories, repo) - } - // // set-up dependencies // diff --git a/pkg/builder/builder_steps_test.go b/pkg/builder/builder_steps_test.go index 19dcd650d7..f85a80e3d0 100644 --- a/pkg/builder/builder_steps_test.go +++ b/pkg/builder/builder_steps_test.go @@ -28,6 +28,67 @@ import ( "github.com/stretchr/testify/assert" ) +func TestMavenRepositories(t *testing.T) { + catalog, err := test.DefaultCatalog() + assert.Nil(t, err) + + ctx := Context{ + Catalog: catalog, + Request: Request{ + Catalog: catalog, + RuntimeVersion: defaults.RuntimeVersion, + Platform: v1alpha1.IntegrationPlatformSpec{ + Build: v1alpha1.IntegrationPlatformBuildSpec{ + CamelVersion: catalog.Version, + }, + }, + Dependencies: []string{ + "runtime:jvm", + }, + Repositories: []string{ + "https://repository.apache.org/content/repositories/snapshots@id=apache.snapshots@snapshots@noreleases", + "https://oss.sonatype.org/content/repositories/snapshots/@id=sonatype.snapshots@snapshots", + }, + }, + } + + err = GenerateProject(&ctx) + assert.Nil(t, err) + err = InjectDependencies(&ctx) + assert.Nil(t, err) + + assert.Equal(t, 2, len(ctx.Project.Repositories)) + assert.Equal(t, 2, len(ctx.Project.PluginRepositories)) + + assert.Contains(t, ctx.Project.Repositories, maven.Repository{ + ID: "apache.snapshots", + URL: "https://repository.apache.org/content/repositories/snapshots", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: false}, + }) + + assert.Contains(t, ctx.Project.Repositories, maven.Repository{ + ID: "sonatype.snapshots", + URL: "https://oss.sonatype.org/content/repositories/snapshots/", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: true}, + }) + + assert.Contains(t, ctx.Project.PluginRepositories, maven.Repository{ + ID: "apache.snapshots", + URL: "https://repository.apache.org/content/repositories/snapshots", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: false}, + }) + + assert.Contains(t, ctx.Project.PluginRepositories, maven.Repository{ + ID: "sonatype.snapshots", + URL: "https://oss.sonatype.org/content/repositories/snapshots/", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: true}, + }) +} + func TestGenerateJvmProject(t *testing.T) { catalog, err := test.DefaultCatalog() assert.Nil(t, err) diff --git a/pkg/builder/builder_utils.go b/pkg/builder/builder_utils.go index 45d5b2505f..3256b65a8f 100644 --- a/pkg/builder/builder_utils.go +++ b/pkg/builder/builder_utils.go @@ -19,6 +19,7 @@ package builder import ( "encoding/xml" + "fmt" "github.com/apache/camel-k/pkg/util/defaults" @@ -40,6 +41,9 @@ func ArtifactIDs(artifacts []v1alpha1.Artifact) []string { // NewProject -- func NewProject(ctx *Context) (maven.Project, error) { + // + // Catalog + // if ctx.Catalog == nil { c, err := camel.Catalog(ctx.Request.C, ctx.Client, ctx.Namespace, ctx.Request.Platform.Build.CamelVersion) if err != nil { @@ -73,5 +77,22 @@ func NewProject(ctx *Context) (maven.Project, error) { Dependencies: make([]maven.Dependency, 0), } + // + // Repositories + // + + p.Repositories = make([]maven.Repository, 0, len(ctx.Request.Repositories)) + p.PluginRepositories = make([]maven.Repository, 0, len(ctx.Request.Repositories)) + + for i, r := range ctx.Request.Repositories { + repo := maven.NewRepository(r) + if repo.ID == "" { + repo.ID = fmt.Sprintf("repo-%03d", i) + } + + p.Repositories = append(p.Repositories, repo) + p.PluginRepositories = append(p.PluginRepositories, repo) + } + return p, nil } diff --git a/pkg/builder/springboot/generator.go b/pkg/builder/springboot/generator.go index 1062b9e292..7b9f9f4c4e 100644 --- a/pkg/builder/springboot/generator.go +++ b/pkg/builder/springboot/generator.go @@ -34,21 +34,6 @@ func GenerateProject(ctx *builder.Context) error { ctx.Project = p - // - // Repositories - // - - ctx.Project.Repositories = make([]maven.Repository, 0, len(ctx.Request.Repositories)) - - for i, r := range ctx.Request.Repositories { - repo := maven.NewRepository(r) - if repo.ID == "" { - repo.ID = fmt.Sprintf("repo-%03d", i) - } - - ctx.Project.Repositories = append(ctx.Project.Repositories, repo) - } - // // set-up dependencies // diff --git a/pkg/builder/springboot/generator_test.go b/pkg/builder/springboot/generator_test.go new file mode 100644 index 0000000000..3c0e1a5e69 --- /dev/null +++ b/pkg/builder/springboot/generator_test.go @@ -0,0 +1,90 @@ +/* +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 springboot + +import ( + "testing" + + "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" + "github.com/apache/camel-k/pkg/builder" + "github.com/apache/camel-k/pkg/util/defaults" + "github.com/apache/camel-k/pkg/util/maven" + "github.com/apache/camel-k/pkg/util/test" + "github.com/stretchr/testify/assert" +) + +func TestMavenRepositories(t *testing.T) { + catalog, err := test.DefaultCatalog() + assert.Nil(t, err) + + ctx := builder.Context{ + Catalog: catalog, + Request: builder.Request{ + Catalog: catalog, + RuntimeVersion: defaults.RuntimeVersion, + Platform: v1alpha1.IntegrationPlatformSpec{ + Build: v1alpha1.IntegrationPlatformBuildSpec{ + CamelVersion: catalog.Version, + }, + }, + Dependencies: []string{ + "runtime:jvm", + }, + Repositories: []string{ + "https://repository.apache.org/content/repositories/snapshots@id=apache.snapshots@snapshots@noreleases", + "https://oss.sonatype.org/content/repositories/snapshots/@id=sonatype.snapshots@snapshots", + }, + }, + } + + err = GenerateProject(&ctx) + assert.Nil(t, err) + err = builder.InjectDependencies(&ctx) + assert.Nil(t, err) + + assert.Equal(t, 2, len(ctx.Project.Repositories)) + assert.Equal(t, 2, len(ctx.Project.PluginRepositories)) + + assert.Contains(t, ctx.Project.Repositories, maven.Repository{ + ID: "apache.snapshots", + URL: "https://repository.apache.org/content/repositories/snapshots", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: false}, + }) + + assert.Contains(t, ctx.Project.Repositories, maven.Repository{ + ID: "sonatype.snapshots", + URL: "https://oss.sonatype.org/content/repositories/snapshots/", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: true}, + }) + + assert.Contains(t, ctx.Project.PluginRepositories, maven.Repository{ + ID: "apache.snapshots", + URL: "https://repository.apache.org/content/repositories/snapshots", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: false}, + }) + + assert.Contains(t, ctx.Project.PluginRepositories, maven.Repository{ + ID: "sonatype.snapshots", + URL: "https://oss.sonatype.org/content/repositories/snapshots/", + Snapshots: maven.RepositoryPolicy{Enabled: true}, + Releases: maven.RepositoryPolicy{Enabled: true}, + }) +} diff --git a/pkg/controller/integrationplatform/initialize.go b/pkg/controller/integrationplatform/initialize.go index 71825752d9..fe847759ed 100644 --- a/pkg/controller/integrationplatform/initialize.go +++ b/pkg/controller/integrationplatform/initialize.go @@ -115,7 +115,7 @@ func (action *initializeAction) Handle(ctx context.Context, ip *v1alpha1.Integra action.L.Info("Repositories:") } - action.L.Infof(" %d - %s", i, r) + action.L.Infof("%d - %s", i, r) } err = action.client.Update(ctx, target)