|
1 | 1 | package com.github.adminfaces.addon.util; |
2 | 2 |
|
| 3 | +import static com.github.adminfaces.addon.util.AdminScaffoldUtils.LOG; |
3 | 4 | import static com.github.adminfaces.addon.util.DependencyUtil.ADMIN_PERSISTENCE_COORDINATE; |
4 | 5 |
|
| 6 | +import java.io.ByteArrayInputStream; |
5 | 7 | import java.io.File; |
6 | 8 | import java.io.FileNotFoundException; |
7 | 9 | import java.io.FileOutputStream; |
@@ -251,7 +253,20 @@ private static void configDeltaSpike(Project project) { |
251 | 253 | } |
252 | 254 | } |
253 | 255 | 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); |
255 | 270 | Node node = XMLParser.parse(beansXml.getResourceInputStream()); |
256 | 271 | Node alternativesNode = node.getOrCreate("alternatives"); |
257 | 272 | Optional<Node> deltaspikeTransactionStrategy = alternativesNode.getChildren().stream() |
|
0 commit comments