Skip to content

Commit

Permalink
Module sbm-support-jee compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Sep 20, 2023
1 parent 049155c commit e870c59
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions components/sbm-support-jee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<artifactId>sbm-support-jee</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +34,7 @@
public class PersistenceXmlProjectResourceRegistrar implements ProjectResourceWrapper<RewriteSourceFileHolder<Xml.Document>> {

public static final String PERSISTENCE_XML_PATH = "META-INF/persistence.xml";
private final ExecutionContext executionContext;

@Override
public boolean shouldHandle(RewriteSourceFileHolder<? extends SourceFile> rewriteSourceFileHolder) {
Expand All @@ -45,7 +48,7 @@ public boolean shouldHandle(RewriteSourceFileHolder<? extends SourceFile> rewrit
}

private boolean hasPersistenceRootTag(Xml.Document xml) {
List<Result> results = new FindTags("/persistence").run(List.of(xml)).getResults();
List<Result> results = new FindTags("/persistence").run(new InMemoryLargeSourceSet(List.of(xml)), executionContext).getChangeset().getAllResults();
return ! results.isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +36,9 @@
@Configuration
public class JeeWebXmlProjectResourceRegistrar implements ProjectResourceWrapper<RewriteSourceFileHolder<Xml.Document>> {

@Autowired
private ExecutionContext executionContext;

// @EventListener(ProjectContextBuiltEvent.class)
// public void onProjectContextBuiltEvent(ProjectContextBuiltEvent projectContextBuiltEvent) {
// ProjectContext projectContext = projectContextBuiltEvent.getProjectContext();
Expand Down Expand Up @@ -65,10 +71,16 @@ private WebAppType parseXml(String xml) {

@Override
public boolean shouldHandle(RewriteSourceFileHolder<? extends SourceFile> rewriteSourceFileHolder) {
boolean sourceFileIsXmlDocument = Xml.Document.class.isAssignableFrom(rewriteSourceFileHolder.getSourceFile().getClass());
boolean fileNameEndsWithWebXml = rewriteSourceFileHolder.getAbsolutePath().getFileName().endsWith("web.xml");
List<SourceFile> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void unmarshal_no_schema() throws JAXBException {
"</ejb-jar>";

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void deserializeMovieFunExampleWebXml() {
</servlet-mapping>
</web-app>
""";
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<ServletDefinition> servletDefinitions = webXml.getServletDefinitions();

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<module>components/test-helper</module>
<module>components/recipe-test-support</module>
<module>components/sbm-support-boot</module>
<module>components/sbm-support-jee</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down

0 comments on commit e870c59

Please sign in to comment.