11package pl .wavesoftware .gasper ;
22
3- import com .google .common .collect .ImmutableMap ;
43import org .slf4j .event .Level ;
54import pl .wavesoftware .eid .utils .EidPreconditions ;
65import pl .wavesoftware .gasper .internal .Executor ;
1110import java .net .ServerSocket ;
1211import java .nio .file .Path ;
1312import java .nio .file .Paths ;
13+ import java .util .ArrayList ;
14+ import java .util .Collections ;
1415import java .util .LinkedHashMap ;
16+ import java .util .List ;
1517import java .util .Map ;
1618import java .util .function .Function ;
1719
@@ -25,9 +27,10 @@ public final class GasperBuilder extends Gasper.RunnerCreator {
2527
2628 private String packaging = MavenResolver .DEFAULT_PACKAGING ;
2729 private String classifier = "" ;
28- private Map <String , String > javaOptions = new LinkedHashMap <>();
30+ private Map <String , String > systemProperties = new LinkedHashMap <>();
31+ private List <String > jvmOptions = new ArrayList <>();
2932 private Map <String , String > environment = new LinkedHashMap <>();
30- private String portJavaOption ;
33+ private String systemPropertyForPort ;
3134 private Integer port ;
3235 private boolean inheritIO = false ;
3336 private String context = Gasper .DEFAULT_CONTEXT ;
@@ -39,12 +42,12 @@ public final class GasperBuilder extends Gasper.RunnerCreator {
3942
4043 protected GasperBuilder () {}
4144
42- public GasperBuilder withPackaging (String packaging ) {
45+ public GasperBuilder withArtifactPackaging (String packaging ) {
4346 this .packaging = packaging ;
4447 return this ;
4548 }
4649
47- public GasperBuilder withClassifier (String classifier ) {
50+ public GasperBuilder withArtifactClassifier (String classifier ) {
4851 this .classifier = classifier ;
4952 return this ;
5053 }
@@ -54,8 +57,13 @@ public GasperBuilder withEnvironmentVariable(String key, String value) {
5457 return this ;
5558 }
5659
57- public GasperBuilder withJavaOption (String key , String value ) {
58- javaOptions .put (key , value );
60+ public GasperBuilder withSystemProperty (String key , String value ) {
61+ systemProperties .put (key , value );
62+ return this ;
63+ }
64+
65+ public GasperBuilder withJVMOptions (String ... options ) {
66+ Collections .addAll (jvmOptions , options );
5967 return this ;
6068 }
6169
@@ -64,72 +72,72 @@ public GasperBuilder withPort(int port) {
6472 return this ;
6573 }
6674
67- public GasperBuilder usePortJavaOptionFor (String portJavaOption ) {
68- this .portJavaOption = portJavaOption ;
75+ public GasperBuilder usingSystemPropertyForPort (String systemPropertyForPort ) {
76+ this .systemPropertyForPort = systemPropertyForPort ;
6977 return this ;
7078 }
7179
72- public GasperBuilder usePomFile (Path pomfile ) {
80+ public GasperBuilder usingPomFile (Path pomfile ) {
7381 this .pomfile = pomfile ;
7482 return this ;
7583 }
7684
77- public GasperBuilder inheritIO () {
78- return inheritIO (true );
85+ public GasperBuilder withServerLoggingOnConsole () {
86+ return withServerLoggingOnConsole (true );
7987 }
8088
81- public GasperBuilder inheritIO (boolean inheritIO ) {
89+ public GasperBuilder withServerLoggingOnConsole (boolean inheritIO ) {
8290 this .inheritIO = inheritIO ;
8391 return this ;
8492 }
8593
86- public Gasper build () {
87- if (port == null ) {
88- port = findNotBindedPort ();
89- }
90- if (portJavaOption != null ) {
91- withJavaOption (portJavaOption , port .toString ());
92- }
93- Settings settings = new Settings (
94- packaging , classifier , port ,
95- ImmutableMap .copyOf (javaOptions ), ImmutableMap .copyOf (environment ),
96- inheritIO , context , contextChecker ,
97- portAvailableMaxTime , deploymentMaxTime ,
98- pomfile , level
99- );
100- return create (settings );
101- }
102-
103- public GasperBuilder maxStartupTime (int seconds ) {
94+ public GasperBuilder withMaxStartupTime (int seconds ) {
10495 this .portAvailableMaxTime = seconds ;
10596 return this ;
10697 }
10798
108- public GasperBuilder maxDeploymentTime (int seconds ) {
99+ public GasperBuilder withMaxDeploymentTime (int seconds ) {
109100 this .deploymentMaxTime = seconds ;
110101 return this ;
111102 }
112103
113- public GasperBuilder waitForContext (String context ) {
104+ public GasperBuilder waitForWebContext (String context ) {
114105 this .context = context ;
115106 return this ;
116107 }
117108
118- public GasperBuilder useContextChecker (Function <HttpEndpoint , Boolean > contextChecker ) {
109+ public GasperBuilder usingWebContextChecker (Function <HttpEndpoint , Boolean > contextChecker ) {
119110 this .contextChecker = contextChecker ;
120111 return this ;
121112 }
122113
123- public GasperBuilder silent () {
124- useLogLevel (Level .WARN );
114+ public GasperBuilder silentGasperMessages () {
115+ usingLogLevel (Level .WARN );
125116 return this ;
126117 }
127118
128- public GasperBuilder useLogLevel (Level level ) {
119+ public GasperBuilder usingLogLevel (Level level ) {
129120 this .level = level ;
130121 return this ;
131122 }
132123
124+ public Gasper build () {
125+ if (port == null ) {
126+ port = findNotBindedPort ();
127+ }
128+ if (systemPropertyForPort != null ) {
129+ withSystemProperty (systemPropertyForPort , port .toString ());
130+ }
131+ Settings settings = new Settings (
132+ packaging , classifier , port ,
133+ systemProperties , jvmOptions , environment ,
134+ inheritIO , context , contextChecker ,
135+ portAvailableMaxTime , deploymentMaxTime ,
136+ pomfile , level
137+ );
138+ return create (settings );
139+ }
140+
133141 private static Integer findNotBindedPort () {
134142 return tryToExecute ((EidPreconditions .UnsafeSupplier <Integer >) () -> {
135143 try (ServerSocket socket = new ServerSocket (0 )) {
0 commit comments