Skip to content

Commit

Permalink
Move updating application property file related code from appdetect.g…
Browse files Browse the repository at this point in the history
…o to app_init.go.
  • Loading branch information
rujche committed Jan 24, 2025
1 parent b16f2ec commit a3f83b7
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 340 deletions.
17 changes: 17 additions & 0 deletions cli/azd/internal/appdetect/appdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ func (f Dependency) IsWebUIFramework() bool {
return false
}

type RawDependency struct {
Kind RawDependencyKind
Name string
Version string
}

type RawDependencyKind string

const RawDependencyKindMaven RawDependencyKind = "maven"
const MavenDependencyNameMySqlConnectorJ = "com.mysql:mysql-connector-j"
const MavenDependencyNamePostgresql = "org.postgresql:postgresql"
const MavenDependencyNameSpringCloudAzureStarterJdbcPostgresql = "com.azure.spring:spring-cloud-azure-starter-jdbc-postgresql"
const MavenDependencyNameSpringBootMavenPlugin = "org.springframework.boot:spring-boot-maven-plugin"

// A type of database that is inferred through heuristics while scanning project information.
type DatabaseDep string

Expand Down Expand Up @@ -138,6 +152,9 @@ type Project struct {
// Dependencies scanned in the project.
Dependencies []Dependency

// RawDependencies scanned in the project.
RawDependencies []RawDependency

// Experimental: Database dependencies inferred through heuristics while scanning dependencies in the project.
DatabaseDeps []DatabaseDep

Expand Down
30 changes: 19 additions & 11 deletions cli/azd/internal/appdetect/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,35 @@ func readMavenProject(filePath string) (*mavenProject, error) {
func detectDependencies(mavenProject *mavenProject, project *Project) (*Project, error) {
databaseDepMap := map[DatabaseDep]struct{}{}
for _, dep := range mavenProject.Dependencies {
if dep.GroupId == "com.mysql" && dep.ArtifactId == "mysql-connector-j" {
name := toDependencyName(dep.GroupId, dep.ArtifactId)
switch name {
case MavenDependencyNameMySqlConnectorJ:
databaseDepMap[DbMySql] = struct{}{}
}

if (dep.GroupId == "org.postgresql" && dep.ArtifactId == "postgresql") ||
(dep.GroupId == "com.azure.spring" && dep.ArtifactId == "spring-cloud-azure-starter-jdbc-postgresql") {
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
case MavenDependencyNamePostgresql, MavenDependencyNameSpringCloudAzureStarterJdbcPostgresql:
databaseDepMap[DbPostgres] = struct{}{}
// todo: Only call this func when it's a spring-boot project
err := addPostgresqlConnectionProperties(project.Path)
if err != nil {
return nil, err
}
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
}
}

if len(databaseDepMap) > 0 {
project.DatabaseDeps = slices.SortedFunc(maps.Keys(databaseDepMap),
func(a, b DatabaseDep) int {
return strings.Compare(string(a), string(b))
})
}
for _, dep := range mavenProject.Build.Plugins {
name := toDependencyName(dep.GroupId, dep.ArtifactId)
if name == MavenDependencyNameSpringBootMavenPlugin {
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
}
}

return project, nil
}

func toDependencyName(groupId string, artifactId string) string {
return groupId + ":" + artifactId
}
187 changes: 0 additions & 187 deletions cli/azd/internal/appdetect/spring_boot_properties_file.go

This file was deleted.

Loading

0 comments on commit a3f83b7

Please sign in to comment.