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