Skip to content

Commit 225d046

Browse files
committed
add beans.xml is it doesn't exists
1 parent d000ca9 commit 225d046

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/com/github/adminfaces/addon/ui/AdminSetupCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public Result execute(UIExecutionContext context) throws Exception {
128128

129129
updatePom(project);
130130

131+
132+
131133
addAdminFacesResources(project).forEach(r -> results.add(Results
132134
.success("Added " + r.getFullyQualifiedName().replace(project.getRoot().getFullyQualifiedName(), ""))));
133135
setupWebXML(project);

src/main/java/com/github/adminfaces/addon/util/AdminScaffoldUtils.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.adminfaces.addon.util;
22

3+
import static com.github.adminfaces.addon.util.AdminScaffoldUtils.LOG;
34
import static com.github.adminfaces.addon.util.DependencyUtil.ADMIN_PERSISTENCE_COORDINATE;
45

6+
import java.io.ByteArrayInputStream;
57
import java.io.File;
68
import java.io.FileNotFoundException;
79
import java.io.FileOutputStream;
@@ -251,7 +253,20 @@ private static void configDeltaSpike(Project project) {
251253
}
252254
}
253255
WebResourcesFacet webResources = project.getFacet(WebResourcesFacet.class);
254-
FileResource<?> beansXml = webResources.getWebRootDirectory().getChildDirectory("WEB-INF").getChild("beans.xml").reify(FileResource.class);
256+
DirectoryResource webInfDir = webResources.getWebRootDirectory().getChildDirectory("WEB-INF");
257+
if(!webInfDir.getChild("beans.xml").exists()) {
258+
try (InputStream is = new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
259+
+ "<beans xmlns=\"http://java.sun.com/xml/ns/javaee\"\n"
260+
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
261+
+ " xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd\">\n"
262+
+ "</beans>").getBytes())) {
263+
IOUtils.copy(is, new FileOutputStream(
264+
new File(webInfDir.getFullyQualifiedName() + "/beans.xml")));
265+
} catch (Exception e) {
266+
LOG.log(Level.SEVERE, "Could not add 'beans.xml'.", e);
267+
}
268+
}
269+
FileResource<?> beansXml = webInfDir.getChild("beans.xml").reify(FileResource.class);
255270
Node node = XMLParser.parse(beansXml.getResourceInputStream());
256271
Node alternativesNode = node.getOrCreate("alternatives");
257272
Optional<Node> deltaspikeTransactionStrategy = alternativesNode.getChildren().stream()

0 commit comments

Comments
 (0)