Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit a3f6176

Browse files
author
Benoit Guerin
committed
Refactor again
1 parent 483e41a commit a3f6176

File tree

11 files changed

+262
-136
lines changed

11 files changed

+262
-136
lines changed

.settings/CasperJS_format_profile.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
1717
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
1818
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
19-
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
19+
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
2020
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
2121
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
2222
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
282282
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
283283
org.eclipse.jdt.core.formatter.tabulation.char=space
284284
org.eclipse.jdt.core.formatter.tabulation.size=4
285-
org.eclipse.jdt.core.formatter.use_on_off_tags=false
285+
org.eclipse.jdt.core.formatter.use_on_off_tags=true
286286
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true
287287
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
288288
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true

src/main/java/com/github/casperjs/casperjsrunner/AbstractCasperJSRunnerMojo.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
import org.apache.maven.plugins.annotations.Parameter;
2020
import org.apache.maven.toolchain.ToolchainManager;
2121

22+
import com.github.casperjs.casperjsrunner.cmd.CasperJsRuntime;
23+
import com.github.casperjs.casperjsrunner.cmd.NativeOptions;
24+
import com.github.casperjs.casperjsrunner.cmd.Reports;
25+
import com.github.casperjs.casperjsrunner.cmd.ScriptOptions;
26+
import com.github.casperjs.casperjsrunner.cmd.TestOptions;
27+
2228
import java.io.File;
2329
import java.util.ArrayList;
2430
import java.util.Collection;
@@ -398,10 +404,18 @@ private Result executeScripts(final Collection<String> files) {
398404

399405
private int executeScript(final File f) {
400406
final String scriptName = buildName(scriptsDir, f);
407+
408+
//@formatter:off
401409
return executeCommand(
402-
computeCmdLine(buildParameters(casperRuntime, casperJsVersion, failFast, casperjsVerbose, logLevel, engine, includes,
403-
includesPatterns, includesDir, pre, post, testsDir, enableXmlReports, reportsDir, scriptName, f, arguments)),
410+
computeCmdLine(
411+
buildParameters(
412+
new CasperJsRuntime(casperRuntime, casperJsVersion),
413+
new NativeOptions(failFast, casperjsVerbose, logLevel),
414+
new TestOptions(engine, includes, includesPatterns, includesDir, pre, post, testsDir),
415+
new Reports(enableXmlReports, reportsDir),
416+
new ScriptOptions(scriptName, f, arguments))),
404417
environmentVariables, verbose, computeLogFile(scriptName));
418+
//@formatter:on
405419
}
406420

407421
private File computeLogFile(final String scriptName) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.casperjs.casperjsrunner.cmd;
2+
3+
import org.apache.maven.artifact.versioning.ArtifactVersion;
4+
5+
public class CasperJsRuntime {
6+
7+
private String exe;
8+
private ArtifactVersion version;
9+
10+
public CasperJsRuntime(final String exe, final ArtifactVersion version) {
11+
this.exe = exe;
12+
this.version = version;
13+
}
14+
15+
public String getExe() {
16+
return exe;
17+
}
18+
19+
public ArtifactVersion getVersion() {
20+
return version;
21+
}
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.casperjs.casperjsrunner.cmd;
2+
3+
public class NativeOptions {
4+
5+
private boolean failFast;
6+
private boolean verbose;
7+
private String level;
8+
9+
public NativeOptions(final boolean failFast, final boolean verbose, final String level) {
10+
this.failFast = failFast;
11+
this.verbose = verbose;
12+
this.level = level;
13+
}
14+
15+
public boolean isFailFast() {
16+
return failFast;
17+
}
18+
19+
public boolean isVerbose() {
20+
return verbose;
21+
}
22+
23+
public String getLevel() {
24+
return level;
25+
}
26+
}

src/main/java/com/github/casperjs/casperjsrunner/cmd/Parameters.java

Lines changed: 84 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,89 @@
55
import java.io.File;
66
import java.util.List;
77

8-
public interface Parameters {
9-
10-
String getCasperRuntime();
11-
12-
ArtifactVersion getCasperJsVersion();
13-
14-
boolean isFailFast();
15-
16-
boolean isCasperjsVerbose();
17-
18-
String getLogLevel();
19-
20-
String getEngine();
21-
22-
String getIncludes();
23-
24-
List<String> getIncludesPatterns();
25-
26-
File getIncludesDir();
27-
28-
String getPre();
29-
30-
String getPost();
31-
32-
File getTestsDir();
33-
34-
boolean isEnableXmlReports();
35-
36-
File getReportsDir();
37-
38-
String getScriptName();
39-
40-
File getScriptFile();
41-
42-
List<String> getArguments();
8+
public class Parameters {
9+
10+
private CasperJsRuntime runtime;
11+
private NativeOptions nativeOptions;
12+
private TestOptions testOptions;
13+
private Reports reports;
14+
private ScriptOptions scriptOptions;
15+
16+
public Parameters(final CasperJsRuntime runtime, final NativeOptions nativeOptions, final TestOptions testOptions, final Reports reports,
17+
final ScriptOptions scriptOptions) {
18+
this.runtime = runtime;
19+
this.nativeOptions = nativeOptions;
20+
this.testOptions = testOptions;
21+
this.reports = reports;
22+
this.scriptOptions = scriptOptions;
23+
}
24+
25+
public String getCasperRuntime() {
26+
return runtime.getExe();
27+
}
28+
29+
public ArtifactVersion getCasperJsVersion() {
30+
return runtime.getVersion();
31+
}
32+
33+
public boolean isFailFast() {
34+
return nativeOptions.isFailFast();
35+
}
36+
37+
public boolean isCasperjsVerbose() {
38+
return nativeOptions.isVerbose();
39+
}
40+
41+
public String getLogLevel() {
42+
return nativeOptions.getLevel();
43+
}
44+
45+
public String getEngine() {
46+
return testOptions.getEngine();
47+
}
48+
49+
public String getIncludes() {
50+
return testOptions.getIncludes();
51+
}
52+
53+
public List<String> getIncludesPatterns() {
54+
return testOptions.getIncludesPatterns();
55+
}
56+
57+
public File getIncludesDir() {
58+
return testOptions.getIncludesDir();
59+
}
60+
61+
public String getPre() {
62+
return testOptions.getPre();
63+
}
64+
65+
public String getPost() {
66+
return testOptions.getPost();
67+
}
68+
69+
public File getTestsDir() {
70+
return testOptions.getTestsDir();
71+
}
72+
73+
public boolean isEnableXmlReports() {
74+
return reports.isEnable();
75+
}
76+
77+
public File getReportsDir() {
78+
return reports.getDirectory();
79+
}
80+
81+
public String getScriptName() {
82+
return scriptOptions.getScriptName();
83+
}
84+
85+
public File getScriptFile() {
86+
return scriptOptions.getFile();
87+
}
88+
89+
public List<String> getArguments() {
90+
return scriptOptions.getArguments();
91+
}
4392

4493
}
Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,13 @@
11
package com.github.casperjs.casperjsrunner.cmd;
22

3-
import org.apache.maven.artifact.versioning.ArtifactVersion;
4-
5-
import java.io.File;
6-
import java.util.List;
7-
83
public class ParametersFactory {
94

105
private ParametersFactory() {
116
// only used as static
127
}
138

14-
public static Parameters buildParameters(final String casperRuntime, final ArtifactVersion casperJsVersion, final boolean failFast,
15-
final boolean casperjsVerbose, final String logLevel, final String engine, final String includes, final List<String> includesPatterns,
16-
final File includesDir, final String pre, final String post, final File testsDir, final boolean enableXmlReports, final File reportsDir,
17-
final String scriptName, final File f, final List<String> arguments) {
18-
return new Parameters() {
19-
@Override
20-
public String getCasperRuntime() {
21-
return casperRuntime;
22-
}
23-
24-
@Override
25-
public ArtifactVersion getCasperJsVersion() {
26-
return casperJsVersion;
27-
}
28-
29-
@Override
30-
public boolean isFailFast() {
31-
return failFast;
32-
}
33-
34-
@Override
35-
public boolean isCasperjsVerbose() {
36-
return casperjsVerbose;
37-
}
38-
39-
@Override
40-
public String getLogLevel() {
41-
return logLevel;
42-
}
43-
44-
@Override
45-
public String getEngine() {
46-
return engine;
47-
}
48-
49-
@Override
50-
public String getIncludes() {
51-
return includes;
52-
}
53-
54-
@Override
55-
public List<String> getIncludesPatterns() {
56-
return includesPatterns;
57-
}
58-
59-
@Override
60-
public File getIncludesDir() {
61-
return includesDir;
62-
}
63-
64-
@Override
65-
public String getPre() {
66-
return pre;
67-
}
68-
69-
@Override
70-
public String getPost() {
71-
return post;
72-
}
73-
74-
@Override
75-
public File getTestsDir() {
76-
return testsDir;
77-
}
78-
79-
@Override
80-
public boolean isEnableXmlReports() {
81-
return enableXmlReports;
82-
}
83-
84-
@Override
85-
public File getReportsDir() {
86-
return reportsDir;
87-
}
88-
89-
@Override
90-
public String getScriptName() {
91-
return scriptName;
92-
}
93-
94-
@Override
95-
public File getScriptFile() {
96-
return f;
97-
}
98-
99-
@Override
100-
public List<String> getArguments() {
101-
return arguments;
102-
}
103-
};
9+
public static Parameters buildParameters(final CasperJsRuntime runtime, final NativeOptions nativeOptions, final TestOptions testOptions,
10+
final Reports reports, final ScriptOptions scriptOptions) {
11+
return new Parameters(runtime, nativeOptions, testOptions, reports, scriptOptions);
10412
}
10513
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.casperjs.casperjsrunner.cmd;
2+
3+
import java.io.File;
4+
5+
public class Reports {
6+
7+
private boolean enable;
8+
private File directory;
9+
10+
public Reports(final boolean enable, final File directory) {
11+
this.enable = enable;
12+
this.directory = directory;
13+
}
14+
15+
public boolean isEnable() {
16+
return enable;
17+
}
18+
19+
public File getDirectory() {
20+
return directory;
21+
}
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.casperjs.casperjsrunner.cmd;
2+
3+
import java.io.File;
4+
import java.util.List;
5+
6+
public class ScriptOptions {
7+
8+
private String scriptName;
9+
private File file;
10+
private List<String> arguments;
11+
12+
public ScriptOptions(final String scriptName, final File file, final List<String> arguments) {
13+
this.scriptName = scriptName;
14+
this.file = file;
15+
this.arguments = arguments;
16+
}
17+
18+
public String getScriptName() {
19+
return scriptName;
20+
}
21+
22+
public File getFile() {
23+
return file;
24+
}
25+
26+
public List<String> getArguments() {
27+
return arguments;
28+
}
29+
}

0 commit comments

Comments
 (0)