This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push: new 79f8d22 dependencies: add support for boms 79f8d22 is described below commit 79f8d2282816863030a875799c2cb3ef234a8a69 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Mon Mar 18 23:03:06 2019 +0100 dependencies: add support for boms --- pkg/builder/builder_steps.go | 2 + pkg/builder/builder_utils.go | 67 ++++++++++++++++++++++---------- pkg/builder/builder_utils_test.go | 77 +++++++++++++++++++++++++++++++++++++ pkg/builder/springboot/generator.go | 2 + 4 files changed, 127 insertions(+), 21 deletions(-) diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go index f12470d..dd465a5 100644 --- a/pkg/builder/builder_steps.go +++ b/pkg/builder/builder_steps.go @@ -80,6 +80,8 @@ func GenerateProject(ctx *Context) error { artifactID := strings.Replace(d, "runtime:", "camel-k-runtime-", 1) ctx.Project.AddDependencyGAV("org.apache.camel.k", artifactID, ctx.Request.RuntimeVersion) + case strings.HasPrefix(d, "bom:"): + // no-op default: return fmt.Errorf("unknown dependency type: %s", d) } diff --git a/pkg/builder/builder_utils.go b/pkg/builder/builder_utils.go index 3256b65..5c49a8a 100644 --- a/pkg/builder/builder_utils.go +++ b/pkg/builder/builder_utils.go @@ -20,6 +20,7 @@ package builder import ( "encoding/xml" "fmt" + "strings" "github.com/apache/camel-k/pkg/util/defaults" @@ -54,30 +55,54 @@ func NewProject(ctx *Context) (maven.Project, error) { } p := maven.Project{ - XMLName: xml.Name{Local: "project"}, - XMLNs: "http://maven.apache.org/POM/4.0.0", - XMLNsXsi: "http://www.w3.org/2001/XMLSchema-instance", - XsiSchemaLocation: "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd", - ModelVersion: "4.0.0", - GroupID: "org.apache.camel.k.integration", - ArtifactID: "camel-k-integration", - Version: defaults.Version, - Properties: ctx.Request.Platform.Build.Properties, - DependencyManagement: maven.DependencyManagement{ - Dependencies: []maven.Dependency{ - { - GroupID: "org.apache.camel", - ArtifactID: "camel-bom", - Version: ctx.Catalog.Version, - Type: "pom", - Scope: "import", - }, - }, - }, - Dependencies: make([]maven.Dependency, 0), + XMLName: xml.Name{Local: "project"}, + XMLNs: "http://maven.apache.org/POM/4.0.0", + XMLNsXsi: "http://www.w3.org/2001/XMLSchema-instance", + XsiSchemaLocation: "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd", + ModelVersion: "4.0.0", + GroupID: "org.apache.camel.k.integration", + ArtifactID: "camel-k-integration", + Version: defaults.Version, + Properties: ctx.Request.Platform.Build.Properties, + DependencyManagement: maven.DependencyManagement{Dependencies: make([]maven.Dependency, 0)}, + Dependencies: make([]maven.Dependency, 0), } // + // DependencyManagement + // + + p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies, maven.Dependency{ + GroupID: "org.apache.camel", + ArtifactID: "camel-bom", + Version: ctx.Catalog.Version, + Type: "pom", + Scope: "import", + }) + + for _, d := range ctx.Request.Dependencies { + if strings.HasPrefix(d, "bom:") { + mid := strings.TrimPrefix(d, "bom:") + gav := strings.Replace(mid, "/", ":", -1) + + d, err := maven.ParseGAV(gav) + if err != nil { + return maven.Project{}, err + } + + p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies, maven.Dependency{ + GroupID: d.GroupID, + ArtifactID: d.ArtifactID, + Version: d.Version, + Type: "pom", + Scope: "import", + }) + } + } + + //p.DependencyManagement.Dependencies = dm + + // // Repositories // diff --git a/pkg/builder/builder_utils_test.go b/pkg/builder/builder_utils_test.go new file mode 100644 index 0000000..c68fd83 --- /dev/null +++ b/pkg/builder/builder_utils_test.go @@ -0,0 +1,77 @@ +/* +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 builder + +import ( + "testing" + + "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" + "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 TestNewProject(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", + "bom:my.company/my-artifact-1/1.0.0", + "bom:my.company/my-artifact-2/2.0.0", + }, + }, + } + + err = GenerateProject(&ctx) + assert.Nil(t, err) + + assert.Len(t, ctx.Project.DependencyManagement.Dependencies, 3) + assert.Contains(t, ctx.Project.DependencyManagement.Dependencies, maven.Dependency{ + GroupID: "org.apache.camel", + ArtifactID: "camel-bom", + Version: ctx.Catalog.Version, + Type: "pom", + Scope: "import", + }) + assert.Contains(t, ctx.Project.DependencyManagement.Dependencies, maven.Dependency{ + GroupID: "my.company", + ArtifactID: "my-artifact-1", + Version: "1.0.0", + Type: "pom", + Scope: "import", + }) + assert.Contains(t, ctx.Project.DependencyManagement.Dependencies, maven.Dependency{ + GroupID: "my.company", + ArtifactID: "my-artifact-2", + Version: "2.0.0", + Type: "pom", + Scope: "import", + }) +} diff --git a/pkg/builder/springboot/generator.go b/pkg/builder/springboot/generator.go index 7b9f9f4..4d95196 100644 --- a/pkg/builder/springboot/generator.go +++ b/pkg/builder/springboot/generator.go @@ -129,6 +129,8 @@ func GenerateProject(ctx *builder.Context) error { dependency := maven.NewDependency("org.apache.camel.k", artifactID, ctx.Request.RuntimeVersion) ctx.Project.AddDependency(dependency) + case strings.HasPrefix(d, "bom:"): + // no-op default: return fmt.Errorf("unknown dependency type: %s", d) }