Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DroolsCompileTest |
|
| 1.7777777777777777;1.778 |
1 | /* | |
2 | Drools4 Integration Helper | |
3 | Copyright (C) 2009 Mathieu Boretti mathieu.boretti@gmail.com | |
4 | ||
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation, either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | */ | |
19 | package org.boretti.drools.integration.drools4; | |
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 | * This goal compile drools for test | |
34 | * @author mbo | |
35 | * @goal drools-compile-test | |
36 | * @phase test-compile | |
37 | * @requiresDependencyResolution runtime | |
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)) ok=false; |
59 | } | |
60 | 0 | if (!ok) { |
61 | 0 | throw new MojoExecutionException("Validation error of the drools"); |
62 | } | |
63 | 0 | } |
64 | ||
65 | /** | |
66 | * @parameter expression="${session}" | |
67 | * | |
68 | * @readonly | |
69 | * @required | |
70 | */ | |
71 | protected MavenSession session; | |
72 | ||
73 | /** | |
74 | * @parameter expression="${project}" | |
75 | * @required | |
76 | * @readonly | |
77 | */ | |
78 | protected MavenProject project; | |
79 | ||
80 | /** | |
81 | * The output directory into which to copy the rules. | |
82 | * | |
83 | * @parameter expression="${project.basedir}/target/test-classes" | |
84 | * @required | |
85 | */ | |
86 | private File outputDirectory; | |
87 | ||
88 | /** | |
89 | * The input directory from where to copy the rules. | |
90 | * | |
91 | * @parameter expression="${project.basedir}/src/test/drools" | |
92 | * @required | |
93 | */ | |
94 | private File inputDirectory; | |
95 | ||
96 | /** | |
97 | * The default extension for drools file | |
98 | * | |
99 | * @parameter expression=".drl" | |
100 | * @required | |
101 | */ | |
102 | private String extension; | |
103 | ||
104 | /** | |
105 | * The default extension for compiled drools file | |
106 | * | |
107 | * @parameter expression=".cdrl" | |
108 | * @required | |
109 | */ | |
110 | private String compiledExtension; | |
111 | ||
112 | /** | |
113 | * | |
114 | * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default" | |
115 | * @required | |
116 | */ | |
117 | protected MavenResourcesFiltering mavenResourcesFiltering; | |
118 | ||
119 | public File getOutputDirectory() { | |
120 | 0 | return outputDirectory; |
121 | } | |
122 | ||
123 | public void setOutputDirectory(File outputDirectory) { | |
124 | 0 | this.outputDirectory = outputDirectory; |
125 | 0 | } |
126 | ||
127 | public File getInputDirectory() { | |
128 | 0 | return inputDirectory; |
129 | } | |
130 | ||
131 | public void setInputDirectory(File inputDirectory) { | |
132 | 0 | this.inputDirectory = inputDirectory; |
133 | 0 | } |
134 | ||
135 | public String getExtension() { | |
136 | 0 | return extension; |
137 | } | |
138 | ||
139 | public void setExtension(String extension) { | |
140 | 0 | this.extension = extension; |
141 | 0 | } |
142 | ||
143 | public String getCompiledExtension() { | |
144 | 0 | return compiledExtension; |
145 | } | |
146 | ||
147 | public void setCompiledExtension(String compiledExtension) { | |
148 | 0 | this.compiledExtension = compiledExtension; |
149 | 0 | } |
150 | ||
151 | } |