Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class AddMockitoJavaAgentToMavenSurefirePlugin extends Recipe {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new DependencyInsight("org.mockito", "mockito-core", "test", null, false), new MavenIsoVisitor<ExecutionContext>() {
private final String CONFIGURATION_TAG_TEMPLATE = "<configuration><!--suppress MavenModelInspection --><argLine>%s</argLine></configuration>";
// The newline before the comment keeps auto-format from attaching it to a preceding sibling as a trailing comment
private final String CONFIGURATION_TAG_TEMPLATE = "<configuration>\n<!--suppress MavenModelInspection --><argLine>%s</argLine></configuration>";

private String getArgLineJavaAgentArgument() {
String mockitoCoreVersion = getResolutionResult().getDependencies().getOrDefault(Scope.Test, emptyList()).stream()
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/openrewrite/java/migrate/JpaCacheProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.xml.RemoveContentVisitor;
import org.openrewrite.xml.XPathMatcher;
import org.openrewrite.xml.XmlVisitor;
import org.openrewrite.xml.tree.Content;
Expand All @@ -31,7 +32,6 @@
import java.util.Optional;

import static org.openrewrite.xml.AddOrUpdateChild.addOrUpdateChild;
import static org.openrewrite.xml.FilterTagChildrenVisitor.filterTagChildren;

@EqualsAndHashCode(callSuper = false)
@Value
Expand Down Expand Up @@ -185,20 +185,28 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (sdh.openJPACacheProperty != null) {
String attrValue = getAttributeValue("value", sdh.openJPACacheProperty);
if ("true".equalsIgnoreCase(attrValue) || "false".equalsIgnoreCase(attrValue)) {
sdh.propertiesElement = filterTagChildren(sdh.propertiesElement, child -> child != sdh.openJPACacheProperty);
sdh.propertiesElement = removeContent(sdh.propertiesElement, sdh.openJPACacheProperty, ctx);
t = addOrUpdateChild(t, sdh.propertiesElement, getCursor().getParentOrThrow());
}
}

// if both shared-cache-mode and javax cache property are set, delete the
// javax cache property
if (sdh.sharedCacheModeElement != null && sdh.sharedCacheModeProperty != null) {
sdh.propertiesElement = filterTagChildren(sdh.propertiesElement, child -> child != sdh.sharedCacheModeProperty);
sdh.propertiesElement = removeContent(sdh.propertiesElement, sdh.sharedCacheModeProperty, ctx);
t = addOrUpdateChild(t, sdh.propertiesElement, getCursor().getParentOrThrow());
}
return t;
}

/**
* Unlike {@code filterTagChildren}, this hands the removed element's prefix to a comment that trailed it,
* so the comment keeps its own line rather than collapsing onto the preceding sibling.
*/
private static Xml.Tag removeContent(Xml.Tag parent, Xml.Tag child, ExecutionContext ctx) {
return (Xml.Tag) new RemoveContentVisitor<ExecutionContext>(child, false, false).visitNonNull(parent, ctx);
}

private SharedDataHolder extractData(Xml.Tag puNode) {
SharedDataHolder sdh = new SharedDataHolder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ void notset_set_set1() {
<properties>
<!-- Connection properties -->
<!-- remove -->
<property name="javax.persistence.sharedCache.mode" value="NONE"/>
<!-- leave -->
<property name="javax.persistence.sharedCache.mode" value="NONE"/><!-- leave -->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -644,8 +643,7 @@ void notset_set_set2() {
<properties>
<!-- Connection properties -->
<!-- remove -->
<property name="javax.persistence.sharedCache.mode" value="ALL"/>
<!-- leave -->
<property name="javax.persistence.sharedCache.mode" value="ALL"/><!-- leave -->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -681,8 +679,7 @@ void notset_set_set3() {
<properties>
<!-- Connection properties -->
<!-- remove -->
<property name="javax.persistence.sharedCache.mode" value="ALL"/>
<!-- change to ALL -->
<property name="javax.persistence.sharedCache.mode" value="ALL"/><!-- change to ALL -->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -783,8 +780,7 @@ void notset_set_notset3() {
<validation-mode>NONE</validation-mode>
<properties>
<!-- Connection properties -->
<property name="javax.persistence.sharedCache.mode" value="NONE"/>
<!-- change to NONE -->
<property name="javax.persistence.sharedCache.mode" value="NONE"/><!-- change to NONE -->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -909,14 +905,12 @@ void notset_notset_set3() {
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="notset_notset_set3">
<!-- flag -->
<!-- add shared-cache-mode ENABLE_SELECTIVE -->
<!-- flag --> <!-- add shared-cache-mode ENABLE_SELECTIVE -->
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
<!-- Connection properties -->
<property name="openjpa.DataCache" value="truE(Types=foo.bar.Person;foo.bar.Employee)"/>
<!-- leave - manual fix-->
<property name="openjpa.DataCache" value="truE(Types=foo.bar.Person;foo.bar.Employee)"/><!-- leave - manual fix-->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -947,14 +941,12 @@ void notset_notset_set4() {
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="notset_notset_set4">
<!-- flag -->
<!-- add shared-cache-mode DISABLE_SELECTIVE -->
<!-- flag --> <!-- add shared-cache-mode DISABLE_SELECTIVE -->
<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
<!-- Connection properties -->
<property name="openjpa.DataCache" value="TRUE(ExcludedTypes=foo.bar.Person;foo.bar.Employee)"/>
<!-- leave - manual fix -->
<property name="openjpa.DataCache" value="TRUE(ExcludedTypes=foo.bar.Person;foo.bar.Employee)"/><!-- leave - manual fix -->
</properties>
</persistence-unit>
</persistence>
Expand Down Expand Up @@ -1139,8 +1131,7 @@ void openjpa_cache3_flagged() {
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="openjpa_cache3_flagged">
<!-- flag -->
<!-- create shared-cache-mode NONE -->
<!-- flag --><!-- create shared-cache-mode NONE -->
<shared-cache-mode>NONE</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
Expand Down
Loading