-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Java analyzer #4422
Closed
Closed
Add Java analyzer #4422
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
849de05
Add a new child action "orchestrate". And create a sample azure.yaml …
rujche acee60b
Get list of pom files.
rujche 88d4d1b
add the code for azd java analyzer
saragluna 6ba0816
Hook the java analyzer with the azd init.
saragluna 6a4b664
Enhance
saragluna bafcbc4
Implement java_project_bicep_file_generator.go.
rujche b69a47e
Improve log: Add information about the file path.
rujche 69bc59a
Enhance the java analyzer
saragluna 8d67fc5
Add feature: Support add mysql when run "azd init".
rujche 91900aa
Delete java_project_bicep_file_generator.go.
rujche 2da438b
Add logic about accessing mysql in aca.
rujche f4e00ef
Merge pull request #1 from rujche/rujche/java-analyzer
saragluna 2aa6cac
Fix typo by changing "DbMysql" to "DbMySql".
rujche cace7fa
Merge pull request #2 from rujche/rujche/java-analyzer
saragluna 082b9b2
Use managed-identity instead of username and password. Now it has err…
rujche b0c39a6
Access MySql by managed identity instead of username&password.
rujche f90416f
Add Azure Deps in appdetect.go
saragluna 84b7852
Customize the azd VS Code extension
saragluna 6587f83
improve the java analyzer for event-driven
saragluna 103a005
refactor the java analyzer
saragluna 2e01347
Create service connector by bicep file.
rujche 708681a
1. Remove duplicated 'azd extension add'.
rujche 353a802
Update name of resources: linkerCreatorIdentity and appLinkToMySql
rujche 6d853de
Merge remote-tracking branch 'saragluna/java-analyzer' into rujche/ja…
rujche 85ec20b
Merge pull request #3 from rujche/rujche/java-analyzer
saragluna 2856fb9
Merge remote-tracking branch 'saragluna/java-analyzer' into rujche/ja…
rujche b70878e
1. Add rule about postgresql in project_analyzer_java.go.
rujche 437eeb6
Fix the error about CORS.
rujche 3410c97
Merge pull request #4 from rujche/rujche/java-analyzer
saragluna f244293
Merge branch 'main' into saragluna/java-analyzer
rujche df2f5f2
add support for service bus
saragluna b6e6ecc
fix servicebus
saragluna 073d857
Remove the logic of create tag after create service connector.
rujche ef73ce1
Merge remote-tracking branch 'saragluna/java-analyzer' into rujche/ja…
rujche 4c84661
Merge pull request #5 from rujche/rujche/java-analyzer
rujche f1e2fc1
support both mi and connection string for service bus
saragluna 23362f8
For PostgreSQL, support both password and passwordless.
rujche 193f054
For MySQL, support both password and passwordless.
rujche 48cbeb5
Remove logic of adding tag after creating service connector. Because …
rujche 9f4fe27
Fix bug: create service connector only work for the first time run of…
rujche 207ffa3
Merge pull request #6 from rujche/rujche/java-analyzer
rujche 0594412
Add new feature: analyze project to add Mongo DB.
rujche c45382a
Delete unused content in main.bicept.
rujche dca325f
Merge pull request #7 from rujche/rujche/java-analyzer
rujche babf604
Fix bug: Get auth type should only be required for MySQL and PostgreSQL.
rujche 12b169e
Merge pull request #8 from rujche/rujche/java-analyzer
rujche a2a3a73
Make sure app work well after deployed to ACA no matter what value "s…
rujche 2f4d2e9
Merge pull request #9 from rujche/rujche/java-analyzer
rujche a83f7d7
Implement feature: detect port in Dockerfile.
rujche 35f762c
Merge pull request #10 from rujche/rujche/java-analyzer
rujche de2e922
Implement feature: detect redis by analyzing pom file.
rujche 8607043
Merge pull request #11 from rujche/rujche/java-analyzer
rujche a482496
Detect Mongo DB by dependency spring-boot-starter-data-mongodb-reacti…
rujche 671902a
Merge pull request #12 from rujche/rujche/java-analyzer
rujche 9c53e73
Support all kinds of properties file like application(-profile).yaml(…
rujche 6e14a1b
Merge pull request #13 from rujche/rujche/java-analyzer
rujche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/azure/azure-dev/cli/azd/cmd/actions" | ||
"github.com/azure/azure-dev/cli/azd/internal" | ||
"github.com/azure/azure-dev/cli/azd/pkg/output" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func newOrchestrateFlags(cmd *cobra.Command, global *internal.GlobalCommandOptions) *orchestrateFlags { | ||
flags := &orchestrateFlags{} | ||
return flags | ||
} | ||
|
||
func newOrchestrateCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "orchestrate", | ||
Short: "Orchestrate an existing application. (Beta)", | ||
} | ||
} | ||
|
||
type orchestrateFlags struct { | ||
global *internal.GlobalCommandOptions | ||
} | ||
|
||
type orchestrateAction struct { | ||
} | ||
|
||
func (action orchestrateAction) Run(ctx context.Context) (*actions.ActionResult, error) { | ||
azureYamlFile, err := os.Create("azure.yaml") | ||
if err != nil { | ||
return nil, fmt.Errorf("creating azure.yaml: %w", err) | ||
} | ||
defer azureYamlFile.Close() | ||
|
||
files, err := findPomFiles(".") | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
return nil, fmt.Errorf("find pom files: %w", err) | ||
} | ||
|
||
for _, file := range files { | ||
if _, err := azureYamlFile.WriteString(file + "\n"); err != nil { | ||
return nil, fmt.Errorf("writing azure.yaml: %w", err) | ||
} | ||
} | ||
|
||
if err := azureYamlFile.Sync(); err != nil { | ||
return nil, fmt.Errorf("saving azure.yaml: %w", err) | ||
} | ||
return nil, nil | ||
} | ||
|
||
func newOrchestrateAction() actions.Action { | ||
return &orchestrateAction{} | ||
} | ||
|
||
func getCmdOrchestrateHelpDescription(*cobra.Command) string { | ||
return generateCmdHelpDescription("Orchestrate an existing application in your current directory.", | ||
[]string{ | ||
formatHelpNote( | ||
fmt.Sprintf("Running %s without flags specified will prompt "+ | ||
"you to orchestrate using your existing code.", | ||
output.WithHighLightFormat("orchestrate"), | ||
)), | ||
}) | ||
} | ||
|
||
func getCmdOrchestrateHelpFooter(*cobra.Command) string { | ||
return generateCmdHelpSamplesBlock(map[string]string{ | ||
"Orchestrate a existing project.": fmt.Sprintf("%s", | ||
output.WithHighLightFormat("azd orchestrate"), | ||
), | ||
}) | ||
} | ||
|
||
func findPomFiles(root string) ([]string, error) { | ||
var files []string | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() && filepath.Base(path) == "pom.xml" { | ||
files = append(files, path) | ||
} | ||
return nil | ||
}) | ||
return files, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package javaanalyze | ||
|
||
type AzureYaml struct { | ||
Service *Service `json:"service"` | ||
Resources []IResource `json:"resources"` | ||
ServiceBindings []ServiceBinding `json:"serviceBindings"` | ||
} | ||
|
||
type IResource interface { | ||
GetName() string | ||
GetType() string | ||
GetBicepParameters() []BicepParameter | ||
GetBicepProperties() []BicepProperty | ||
} | ||
|
||
type Resource struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
BicepParameters []BicepParameter `json:"bicepParameters"` | ||
BicepProperties []BicepProperty `json:"bicepProperties"` | ||
} | ||
|
||
func (r *Resource) GetName() string { | ||
return r.Name | ||
} | ||
|
||
func (r *Resource) GetType() string { | ||
return r.Type | ||
} | ||
|
||
func (r *Resource) GetBicepParameters() []BicepParameter { | ||
return r.BicepParameters | ||
} | ||
|
||
func (r *Resource) GetBicepProperties() []BicepProperty { | ||
return r.BicepProperties | ||
} | ||
|
||
type ServiceBusResource struct { | ||
Resource | ||
Queues []string `json:"queues"` | ||
TopicAndSubscriptions []string `json:"topicAndSubscriptions"` | ||
} | ||
|
||
type BicepParameter struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type BicepProperty struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type ResourceType int32 | ||
|
||
const ( | ||
RESOURCE_TYPE_MYSQL ResourceType = 0 | ||
RESOURCE_TYPE_AZURE_STORAGE ResourceType = 1 | ||
) | ||
|
||
// Service represents a specific service's configuration. | ||
type Service struct { | ||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
ResourceURI string `json:"resourceUri"` | ||
Description string `json:"description"` | ||
Environment []Environment `json:"environment"` | ||
} | ||
|
||
type Environment struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type ServiceBinding struct { | ||
Name string `json:"name"` | ||
ResourceURI string `json:"resourceUri"` | ||
AuthType AuthType `json:"authType"` | ||
} | ||
|
||
type AuthType int32 | ||
|
||
const ( | ||
// Authentication type not specified. | ||
AuthType_SYSTEM_MANAGED_IDENTITY AuthType = 0 | ||
// Username and Password Authentication. | ||
AuthType_USER_PASSWORD AuthType = 1 | ||
) |
41 changes: 41 additions & 0 deletions
41
cli/azd/internal/appdetect/javaanalyze/project_analyzer_java.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package javaanalyze | ||
|
||
import "os" | ||
|
||
type javaProject struct { | ||
springProject springProject | ||
mavenProject mavenProject | ||
} | ||
|
||
func Analyze(path string) []AzureYaml { | ||
var result []AzureYaml | ||
rules := []rule{ | ||
&ruleService{}, | ||
&ruleMysql{}, | ||
&rulePostgresql{}, | ||
&ruleMongo{}, | ||
&ruleRedis{}, | ||
&ruleStorage{}, | ||
&ruleServiceBusScsb{}, | ||
} | ||
|
||
entries, err := os.ReadDir(path) | ||
if err == nil { | ||
for _, entry := range entries { | ||
if "pom.xml" == entry.Name() { | ||
mavenProjects, _ := analyzeMavenProject(path) | ||
|
||
for _, mavenProject := range mavenProjects { | ||
javaProject := &javaProject{ | ||
mavenProject: mavenProject, | ||
springProject: analyzeSpringProject(mavenProject.path), | ||
} | ||
azureYaml, _ := applyRules(javaProject, rules) | ||
result = append(result, *azureYaml) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can replace these rules with
switch
statements like Python, and I feel comfortable moving all the logic here intojava.go
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure