Skip to content

Commit

Permalink
Allow to configure the location fo the local maven repo #358
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Jan 23, 2019
1 parent f7714fe commit dbc8a6c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions deploy/platform-cr.yaml
Expand Up @@ -8,3 +8,4 @@ spec:
build:
camelVersion: "2.23.1"
baseImage: "fabric8/s2i-java:3.0-java8"
localRepository: "/tmp/artifacts/m2"
1 change: 1 addition & 0 deletions deploy/resources.go

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

1 change: 1 addition & 0 deletions pkg/apis/camel/v1alpha1/integrationplatform_types.go
Expand Up @@ -78,6 +78,7 @@ type IntegrationPlatformBuildSpec struct {
CamelVersion string `json:"camelVersion,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
LocalRepository string `json:"localRepository,omitempty"`
Repositories []string `json:"repositories,omitempty"`
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/builder/builder_steps.go
Expand Up @@ -111,9 +111,11 @@ func ComputeDependencies(ctx *Context) error {
return err
}

goal := fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-dependency-list", version.Version)
opts := make([]string, 0, 2)
opts = append(opts, maven.ExtraOptions(ctx.Request.Platform.Build)...)
opts = append(opts, fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-dependency-list", version.Version))

err = maven.Run(p, goal)
err = maven.Run(p, opts...)
if err != nil {
return errors.Wrap(err, "failure while determining classpath")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/install.go
Expand Up @@ -52,6 +52,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringVar(&impl.organization, "organization", "", "A organization on the Docker registry that can be used to publish images")
cmd.Flags().StringVar(&impl.pushSecret, "push-secret", "", "A secret used to push images to the Docker registry")
cmd.Flags().StringSliceVar(&impl.repositories, "repository", nil, "Add a maven repository")
cmd.Flags().StringVar(&impl.localRepository, "local-repository", "", "Location of the local maven repository")
cmd.Flags().StringSliceVarP(&impl.properties, "property", "p", nil, "Add a camel property")
cmd.Flags().StringVar(&impl.camelVersion, "camel-version", "", "Set the camel version")
cmd.Flags().StringVar(&impl.baseImage, "base-image", "", "Set the base image used to run integrations")
Expand Down Expand Up @@ -81,6 +82,7 @@ type installCmdOptions struct {
pushSecret string
camelVersion string
baseImage string
localRepository string
repositories []string
properties []string
contexts []string
Expand Down Expand Up @@ -140,6 +142,9 @@ func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error {
}
}
}
if o.localRepository != "" {
platform.Spec.Build.LocalRepository = o.localRepository
}
if len(o.repositories) > 0 {
platform.Spec.Build.Repositories = o.repositories
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/trait/rest.go
Expand Up @@ -99,11 +99,13 @@ func (t *restTrait) Apply(e *Environment) error {
return err
}

goal := fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-rest-xml", version.Version)
iArg := "-Dopenapi.spec=" + in
oArg := "-Ddsl.out=" + out
opts := make([]string, 0, 4)
opts = append(opts, maven.ExtraOptions(e.Platform.Spec.Build)...)
opts = append(opts, fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-rest-xml", version.Version))
opts = append(opts, "-Dopenapi.spec="+in)
opts = append(opts, "-Ddsl.out="+out)

if err := maven.Run(tmpDir, goal, iArg, oArg); err != nil {
if err := maven.Run(tmpDir, opts...); err != nil {
return err
}

Expand Down
15 changes: 6 additions & 9 deletions pkg/util/maven/maven.go
Expand Up @@ -80,11 +80,7 @@ func Run(buildDir string, args ...string) error {
"logger": "maven",
})

cmdArgs := make([]string, 0, 1+len(args))
cmdArgs = append(cmdArgs, extraOptions())
cmdArgs = append(cmdArgs, args...)

cmd := exec.Command(mvnCmd, cmdArgs...)
cmd := exec.Command(mvnCmd, args...)
cmd.Dir = buildDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down Expand Up @@ -126,9 +122,10 @@ func ParseGAV(gav string) (Dependency, error) {
return dep, nil
}

func extraOptions() string {
if _, err := os.Stat("/tmp/artifacts/m2"); err == nil {
return "-Dmaven.repo.local=/tmp/artifacts/m2"
// ExtraOptions --
func ExtraOptions(spec v1alpha1.IntegrationPlatformBuildSpec) []string {
if _, err := os.Stat(spec.LocalRepository); err == nil {
return []string{"-Dmaven.repo.local=" + spec.LocalRepository}
}
return "-Dcamel.noop=true"
return []string{"-Dcamel.noop=true"}
}

0 comments on commit dbc8a6c

Please sign in to comment.