You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/11/26 08:34:10 UTC
[camel-k] branch master updated: initial support for custom maven
repositories
This is an automated email from the ASF dual-hosted git repository.
nferraro 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 ba28129 initial support for custom maven repositories
ba28129 is described below
commit ba281296fb6a09d412436b7fd97345ef9d9dfcf7
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Fri Nov 23 18:36:12 2018 +0100
initial support for custom maven repositories
---
pkg/apis/camel/v1alpha1/types.go | 2 +
pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 47 ++++++++++++++++--------
pkg/builder/builder_steps.go | 17 +++++++++
pkg/builder/builder_types.go | 1 +
pkg/client/cmd/context_create.go | 3 ++
pkg/client/cmd/run.go | 3 ++
pkg/stub/action/context/build.go | 1 +
pkg/stub/action/integration/build.go | 2 +
pkg/util/maven/maven_project.go | 47 +++++++++++++++++++++---
pkg/util/maven/maven_test.go | 44 +++++++++++++++++-----
10 files changed, 138 insertions(+), 29 deletions(-)
diff --git a/pkg/apis/camel/v1alpha1/types.go b/pkg/apis/camel/v1alpha1/types.go
index 691b528..acb2270 100644
--- a/pkg/apis/camel/v1alpha1/types.go
+++ b/pkg/apis/camel/v1alpha1/types.go
@@ -56,6 +56,7 @@ type IntegrationSpec struct {
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
+ Repositories []string `json:"repositories,omitempty"`
}
// AddSource --
@@ -162,6 +163,7 @@ type IntegrationContextSpec struct {
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
+ Repositories []string `json:"repositories,omitempty"`
}
// IntegrationContextStatus --
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 4aa466b..9ae3d88 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -154,11 +154,23 @@ func (in *IntegrationContextSpec) DeepCopyInto(out *IntegrationContextSpec) {
*out = make([]string, len(*in))
copy(*out, *in)
}
+ if in.Traits != nil {
+ in, out := &in.Traits, &out.Traits
+ *out = make(map[string]IntegrationTraitSpec, len(*in))
+ for key, val := range *in {
+ (*out)[key] = *val.DeepCopy()
+ }
+ }
if in.Configuration != nil {
in, out := &in.Configuration, &out.Configuration
*out = make([]ConfigurationSpec, len(*in))
copy(*out, *in)
}
+ if in.Repositories != nil {
+ in, out := &in.Repositories, &out.Repositories
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
return
}
@@ -337,45 +349,50 @@ func (in *IntegrationPlatformStatus) DeepCopy() *IntegrationPlatformStatus {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (is *IntegrationSpec) DeepCopyInto(out *IntegrationSpec) {
- *out = *is
- if is.Replicas != nil {
- in, out := &is.Replicas, &out.Replicas
+func (in *IntegrationSpec) DeepCopyInto(out *IntegrationSpec) {
+ *out = *in
+ if in.Replicas != nil {
+ in, out := &in.Replicas, &out.Replicas
*out = new(int32)
**out = **in
}
- if is.Sources != nil {
- in, out := &is.Sources, &out.Sources
+ if in.Sources != nil {
+ in, out := &in.Sources, &out.Sources
*out = make([]SourceSpec, len(*in))
copy(*out, *in)
}
- if is.Dependencies != nil {
- in, out := &is.Dependencies, &out.Dependencies
+ if in.Dependencies != nil {
+ in, out := &in.Dependencies, &out.Dependencies
*out = make([]string, len(*in))
copy(*out, *in)
}
- if is.Traits != nil {
- in, out := &is.Traits, &out.Traits
+ if in.Traits != nil {
+ in, out := &in.Traits, &out.Traits
*out = make(map[string]IntegrationTraitSpec, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
- if is.Configuration != nil {
- in, out := &is.Configuration, &out.Configuration
+ if in.Configuration != nil {
+ in, out := &in.Configuration, &out.Configuration
*out = make([]ConfigurationSpec, len(*in))
copy(*out, *in)
}
+ if in.Repositories != nil {
+ in, out := &in.Repositories, &out.Repositories
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationSpec.
-func (is *IntegrationSpec) DeepCopy() *IntegrationSpec {
- if is == nil {
+func (in *IntegrationSpec) DeepCopy() *IntegrationSpec {
+ if in == nil {
return nil
}
out := new(IntegrationSpec)
- is.DeepCopyInto(out)
+ in.DeepCopyInto(out)
return out
}
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index b339d1d..b29e81e 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -73,6 +73,23 @@ func GenerateProject(ctx *Context) error {
}
//
+ // Repositories
+ //
+
+ ctx.Project.Repositories = maven.Repositories{
+ 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.Repositories = append(ctx.Project.Repositories.Repositories, repo)
+ }
+
+ //
// set-up dependencies
//
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index 000425f..e23dfc0 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -95,6 +95,7 @@ type Request struct {
Platform v1alpha1.IntegrationPlatformSpec
Code v1alpha1.SourceSpec
Dependencies []string
+ Repositories []string
Steps []Step
BuildDir string
}
diff --git a/pkg/client/cmd/context_create.go b/pkg/client/cmd/context_create.go
index 739fc8d..2b2b2d2 100644
--- a/pkg/client/cmd/context_create.go
+++ b/pkg/client/cmd/context_create.go
@@ -53,6 +53,7 @@ func newContextCreateCmd(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringSliceVarP(&impl.properties, "property", "p", nil, "Add a camel property")
cmd.Flags().StringSliceVar(&impl.configmaps, "configmap", nil, "Add a ConfigMap")
cmd.Flags().StringSliceVar(&impl.secrets, "secret", nil, "Add a Secret")
+ cmd.Flags().StringSliceVar(&impl.Repositories, "repository", nil, "Add a maven repository")
// completion support
configureKnownCompletions(&cmd)
@@ -68,6 +69,7 @@ type contextCreateCommand struct {
properties []string
configmaps []string
secrets []string
+ Repositories []string
}
func (command *contextCreateCommand) validateArgs(cmd *cobra.Command, args []string) error {
@@ -97,6 +99,7 @@ func (command *contextCreateCommand) run(cmd *cobra.Command, args []string) erro
ctx.Spec = v1alpha1.IntegrationContextSpec{
Dependencies: make([]string, 0, len(command.dependencies)),
Configuration: make([]v1alpha1.ConfigurationSpec, 0),
+ Repositories: command.Repositories,
}
for _, item := range command.dependencies {
diff --git a/pkg/client/cmd/run.go b/pkg/client/cmd/run.go
index 490adfe..3a1f05c 100644
--- a/pkg/client/cmd/run.go
+++ b/pkg/client/cmd/run.go
@@ -77,6 +77,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringSliceVarP(&options.Properties, "property", "p", nil, "Add a camel property")
cmd.Flags().StringSliceVar(&options.ConfigMaps, "configmap", nil, "Add a ConfigMap")
cmd.Flags().StringSliceVar(&options.Secrets, "secret", nil, "Add a Secret")
+ cmd.Flags().StringSliceVar(&options.Repositories, "repository", nil, "Add a maven repository")
cmd.Flags().BoolVar(&options.Logs, "logs", false, "Print integration logs")
cmd.Flags().BoolVar(&options.Sync, "sync", false, "Synchronize the local source file with the cluster, republishing at each change")
cmd.Flags().BoolVar(&options.Dev, "dev", false, "Enable Dev mode (equivalent to \"-w --logs --sync\")")
@@ -100,6 +101,7 @@ type runCmdOptions struct {
Properties []string
ConfigMaps []string
Secrets []string
+ Repositories []string
Wait bool
Logs bool
Sync bool
@@ -277,6 +279,7 @@ func (o *runCmdOptions) updateIntegrationCode(sources []string) (*v1alpha1.Integ
Dependencies: make([]string, 0, len(o.Dependencies)),
Context: o.IntegrationContext,
Configuration: make([]v1alpha1.ConfigurationSpec, 0),
+ Repositories: o.Repositories,
Profile: v1alpha1.TraitProfileByName(o.Profile),
},
}
diff --git a/pkg/stub/action/context/build.go b/pkg/stub/action/context/build.go
index 2b85770..4734bbc 100644
--- a/pkg/stub/action/context/build.go
+++ b/pkg/stub/action/context/build.go
@@ -64,6 +64,7 @@ func (action *buildAction) Handle(context *v1alpha1.IntegrationContext) error {
r := builder.Request{
Meta: context.ObjectMeta,
Dependencies: context.Spec.Dependencies,
+ Repositories: context.Spec.Repositories,
Steps: env.Steps,
Platform: env.Platform.Spec,
}
diff --git a/pkg/stub/action/integration/build.go b/pkg/stub/action/integration/build.go
index e107642..02387ce 100644
--- a/pkg/stub/action/integration/build.go
+++ b/pkg/stub/action/integration/build.go
@@ -19,6 +19,7 @@ package integration
import (
"fmt"
+
"github.com/sirupsen/logrus"
"github.com/apache/camel-k/pkg/util"
@@ -117,6 +118,7 @@ func (action *buildAction) Handle(integration *v1alpha1.Integration) error {
// Set the context to have the same dependencies as the integrations
platformCtx.Spec = v1alpha1.IntegrationContextSpec{
Dependencies: integration.Spec.Dependencies,
+ Repositories: integration.Spec.Repositories,
}
if err := sdk.Create(&platformCtx); err != nil {
diff --git a/pkg/util/maven/maven_project.go b/pkg/util/maven/maven_project.go
index 2a04968..5c7ec5d 100644
--- a/pkg/util/maven/maven_project.go
+++ b/pkg/util/maven/maven_project.go
@@ -19,6 +19,7 @@ package maven
import (
"encoding/xml"
+ "strings"
)
// Project represent a maven project
@@ -106,22 +107,58 @@ type PluginRepositories struct {
// Repository --
type Repository struct {
ID string `xml:"id"`
- Name string `xml:"name"`
+ Name string `xml:"name,omitempty"`
URL string `xml:"url"`
- Snapshots Snapshots `xml:"snapshots"`
- Releases Releases `xml:"releases"`
+ Snapshots Snapshots `xml:"snapshots,omitempty"`
+ Releases Releases `xml:"releases,omitempty"`
+}
+
+//
+// NewRepository parse the given repo url ang generated the related struct.
+//
+// The repository can be customized by appending @instruction to the repository
+// uri, as example:
+//
+// http://my-nexus:8081/repository/publicc@id=my-repo@snapshots
+//
+// Will enable snapshots and sets the repo it to my-repo
+//
+func NewRepository(repo string) Repository {
+ r := Repository{
+ URL: repo,
+ Releases: Releases{
+ Enabled: true,
+ },
+ Snapshots: Snapshots{
+ Enabled: false,
+ },
+ }
+
+ if idx := strings.Index(repo, "@"); idx != -1 {
+ r.URL = repo[:idx]
+
+ for _, attribute := range strings.Split(repo[idx+1:], "@") {
+ if attribute == "snapshots" {
+ r.Snapshots.Enabled = true
+ } else if strings.HasPrefix(attribute, "id=") {
+ r.ID = attribute[3:]
+ }
+ }
+ }
+
+ return r
}
// Snapshots --
type Snapshots struct {
Enabled bool `xml:"enabled"`
- UpdatePolicy string `xml:"updatePolicy"`
+ UpdatePolicy string `xml:"updatePolicy,omitempty"`
}
// Releases --
type Releases struct {
Enabled bool `xml:"enabled"`
- UpdatePolicy string `xml:"updatePolicy"`
+ UpdatePolicy string `xml:"updatePolicy,omitempty"`
}
// Build --
diff --git a/pkg/util/maven/maven_test.go b/pkg/util/maven/maven_test.go
index e7f5685..59e43cb 100644
--- a/pkg/util/maven/maven_test.go
+++ b/pkg/util/maven/maven_test.go
@@ -51,11 +51,9 @@ const expectedPom = `<?xml version="1.0" encoding="UTF-8"?>
<repositories>
<repository>
<id>central</id>
- <name></name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
- <updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
@@ -66,11 +64,9 @@ const expectedPom = `<?xml version="1.0" encoding="UTF-8"?>
<pluginRepositories>
<pluginRepository>
<id>central</id>
- <name></name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
- <updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
@@ -118,8 +114,7 @@ func TestPomGeneration(t *testing.T) {
ID: "central",
URL: "https://repo.maven.apache.org/maven2",
Snapshots: Snapshots{
- Enabled: false,
- UpdatePolicy: "never",
+ Enabled: false,
},
Releases: Releases{
Enabled: true,
@@ -134,8 +129,7 @@ func TestPomGeneration(t *testing.T) {
ID: "central",
URL: "https://repo.maven.apache.org/maven2",
Snapshots: Snapshots{
- Enabled: false,
- UpdatePolicy: "never",
+ Enabled: false,
},
Releases: Releases{
Enabled: true,
@@ -151,7 +145,7 @@ func TestPomGeneration(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, pom)
- assert.Equal(t, pom, expectedPom)
+ assert.Equal(t, expectedPom, pom)
}
func TestParseSimpleGAV(t *testing.T) {
@@ -186,3 +180,35 @@ func TestParseGAVWithClassifierAndType(t *testing.T) {
assert.Equal(t, dep.Type, "war")
assert.Equal(t, dep.Classifier, "test")
}
+
+func TestNewRepository(t *testing.T) {
+ r := NewRepository("http://nexus/public")
+ assert.Equal(t, "", r.ID)
+ assert.Equal(t, "http://nexus/public", r.URL)
+ assert.True(t, r.Releases.Enabled)
+ assert.False(t, r.Snapshots.Enabled)
+}
+
+func TestNewRepositoryWithSnapshots(t *testing.T) {
+ r := NewRepository("http://nexus/public@snapshots")
+ assert.Equal(t, "", r.ID)
+ assert.Equal(t, "http://nexus/public", r.URL)
+ assert.True(t, r.Releases.Enabled)
+ assert.True(t, r.Snapshots.Enabled)
+}
+
+func TestNewRepositoryWithSnapshotsAndID(t *testing.T) {
+ r := NewRepository("http://nexus/public@snapshots@id=test")
+ assert.Equal(t, "test", r.ID)
+ assert.Equal(t, "http://nexus/public", r.URL)
+ assert.True(t, r.Releases.Enabled)
+ assert.True(t, r.Snapshots.Enabled)
+}
+
+func TestNewRepositoryWithID(t *testing.T) {
+ r := NewRepository("http://nexus/public@id=test")
+ assert.Equal(t, "test", r.ID)
+ assert.Equal(t, "http://nexus/public", r.URL)
+ assert.True(t, r.Releases.Enabled)
+ assert.False(t, r.Snapshots.Enabled)
+}