Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 67584a843c18b8d7fb8ea2d83d28fdd6bea350fe
Merge: 986d24e 7627037
Author: Emily McMullan <[email protected]>
Date:   Mon Sep 18 17:07:41 2023 -0400

    Merge branch 'main' of https://github.com/konveyor-ecosystem/kantra into json-output

commit 986d24ef68f228615e6c2f3d742e4777d761f61c
Author: Emily McMullan <[email protected]>
Date:   Mon Sep 18 16:56:57 2023 -0400

    Squashed commit of the following:

    commit 70c4efd
    Author: Shawn Hurley <[email protected]>
    Date:   Mon Sep 18 08:11:39 2023 -0400

        :bug: fixing ci with latest analyzer-lsp (#68)

        Signed-off-by: Shawn Hurley <[email protected]>
        Signed-off-by: Emily McMullan <[email protected]>

    commit 4ae7388
    Author: Pranav Gaikwad <[email protected]>
    Date:   Thu Sep 14 16:07:46 2023 -0400

        :ghost: script to replace name & image (#64)

        Signed-off-by: Pranav Gaikwad <[email protected]>
        Signed-off-by: Emily McMullan <[email protected]>

    commit 55ba073
    Author: Emily McMullan <[email protected]>
    Date:   Thu Sep 14 16:07:37 2023 -0400

        add examples to readme (#66)

        Signed-off-by: Emily McMullan <[email protected]>

    commit d26973c
    Author: Savitha Raghunathan <[email protected]>
    Date:   Thu Sep 14 08:28:19 2023 -0400

        Create bug.yaml (#65)

        Signed-off-by: Emily McMullan <[email protected]>

    commit 5f87ca9
    Author: Emily McMullan <[email protected]>
    Date:   Wed Sep 13 13:31:30 2023 -0400

        add json output flag

        Signed-off-by: Emily McMullan <[email protected]>

commit 7627037
Author: Shawn Hurley <[email protected]>
Date:   Mon Sep 18 08:11:39 2023 -0400

    :bug: fixing ci with latest analyzer-lsp (#68)

    Signed-off-by: Shawn Hurley <[email protected]>

commit 437a34a
Author: Pranav Gaikwad <[email protected]>
Date:   Thu Sep 14 16:07:46 2023 -0400

    :ghost: script to replace name & image (#64)

    Signed-off-by: Pranav Gaikwad <[email protected]>

commit 423beaa
Author: Emily McMullan <[email protected]>
Date:   Thu Sep 14 16:07:37 2023 -0400

    add examples to readme (#66)
  • Loading branch information
eemcmullan committed Sep 18, 2023
1 parent 4a12b5c commit 485a542
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 85 deletions.
66 changes: 59 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Kantra is an experimental CLI that unifies analysis and transformation capabilities of Konveyor.

## Installation
### Linux
The easiest way to install Kantra is to get it via the container image. To download latest container image, run:

Easiest way to install Kantra is to get it via the container image. To download latest container image, run:
### Linux

```sh
podman pull quay.io/konveyor/kantra:latest && podman run --name kantra-download quay.io/konveyor/kantra:latest 1> /dev/null 2> /dev/null && podman cp kantra-download:/usr/local/bin/kantra . && podman rm kantra-download
Expand All @@ -25,12 +25,19 @@ Ensure that we use the connection to the VM `<vm_name>` we created earlier by de
podman system connection default <vm_name>
```


```sh
podman pull quay.io/konveyor/kantra:latest && podman run --name kantra-download quay.io/konveyor/kantra:latest 1> /dev/null 2> /dev/null && podman cp kantra-download:/usr/local/bin/darwin-kantra kantra && podman rm kantra-download
```

This will copy the binary into your current working directory. To make it available system-wide, run:
### Windows

```sh
podman pull quay.io/konveyor/kantra:latest && podman run --name kantra-download quay.io/konveyor/kantra:latest 1> /dev/null 2> /dev/null && podman cp kantra-download:/usr/local/bin/windows-kantra kantra && podman rm kantra-download
```

---

The above will copy the binary into your current directory. Move it to PATH for system-wide use:

```sh
sudo mv ./kantra /usr/local/bin/
Expand Down Expand Up @@ -70,7 +77,7 @@ Use "kantra [command] --help" for more information about a command.

### Analyze

Analyze allows running source code and binary analysis using analyzer-lsp.
Analyze allows running source code and binary analysis using [analyzer-lsp](https://github.com/konveyor/analyzer-lsp)

To run analysis on application source code, run:

Expand All @@ -90,6 +97,7 @@ Flags:
--analyze-known-libraries analyze known open-source libraries
-h, --help help for analyze
-i, --input string path to application source code or a binary
--json-output create analysis and dependency output as json
--list-sources list rules for available migration sources
--list-targets list rules for available migration targets
-m, --mode string analysis mode. Must be one of 'full' or 'source-only' (default "full")
Expand Down Expand Up @@ -129,7 +137,7 @@ Use "kantra transform [command] --help" for more information about a command.

#### OpenRewrite

`openrewrite` subcommand allows running OpenRewrite recipes on source code.
`openrewrite` subcommand allows running [OpenRewrite](https://docs.openrewrite.org/) recipes on source code.


```sh
Expand Down Expand Up @@ -157,7 +165,7 @@ kantra transform openrewrite --input=<path/to/source/code> --target=<exactly_one

#### Rules

`rules` subcommand allows converting Windup XML rules to analyzer-lsp YAML rules.
`rules` subcommand allows converting Windup XML rules to analyzer-lsp YAML rules using [windup-shim](https://github.com/konveyor/windup-shim)

```sh
Convert XML rules to YAML
Expand All @@ -180,6 +188,50 @@ To run `transform rules` on application source code, run:
kantra transform rules --input=<path/to/xmlrules> --output=<path/to/output/dir>
```

## Quick Demos

Once you have kantra installed, these examples will help you run both an
analyze and a transform command.

### Analyze

- Get the example application to run analysis on
`git clone https://github.com/konveyor/example-applications`

- List available target technologies
`kantra analyze --list-targets`

- Run analysis with a specified target technology
`kantra analyze --input=<path-to/example-applications/example-1> --output=<path-to-output-dir> --target=cloud-readiness`

- Several analysis reports will have been created in your specified output path:

```sh
$ ls ./output/ -1
analysis.log
dependencies.yaml
dependency.log
output.yaml
static-report
```

`output.yaml` is the file that contains issues report.
`static-report` contains the static HTML report.
`dependencies.yaml`contains a dependencies report.

### Transform

- Get the example application to transform source code
`git clone https://github.com/ivargrimstad/jakartaee-duke`

- View available OpenRewrite recipes
`kantra transform openrewrite --list-targets`

- Run a recipe on the example application
`kantra transform openrewrite --input=<path-to/jakartaee-duke> --target=jakarta-imports`

- Inspect the `jakartaee-duke` application source code diff to see the transformation


## Code of Conduct
Refer to Konveyor's Code of Conduct [here](https://github.com/konveyor/community/blob/main/CODE_OF_CONDUCT.md).
61 changes: 61 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type analyzeCommand struct {
listTargets bool
skipStaticReport bool
analyzeKnownLibraries bool
jsonOutput bool
mavenSettingsFile string
sources []string
targets []string
Expand Down Expand Up @@ -106,6 +107,11 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
log.Error(err, "failed to run analysis")
return err
}
err = analyzeCmd.CreateJSONOutput()
if err != nil {
log.Error(err, "failed to create json output file")
return err
}
err = analyzeCmd.GenerateStaticReport(cmd.Context())
if err != nil {
log.Error(err, "failed to generate static report")
Expand Down Expand Up @@ -136,6 +142,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
analyzeCommand.Flags().BoolVar(&analyzeCmd.analyzeKnownLibraries, "analyze-known-libraries", false, "analyze known open-source libraries")
analyzeCommand.Flags().StringVar(&analyzeCmd.mavenSettingsFile, "maven-settings", "", "path to a custom maven settings file to use")
analyzeCommand.Flags().StringVarP(&analyzeCmd.mode, "mode", "m", string(provider.FullAnalysisMode), "analysis mode. Must be one of 'full' or 'source-only'")
analyzeCommand.Flags().BoolVar(&analyzeCmd.jsonOutput, "json-output", false, "create analysis and dependency output as json")

return analyzeCommand
}
Expand Down Expand Up @@ -580,6 +587,60 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e
return nil
}

func (a *analyzeCommand) CreateJSONOutput() error {
if !a.jsonOutput {
return nil
}
outputPath := filepath.Join(a.output, "output.yaml")
depPath := filepath.Join(a.output, "dependencies.yaml")

data, err := ioutil.ReadFile(outputPath)
if err != nil {
return err
}
ruleOutput := &[]outputv1.RuleSet{}
err = yaml.Unmarshal(data, ruleOutput)
if err != nil {
a.log.V(1).Error(err, "failed to unmarshal output yaml")
return err
}

jsonData, err := json.MarshalIndent(ruleOutput, "", " ")
if err != nil {
a.log.V(1).Error(err, "failed to marshal output file to json")
return err
}
err = ioutil.WriteFile(filepath.Join(a.output, "output.json"), jsonData, os.ModePerm)
if err != nil {
a.log.V(1).Error(err, "failed to write json output", "dir", a.output, "file", "output.json")
return err
}

depData, err := ioutil.ReadFile(depPath)
if err != nil {
return err
}
depOutput := &[]outputv1.DepsFlatItem{}
err = yaml.Unmarshal(depData, depOutput)
if err != nil {
a.log.V(1).Error(err, "failed to unmarshal dependencies yaml")
return err
}

jsonDataDep, err := json.MarshalIndent(depOutput, "", " ")
if err != nil {
a.log.V(1).Error(err, "failed to marshal dependencies file to json")
return err
}
err = ioutil.WriteFile(filepath.Join(a.output, "dependencies.json"), jsonDataDep, os.ModePerm)
if err != nil {
a.log.V(1).Error(err, "failed to write json dependencies output", "dir", a.output, "file", "dependencies.json")
return err
}

return nil
}

func (a *analyzeCommand) GenerateStaticReport(ctx context.Context) error {
if a.skipStaticReport {
return nil
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUe
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
Expand Down Expand Up @@ -142,6 +143,7 @@ golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag=
Expand Down
12 changes: 12 additions & 0 deletions hack/update-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Set IMAGE and NAME environment variables, and run the script in root dir:
# $ IMAGE=quay.io/konveyor/kantra NAME=kantra ./hack/update-settings.sh

image="${IMAGE:-quay.io/konveyor/kantra}"
name="${NAME:-kantra}"

sed -i \
-e "s,\(RootCommandName *string.*default:\"\)[^\"]*\",\1$name\"," \
-e "s,\(RunnerImage *string.*default:\"\)[^\"]*\",\1$image\"," \
./cmd/settings.go
27 changes: 13 additions & 14 deletions test-data/analysis-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@
labels:
- konveyor.io/target=cloud-readiness
- discovery
- konveyor.io/source
- konveyor.io/target
incidents:
- uri: file:///opt/input/source/target/classes/persistence.properties
- uri: file:///opt/input/source/src/main/resources/persistence.properties
message: When migrating environments, hard-coded IP addresses may need to be modified or eliminated.
codeSnip: |2
1 jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
Expand All @@ -151,7 +153,7 @@
lineNumber: 2
variables:
matchingText: 169.60.225.216
- uri: file:///opt/input/source/src/main/resources/persistence.properties
- uri: file:///opt/input/source/target/classes/persistence.properties
message: When migrating environments, hard-coded IP addresses may need to be modified or eliminated.
codeSnip: |2
1 jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
Expand All @@ -163,7 +165,6 @@
lineNumber: 2
variables:
matchingText: 169.60.225.216
extras: []
effort: 1
unmatched:
- discover-license
Expand Down Expand Up @@ -1446,28 +1447,27 @@
- konveyor.io/source
- jni
incidents:
- uri: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
- uri: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
message: Java native libraries might not run in a cloud or container environment.. Recommendations. * Review the purpose of the native library in your application.. * Check whether the native library is compatible with a cloud environment.. * Reuse or embed the native library or application in a cloud environment, for example, in a JBoss module.. * Replace, remove, or rewrite the native library or application using a cloud-compatible equivalent.
codeSnip: " 1 package io.konveyor.demo.config;\n 2 \n 3 import java.io.FileInputStream;\n 4 import java.io.InputStream;\n 5 import java.util.Properties;\n 6 \n 7 public class ApplicationConfiguration {\n 8 \n 9 \tprivate Properties config;\n 10 \n 11 \tpublic ApplicationConfiguration() {\n 12 \t\tsuper();\n 13 \t\tthis.config = loadProperties();\n 14 \n 15 \t}\n 16 \n 17 \tprivate Properties loadProperties() {\n 18 \t\tProperties properties = new Properties();\n 19 \n 20 \t\ttry (InputStream inputStream = new FileInputStream(\"/opt/config/persistence.properties\")) {\n 21 \n 22 \t\t\tproperties.load(inputStream);\n 23 \n 24 \t\t} catch (Exception e) {\n 25 \t\t\tSystem.out.println(\"Exception: \" + e);\n 26 \t\t}\n 27 \n 28 \t\treturn properties;\n 29 \t}\n 30 \n 31 \tpublic String getProperty (String name) {\n 32 \t\treturn config.getProperty(name);\n 33 \t}\n 34 \n 35 \n 36 \n 37 }\n"
lineNumber: 12
variables:
file: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
file: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
kind: Constructor
name: ApplicationConfiguration
- uri: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
- uri: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
message: Java native libraries might not run in a cloud or container environment.. Recommendations. * Review the purpose of the native library in your application.. * Check whether the native library is compatible with a cloud environment.. * Reuse or embed the native library or application in a cloud environment, for example, in a JBoss module.. * Replace, remove, or rewrite the native library or application using a cloud-compatible equivalent.
codeSnip: " 1 package io.konveyor.demo.config;\n 2 \n 3 import java.io.FileInputStream;\n 4 import java.io.InputStream;\n 5 import java.util.Properties;\n 6 \n 7 public class ApplicationConfiguration {\n 8 \n 9 \tprivate Properties config;\n 10 \n 11 \tpublic ApplicationConfiguration() {\n 12 \t\tsuper();\n 13 \t\tthis.config = loadProperties();\n 14 \n 15 \t}\n 16 \n 17 \tprivate Properties loadProperties() {\n 18 \t\tProperties properties = new Properties();\n 19 \n 20 \t\ttry (InputStream inputStream = new FileInputStream(\"/opt/config/persistence.properties\")) {\n 21 \n 22 \t\t\tproperties.load(inputStream);\n 23 \n 24 \t\t} catch (Exception e) {\n 25 \t\t\tSystem.out.println(\"Exception: \" + e);\n 26 \t\t}\n 27 \n 28 \t\treturn properties;\n 29 \t}\n 30 \n 31 \tpublic String getProperty (String name) {\n 32 \t\treturn config.getProperty(name);\n 33 \t}\n 34 \n 35 \n 36 \n 37 }\n"
lineNumber: 21
variables:
file: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
file: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
kind: Method
name: loadProperties
links:
- url: https://access.redhat.com/solutions/229443
title: How to load native libraries and access them via JNI in EAP (with or without a module)
- url: https://access.redhat.com/solutions/1444643
title: Is it supported to compile the JNI code as 32-bit shared libraries and use it in 64-bit compiled Java code ?
extras: []
effort: 7
local-storage-00001:
description: |-
Expand All @@ -1479,12 +1479,12 @@
- konveyor.io/source
- storage
incidents:
- uri: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
- uri: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
message: 'An application running inside a container could lose access to a file in local storage.. Recommendations. The following recommendations depend on the function of the file in local storage:. * Logging: Log to standard output and use a centralized log collector to analyze the logs.. * Caching: Use a cache backing service.. * Configuration: Store configuration settings in environment variables so that they can be updated without code changes.. * Data storage: Use a database backing service for relational data or use a persistent data storage system.. * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.'
codeSnip: " 1 package io.konveyor.demo.config;\n 2 \n 3 import java.io.FileInputStream;\n 4 import java.io.InputStream;\n 5 import java.util.Properties;\n 6 \n 7 public class ApplicationConfiguration {\n 8 \n 9 \tprivate Properties config;\n 10 \n 11 \tpublic ApplicationConfiguration() {\n 12 \t\tsuper();\n 13 \t\tthis.config = loadProperties();\n 14 \n 15 \t}\n 16 \n 17 \tprivate Properties loadProperties() {\n 18 \t\tProperties properties = new Properties();\n 19 \n 20 \t\ttry (InputStream inputStream = new FileInputStream(\"/opt/config/persistence.properties\")) {\n 21 \n 22 \t\t\tproperties.load(inputStream);\n 23 \n 24 \t\t} catch (Exception e) {\n 25 \t\t\tSystem.out.println(\"Exception: \" + e);\n 26 \t\t}\n 27 \n 28 \t\treturn properties;\n 29 \t}\n 30 \n 31 \tpublic String getProperty (String name) {\n 32 \t\treturn config.getProperty(name);\n 33 \t}\n 34 \n 35 \n 36 \n 37 }\n"
lineNumber: 19
variables:
file: konveyor-jdt://contents/root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class&source-range=true
file: file:///root/.m2/repository/io/konveyor/demo/config-utils/1.0.0/io/konveyor/demo/config/ApplicationConfiguration.java
kind: Constructor
name: loadProperties
links:
Expand All @@ -1500,7 +1500,6 @@
title: 'OpenShift Container Platform: Input secrets and ConfigMaps'
- url: https://docs.openshift.com/container-platform/4.5/storage/understanding-persistent-storage.html
title: 'OpenShift Container Platform: Understanding persistent storage'
extras: []
effort: 1
unmatched:
- embedded-cache-libraries-01000
Expand All @@ -1521,18 +1520,18 @@
- logging-0000
- logging-0001
- jca-00000
- local-storage-00003
- local-storage-00004
- local-storage-00003
- session-00000
- java-rmi-00000
- logging-0001
- java-rpc-00000
- logging-0000
- java-rpc-00000
- socket-communication-00001
- mail-00000
- local-storage-00005
- session-00001
- local-storage-00002
- local-storage-00005
- socket-communication-00000
- name: os/windows
description: This is a ruleset for Windows operating system specific rules while migrating to Linux operating system.
Expand Down
Loading

0 comments on commit 485a542

Please sign in to comment.