Skip to content

Commit 79387ba

Browse files
committed
PL-10430 Fix beans.xml generation in test / themes modules
1 parent 8f78a2f commit 79387ba

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

src/main/groovy/CubaPlugin.groovy

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818

19+
import com.haulmont.gradle.javaeecdi.CubaBeansXml
1920
import com.haulmont.gradle.polymer.CubaPolymerToolingInfoTask
2021
import com.haulmont.gradle.task.db.CubaHsqlStart
2122
import com.haulmont.gradle.task.db.CubaHsqlStop
@@ -676,29 +677,14 @@ class CubaPlugin implements Plugin<Project> {
676677

677678
private void setJavaeeCdiNoScan(Project project) {
678679
if (!project.hasProperty('noBeansXml')) {
679-
def beansXmlDir = new File(project.buildDir, 'beansXml')
680-
681680
// create META-INF/beans.xml
682-
def beansXmlTask = project.task('beansXml') {
683-
group = 'Compile'
684-
description = 'Generates beans.xml file to disable JavaEE CDI'
685-
686-
outputs.dir(beansXmlDir)
687-
688-
doLast {
689-
def file = new File(beansXmlDir, 'META-INF/beans.xml')
690-
file.parentFile.mkdirs()
691-
file.write(getClass().getResource('/javaeecdi/beans.xml').text)
692-
}
693-
}
681+
def beansXmlTask = project.task([type: CubaBeansXml], CubaBeansXml.NAME)
694682

695683
project.jar.dependsOn beansXmlTask
696684

697685
project.jar {
698686
// add META-INF/beans.xml
699-
from(beansXmlDir) {
700-
include 'META-INF/beans.xml'
701-
}
687+
from(beansXmlTask)
702688
}
703689
}
704690
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2008-2018 Haulmont.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.haulmont.gradle.javaeecdi;
18+
19+
import org.apache.commons.io.FileUtils;
20+
import org.apache.commons.io.IOUtils;
21+
import org.gradle.api.DefaultTask;
22+
import org.gradle.api.GradleException;
23+
import org.gradle.api.tasks.OutputDirectory;
24+
import org.gradle.api.tasks.TaskAction;
25+
26+
import java.io.File;
27+
import java.io.IOException;
28+
29+
public class CubaBeansXml extends DefaultTask {
30+
31+
public static final String NAME = "beansXml";
32+
33+
public CubaBeansXml() {
34+
setGroup("Compile");
35+
setDescription("Generates beans.xml file to disable JavaEE CDI");
36+
}
37+
38+
@OutputDirectory
39+
public File getOutputDir() {
40+
return new File(getProject().getBuildDir(), "beans-xml");
41+
}
42+
43+
@TaskAction
44+
public void generate() {
45+
File beansXmlDir = getOutputDir();
46+
47+
File file = new File(beansXmlDir, "META-INF/beans.xml");
48+
//noinspection ResultOfMethodCallIgnored
49+
file.getParentFile().mkdirs();
50+
51+
try {
52+
FileUtils.write(file, IOUtils.toString(CubaBeansXml.class.getResource("/javaeecdi/beans.xml")));
53+
} catch (IOException e) {
54+
throw new GradleException("Unable to create beans.xml", e);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)