/
JavaProfile.java
1432 lines (1350 loc) · 48.2 KB
/
JavaProfile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright 2016 Jalian Systems Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package net.sourceforge.marathon.javadriver;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.os.CommandLine;
import net.sourceforge.marathon.javaagent.JavaAgent;
import net.sourceforge.marathon.javafxagent.JavaFXAgent;
/**
* Class to specify options to {@link JavaDriver}.
*
* <p>
* The {@code JavaProfile} class provides methods to configure the Java/Swing or
* Java/FX application under test and is used construct a {@link JavaDriver} to
* perform operations.
* </p>
*
*/
public class JavaProfile {
/**
* Logger
*/
public static final Logger LOGGER = Logger.getLogger(JavaProfile.class.getName());
private static final String PROP_HOME = "marathon.home";
private static final String MARATHON_AGENT = "marathon.agent";
private static final String MARATHON_RECORDER = "marathon.recorder";
private static Map<String, File> jnlpFiles = new HashMap<String, File>();
private static final File NULLFILE = new File("");
/**
* {@code LaunchType} specifies the type of application either
* {@code SWING_APPLICATION} or {@code FX_APPLICATION}.
*/
public enum LaunchType {
// @formatter:off
/**
* Identifies a Java/Swing application.
*/
SWING_APPLICATION("java"),
/**
* Identifies a Java/FX application.
*/
FX_APPLICATION("javafx"),
;
private String prefix;
// @formatter:on
LaunchType(String prefix) {
this.prefix = prefix;
}
/**
* Get the prefix used to find java agent files.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
}
/**
* {@code LaunchMode} identifies how a Java application under test is
* launched.
*
*/
public enum LaunchMode {
// @formatter:off
/**
* EMBEDDED - in application testing. Can be used for unit testing. Created using
* {@link JavaProfile#JavaProfile()} default constructor.
*/
EMBEDDED("unittesting", "Unit Testing"),
/**
* Launched using java command line.
*/
JAVA_COMMAND_LINE("javacommand", "Java Command Line", "vmargument", "classpath", "mainclass", "appargument"),
/**
* A Java WebStart application
*/
JAVA_WEBSTART("webstart", "WebStart Application", "vmargument", "wsargument", "jnlppath", "jnlpnolocalcopy", "startwindowtitle"),
/**
* Launched using a command - either a shell script or an executable
*/
COMMAND_LINE("commandline", "Command Line", "command", "appargument", "startwindowtitle", "vmargument"),
/**
* Applet
*/
JAVA_APPLET("applet", "Applet Application", "vmargument", "appleturl", "startwindowtitle"),
/**
* Launched using an executable jar. <code>java -jar</code>
*/
EXECUTABLE_JAR("executablejar", "Executable JAR", "executablejar", "appargument", "startwindowtitle", "vmargument"),
;
// @formatter:on
private String name;
private String description;
private List<String> validProperties = new ArrayList<String>();
LaunchMode(String name, String description, String... validProperties) {
this.name = name;
this.description = description;
for (String prop : validProperties) {
this.validProperties.add(prop);
}
}
/**
* Check whether the given property is valid for this {@code LaunchMode}
*
* @param property
* the property
* @return true if valid, false otherwise
*/
public boolean isValidProperty(String property) {
return validProperties.contains(property);
}
@Override
public String toString() {
return "Launchmode " + description;
}
/**
* Return the name of the LaunchMode
*
* @return the name
*/
public String getName() {
return name;
}
}
private List<String> classPathEntries = new ArrayList<String>();
private List<String> vmArguments = new ArrayList<String>();
private List<String> wsArguments = new ArrayList<String>();
private List<String> appArguments = new ArrayList<String>();
private LaunchMode launchMode;
private LaunchType launchType = LaunchType.SWING_APPLICATION;
private String mainClass;
private String jnlpPath;
private int port;
private String startWindowTitle;
private String workingDirectory;
private String vmCommand;
private String command;
private String appletURL;
private static String dirOfMarathonJavaDriverJar;
private boolean keepLog = false;
private int recordingPort = -1;
private OutputStream outputStream;
private String javaHome;
private boolean nativeEvents;
private String executableJar;
private boolean jnlpNoLocalCopy;
static {
dirOfMarathonJavaDriverJar = ClassPathHelper.getClassPath(JavaProfile.class.getName());
File dir = new File(dirOfMarathonJavaDriverJar).getParentFile();
if (dir.exists()) {
dirOfMarathonJavaDriverJar = dir.getAbsolutePath();
} else {
dirOfMarathonJavaDriverJar = ".";
}
}
/**
* Constructs a {@code JavaProfile} in embedded mode.
*
* <p>
* In embedded mode, {@link JavaDriver#quit()} doesn't stop the VM, allowing
* you to execute multiple tests.
* </p>
*
* <p>
* We used it in Unit tests - however not well tested. It's your
* responsibility to close and open the windows before executing the tests.
* </p>
*/
public JavaProfile() {
this(LaunchMode.EMBEDDED);
}
/**
* Create a {@code JavaProfile} with the given {@link LaunchMode}.
*
* @param launchMode
* the launch mode, one of JAVA_COMMAND_LINE, JAVA_WEBSTART,
* COMMAND_LINE or EXECUTABLE_JAR
*/
public JavaProfile(LaunchMode launchMode) {
this.launchMode = launchMode;
this.port = findPort();
}
/**
* Given a URL created using {@link JavaProfile#asURL()} reconstructs the
* {@code JavaProfile} object. Similar to serialization and used in
* MarathonGrid.
*
* @param url
* the url to parse
* @throws URISyntaxException
* on error
*/
public JavaProfile(URL url) throws URISyntaxException {
parse(url);
this.port = findPort();
}
/**
* Get the port number the WebDriver server listens to
*
* @return the port
*/
public int getPort() {
return port;
}
/**
* Creates the {@link org.openqa.selenium.os.CommandLine} from the profile.
* Executing this command line, starts the AUT and listens on the port.
*
* @return commandline
*/
public CommandLine getCommandLine() {
if (launchMode == LaunchMode.JAVA_COMMAND_LINE) {
List<String> args = new ArrayList<String>();
args.add(findJavaBinary());
if (classPathEntries.size() > 0) {
args.add("-cp");
args.add(getClassPath());
}
args.add(mainClass);
args.addAll(appArguments);
CommandLine commandLine = new CommandLine(args.toArray(new String[args.size()]));
setToolOptions(commandLine);
if (javaHome != null) {
commandLine.setEnvironmentVariable("JAVA_HOME", javaHome);
}
if (workingDirectory != null) {
commandLine.setWorkingDirectory(workingDirectory);
}
if (outputStream != null) {
commandLine.copyOutputTo(outputStream);
}
return commandLine;
}
if (launchMode == LaunchMode.JAVA_WEBSTART) {
List<String> args = new ArrayList<String>();
args.add(findJavaWSBinary());
args.addAll(wsArguments);
if (jnlpPath != null) {
args.add(getLocalCopy(jnlpPath));
} else {
throw new WebDriverException("You must set either JNLP URL or File");
}
CommandLine commandLine = new CommandLine(args.toArray(new String[args.size()]));
setToolOptions(commandLine);
if (javaHome != null) {
commandLine.setEnvironmentVariable("JAVA_HOME", javaHome);
}
if (workingDirectory != null) {
commandLine.setWorkingDirectory(workingDirectory);
}
if (outputStream != null) {
commandLine.copyOutputTo(outputStream);
}
return commandLine;
}
if (launchMode == LaunchMode.JAVA_APPLET) {
List<String> args = new ArrayList<String>();
args.add(findAppletViewerBinary());
if (appletURL != null) {
args.add(appletURL);
}
CommandLine commandLine = new CommandLine(args.toArray(new String[args.size()]));
setToolOptions(commandLine);
if (javaHome != null) {
commandLine.setEnvironmentVariable("JAVA_HOME", javaHome);
}
if (workingDirectory != null) {
commandLine.setWorkingDirectory(workingDirectory);
}
if (outputStream != null) {
commandLine.copyOutputTo(outputStream);
}
return commandLine;
}
if (launchMode == LaunchMode.COMMAND_LINE) {
List<String> args = new ArrayList<String>();
args.add(command);
args.addAll(appArguments);
CommandLine commandLine = new CommandLine(args.toArray(new String[args.size()]));
if (javaHome != null) {
commandLine.setEnvironmentVariable("JAVA_HOME", javaHome);
}
setToolOptions(commandLine);
if (workingDirectory != null) {
commandLine.setWorkingDirectory(workingDirectory);
}
if (outputStream != null) {
commandLine.copyOutputTo(outputStream);
}
return commandLine;
}
if (launchMode == LaunchMode.EXECUTABLE_JAR) {
List<String> args = new ArrayList<String>();
args.add(findJavaBinary());
args.add("-jar");
args.add(executableJar);
args.addAll(appArguments);
CommandLine commandLine = new CommandLine(args.toArray(new String[args.size()]));
if (javaHome != null) {
commandLine.setEnvironmentVariable("JAVA_HOME", javaHome);
}
setToolOptions(commandLine);
if (workingDirectory != null) {
commandLine.setWorkingDirectory(workingDirectory);
}
if (outputStream != null) {
commandLine.copyOutputTo(outputStream);
}
return commandLine;
}
return null;
}
/**
* Add the given Files to the class path
*
* @param jarOrDirs
* one or more {@link java.io.File} objects - either JARs or
* Folders.
* @return this
*/
public JavaProfile addClassPath(File... jarOrDirs) {
checkValidProperty("classpath");
for (File jarOrDir : jarOrDirs) {
if (!jarOrDir.exists()) {
throw new WebDriverException(String.format("But unable to locate the requested jar or folder: %s", jarOrDir));
}
classPathEntries.add(jarOrDir.getAbsolutePath());
}
return this;
}
/**
* Add the given paths to the class path
*
* @param jarOrDirs
* one or more {java.lang.String} objects - either JARs or
* Folders
* @return this
*/
public JavaProfile addClassPath(String... jarOrDirs) {
checkValidProperty("classpath");
for (String s : jarOrDirs) {
if (!s.matches(".*%[^%]*%.*") && !new File(s).exists()) {
throw new WebDriverException(String.format("But unable to locate the requested jar or folder: %s", new File(s)));
}
classPathEntries.add(s);
}
return this;
}
/**
* Add the given arguments to the AUT Java command
*
* <p>
* Marathon adds these arguments to the <code>JAVA_TOOL_OPTIONS</code>
* environment variable before launching the application.
* </p>
*
* @param arg
* one or more java command arguments
* @return this
*/
public JavaProfile addVMArgument(String... arg) {
checkValidProperty("vmargument");
for (String a : arg) {
vmArguments.add(a);
}
return this;
}
/**
* Add the given arguments to the javaws command
*
* <p>
* Add these arguments to the <code>javaws</code> command while the
* application is launched.
* </p>
*
* @param arg
* one or more javaws command arguments
* @return this
*/
public JavaProfile addWSArgument(String... arg) {
checkValidProperty("wsargument");
for (String a : arg) {
wsArguments.add(a);
}
return this;
}
/**
* Add the given arguments to the application
*
* <p>
* When using COMMAND_LINE, JAVA_COMMAND_LINE or EXECUTABLE_JAR launch
* modes, these arguments are passed to the application on the command line.
* </p>
*
* @param arg
* one or more command line arguments
* @return this
*/
public JavaProfile addApplicationArguments(String... arg) {
checkValidProperty("appargument");
for (String a : arg) {
appArguments.add(a);
}
return this;
}
/**
* Sets the main class used for launching the application
*
* <p>
* When using the JAVA_COMMAND_LINE launch mode, set the main class name
* using this method. The main class name should be fully qualified - should
* have the package along with the class name.
* </p>
*
* @param mainClass
* the main class
* @return this
*/
public JavaProfile setMainClass(String mainClass) {
checkValidProperty("mainclass");
this.mainClass = mainClass;
return this;
}
/**
* Set the local/remote path to the JNLP file
*
* <p>
* When using JAVA_WEBSTART launch mode this method is used to set the path
* to the JNLP file. The path can be a local file or a remote URL.
* </p>
*
* @param url
* the path to JNLP file
* @return this
*/
public JavaProfile setJNLPPath(String url) {
checkValidProperty("jnlppath");
this.jnlpPath = url;
return this;
}
/**
* Set the URL to be used for Applet Viewer
*
* <p>
* When using JAVA_APPLET launch mode this method is used to set the either
* the file path or the URL to the HTML file with applet code. The path is
* used to launch the <code>appletviewer</code> command.
* </p>
*
* @param url
* the path to the HTML file with applet
* @return this
*/
public JavaProfile setAppletURL(String url) {
checkValidProperty("appleturl");
this.appletURL = url;
return this;
}
/**
* Set the start window title of the application
*
* <p>
* Setting the start window title makes Marathon to wait till the window
* with title appear before starting the recording/playback session. This
* setting is mandatory for JAVA_WEBSTART launch mode.
* </p>
*
* <p>
* You can use regular expression for the title by starting it with a '/'.
* If the original title starts with a '/' use '// to escape it.
* </p>
*
* @param title
* the window title
* @return this
*/
public JavaProfile setStartWindowTitle(String title) {
checkValidProperty("startwindowtitle");
this.startWindowTitle = title;
return this;
}
/**
* Set the working directory for the application
*
* <p>
* When application accesses the local resources using relative path names,
* you may have to launch the AUT from a specific working directory. Use
* this method to specify the working folder. This setting is applicable
* only for JAVA_COMMAND_LINE, COMMAND_LINE and EXECUTABLE_JAR launch modes.
* </p>
*
* @param workingDirectory
* the working folder
* @return this
*/
public JavaProfile setWorkingDirectory(String workingDirectory) {
this.workingDirectory = workingDirectory;
return this;
}
/**
* Set the command to be executed for launching the application
*
* <p>
* When using COMMAND_LINE launch mode, use this method to set the path to
* the command. The command can either be a executable or a batch script.
* </p>
*
* @param c
* the path to the command
* @return this
*/
public JavaProfile setCommand(String c) {
checkValidProperty("command");
this.command = c;
return this;
}
/**
* Used internally by Marathon before starting a recording session
*
* <p>
* Setting the recording port, adds <b>recording</b> java agent to the
* command line. Used internally - not for public use.
* </p>
*
* @param recordingPort
* the recording port where the server is listening
*/
public void setRecordingPort(int recordingPort) {
this.recordingPort = recordingPort;
}
/**
* The URL where the JavaServer is listening.
*
* <p>
* When you execute the command line created through the
* {@link JavaProfile#getCommandLine()}, a WebDriver compatible server is
* started using a java agent. This method returns the URL where the server
* is listening. The URL can be used with RemoteWebDriver to communicate
* with the AUT.
* </p>
*
* @return the url
*/
public String getURL() {
return "http://localhost:" + getPort();
}
/**
* Copy the output from the application to the given output stream
*
* <p>
* Both the standard output and standard error are merged in the output.
* </p>
*
* @param outputStream
* the output stream
*/
public void copyOutputTo(OutputStream outputStream) {
this.outputStream = outputStream;
}
/**
* Get the output stream.
*
* <p>
* If the output is not redirected, uses {@link System#err}
*
* @return the output stream
*/
public OutputStream getOutputStream() {
if (outputStream == null) {
return System.err;
}
return outputStream;
}
/**
* Set Java Home
*
* <p>
* By default {@link JavaDriver} uses the <code>java</code>,
* <code>javaws</code> commands from the PATH. If you wan't to use a
* different version, you may use this method to set the java home. The
* environment variable <code>JAVA_HOME</code> is also set before launching
* the application.
* </p>
*
* @param javaHome
* path to the Java home folder
* @return this
*/
public JavaProfile setJavaHome(String javaHome) {
this.javaHome = javaHome;
return this;
}
/**
* Used internally for testing
*
* @param vmCommand
* the java/javaws command to be used
* @return this
*/
public JavaProfile setJavaCommand(String vmCommand) {
this.vmCommand = vmCommand;
return this;
}
/**
* Converts <code>this</code> profile object into a URL. Used by
* MarathonGrid
*
* @return profile as a URL
* @throws URISyntaxException
* on error in constructing the URL
* @throws IOException
* on error
*/
public URL asURL() throws URISyntaxException, IOException {
URIBuilder builder = new URIBuilder("http://javaprofile");
builder.addParameter("launchmode", launchMode.name());
for (int i = 1; i <= appArguments.size(); i++) {
builder.addParameter("arg" + i, appArguments.get(i - 1));
}
if (command != null) {
builder.addParameter("command", command);
}
if (startWindowTitle != null) {
builder.addParameter("swt", startWindowTitle);
}
if (javaHome != null) {
builder.addParameter("javahome", javaHome);
}
if (vmCommand != null) {
builder.addParameter("vmcommand", vmCommand);
}
for (int i = 1; i <= vmArguments.size(); i++) {
builder.addParameter("vmarg" + i, vmArguments.get(i - 1));
}
for (int i = 1; i <= classPathEntries.size(); i++) {
builder.addParameter("cp" + i, classPathEntries.get(i - 1));
}
if (mainClass != null) {
builder.addParameter("mainclass", mainClass);
}
for (int i = 1; i <= wsArguments.size(); i++) {
builder.addParameter("wsarg" + i, wsArguments.get(i - 1));
}
if (jnlpPath != null) {
builder.addParameter("jnlp", jnlpPath);
}
builder.addParameter("jnlpNoLocalCopy", Boolean.toString(jnlpNoLocalCopy));
if (appletURL != null) {
builder.addParameter("appleturl", appletURL);
}
if (nativeEvents) {
builder.addParameter("nativeevents", nativeEvents + "");
}
if (executableJar != null) {
builder.addParameter("executablejar", executableJar);
}
if (launchType != null) {
builder.addParameter("launchtype", launchType.name());
}
builder.addParameter("keepLog", Boolean.toString(keepLog));
return builder.build().toURL();
}
public void setNativeEvents(boolean nativeEvents) {
this.nativeEvents = nativeEvents;
}
@Override
public String toString() {
return "JavaProfile [classPathEntries=" + classPathEntries + ", vmArguments=" + vmArguments + ", wsArguments=" + wsArguments
+ ", appArguments=" + appArguments + ", launchMode=" + launchMode + ", mainClass=" + mainClass + ", jnlpPath="
+ jnlpPath + ", jnlpNoLocalCopy = " + jnlpNoLocalCopy + ", port=" + port + ", startWindowTitle=" + startWindowTitle
+ ", workingDirectory=" + workingDirectory + ", vmCommand=" + vmCommand + ", command=" + command + ", appletURL="
+ appletURL + ", recordingPort=" + recordingPort + ", javaHome=" + javaHome + ", nativeEvents=" + nativeEvents
+ "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (appArguments == null ? 0 : appArguments.hashCode());
result = prime * result + (appletURL == null ? 0 : appletURL.hashCode());
result = prime * result + (classPathEntries == null ? 0 : classPathEntries.hashCode());
result = prime * result + (command == null ? 0 : command.hashCode());
result = prime * result + (javaHome == null ? 0 : javaHome.hashCode());
result = prime * result + (jnlpPath == null ? 0 : jnlpPath.hashCode());
result = prime * result + (jnlpNoLocalCopy ? 0 : 1);
result = prime * result + (launchMode == null ? 0 : launchMode.hashCode());
result = prime * result + (mainClass == null ? 0 : mainClass.hashCode());
result = prime * result + (nativeEvents ? 1231 : 1237);
result = prime * result + (startWindowTitle == null ? 0 : startWindowTitle.hashCode());
result = prime * result + (vmArguments == null ? 0 : vmArguments.hashCode());
result = prime * result + (vmCommand == null ? 0 : vmCommand.hashCode());
result = prime * result + (workingDirectory == null ? 0 : workingDirectory.hashCode());
result = prime * result + (wsArguments == null ? 0 : wsArguments.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
JavaProfile other = (JavaProfile) obj;
if (appArguments == null) {
if (other.appArguments != null) {
return false;
}
} else if (!appArguments.equals(other.appArguments)) {
return false;
}
if (appletURL == null) {
if (other.appletURL != null) {
return false;
}
} else if (!appletURL.equals(other.appletURL)) {
return false;
}
if (classPathEntries == null) {
if (other.classPathEntries != null) {
return false;
}
} else if (!classPathEntries.equals(other.classPathEntries)) {
return false;
}
if (command == null) {
if (other.command != null) {
return false;
}
} else if (!command.equals(other.command)) {
return false;
}
if (javaHome == null) {
if (other.javaHome != null) {
return false;
}
} else if (!javaHome.equals(other.javaHome)) {
return false;
}
if (jnlpPath == null) {
if (other.jnlpPath != null) {
return false;
}
} else if (!jnlpPath.equals(other.jnlpPath)) {
return false;
}
if (jnlpNoLocalCopy != other.jnlpNoLocalCopy)
return false;
if (launchMode != other.launchMode) {
return false;
}
if (mainClass == null) {
if (other.mainClass != null) {
return false;
}
} else if (!mainClass.equals(other.mainClass)) {
return false;
}
if (nativeEvents != other.nativeEvents) {
return false;
}
if (startWindowTitle == null) {
if (other.startWindowTitle != null) {
return false;
}
} else if (!startWindowTitle.equals(other.startWindowTitle)) {
return false;
}
if (vmArguments == null) {
if (other.vmArguments != null) {
return false;
}
} else if (!vmArguments.equals(other.vmArguments)) {
return false;
}
if (vmCommand == null) {
if (other.vmCommand != null) {
return false;
}
} else if (!vmCommand.equals(other.vmCommand)) {
return false;
}
if (workingDirectory == null) {
if (other.workingDirectory != null) {
return false;
}
} else if (!workingDirectory.equals(other.workingDirectory)) {
return false;
}
if (wsArguments == null) {
if (other.wsArguments != null) {
return false;
}
} else if (!wsArguments.equals(other.wsArguments)) {
return false;
}
return true;
}
/**
* Is native events options set
*
* <p>
* Works only for Swing applications
* </p>
*
* @return true if native events are used, false otherwise
*/
public boolean isNativeEvents() {
return nativeEvents;
}
/**
* Set the path to the executable JAR file
*
* <p>
* Valid only for {@link LaunchMode#EXECUTABLE_JAR} launch mode. Sets the
* path to the jar file to be executed for launching the application.
* </p>
*
* @param jar
* the JAR file path
* @return this
*/
public JavaProfile setExecutableJar(String jar) {
checkValidProperty("executablejar");
this.executableJar = jar;
return this;
}
/**
* Check whether the mode is {@link LaunchMode#EMBEDDED}
*
* @return true if embedded mode
*/
public boolean isEmbedded() {
return launchMode == LaunchMode.EMBEDDED;
}
/**
* Check whether launch mode is {@link LaunchMode#COMMAND_LINE}
*
* @return true if the launch mode is command line
*/
public boolean isCommandLine() {
return launchMode == LaunchMode.COMMAND_LINE;
}
/**
* Check whether the launch mode is {@link LaunchMode#JAVA_COMMAND_LINE}
*
* @return true if the mode is java command line
*/
public boolean isJavaCommandLine() {
return launchMode == LaunchMode.JAVA_COMMAND_LINE;
}
/**
* Check whether the launch mode is {@link LaunchMode#EXECUTABLE_JAR}
*
* @return true if the mode is executable JAR
*/
public boolean isExecutableJar() {
return launchMode == LaunchMode.EXECUTABLE_JAR;
}
/**
* Check whether the launch mode is {@link LaunchMode#JAVA_APPLET}
*
* @return true if the mode is Java applet
*/
public boolean isJavaApplet() {
return launchMode == LaunchMode.JAVA_APPLET;
}
/**
* Check whether the launch mode is {@link LaunchMode#JAVA_WEBSTART}
*
* @return true if the mode is web start
*/
public boolean isJavaWebStart() {
return launchMode == LaunchMode.JAVA_WEBSTART;
}
/**
* Set the launch type
*
* <p>
* {@code JavaProfile} defaults to {@link LaunchType#SWING_APPLICATION}. Use
* this method to change it to {@link LaunchType#FX_APPLICATION}
* </p>
*
* @param launchType
* the launchType
* @return this
*/
public JavaProfile setLaunchType(LaunchType launchType) {
this.launchType = launchType;
return this;
}
/**
* Get the {@link LaunchType}
*
* @return the launch type
*/
public LaunchType getLaunchType() {
return launchType;
}
/**
* Set the keepLog flag
*
* @param keepLog