|
39 | 39 | import org.openrewrite.maven.internal.MavenParsingException; |
40 | 40 | import org.openrewrite.maven.tree.*; |
41 | 41 | import org.openrewrite.test.RewriteTest; |
| 42 | +import org.openrewrite.test.SourceSpecs; |
42 | 43 | import org.openrewrite.test.TypeValidation; |
43 | 44 | import org.openrewrite.tree.ParseError; |
44 | 45 |
|
|
51 | 52 | import static org.assertj.core.api.Assertions.*; |
52 | 53 | import static org.openrewrite.java.Assertions.mavenProject; |
53 | 54 | import static org.openrewrite.maven.Assertions.pomXml; |
| 55 | +import static org.openrewrite.test.SourceSpecs.dir; |
54 | 56 |
|
55 | 57 | class MavenParserTest implements RewriteTest { |
56 | 58 |
|
@@ -4810,4 +4812,86 @@ void transitiveDependencyVersion() { |
4810 | 4812 | ) |
4811 | 4813 | ); |
4812 | 4814 | } |
| 4815 | + |
| 4816 | + @Test |
| 4817 | + void groupIdAndArtifactIdAsProperties() { |
| 4818 | + rewriteRun( |
| 4819 | + mavenProject("my-app", |
| 4820 | + pomXml(""" |
| 4821 | + <project> |
| 4822 | + <groupId>com.example</groupId> |
| 4823 | + <artifactId>parent</artifactId> |
| 4824 | + <version>1</version> |
| 4825 | + <packaging>pom</packaging> |
| 4826 | + <properties> |
| 4827 | + <my-app.child-a.groupId>com.example</my-app.child-a.groupId> |
| 4828 | + <my-app.child-a.artifactId>child-a</my-app.child-a.artifactId> |
| 4829 | + </properties> |
| 4830 | + <modules> |
| 4831 | + <module>child-a</module> |
| 4832 | + <module>child-b</module> |
| 4833 | + </modules> |
| 4834 | + </project> |
| 4835 | + """ |
| 4836 | + ), |
| 4837 | + dir("child-a", |
| 4838 | + pomXml( |
| 4839 | + """ |
| 4840 | + <project> |
| 4841 | + <groupId>${my-app.child-a.groupId}</groupId> |
| 4842 | + <artifactId>${my-app.child-a.artifactId}</artifactId> |
| 4843 | + <version>1</version> |
| 4844 | + <parent> |
| 4845 | + <groupId>com.example</groupId> |
| 4846 | + <artifactId>parent</artifactId> |
| 4847 | + <version>1</version> |
| 4848 | + </parent> |
| 4849 | + <dependencies> |
| 4850 | + <dependency> |
| 4851 | + <groupId>org.springframework</groupId> |
| 4852 | + <artifactId>spring-core</artifactId> |
| 4853 | + <version>6.2.15</version> |
| 4854 | + </dependency> |
| 4855 | + </dependencies> |
| 4856 | + </project> |
| 4857 | + """ |
| 4858 | + ) |
| 4859 | + ), |
| 4860 | + dir("child-b", |
| 4861 | + pomXml( |
| 4862 | + """ |
| 4863 | + <project> |
| 4864 | + <groupId>com.example</groupId> |
| 4865 | + <artifactId>child-b</artifactId> |
| 4866 | + <version>1</version> |
| 4867 | + <parent> |
| 4868 | + <groupId>com.example</groupId> |
| 4869 | + <artifactId>parent</artifactId> |
| 4870 | + <version>1</version> |
| 4871 | + </parent> |
| 4872 | + <dependencies> |
| 4873 | + <dependency> |
| 4874 | + <groupId>${my-app.child-a.groupId}</groupId> |
| 4875 | + <artifactId>${my-app.child-a.artifactId}</artifactId> |
| 4876 | + <version>1</version> |
| 4877 | + </dependency> |
| 4878 | + </dependencies> |
| 4879 | + </project> |
| 4880 | + """, |
| 4881 | + spec -> spec.afterRecipe(pom -> { |
| 4882 | + assertThat(pom).isNotNull(); |
| 4883 | + Optional<MavenResolutionResult> maybeMrr = pom.getMarkers().findFirst(MavenResolutionResult.class); |
| 4884 | + assertThat(maybeMrr).isPresent(); |
| 4885 | + |
| 4886 | + MavenResolutionResult mrr = maybeMrr.get(); |
| 4887 | + assertThat(mrr.getDependencies().get(Scope.Compile).stream()) |
| 4888 | + .anyMatch(resolvedDependency -> "org.springframework".equals(resolvedDependency.getGroupId()) && |
| 4889 | + "spring-core".equals(resolvedDependency.getArtifactId()) && |
| 4890 | + "6.2.15".equals(resolvedDependency.getVersion())); |
| 4891 | + }) |
| 4892 | + ) |
| 4893 | + ) |
| 4894 | + ) |
| 4895 | + ); |
| 4896 | + } |
4813 | 4897 | } |
0 commit comments