View Javadoc
1   package com.github.searls.jasmine.runner;
2   
3   import com.github.searls.jasmine.config.JasmineConfiguration;
4   import com.github.searls.jasmine.io.IOUtilsWrapper;
5   import com.github.searls.jasmine.io.scripts.ScriptResolver;
6   import org.apache.commons.io.FileUtils;
7   
8   import java.io.File;
9   import java.io.IOException;
10  
11  public class HtmlGeneratorConfiguration {
12    private final String sourceEncoding;
13    private final ReporterType reporterType;
14    private final File customRunnerTemplate;
15    private final File customRunnerConfiguration;
16    private final IOUtilsWrapper ioUtilsWrapper;
17    private final SpecRunnerTemplate specRunnerTemplate;
18    private final ScriptResolver scriptResolver;
19    private final String srcDirectoryName;
20    private final String specDirectoryName;
21    private final int autoRefreshInterval;
22    private final boolean autoRefresh;
23  
24    public HtmlGeneratorConfiguration(ReporterType reporterType, JasmineConfiguration configuration, ScriptResolver scriptResolver) throws IOException {
25      this(new IOUtilsWrapper(), reporterType, configuration, scriptResolver);
26    }
27  
28    public HtmlGeneratorConfiguration(IOUtilsWrapper ioUtilsWrapper, ReporterType reporterType, JasmineConfiguration configuration, ScriptResolver scriptResolver) throws IOException {
29      this.ioUtilsWrapper = ioUtilsWrapper;
30      this.sourceEncoding = configuration.getSourceEncoding();
31      this.reporterType = reporterType;
32      this.customRunnerTemplate = configuration.getCustomRunnerTemplate();
33      this.specRunnerTemplate = configuration.getSpecRunnerTemplate();
34      this.scriptResolver = scriptResolver;
35      this.customRunnerConfiguration = configuration.getCustomRunnerConfiguration();
36      this.srcDirectoryName = configuration.getSrcDirectoryName();
37      this.specDirectoryName = configuration.getSpecDirectoryName();
38      this.autoRefreshInterval = configuration.getAutoRefreshInterval();
39      this.autoRefresh = this.autoRefreshInterval > 0 && ReporterType.HtmlReporter.equals(reporterType);
40    }
41  
42    public String getSourceEncoding() {
43      return this.sourceEncoding;
44    }
45  
46    public ReporterType getReporterType() {
47      return this.reporterType;
48    }
49  
50    public File getCustomRunnerTemplate() {
51      return this.customRunnerTemplate;
52    }
53  
54    public String IOtoString(String defaultHtmlTemplatePath) throws IOException {
55      return this.ioUtilsWrapper.toString(defaultHtmlTemplatePath);
56    }
57  
58    public String getRunnerTemplate() throws IOException {
59      if (this.getCustomRunnerTemplate() != null) {
60        return FileUtils.readFileToString(this.getCustomRunnerTemplate());
61      } else {
62        SpecRunnerTemplate template = this.getSpecRunnerTemplate();
63        if (template == null) {
64          template = SpecRunnerTemplate.DEFAULT;
65        }
66        return this.IOtoString(template.getTemplate());
67      }
68    }
69  
70    public SpecRunnerTemplate getSpecRunnerTemplate() {
71      return this.specRunnerTemplate;
72    }
73  
74    public ScriptResolver getScriptResolver() {
75      return this.scriptResolver;
76    }
77  
78    @Override
79    public boolean equals(Object o) {
80      if (this == o) return true;
81      if (o == null || this.getClass() != o.getClass()) return false;
82  
83      HtmlGeneratorConfiguration that = (HtmlGeneratorConfiguration) o;
84  
85      if (this.customRunnerTemplate != null ? !this.customRunnerTemplate.equals(that.customRunnerTemplate) : that.customRunnerTemplate != null)
86        return false;
87      if (this.reporterType != that.reporterType) return false;
88      if (this.sourceEncoding != null ? !this.sourceEncoding.equals(that.sourceEncoding) : that.sourceEncoding != null)
89        return false;
90      if (this.specRunnerTemplate != null ? !this.specRunnerTemplate.equals(that.specRunnerTemplate) : that.specRunnerTemplate != null)
91        return false;
92  
93      return true;
94    }
95  
96    @Override
97    public int hashCode() {
98      int result = this.sourceEncoding != null ? this.sourceEncoding.hashCode() : 0;
99      result = 31 * result + (this.reporterType != null ? this.reporterType.hashCode() : 0);
100     result = 31 * result + (this.customRunnerTemplate != null ? this.customRunnerTemplate.hashCode() : 0);
101     result = 31 * result + (this.specRunnerTemplate != null ? this.specRunnerTemplate.hashCode() : 0);
102     return result;
103   }
104 
105   public String getCustomRunnerConfiguration() throws IOException {
106     return this.customRunnerConfiguration == null ? null : FileUtils.readFileToString(this.customRunnerConfiguration);
107   }
108 
109   public String getSrcDirectoryName() {
110     return this.srcDirectoryName;
111   }
112 
113   public String getSpecDirectoryName() {
114     return this.specDirectoryName;
115   }
116 
117   public int getAutoRefreshInterval() {
118     return this.autoRefreshInterval;
119   }
120 
121   public boolean getAutoRefresh() {
122     return this.autoRefresh;
123   }
124 }
125 
126