Skip to content

Commit

Permalink
Automated Updates: support parents and dependency imports (#890)
Browse files Browse the repository at this point in the history
This PR adds support for parents and dependency imports:
 - fetching and parsing upstream pom.xml files
 - then merging the data into Maven project
- add `RequirementsFromOtherPOMs` to system-specific data to store
requirements that we don't have access

Some of the Maven code should be provided by `deps.dev/util/maven` and
`deps.dev/util/resolve` soon...
  • Loading branch information
cuixq committed May 2, 2024
1 parent 8abdafa commit 6a43a91
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 107 deletions.
12 changes: 5 additions & 7 deletions internal/resolution/datasource/maven_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ import (
const MavenCentral = "https://repo.maven.apache.org/maven2"

type MavenRegistryAPIClient struct {
Registry string // Base URL of the registry that we are making requests
registry string // Base URL of the registry that we are making requests
}

func NewMavenRegistryAPIClient() (*MavenRegistryAPIClient, error) {
return &MavenRegistryAPIClient{
Registry: MavenCentral,
}, nil
func NewMavenRegistryAPIClient(registry string) *MavenRegistryAPIClient {
return &MavenRegistryAPIClient{registry: registry}
}

func (m *MavenRegistryAPIClient) GetProject(ctx context.Context, groupID, artifactID, version string) (maven.Project, error) {
url, err := url.JoinPath(m.Registry, strings.ReplaceAll(groupID, ".", "/"), artifactID, version, fmt.Sprintf("%s-%s.pom", artifactID, version))
u, err := url.JoinPath(m.registry, strings.ReplaceAll(groupID, ".", "/"), artifactID, version, fmt.Sprintf("%s-%s.pom", artifactID, version))
if err != nil {
return maven.Project{}, fmt.Errorf("failed to join path: %w", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
if err != nil {
return maven.Project{}, fmt.Errorf("failed to make new request: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/resolution/datasource/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ func TestGetProject(t *testing.T) {

srv := testutility.NewMockHTTPServer(t)
client := &MavenRegistryAPIClient{
Registry: srv.URL,
registry: srv.URL,
}

srv.SetResponse(t, "org/example/x.y.z/1.0.0/x.y.z-1.0.0.pom", []byte(`
<project>
<groupId>org.example</groupId>
<artifactId>x.y.z</artifactId>
<version>1.0.0</version>
</project>
`))

got, err := client.GetProject(context.Background(), "org.example", "x.y.z", "1.0.0")
if err != nil {
t.Fatalf("failed to get Maven project %s:%s verion %s: %v", "org.example", "x.y.z", "1.0.0", err)
Expand Down
8 changes: 8 additions & 0 deletions internal/resolution/manifest/__snapshots__/maven_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<groupId>org.parent</groupId>
<artifactId>parent-pom</artifactId>
<version>1.2.0</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>

<properties>
Expand Down Expand Up @@ -48,6 +49,13 @@
<artifactId>xyz</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.import</groupId>
<artifactId>import</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
37 changes: 37 additions & 0 deletions internal/resolution/manifest/fixtures/parent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.parent</groupId>
<artifactId>parent-pom</artifactId>
<version>1.1.1</version>

<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<packaging>pom</packaging>

<parent>
<groupId>org.upstream</groupId>
<artifactId>parent-pom</artifactId>
<version>1.2.3</version>
</parent>

<properties>
<aaa.version>1.1.1</aaa.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>aaa</artifactId>
<version>${aaa.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

</project>
8 changes: 8 additions & 0 deletions internal/resolution/manifest/fixtures/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<groupId>org.parent</groupId>
<artifactId>parent-pom</artifactId>
<version>1.1.1</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>

<properties>
Expand Down Expand Up @@ -46,6 +47,13 @@
<artifactId>xyz</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.import</groupId>
<artifactId>import</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
2 changes: 1 addition & 1 deletion internal/resolution/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func GetManifestIO(pathToManifest string) (ManifestIO, error) {
base := filepath.Base(pathToManifest)
switch {
case base == "pom.xml":
return MavenManifestIO{}, nil
return NewMavenManifestIO(), nil
case base == "package.json":
return NpmManifestIO{}, nil
default:
Expand Down
Loading

0 comments on commit 6a43a91

Please sign in to comment.