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 | |
import java.io.IOException; |
23 | |
|
24 | |
import org.apache.maven.execution.MavenSession; |
25 | |
import org.apache.maven.plugin.AbstractMojo; |
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.MojoFailureException; |
28 | |
import org.apache.maven.project.MavenProject; |
29 | |
import org.apache.maven.shared.filtering.MavenResourcesFiltering; |
30 | |
import org.codehaus.plexus.util.DirectoryScanner; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class DroolsCopyAndValidate extends AbstractMojo { |
41 | |
|
42 | |
@Override |
43 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
44 | 0 | if (getLog().isDebugEnabled()) getLog().debug("starting drools copy and validation"); |
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 | getOutputDirectory().mkdirs(); |
55 | 0 | for (String file : scanner.getIncludedFiles()) { |
56 | 0 | File sfile = new File(getInputDirectory(), file); |
57 | 0 | File dfile = new File(getOutputDirectory(),file); |
58 | 0 | dfile.getParentFile().mkdirs(); |
59 | 0 | if (!DroolsHelper.validateSourceFile(getLog(), project, sfile,false)) ok=false; |
60 | |
try { |
61 | 0 | FileHelper.copyFile(sfile, dfile); |
62 | 0 | } catch (IOException e) { |
63 | 0 | getLog().error("Unable to copy file :"+e.getMessage(),e); |
64 | 0 | throw new MojoExecutionException("Unable to coyp file :"+e.getMessage(),e); |
65 | 0 | } |
66 | |
} |
67 | 0 | scanner = new DirectoryScanner(); |
68 | 0 | if (!getInputDirectory().exists()) { |
69 | 0 | getLog().warn("Skipping not existing directory "+getInputDirectory()); |
70 | 0 | return; |
71 | |
} |
72 | 0 | scanner.setBasedir(getInputDirectory()); |
73 | 0 | scanner.setIncludes(new String[] { "**/*"+getXmlExtension(),"*"+getXmlExtension() }); |
74 | 0 | scanner.scan(); |
75 | 0 | getOutputDirectory().mkdirs(); |
76 | 0 | for (String file : scanner.getIncludedFiles()) { |
77 | 0 | File sfile = new File(getInputDirectory(), file); |
78 | 0 | File dfile = new File(getOutputDirectory(),file); |
79 | 0 | dfile.getParentFile().mkdirs(); |
80 | 0 | if (!DroolsHelper.validateSourceFile(getLog(), project, sfile,true)) ok=false; |
81 | |
try { |
82 | 0 | FileHelper.copyFile(sfile, dfile); |
83 | 0 | } catch (IOException e) { |
84 | 0 | getLog().error("Unable to copy file :"+e.getMessage(),e); |
85 | 0 | throw new MojoExecutionException("Unable to coyp file :"+e.getMessage(),e); |
86 | 0 | } |
87 | |
} |
88 | 0 | if (!ok) { |
89 | 0 | throw new MojoExecutionException("Validation error of the drools"); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
protected MavenSession session; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
protected MavenProject project; |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
private File outputDirectory; |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
private File inputDirectory; |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
private String extension; |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
private String xmlExtension; |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
protected MavenResourcesFiltering mavenResourcesFiltering; |
146 | |
|
147 | |
public File getOutputDirectory() { |
148 | 0 | return outputDirectory; |
149 | |
} |
150 | |
|
151 | |
public void setOutputDirectory(File outputDirectory) { |
152 | 0 | this.outputDirectory = outputDirectory; |
153 | 0 | } |
154 | |
|
155 | |
public File getInputDirectory() { |
156 | 0 | return inputDirectory; |
157 | |
} |
158 | |
|
159 | |
public void setInputDirectory(File inputDirectory) { |
160 | 0 | this.inputDirectory = inputDirectory; |
161 | 0 | } |
162 | |
|
163 | |
public String getExtension() { |
164 | 0 | return extension; |
165 | |
} |
166 | |
|
167 | |
public void setExtension(String extension) { |
168 | 0 | this.extension = extension; |
169 | 0 | } |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public String getXmlExtension() { |
175 | 0 | return xmlExtension; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public void setXmlExtension(String xmlExtension) { |
182 | 0 | this.xmlExtension = xmlExtension; |
183 | 0 | } |
184 | |
|
185 | |
} |