Skip to content

Commit

Permalink
MavenVisitor should not return incorrect ResolutionResult for mul…
Browse files Browse the repository at this point in the history
…ti module maven projects (#4074)

* fix find maven dependencies for multi module maven projects

* revert to see if build is succesfull

* Defensive copy in addClasspathEntry so that it won't attempt to add an element to a read-only list

* Make `JavaParser.Builder#addClasspathEntry()` public

* Basic JSP support (#4075)

* Improve `UsesField`

* Improve `UsesField` a bit more

* Fix RenameVariable for variables referenced through type casts (#4082)

* Fix RenameVariable for variables referenced through type casts

* Add unit test

* Be explicit about null handling and types

---------

Co-authored-by: Tim te Beek <tim@moderne.io>

* Java version equality should not be based on id.

Plugins create a JavaVersion per source set, but if they have the same fields excluding id they should be considered equal.

* `MethodMatcher`: Improve construction time performance

Avoid expensive regular expressions for simple and common cases.

* `MethodMatcher`: Optimize performance of common argument matching

* `XPathMatcher`: Implement attribute value conditions like `/a[@b='c']` (#4084)

Fixes: #4083

* Fix class cast exception in MarkIndividualDependency

* Add table and version matcher to Maven FindProperties (#4085)

The valuePattern allows use as DevCenter measurement, while the table enables custom visualizations. Target use is the `<jenkins.version>` used in Jenkins plugins.

* ensuring connection timeouts get wrapped by MavenDownloadingException (#4081)

* ensuring connection timeouts get wrapped by MavenDownloadingException

* polish

* removed a condition which I believe no longer made sense, and was causing tests to fail with latest changes

* Apply suggestions from code review

* adjusting so that IOExceptions can get caught and wrapped into MavenDownloadingException

* clarifying checked exception types for `sendRequest` and related methods

---------

Co-authored-by: Tim te Beek <tim@moderne.io>

* HasMiniumJavaVersion

* Remove explicit `Properties.File#getContent()` method

While indeed the LST should not be modified by modifying a `List` returned by a getter, it is also not right for a getter to return a new list every time (e.g. by wrapping an internal field using `Collections.unmodifiableList()`.

This commit removes the explicit getter and wither and instead has these generated by Lombok. Further, the initial contents, as populated by the parser, are now wrapped using `Collections.unmodifiableList()` to avoid any situations, where the contents are directly modified.

* Add dependency now works with empty maven projects (#4006)

* Printable Recipe Datatables  (#4087)

* Added method to export datatable information as csv to RecipeRun class

* Wrapped column value in quotes to escape commas in value

* Refactored streams to iterative loops. Log exceptions through Execution Context error handler

* Added formatCsv method. Added logic to ensure directories exist before creating files

* Refactored export logic to be more testable. Added test for csv printing logic

* Failing test cases for Quarkus version matching using `metadataPattern`s

* Add another test case.

* Get the new tests passing

* License headers

* Optimize `JavaParser.Builder#addClasspathEntry()`

* Allow null argument to CommitMessage.message()

* Fix precondition application in UpgradeDependencyVersion.

I'm a bit confused as to how this recipe succeeded before I made this change. The whole visitor, not just the precondition, was wrapped in Preconditions.or().

* Refresh resolved dependencies if possible

---------

Co-authored-by: U808771 <U808771@mobi.ch>
Co-authored-by: Sam Snyder <sam@moderne.io>
Co-authored-by: Knut Wannheden <knut@moderne.io>
Co-authored-by: Jonathan Schnéider <jkschneider@gmail.com>
Co-authored-by: René Grob <rene.grob76@gmail.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
Co-authored-by: Nick McKinney <mckinneynicholas@gmail.com>
Co-authored-by: Adriano Machado <60320+ammachado@users.noreply.github.com>
Co-authored-by: Ryan Hudson <43145457+ryan-hudson@users.noreply.github.com>
  • Loading branch information
10 people authored and app committed Apr 29, 2024
1 parent 962b0b5 commit 9e97fbe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import org.openrewrite.xml.XmlVisitor;
import org.openrewrite.xml.tree.Xml;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Predicate;

import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -59,10 +56,10 @@ public boolean isAcceptable(SourceFile sourceFile, P p) {
}

protected MavenResolutionResult getResolutionResult() {
//noinspection ConstantConditions
if (resolutionResult == null) {
resolutionResult = ((Xml.Document) getCursor()
.getPath(Xml.Document.class::isInstance)
final Iterator<Object> instanceInterator = getCursor()
.getPath(Xml.Document.class::isInstance);
if(instanceInterator.hasNext() ){
resolutionResult = ((Xml.Document) instanceInterator
.next())
.getMarkers().findFirst(MavenResolutionResult.class)
.orElseThrow(() -> new IllegalStateException("Maven visitors should not be visiting XML documents without a Maven marker"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,65 @@ void wrongVersionRange() {
)
);
}

@Test
void multiModule() {
rewriteRun(spec -> spec.recipe(new FindDependency("jakarta.activation", "jakarta.activation-api", null, null)),
pomXml(
"""
<?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.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<modules>
<module>sample-module</module>
</modules>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>
</project>
"""
,sourceSpecs -> sourceSpecs.path("pom.xml")),
pomXml(
"""
<?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.sample</groupId>
<artifactId>sample-module</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</project>
""",
"""
<?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.sample</groupId>
<artifactId>sample-module</artifactId>
<version>1.0.0</version>
<dependencies>
<!--~~>--><dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</project>
"""
,sourceSpecs -> sourceSpecs.path("sample-module/pom.xml"))
);
}
}

0 comments on commit 9e97fbe

Please sign in to comment.