Skip to content

Commit 7e8de49

Browse files
committed
fixes indentation, first test run
1 parent ef501f9 commit 7e8de49

File tree

4 files changed

+225
-247
lines changed

4 files changed

+225
-247
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ buildNumber.properties
1111
*.class
1212
*.swp
1313
.project
14+
local.log
15+

src/main/java/com/BrowserStack/Local.java

Lines changed: 92 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -9,114 +9,97 @@
99
import java.util.Map;
1010
import java.util.Set;
1111

12-
class Local{
13-
14-
Process BrowserStackLocal = null;
15-
List<String> command;
16-
HashMap<String, String> parameters;
17-
18-
void start(HashMap<String,String> options) throws Exception
19-
{
20-
LocalBinary lb = new LocalBinary();
21-
command = new ArrayList<String>();
22-
command.add(lb.binary_path);
23-
command.add(options.get("key"));
12+
class Local {
13+
14+
Process BrowserStackLocal = null;
15+
List<String> command;
16+
HashMap<String, String> parameters;
17+
18+
void start(HashMap<String,String> options) throws Exception {
19+
LocalBinary lb = new LocalBinary();
20+
command = new ArrayList<String>();
21+
command.add(lb.binary_path);
22+
command.add(options.get("key"));
2423

25-
makeCommand(options);
26-
27-
if (BrowserStackLocal == null)
28-
{
29-
ProcessBuilder processBuilder = new ProcessBuilder(command);
24+
makeCommand(options);
25+
26+
if (BrowserStackLocal == null){
27+
ProcessBuilder processBuilder = new ProcessBuilder(command);
3028

31-
System.out.println("Setting up Local Testing connection...");
32-
BrowserStackLocal = processBuilder.start();
33-
BufferedReader reader = new BufferedReader(new InputStreamReader(BrowserStackLocal.getInputStream()));
34-
String string;
35-
int j = 0;
36-
while ((string = reader.readLine()) != null)
37-
{
38-
if (string.equalsIgnoreCase("Press Ctrl-C to exit"))
39-
{
40-
System.out.println("Local Testing connection has been established.");
41-
break;
42-
}
43-
44-
if (string.contains("*** Error"))
45-
{
46-
throw new BrowserStackLocalException(string);
47-
}
48-
if (j++ > 20)
49-
{
50-
throw new BrowserStackLocalException("Could not start BrowserStackLocal");
51-
}
52-
}
53-
54-
}
55-
56-
}
57-
58-
void stop()
59-
{
60-
if (BrowserStackLocal != null)
61-
{
62-
BrowserStackLocal.destroy();
63-
System.out.println("Disconnected successfully");
64-
}
65-
}
66-
67-
boolean isRunning()
68-
{
69-
try
70-
{
71-
BrowserStackLocal.exitValue();
72-
return false;
73-
}
74-
catch (Exception e)
75-
{
76-
return true;
77-
}
78-
}
79-
80-
void init()
81-
{
82-
parameters = new HashMap<String, String>();
83-
parameters.put("v","-v");
84-
parameters.put("f","-f");
85-
parameters.put("h","-h");
86-
parameters.put("version", "-version");
87-
parameters.put("force", "-force");
88-
parameters.put("only", "-only");
89-
parameters.put("forcelocal", "-forcelocal");
90-
parameters.put("onlyAutomate", "-onlyAutomate");
91-
parameters.put("proxyHost", "-proxyHost");
92-
parameters.put("proxyPort", "-proxyPort");
93-
parameters.put("proxyUser", "-proxyUser");
94-
parameters.put("proxyPass", "-proxyPass");
95-
parameters.put("hosts", "-hosts");
96-
parameters.put("logfile", "-logfile");
97-
}
98-
99-
Local() throws Exception
100-
{
101-
init();
102-
}
103-
104-
void makeCommand(HashMap<String,String> options)
105-
{
106-
Set set = options.entrySet();
107-
Iterator i = set.iterator();
108-
while(i.hasNext())
109-
{
110-
Map.Entry me = (Map.Entry)i.next();
111-
String parameter = me.getKey().toString().trim();
112-
if(parameters.get(parameter)!=null)
113-
if(me.getValue()!=null)
114-
{
115-
command.add(parameters.get(parameter));
116-
command.add((String) me.getValue());
117-
}
118-
else
119-
command.add(parameters.get(parameter));
120-
}
121-
}
122-
}
29+
System.out.println("Setting up Local Testing connection...");
30+
BrowserStackLocal = processBuilder.start();
31+
BufferedReader reader = new BufferedReader(new InputStreamReader(BrowserStackLocal.getInputStream()));
32+
String string;
33+
int j = 0;
34+
while ((string = reader.readLine()) != null) {
35+
if (string.equalsIgnoreCase("Press Ctrl-C to exit")) {
36+
System.out.println("Local Testing connection has been established.");
37+
break;
38+
}
39+
40+
if (string.contains("*** Error")){
41+
throw new BrowserStackLocalException(string);
42+
}
43+
if (j++ > 20) {
44+
throw new BrowserStackLocalException("Could not start BrowserStackLocal");
45+
}
46+
}
47+
48+
}
49+
}
50+
51+
void stop(){
52+
if (BrowserStackLocal != null) {
53+
BrowserStackLocal.destroy();
54+
System.out.println("Disconnected successfully");
55+
}
56+
}
57+
58+
boolean isRunning(){
59+
try {
60+
BrowserStackLocal.exitValue();
61+
return false;
62+
}
63+
catch (Exception e) {
64+
return true;
65+
}
66+
}
67+
68+
void init(){
69+
parameters = new HashMap<String, String>();
70+
parameters.put("v","-v");
71+
parameters.put("f","-f");
72+
parameters.put("h","-h");
73+
parameters.put("version", "-version");
74+
parameters.put("force", "-force");
75+
parameters.put("only", "-only");
76+
parameters.put("forcelocal", "-forcelocal");
77+
parameters.put("onlyAutomate", "-onlyAutomate");
78+
parameters.put("proxyHost", "-proxyHost");
79+
parameters.put("proxyPort", "-proxyPort");
80+
parameters.put("proxyUser", "-proxyUser");
81+
parameters.put("proxyPass", "-proxyPass");
82+
parameters.put("hosts", "-hosts");
83+
parameters.put("logfile", "-logfile");
84+
}
85+
86+
Local() throws Exception {
87+
init();
88+
}
89+
90+
void makeCommand(HashMap<String,String> options){
91+
Set set = options.entrySet();
92+
Iterator i = set.iterator();
93+
while(i.hasNext()) {
94+
Map.Entry me = (Map.Entry)i.next();
95+
String parameter = me.getKey().toString().trim();
96+
if(parameters.get(parameter)!=null)
97+
if(me.getValue()!=null){
98+
command.add(parameters.get(parameter));
99+
command.add((String) me.getValue());
100+
}
101+
else
102+
command.add(parameters.get(parameter));
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)