1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
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 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class DroolsCompile 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 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
protected MavenSession session; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
protected MavenProject project; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
private File outputDirectory; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
private File inputDirectory; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
private String extension; |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
private String compiledExtension; |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
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 | |
} |