Skip to content
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 processing for nested modules with a parent version property #4472

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

marcel-gepardec
Copy link
Contributor

What's changed?

Added the ability to process projects with modules in modules where the parent version is a property.

If the project's version does not match the GroupArtifactVersion GAV or cannot be resolved with getValue() because there is no property such as the version string, each parent POM should now be checked to see if the property is set.
If no parent, including the last parent, the root POM, has a property like this, then it can proceed as usual.
If the property is in the root POM and corresponds to the version of the project, this project can be returned and further processed.

What's your motivation?

@ErhardSiegl noticed an incorrect behavior regarding the usage of openrewrite in a project with modules in modules where the parent version is a property. He always got this error message:

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.39.2:run (default-cli) on project test-common-shared: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.39.2:run failed: Error while visiting pom.xml: java.lang.IllegalArgumentException: Illegal character in path at index 66: file:///Users/test/.m2/repository/com/example/exatest/test-common/${revision}/test-common-${revision}.pom
[ERROR]   java.base/java.net.URI.create(URI.java:883)
[ERROR]   org.openrewrite.maven.internal.MavenPomDownloader.download(MavenPomDownloader.java:539)
[ERROR]   org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPom(ResolvedPom.java:500)
[ERROR]  org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:407)
[ERROR]   org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentsRecursively(ResolvedPom.java:365)
[ERROR]   org.openrewrite.maven.tree.ResolvedPom$Resolver.resolve(ResolvedPom.java:354)
[ERROR]   org.openrewrite.maven.tree.ResolvedPom.resolve(ResolvedPom.java:176)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.updateResult(UpdateMavenModel.java:162)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.lambda$updateResult$8(UpdateMavenModel.java:167)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.updateResult(UpdateMavenModel.java:165)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.lambda$updateResult$8(UpdateMavenModel.java:167)
[ERROR]   org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.updateResult(UpdateMavenModel.java:165)
[ERROR]   org.openrewrite.maven.UpdateMavenModel.visitDocument(UpdateMavenModel.java:131)
[ERROR]   org.openrewrite.xml.tree.Xml$Document.acceptXml(Xml.java:145)
[ERROR]   ...

For reference:

rewrite.yml:

---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.exatest.CxfDependencies
displayName: CxfDependencies
recipeList:
  - org.openrewrite.maven.AddManagedDependency:
      groupId: org.apache.cxf
      artifactId: cxf-rt-features-logging
      version: '4.0.0'

test-parent root pom:

<?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>com.example.exatest</groupId>
  <artifactId>test-parent</artifactId>
  <version>${revision}</version>
  <packaging>pom</packaging>
  <name>TEST Parent POM</name>

  <properties>
    <revision>0.1.0-SNAPSHOT</revision>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-features-logging</artifactId>
        <version>3.3.7</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <modules>
    <module>test-common</module>
  </modules>

      <build>
        <plugins>
          <plugin>
            <groupId>org.openrewrite.maven</groupId>
            <artifactId>rewrite-maven-plugin</artifactId>
            <configuration>
              <activeRecipes>
                <recipe>com.example.exatest.CxfDependencies</recipe>
              </activeRecipes>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>org.openrewrite</groupId>
                <artifactId>rewrite-core</artifactId>
                <version>8.33.4</version>
              </dependency>
              <dependency>
                <groupId>org.openrewrite</groupId>
                <artifactId>rewrite-java</artifactId>
                <version>8.33.4</version>
              </dependency>
              <dependency>
                <groupId>org.openrewrite</groupId>
                <artifactId>rewrite-maven</artifactId>
                <version>8.33.4</version>
              </dependency>
              <dependency>
                <groupId>org.openrewrite.recipe</groupId>
                <artifactId>rewrite-migrate-java</artifactId>
                <version>2.22.1</version>
              </dependency>
              <dependency>
                <groupId>org.openrewrite</groupId>
                <artifactId>rewrite-xml</artifactId>
                <version>8.33.4</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
  </build>
</project>

test-common pom:

<?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>

  <parent>
    <groupId>com.example.exatest</groupId>
    <artifactId>test-parent</artifactId>
    <version>${revision}</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>test-common</artifactId>
  <packaging>pom</packaging>

  <modules>
    <module>test-common-shared</module>
  </modules>
</project>

test-common-shared pom:

<?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>
  <parent>
    <groupId>com.example.exatest</groupId>
    <artifactId>test-common</artifactId>
    <version>${revision}</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>test-common-shared</artifactId>
  <packaging>jar</packaging>
</project>

@sambsnyd sambsnyd merged commit bd51eaf into openrewrite:main Oct 11, 2024
2 checks passed
@sambsnyd
Copy link
Member

Thanks @marcel-gepardec !

@timtebeek timtebeek deleted the fix/ModuleInModule branch October 12, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants