1 package org.codehaus.mojo.rspec;
2
3 import java.io.File;
4 import java.io.FileWriter;
5 import java.util.List;
6 import java.util.Properties;
7
8 public abstract class AbstractScriptFactory implements ScriptFactory {
9
10 protected List<String> classpathElements;
11 protected File outputDir;
12 protected String baseDir;
13 protected String sourceDir;
14 protected String reportPath;
15 protected Properties systemProperties;
16
17 public void setClasspathElements(List<String> classpathElements) {
18 this.classpathElements = classpathElements;
19 }
20
21 public void setOutputDir(File outputDir) {
22 this.outputDir = outputDir;
23 }
24
25 public void setBaseDir(String baseDir) {
26 this.baseDir = baseDir;
27 }
28
29 public void setSourceDir(String sourceDir) {
30 this.sourceDir = sourceDir;
31 }
32
33 public void setReportPath(String reportPath) {
34 this.reportPath = reportPath;
35 }
36
37 public void setSystemProperties(Properties systemProperties) {
38 this.systemProperties = systemProperties;
39 }
40
41 protected abstract String getScriptName();
42
43 public void emit() throws Exception {
44 String script = getScript();
45
46 File scriptFile = new File( outputDir, getScriptName() );
47
48 FileWriter out = new FileWriter( scriptFile );
49
50 try {
51 out.write( script );
52 } finally {
53 if ( out != null ) {
54 out.close();
55 }
56 }
57
58 scriptFile.setExecutable(true);
59 }
60
61 }