You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/10/08 15:45:45 UTC

[GitHub] [camel-k] doru1004 opened a new pull request #1757: Add insepct sub-command. Add basic support for top-level dependendcies.

doru1004 opened a new pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757


   <!-- Description -->
   
   
   
   
   <!--
   Enter your extended release note in the below block. If the PR requires
   additional action from users switching to the new release, include the string
   "action required". If no release note is required, write "NONE". 
   
   You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
   the text is added to the right section of the release notes. 
   -->
   
   **Release Note**
   ```release-note
   kind/feature
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] doru1004 commented on pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
doru1004 commented on pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#issuecomment-707326551


   @lburgazzoli I think I addressed all the comments. Please let me know if further changes are required.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] doru1004 commented on pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
doru1004 commented on pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#issuecomment-713634857


   Absolutely, doing this right now. :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro merged pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
nicolaferraro merged pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] doru1004 commented on pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
doru1004 commented on pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#issuecomment-713660335


   That was the last of the changes, resources.go should be correctly updated now.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] lburgazzoli commented on a change in pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
lburgazzoli commented on a change in pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#discussion_r503353557



##########
File path: pkg/cmd/inspect.go
##########
@@ -0,0 +1,184 @@
+/*
+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 cmd
+
+import (
+	"errors"
+	"fmt"
+	"path"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/maven"
+	"github.com/scylladb/go-set/strset"
+	"github.com/spf13/cobra"
+)
+
+func newCmdInspect(rootCmdOptions *RootCmdOptions) (*cobra.Command, *inspectCmdOptions) {
+	options := inspectCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+
+	cmd := cobra.Command{
+		Use:     "inspect [files to inspect]",
+		Short:   "Generate dependencies list the given integration files.",
+		Long:    `Compute and emit the dependencies for a list of integration files.`,
+		PreRunE: decode(&options),
+		RunE: func(_ *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.run(args); err != nil {
+				fmt.Println(err.Error())
+			}
+
+			return nil
+		},
+	}
+
+	// TODO: support the following options:
+	cmd.Flags().Bool("all-dependencies", false, "Include both top level and transitive dependencies.")
+	cmd.Flags().String("dependencies-directory", "", "If set, directory will contain all integration dependencies.")
+	cmd.Flags().String("additional-dependencies", "", "Comma separated list of additional dependencies.")
+
+	return &cmd, &options
+}
+
+type inspectCmdOptions struct {
+	*RootCmdOptions
+	AllDependencies        bool   `mapstructure:"all-dependencies"`
+	DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+	AdditionalDependencies string `mapstructure:"additional-dependencies"`
+}
+
+func (command *inspectCmdOptions) validate(args []string) error {
+	// If no source files have been provided there is nothing to inspect.
+	if len(args) == 0 {
+		return errors.New("no integration files have been provided, nothing to inspect")
+	}
+
+	// Ensure source files exist.
+	for _, arg := range args {
+		// fmt.Printf("Validating file: %v\n", arg)
+		fileExists, err := util.FileExists(arg)
+
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !fileExists {
+			return errors.New("input file " + arg + " file does not exist")
+		}
+	}
+
+	// If provided, ensure that that the dependencies directory exists.
+	if command.DependenciesDirectory != "" {
+		dependenciesDirectoryExists, err := util.DirectoryExists(command.DependenciesDirectory)
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !dependenciesDirectoryExists {
+			return errors.New("input file " + command.DependenciesDirectory + " file does not exist")
+		}
+	}
+
+	// TODO: validate list of additional dependencies i.e. make sure that each dependency is
+	// in the correct format.
+
+	return nil
+}
+
+func (command *inspectCmdOptions) run(args []string) error {
+	// A Camel catalog is requiref for this operatio.
+	settings := ""
+	mvn := v1.MavenSpec{
+		LocalRepository: "",
+	}
+	runtime := v1.RuntimeSpec{
+		Version:  "1.3.0",
+		Provider: v1.RuntimeProviderMain,
+	}
+	providerDependencies := []maven.Dependency{}
+	catalog, err := camel.GenerateLocalCatalog(settings, mvn, runtime, providerDependencies)
+	if err != nil {
+		return err
+	}
+
+	// TODO: compression not supported for this command for now.
+	compression := false
+
+	// List of top-level dependencies.
+	dependencies := strset.New()
+
+	// Invoke the dependency inspector code for each source file.
+	for _, source := range args {
+		data, _, err := loadData(source, compression, compression)
+		if err != nil {
+			return err
+		}
+
+		sourceSpec := v1.SourceSpec{
+			DataSpec: v1.DataSpec{
+				Name:        path.Base(source),
+				Content:     data,
+				Compression: compression,
+			},
+		}
+
+		// Extract list of top-level dependencies.
+		metadata.Extract(catalog, sourceSpec)
+		meta := metadata.Extract(catalog, sourceSpec)
+		lang := sourceSpec.InferLanguage()
+
+		// add auto-detected dependencies
+		dependencies.Merge(meta.Dependencies)
+
+		for loader, v := range catalog.Loaders {
+			// add loader specific dependencies
+			if sourceSpec.Loader != "" && sourceSpec.Loader == loader {
+				dependencies.Add(fmt.Sprintf("mvn:%s/%s", v.GroupID, v.ArtifactID))
+
+				for _, d := range v.Dependencies {
+					dependencies.Add(fmt.Sprintf("mvn:%s/%s", d.GroupID, d.ArtifactID))
+				}
+			} else if sourceSpec.Loader == "" {
+				// add language specific dependencies
+				if util.StringSliceExists(v.Languages, string(lang)) {
+					dependencies.Add(fmt.Sprintf("mvn:%s/%s", v.GroupID, v.ArtifactID))
+
+					for _, d := range v.Dependencies {
+						dependencies.Add(fmt.Sprintf("mvn:%s/%s", d.GroupID, d.ArtifactID))
+					}
+				}
+			}
+		}
+	}
+
+	for _, dep := range dependencies.List() {
+		fmt.Printf("%v\n", dep)

Review comment:
       wonder if there should be a `--output` flag that could allow to have the dependencies listed as json/yaml output (for tooling)

##########
File path: pkg/cmd/inspect.go
##########
@@ -0,0 +1,184 @@
+/*
+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 cmd
+
+import (
+	"errors"
+	"fmt"
+	"path"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/maven"
+	"github.com/scylladb/go-set/strset"
+	"github.com/spf13/cobra"
+)
+
+func newCmdInspect(rootCmdOptions *RootCmdOptions) (*cobra.Command, *inspectCmdOptions) {
+	options := inspectCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+
+	cmd := cobra.Command{
+		Use:     "inspect [files to inspect]",
+		Short:   "Generate dependencies list the given integration files.",
+		Long:    `Compute and emit the dependencies for a list of integration files.`,
+		PreRunE: decode(&options),
+		RunE: func(_ *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.run(args); err != nil {
+				fmt.Println(err.Error())
+			}
+
+			return nil
+		},
+	}
+
+	// TODO: support the following options:
+	cmd.Flags().Bool("all-dependencies", false, "Include both top level and transitive dependencies.")
+	cmd.Flags().String("dependencies-directory", "", "If set, directory will contain all integration dependencies.")
+	cmd.Flags().String("additional-dependencies", "", "Comma separated list of additional dependencies.")
+
+	return &cmd, &options
+}
+
+type inspectCmdOptions struct {
+	*RootCmdOptions
+	AllDependencies        bool   `mapstructure:"all-dependencies"`
+	DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+	AdditionalDependencies string `mapstructure:"additional-dependencies"`
+}
+
+func (command *inspectCmdOptions) validate(args []string) error {
+	// If no source files have been provided there is nothing to inspect.
+	if len(args) == 0 {
+		return errors.New("no integration files have been provided, nothing to inspect")
+	}
+
+	// Ensure source files exist.
+	for _, arg := range args {
+		// fmt.Printf("Validating file: %v\n", arg)
+		fileExists, err := util.FileExists(arg)
+
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !fileExists {
+			return errors.New("input file " + arg + " file does not exist")
+		}
+	}
+
+	// If provided, ensure that that the dependencies directory exists.
+	if command.DependenciesDirectory != "" {
+		dependenciesDirectoryExists, err := util.DirectoryExists(command.DependenciesDirectory)
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !dependenciesDirectoryExists {
+			return errors.New("input file " + command.DependenciesDirectory + " file does not exist")
+		}
+	}
+
+	// TODO: validate list of additional dependencies i.e. make sure that each dependency is
+	// in the correct format.
+
+	return nil
+}
+
+func (command *inspectCmdOptions) run(args []string) error {
+	// A Camel catalog is requiref for this operatio.
+	settings := ""
+	mvn := v1.MavenSpec{
+		LocalRepository: "",
+	}
+	runtime := v1.RuntimeSpec{
+		Version:  "1.3.0",
+		Provider: v1.RuntimeProviderMain,
+	}
+	providerDependencies := []maven.Dependency{}
+	catalog, err := camel.GenerateLocalCatalog(settings, mvn, runtime, providerDependencies)

Review comment:
       A default catalog is embedded in the kamel binary so it should be possible to retrieve it without doing any generation (see [1]) and fall-back to catalog generation only if there's no match. 
   
   [1] https://github.com/apache/camel-k/blob/master/pkg/util/camel/catalog.go#L44-L46
   

##########
File path: pkg/cmd/inspect.go
##########
@@ -0,0 +1,184 @@
+/*
+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 cmd
+
+import (
+	"errors"
+	"fmt"
+	"path"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/maven"
+	"github.com/scylladb/go-set/strset"
+	"github.com/spf13/cobra"
+)
+
+func newCmdInspect(rootCmdOptions *RootCmdOptions) (*cobra.Command, *inspectCmdOptions) {
+	options := inspectCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+
+	cmd := cobra.Command{
+		Use:     "inspect [files to inspect]",
+		Short:   "Generate dependencies list the given integration files.",
+		Long:    `Compute and emit the dependencies for a list of integration files.`,
+		PreRunE: decode(&options),
+		RunE: func(_ *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.run(args); err != nil {
+				fmt.Println(err.Error())
+			}
+
+			return nil
+		},
+	}
+
+	// TODO: support the following options:
+	cmd.Flags().Bool("all-dependencies", false, "Include both top level and transitive dependencies.")
+	cmd.Flags().String("dependencies-directory", "", "If set, directory will contain all integration dependencies.")
+	cmd.Flags().String("additional-dependencies", "", "Comma separated list of additional dependencies.")
+
+	return &cmd, &options
+}
+
+type inspectCmdOptions struct {
+	*RootCmdOptions
+	AllDependencies        bool   `mapstructure:"all-dependencies"`
+	DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+	AdditionalDependencies string `mapstructure:"additional-dependencies"`
+}
+
+func (command *inspectCmdOptions) validate(args []string) error {
+	// If no source files have been provided there is nothing to inspect.
+	if len(args) == 0 {
+		return errors.New("no integration files have been provided, nothing to inspect")
+	}
+
+	// Ensure source files exist.
+	for _, arg := range args {
+		// fmt.Printf("Validating file: %v\n", arg)
+		fileExists, err := util.FileExists(arg)
+
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !fileExists {
+			return errors.New("input file " + arg + " file does not exist")
+		}
+	}
+
+	// If provided, ensure that that the dependencies directory exists.
+	if command.DependenciesDirectory != "" {
+		dependenciesDirectoryExists, err := util.DirectoryExists(command.DependenciesDirectory)
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !dependenciesDirectoryExists {
+			return errors.New("input file " + command.DependenciesDirectory + " file does not exist")
+		}
+	}
+
+	// TODO: validate list of additional dependencies i.e. make sure that each dependency is
+	// in the correct format.
+
+	return nil
+}
+
+func (command *inspectCmdOptions) run(args []string) error {
+	// A Camel catalog is requiref for this operatio.
+	settings := ""
+	mvn := v1.MavenSpec{
+		LocalRepository: "",
+	}
+	runtime := v1.RuntimeSpec{
+		Version:  "1.3.0",
+		Provider: v1.RuntimeProviderMain,
+	}
+	providerDependencies := []maven.Dependency{}
+	catalog, err := camel.GenerateLocalCatalog(settings, mvn, runtime, providerDependencies)
+	if err != nil {
+		return err
+	}
+
+	// TODO: compression not supported for this command for now.
+	compression := false
+
+	// List of top-level dependencies.
+	dependencies := strset.New()
+
+	// Invoke the dependency inspector code for each source file.
+	for _, source := range args {
+		data, _, err := loadData(source, compression, compression)
+		if err != nil {
+			return err
+		}
+
+		sourceSpec := v1.SourceSpec{
+			DataSpec: v1.DataSpec{
+				Name:        path.Base(source),
+				Content:     data,
+				Compression: compression,
+			},
+		}
+
+		// Extract list of top-level dependencies.
+		metadata.Extract(catalog, sourceSpec)
+		meta := metadata.Extract(catalog, sourceSpec)
+		lang := sourceSpec.InferLanguage()
+
+		// add auto-detected dependencies
+		dependencies.Merge(meta.Dependencies)
+
+		for loader, v := range catalog.Loaders {
+			// add loader specific dependencies
+			if sourceSpec.Loader != "" && sourceSpec.Loader == loader {
+				dependencies.Add(fmt.Sprintf("mvn:%s/%s", v.GroupID, v.ArtifactID))
+
+				for _, d := range v.Dependencies {
+					dependencies.Add(fmt.Sprintf("mvn:%s/%s", d.GroupID, d.ArtifactID))
+				}
+			} else if sourceSpec.Loader == "" {
+				// add language specific dependencies
+				if util.StringSliceExists(v.Languages, string(lang)) {
+					dependencies.Add(fmt.Sprintf("mvn:%s/%s", v.GroupID, v.ArtifactID))
+
+					for _, d := range v.Dependencies {
+						dependencies.Add(fmt.Sprintf("mvn:%s/%s", d.GroupID, d.ArtifactID))
+					}
+				}
+			}
+		}
+	}

Review comment:
       wonder if this block could be extricated in an utility method so so it won't break in case the logic changes 

##########
File path: pkg/util/util.go
##########
@@ -219,6 +219,15 @@ func FileExists(name string) (bool, error) {
 	return !info.IsDir(), err
 }
 
+// DirectoryExists --
+func DirectoryExists(directory string) (bool, error) {
+	info, err := os.Stat(directory)
+	if os.IsNotExist(err) {
+		return false, nil
+	}
+	return info.IsDir(), err

Review comment:
       if err != nil, then info could be nil so maybe better to check this case




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] lburgazzoli commented on a change in pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
lburgazzoli commented on a change in pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#discussion_r508643609



##########
File path: pkg/cmd/inspect.go
##########
@@ -0,0 +1,207 @@
+/*
+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 cmd
+
+import (
+	"errors"
+	"fmt"
+	"path"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/maven"
+	"github.com/scylladb/go-set/strset"
+	"github.com/spf13/cobra"
+)
+
+func newCmdInspect(rootCmdOptions *RootCmdOptions) (*cobra.Command, *inspectCmdOptions) {
+	options := inspectCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+
+	cmd := cobra.Command{
+		Use:     "inspect [files to inspect]",
+		Short:   "Generate dependencies list the given integration files.",
+		Long:    `Compute and emit the dependencies for a list of integration files.`,
+		PreRunE: decode(&options),
+		RunE: func(_ *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.run(args); err != nil {
+				fmt.Println(err.Error())
+			}
+
+			return nil
+		},
+	}
+
+	cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
+	// TODO: support the following options:
+	cmd.Flags().Bool("all-dependencies", false, "Include both top level and transitive dependencies.")
+	cmd.Flags().String("dependencies-directory", "", "If set, directory will contain all integration dependencies.")
+	cmd.Flags().String("additional-dependencies", "", "Comma separated list of additional dependencies.")
+
+	return &cmd, &options
+}
+
+type inspectCmdOptions struct {
+	*RootCmdOptions
+	AllDependencies        bool   `mapstructure:"all-dependencies"`
+	OutputFormat           string `mapstructure:"output"`
+	DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+	AdditionalDependencies string `mapstructure:"additional-dependencies"`
+}
+
+func (command *inspectCmdOptions) validate(args []string) error {
+	// If no source files have been provided there is nothing to inspect.
+	if len(args) == 0 {
+		return errors.New("no integration files have been provided, nothing to inspect")
+	}
+
+	// Ensure source files exist.
+	for _, arg := range args {
+		// fmt.Printf("Validating file: %v\n", arg)
+		fileExists, err := util.FileExists(arg)
+
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !fileExists {
+			return errors.New("input file " + arg + " file does not exist")
+		}
+	}
+
+	// If provided, ensure that that the dependencies directory exists.
+	if command.DependenciesDirectory != "" {
+		dependenciesDirectoryExists, err := util.DirectoryExists(command.DependenciesDirectory)
+		// Report any error.
+		if err != nil {
+			return err
+		}
+
+		// Signal file not found.
+		if !dependenciesDirectoryExists {
+			return errors.New("input file " + command.DependenciesDirectory + " file does not exist")
+		}
+	}
+
+	// TODO: validate list of additional dependencies i.e. make sure that each dependency is
+	// in the correct format.
+
+	return nil
+}
+
+func (command *inspectCmdOptions) run(args []string) error {
+	// Attempt to reuse existing Camel catalog if one is present.
+	catalog, err := camel.MainCatalog()
+	if err != nil {
+		return err
+	}
+
+	// Generate catalog if one was not found.
+	if catalog == nil {
+		catalog, err = generateCatalog()
+		if err != nil {
+			return err
+		}
+	}
+
+	// TODO: compression not supported for this command for now.
+	compression := false
+
+	// List of top-level dependencies.
+	dependencies := strset.New()
+
+	// Invoke the dependency inspector code for each source file.
+	for _, source := range args {
+		data, _, err := loadData(source, compression, compression)
+		if err != nil {
+			return err
+		}
+
+		sourceSpec := v1.SourceSpec{
+			DataSpec: v1.DataSpec{
+				Name:        path.Base(source),
+				Content:     data,
+				Compression: compression,
+			},
+		}
+
+		// Extract list of top-level dependencies.
+		dependencies.Merge(trait.AddSourceDependencies(sourceSpec, catalog))
+	}
+
+	if command.OutputFormat != "" {
+		err := printDependencies(command.OutputFormat, dependencies)
+		if err != nil {
+			return err
+		}
+	} else {
+		// Print output in text form.
+		for _, dep := range dependencies.List() {
+			fmt.Printf("%v\n", dep)
+		}
+	}
+
+	return nil
+}
+
+func generateCatalog() (*camel.RuntimeCatalog, error) {
+	// A Camel catalog is requiref for this operatio.
+	settings := ""
+	mvn := v1.MavenSpec{
+		LocalRepository: "",
+	}
+	runtime := v1.RuntimeSpec{
+		Version:  "1.3.0",

Review comment:
       Guess this version can be taken from: https://github.com/apache/camel-k/blob/master/pkg/util/defaults/defaults.go#L29




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#issuecomment-713633900


   > @lburgazzoli just resolved all additional comments.
   
   Thanks @doru1004 ! Can you rebase on master so we can merge this? there are some conflicts.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] lburgazzoli commented on a change in pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
lburgazzoli commented on a change in pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#discussion_r508645637



##########
File path: pkg/cmd/inspect.go
##########
@@ -0,0 +1,207 @@
+/*
+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 cmd
+
+import (
+	"errors"
+	"fmt"
+	"path"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/maven"
+	"github.com/scylladb/go-set/strset"
+	"github.com/spf13/cobra"
+)
+
+func newCmdInspect(rootCmdOptions *RootCmdOptions) (*cobra.Command, *inspectCmdOptions) {
+	options := inspectCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+
+	cmd := cobra.Command{
+		Use:     "inspect [files to inspect]",
+		Short:   "Generate dependencies list the given integration files.",
+		Long:    `Compute and emit the dependencies for a list of integration files.`,
+		PreRunE: decode(&options),
+		RunE: func(_ *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.run(args); err != nil {
+				fmt.Println(err.Error())
+			}
+
+			return nil
+		},
+	}
+
+	cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
+	// TODO: support the following options:
+	cmd.Flags().Bool("all-dependencies", false, "Include both top level and transitive dependencies.")
+	cmd.Flags().String("dependencies-directory", "", "If set, directory will contain all integration dependencies.")
+	cmd.Flags().String("additional-dependencies", "", "Comma separated list of additional dependencies.")
+
+	return &cmd, &options
+}
+
+type inspectCmdOptions struct {
+	*RootCmdOptions
+	AllDependencies        bool   `mapstructure:"all-dependencies"`
+	OutputFormat           string `mapstructure:"output"`
+	DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+	AdditionalDependencies string `mapstructure:"additional-dependencies"`

Review comment:
       looks like `AllDependencies`, `DependenciesDirectory`, `AdditionalDependencies` are not taken into account at this stage, can we remove them ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] doru1004 commented on pull request #1757: Add inspect sub-command with basic support

Posted by GitBox <gi...@apache.org>.
doru1004 commented on pull request #1757:
URL: https://github.com/apache/camel-k/pull/1757#issuecomment-713034982


   @lburgazzoli just resolved all additional comments.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org