forked from azure-javaee/azure-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
409 additions
and
137 deletions.
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
33 changes: 31 additions & 2 deletions
33
...nal/appdetect/javaanalyze/java_project.go → ...ernal/appdetect/javaanalyze/azure_yaml.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
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
package javaanalyze | ||
|
||
import "os" | ||
|
||
type javaProject struct { | ||
springProject springProject | ||
mavenProject mavenProject | ||
} | ||
|
||
func Analyze(path string) []AzureYaml { | ||
var result []AzureYaml | ||
rules := []rule{ | ||
&ruleService{}, | ||
&ruleMysql{}, | ||
&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 | ||
} |
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
78 changes: 78 additions & 0 deletions
78
cli/azd/internal/appdetect/javaanalyze/project_analyzer_spring.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,78 @@ | ||
package javaanalyze | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
type springProject struct { | ||
applicationProperties map[string]interface{} | ||
} | ||
|
||
func analyzeSpringProject(projectPath string) springProject { | ||
return springProject{ | ||
applicationProperties: findSpringApplicationProperties(projectPath), | ||
} | ||
} | ||
|
||
func findSpringApplicationProperties(projectPath string) map[string]interface{} { | ||
yamlFilePath := projectPath + "/src/main/resources/application.yml" | ||
data, err := ioutil.ReadFile(yamlFilePath) | ||
if err != nil { | ||
log.Fatalf("error reading YAML file: %v", err) | ||
} | ||
|
||
// Parse the YAML into a yaml.Node | ||
var root yaml.Node | ||
err = yaml.Unmarshal(data, &root) | ||
if err != nil { | ||
log.Fatalf("error unmarshalling YAML: %v", err) | ||
} | ||
|
||
result := make(map[string]interface{}) | ||
parseYAML("", &root, result) | ||
|
||
return result | ||
} | ||
|
||
// Recursively parse the YAML and build dot-separated keys into a map | ||
func parseYAML(prefix string, node *yaml.Node, result map[string]interface{}) { | ||
switch node.Kind { | ||
case yaml.DocumentNode: | ||
// Process each document's content | ||
for _, contentNode := range node.Content { | ||
parseYAML(prefix, contentNode, result) | ||
} | ||
case yaml.MappingNode: | ||
// Process key-value pairs in a map | ||
for i := 0; i < len(node.Content); i += 2 { | ||
keyNode := node.Content[i] | ||
valueNode := node.Content[i+1] | ||
|
||
// Ensure the key is a scalar | ||
if keyNode.Kind != yaml.ScalarNode { | ||
continue | ||
} | ||
|
||
keyStr := keyNode.Value | ||
newPrefix := keyStr | ||
if prefix != "" { | ||
newPrefix = prefix + "." + keyStr | ||
} | ||
parseYAML(newPrefix, valueNode, result) | ||
} | ||
case yaml.SequenceNode: | ||
// Process items in a sequence (list) | ||
for i, item := range node.Content { | ||
newPrefix := fmt.Sprintf("%s[%d]", prefix, i) | ||
parseYAML(newPrefix, item, result) | ||
} | ||
case yaml.ScalarNode: | ||
// If it's a scalar value, add it to the result map | ||
result[prefix] = node.Value | ||
default: | ||
// Handle other node types if necessary | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package javaanalyze | ||
|
||
type rule interface { | ||
Match(*MavenProject) bool | ||
Apply(*JavaProject) | ||
match(project *javaProject) bool | ||
apply(azureYaml *AzureYaml) | ||
} | ||
|
||
func ApplyRules(mavenProject *MavenProject, rules []rule) (*JavaProject, error) { | ||
javaProject := &JavaProject{} | ||
func applyRules(javaProject *javaProject, rules []rule) (*AzureYaml, error) { | ||
azureYaml := &AzureYaml{} | ||
|
||
for _, r := range rules { | ||
if r.Match(mavenProject) { | ||
r.Apply(javaProject) | ||
if r.match(javaProject) { | ||
r.apply(azureYaml) | ||
} | ||
} | ||
return javaProject, nil | ||
return azureYaml, nil | ||
} |
Oops, something went wrong.