From e870c598a7a5ea3866283c385cf5a70b18b2b557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Wed, 20 Sep 2023 21:34:54 +0200 Subject: [PATCH] Module sbm-support-jee compiles --- components/sbm-support-jee/pom.xml | 4 ++-- ...PersistenceXmlProjectResourceRegistrar.java | 5 ++++- .../api/JeeWebXmlProjectResourceRegistrar.java | 18 +++++++++++++++--- ...ledInstantiationOfExecutionContextTest.java | 2 +- .../sbm/jee/ejb/api/EjbJarXmlTest.java | 2 +- .../sbm/jee/web/api/WebXmlTest.java | 4 ++-- pom.xml | 1 + 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/components/sbm-support-jee/pom.xml b/components/sbm-support-jee/pom.xml index e9bad7e8d..0675c4141 100644 --- a/components/sbm-support-jee/pom.xml +++ b/components/sbm-support-jee/pom.xml @@ -27,8 +27,8 @@ sbm-support-jee - 11 - 11 + 17 + 17 diff --git a/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/jpa/resource/PersistenceXmlProjectResourceRegistrar.java b/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/jpa/resource/PersistenceXmlProjectResourceRegistrar.java index b0a0e4a62..09851296c 100644 --- a/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/jpa/resource/PersistenceXmlProjectResourceRegistrar.java +++ b/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/jpa/resource/PersistenceXmlProjectResourceRegistrar.java @@ -15,6 +15,8 @@ */ package org.springframework.sbm.jee.jpa.resource; +import org.openrewrite.ExecutionContext; +import org.openrewrite.internal.InMemoryLargeSourceSet; import org.springframework.sbm.jee.jpa.api.PersistenceXml; import org.springframework.sbm.project.resource.ProjectResourceWrapper; import org.springframework.sbm.project.resource.RewriteSourceFileHolder; @@ -32,6 +34,7 @@ public class PersistenceXmlProjectResourceRegistrar implements ProjectResourceWrapper> { public static final String PERSISTENCE_XML_PATH = "META-INF/persistence.xml"; + private final ExecutionContext executionContext; @Override public boolean shouldHandle(RewriteSourceFileHolder rewriteSourceFileHolder) { @@ -45,7 +48,7 @@ public boolean shouldHandle(RewriteSourceFileHolder rewrit } private boolean hasPersistenceRootTag(Xml.Document xml) { - List results = new FindTags("/persistence").run(List.of(xml)).getResults(); + List results = new FindTags("/persistence").run(new InMemoryLargeSourceSet(List.of(xml)), executionContext).getChangeset().getAllResults(); return ! results.isEmpty(); } diff --git a/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/web/api/JeeWebXmlProjectResourceRegistrar.java b/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/web/api/JeeWebXmlProjectResourceRegistrar.java index edba1cf73..a1254b6eb 100644 --- a/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/web/api/JeeWebXmlProjectResourceRegistrar.java +++ b/components/sbm-support-jee/src/main/java/org/springframework/sbm/jee/web/api/JeeWebXmlProjectResourceRegistrar.java @@ -15,6 +15,9 @@ */ package org.springframework.sbm.jee.web.api; +import org.openrewrite.ExecutionContext; +import org.openrewrite.internal.InMemoryLargeSourceSet; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.sbm.project.resource.ProjectResourceWrapper; import org.springframework.sbm.project.resource.RewriteSourceFileHolder; import org.springframework.sbm.project.web.api.WebAppType; @@ -33,6 +36,9 @@ @Configuration public class JeeWebXmlProjectResourceRegistrar implements ProjectResourceWrapper> { + @Autowired + private ExecutionContext executionContext; + // @EventListener(ProjectContextBuiltEvent.class) // public void onProjectContextBuiltEvent(ProjectContextBuiltEvent projectContextBuiltEvent) { // ProjectContext projectContext = projectContextBuiltEvent.getProjectContext(); @@ -65,10 +71,16 @@ private WebAppType parseXml(String xml) { @Override public boolean shouldHandle(RewriteSourceFileHolder rewriteSourceFileHolder) { + boolean sourceFileIsXmlDocument = Xml.Document.class.isAssignableFrom(rewriteSourceFileHolder.getSourceFile().getClass()); + boolean fileNameEndsWithWebXml = rewriteSourceFileHolder.getAbsolutePath().getFileName().endsWith("web.xml"); + List sourceFiles = List.of(rewriteSourceFileHolder.getSourceFile()); + InMemoryLargeSourceSet inMemoryLargeSourceSet = new InMemoryLargeSourceSet(sourceFiles); + boolean hasWebAppTag = !new FindTags("/web-app").run(inMemoryLargeSourceSet, executionContext).getChangeset().getAllResults().isEmpty(); return ( - Xml.Document.class.isAssignableFrom(rewriteSourceFileHolder.getSourceFile().getClass()) && - rewriteSourceFileHolder.getAbsolutePath().getFileName().endsWith("web.xml") && - ! new FindTags("/web-app").run(List.of(rewriteSourceFileHolder.getSourceFile())).getResults().isEmpty()); + sourceFileIsXmlDocument && + fileNameEndsWithWebXml && + hasWebAppTag + ); } @Override diff --git a/components/sbm-support-jee/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java b/components/sbm-support-jee/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java index 4ca962036..70e08f74f 100644 --- a/components/sbm-support-jee/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java +++ b/components/sbm-support-jee/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java @@ -24,7 +24,7 @@ import com.tngtech.archunit.lang.ArchRule; import org.openrewrite.ExecutionContext; import org.springframework.sbm.boot.autoconfigure.ScopeConfiguration; -import org.springframework.sbm.openrewrite.RewriteExecutionContext; +import org.springframework.sbm.parsers.RewriteExecutionContext; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; diff --git a/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/ejb/api/EjbJarXmlTest.java b/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/ejb/api/EjbJarXmlTest.java index 749858668..94b529a2b 100644 --- a/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/ejb/api/EjbJarXmlTest.java +++ b/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/ejb/api/EjbJarXmlTest.java @@ -153,7 +153,7 @@ void unmarshal_no_schema() throws JAXBException { ""; Path sourcePath = Path.of("some/path/ejb-jar.xml"); - Xml.Document xml = new XmlParser().parse(ejbJarXmlContent).get(0); + Xml.Document xml = (Xml.Document) new XmlParser().parse(ejbJarXmlContent).toList().get(0); EjbJarXml jeeEjbJarXmlProjectResourceRegistrar = new EjbJarXml(sourcePath, xml); EjbJarType ejbJarType = jeeEjbJarXmlProjectResourceRegistrar.unmarshal(ejbJarXmlContent); Assertions.assertThat(ejbJarType).isNotNull(); diff --git a/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/web/api/WebXmlTest.java b/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/web/api/WebXmlTest.java index b598a5371..fd54c0cab 100644 --- a/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/web/api/WebXmlTest.java +++ b/components/sbm-support-jee/src/test/java/org/springframework/sbm/jee/web/api/WebXmlTest.java @@ -82,7 +82,7 @@ void deserializeMovieFunExampleWebXml() { """; - Xml.Document document = new XmlParser().parse(webXmlSource).get(0).withSourcePath(Path.of("src/main/webapp/WEB-INF/web.xml")); + Xml.Document document = new XmlParser().parse(webXmlSource).toList().get(0).withSourcePath(Path.of("src/main/webapp/WEB-INF/web.xml")); WebXml webXml = new WebXml(Path.of("test-path").toAbsolutePath(), document); List servletDefinitions = webXml.getServletDefinitions(); @@ -141,7 +141,7 @@ void deleteServletDefinition() throws JAXBException { } private WebXml createWebXml(Path absoluteProjectDir) throws JAXBException { - Xml.Document document = new XmlParser().parse(CONTENT).get(0).withSourcePath(Path.of("src/main/webapp/WEB-INF/web.xml")); + Xml.Document document = new XmlParser().parse(CONTENT).toList().get(0).withSourcePath(Path.of("src/main/webapp/WEB-INF/web.xml")); return new WebXml(absoluteProjectDir, document); } diff --git a/pom.xml b/pom.xml index 7c70c56c6..5106915ed 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ components/test-helper components/recipe-test-support components/sbm-support-boot + components/sbm-support-jee