-
Notifications
You must be signed in to change notification settings - Fork 9
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
Migrate from sources
to resolve-sources
for the maven-dependency-plugin
#20
Comments
Thanks for the suggestion @yeikel , and the helpful links out to Jira & the associated PR. I've moved this issue to rewrite-apache, as we might want to shift some of the none-core Maven best practices recipes here. We can use a precondition to limit this to only apply to projects using that particular range of versions, and then within that replace any goals as needed. |
Did a very brief attempt at getting this fixed; here's a quick test and recipe class: import org.junit.jupiter.api.Test;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import static org.junit.jupiter.api.Assertions.*;
import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.maven.Assertions.pomXml;
class SourcesToResolveSourcesTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new SourcesToResolveSources());
}
@Test
void sourcesToResolveSources() {
rewriteRun(
mavenProject("foo",
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<goals>
<goal>resolve-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
"""
))
);
}
} import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.maven.MavenIsoVisitor;
import org.openrewrite.xml.XPathMatcher;
import org.openrewrite.xml.tree.Xml;
public class SourcesToResolveSources extends Recipe {
@Override
public String getDisplayName() {
return "Migrate to `resolve-sources`";
}
@Override
public String getDescription() {
return "Migrate from `sources` to `resolve-sources` for the `maven-dependency-plugin`.";
}
private static final XPathMatcher xPathMatcher = new XPathMatcher("//plugin[artifactId='maven-dependency-plugin']/executions/execution/goals[goal='sources']/goal");
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new MavenIsoVisitor<ExecutionContext>() {
@Override
public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
// TODO Compare version of plugin to determine if it is necessary to change the goal
if (xPathMatcher.matches(getCursor())) {
return tag.withValue("resolve-sources");
}
return super.visitTag(tag, ctx);
}
};
}
} |
What problem are you trying to solve?
What precondition(s) should be checked before applying this recipe?
Describe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
https://issues.apache.org/jira/browse/MDEP-941
https://github.com/apache/maven-dependency-plugin/pull/411/files
The text was updated successfully, but these errors were encountered: