1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.boretti.drools.integration.drools5; |
20 | |
|
21 | |
import java.io.File; |
22 | |
|
23 | |
import org.apache.maven.execution.MavenSession; |
24 | |
import org.apache.maven.plugin.AbstractMojo; |
25 | |
import org.apache.maven.plugin.MojoExecutionException; |
26 | |
import org.apache.maven.plugin.MojoFailureException; |
27 | |
import org.apache.maven.project.MavenProject; |
28 | |
import org.apache.maven.shared.filtering.MavenResourcesFiltering; |
29 | |
import org.codehaus.plexus.util.DirectoryScanner; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class DroolsCompileTest extends AbstractMojo { |
40 | |
|
41 | |
@Override |
42 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
43 | 0 | if (getLog().isDebugEnabled()) getLog().debug("starting drools compilation"); |
44 | 0 | DirectoryScanner scanner = new DirectoryScanner(); |
45 | 0 | if (!getInputDirectory().exists()) { |
46 | 0 | getLog().warn("Skipping not existing directory "+getInputDirectory()); |
47 | 0 | return; |
48 | |
} |
49 | 0 | scanner.setBasedir(getInputDirectory()); |
50 | 0 | scanner.setIncludes(new String[] { "**/*"+getExtension(),"*"+getExtension() }); |
51 | 0 | scanner.scan(); |
52 | 0 | boolean ok=true; |
53 | 0 | getOutputDirectory().mkdirs(); |
54 | 0 | for (String file : scanner.getIncludedFiles()) { |
55 | 0 | File sfile = new File(getInputDirectory(), file); |
56 | 0 | File dfile = new File(getOutputDirectory(),file.replaceFirst(getExtension()+"$", getCompiledExtension())); |
57 | 0 | dfile.getParentFile().mkdirs(); |
58 | 0 | if (!DroolsHelper.compileSourceFile(getLog(), project, sfile,dfile,false)) ok=false; |
59 | |
} |
60 | 0 | scanner = new DirectoryScanner(); |
61 | 0 | if (!getInputDirectory().exists()) { |
62 | 0 | getLog().warn("Skipping not existing directory "+getInputDirectory()); |
63 | 0 | return; |
64 | |
} |
65 | 0 | scanner.setBasedir(getInputDirectory()); |
66 | 0 | scanner.setIncludes(new String[] { "**/*"+getXmlExtension(),"*"+getXmlExtension() }); |
67 | 0 | scanner.scan(); |
68 | 0 | getOutputDirectory().mkdirs(); |
69 | 0 | for (String file : scanner.getIncludedFiles()) { |
70 | 0 | File sfile = new File(getInputDirectory(), file); |
71 | 0 | File dfile = new File(getOutputDirectory(),file.replaceFirst(getXmlExtension()+"$", getCompiledExtension())); |
72 | 0 | dfile.getParentFile().mkdirs(); |
73 | 0 | if (!DroolsHelper.compileSourceFile(getLog(), project, sfile,dfile,true)) ok=false; |
74 | |
} |
75 | 0 | if (!ok) { |
76 | 0 | throw new MojoExecutionException("Validation error of the drools"); |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
protected MavenSession session; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
protected MavenProject project; |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
private File outputDirectory; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
private File inputDirectory; |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
private String extension; |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
private String xmlExtension; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
private String compiledExtension; |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
protected MavenResourcesFiltering mavenResourcesFiltering; |
141 | |
|
142 | |
public File getOutputDirectory() { |
143 | 0 | return outputDirectory; |
144 | |
} |
145 | |
|
146 | |
public void setOutputDirectory(File outputDirectory) { |
147 | 0 | this.outputDirectory = outputDirectory; |
148 | 0 | } |
149 | |
|
150 | |
public File getInputDirectory() { |
151 | 0 | return inputDirectory; |
152 | |
} |
153 | |
|
154 | |
public void setInputDirectory(File inputDirectory) { |
155 | 0 | this.inputDirectory = inputDirectory; |
156 | 0 | } |
157 | |
|
158 | |
public String getExtension() { |
159 | 0 | return extension; |
160 | |
} |
161 | |
|
162 | |
public void setExtension(String extension) { |
163 | 0 | this.extension = extension; |
164 | 0 | } |
165 | |
|
166 | |
public String getCompiledExtension() { |
167 | 0 | return compiledExtension; |
168 | |
} |
169 | |
|
170 | |
public void setCompiledExtension(String compiledExtension) { |
171 | 0 | this.compiledExtension = compiledExtension; |
172 | 0 | } |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public String getXmlExtension() { |
178 | 0 | return xmlExtension; |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public void setXmlExtension(String xmlExtension) { |
185 | 0 | this.xmlExtension = xmlExtension; |
186 | 0 | } |
187 | |
|
188 | |
} |