Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DroolsClassPostProcessor |
|
| 2.2;2.2 |
1 | /* | |
2 | Drools5 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.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 | * This goal compile drools | |
34 | * @author mbo | |
35 | * @since 1.0.0 | |
36 | * @goal drools-postprocessor | |
37 | * @phase process-classes | |
38 | * @requiresDependencyResolution runtime | |
39 | */ | |
40 | 0 | public class DroolsClassPostProcessor extends AbstractMojo { |
41 | ||
42 | @Override | |
43 | public void execute() throws MojoExecutionException, MojoFailureException { | |
44 | 0 | if (getLog().isDebugEnabled()) getLog().debug("starting drools post-compilation"); |
45 | 0 | DirectoryScanner scanner = new DirectoryScanner(); |
46 | 0 | if (!getInputDirectory().exists()) { |
47 | 0 | getLog().warn("Skipping not existing directory "+getInputDirectory()); |
48 | 0 | return; |
49 | } | |
50 | 0 | scanner.setBasedir(getInputDirectory()); |
51 | 0 | scanner.setIncludes(new String[] { "**/*"+getExtension(),"*"+getExtension() }); |
52 | 0 | scanner.scan(); |
53 | 0 | boolean ok=true; |
54 | 0 | for (String file : scanner.getIncludedFiles()) { |
55 | 0 | File sfile = new File(getInputDirectory(), file); |
56 | 0 | DroolsClassProcessor.ClassProcessor(getLog(), sfile); |
57 | } | |
58 | 0 | if (!ok) { |
59 | 0 | throw new MojoExecutionException("Error of the drools"); |
60 | } | |
61 | 0 | } |
62 | ||
63 | /** | |
64 | * @parameter expression="${session}" | |
65 | * | |
66 | * @readonly | |
67 | * @required | |
68 | */ | |
69 | protected MavenSession session; | |
70 | ||
71 | /** | |
72 | * @parameter expression="${project}" | |
73 | * @required | |
74 | * @readonly | |
75 | */ | |
76 | protected MavenProject project; | |
77 | ||
78 | /** | |
79 | * The input directory from where to copy the rules. | |
80 | * | |
81 | * @parameter expression="${project.basedir}/target/classes" | |
82 | * @required | |
83 | */ | |
84 | private File inputDirectory; | |
85 | ||
86 | /** | |
87 | * The default extension for drools file | |
88 | * | |
89 | * @parameter expression=".class" | |
90 | * @required | |
91 | */ | |
92 | private String extension; | |
93 | ||
94 | /** | |
95 | * | |
96 | * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default" | |
97 | * @required | |
98 | */ | |
99 | protected MavenResourcesFiltering mavenResourcesFiltering; | |
100 | ||
101 | public File getInputDirectory() { | |
102 | 0 | return inputDirectory; |
103 | } | |
104 | ||
105 | public void setInputDirectory(File inputDirectory) { | |
106 | 0 | this.inputDirectory = inputDirectory; |
107 | 0 | } |
108 | ||
109 | public String getExtension() { | |
110 | 0 | return extension; |
111 | } | |
112 | ||
113 | public void setExtension(String extension) { | |
114 | 0 | this.extension = extension; |
115 | 0 | } |
116 | ||
117 | } |