Skip to content

Commit

Permalink
Add version paramater to DependencyInsight
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Nov 9, 2023
1 parent c9e7157 commit 3840fdb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ public String getDescription() {
example = "jackson-module-*")
String artifactIdPattern;

@Option(displayName = "Version",
description = "Match only dependencies with the specified version. " +
"Node-style [version selectors](https://docs.openrewrite.org/reference/dependency-version-selectors) may be used." +
"All versions are searched by default.",
example = "1.x",
required = false)
@Nullable
String version;

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
final TreeVisitor<?, ExecutionContext> gdi = new org.openrewrite.gradle.search.DependencyInsight(groupIdPattern, artifactIdPattern, null)
final TreeVisitor<?, ExecutionContext> gdi = new org.openrewrite.gradle.search.DependencyInsight(groupIdPattern, artifactIdPattern, version,null)
.getVisitor();
final TreeVisitor<?, ExecutionContext> mdi = new org.openrewrite.maven.search.DependencyInsight(groupIdPattern, artifactIdPattern, null, false)
final TreeVisitor<?, ExecutionContext> mdi = new org.openrewrite.maven.search.DependencyInsight(groupIdPattern, artifactIdPattern, null, version, false)
.getVisitor();
@Override
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.openrewrite.java.dependencies;

import org.junit.jupiter.api.Test;
import org.openrewrite.maven.Assertions;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

Expand All @@ -26,7 +25,7 @@ public class DependencyInsightTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new DependencyInsight("org.springframework*", "*"));
spec.recipe(new DependencyInsight("org.springframework*", "*", null));
}

@Test
Expand All @@ -35,9 +34,9 @@ void maven() {
//language=xml
pomXml("""
<project>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
Expand All @@ -50,9 +49,9 @@ void maven() {
""",
"""
<project>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<dependencies>
<!--~~>--><dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ void gradle() {
id("java")
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://nonexistent.moderne.io/maven2"
}
Expand Down

0 comments on commit 3840fdb

Please sign in to comment.