Skip to content

Commit dc16876

Browse files
committed
Moving utility method isScriptFile to the only class where it is needed
1 parent ad20744 commit dc16876

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

Diff for: java/client/src/org/openqa/selenium/browserlaunchers/LauncherUtils.java

-21
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222

2323
import org.openqa.selenium.Capabilities;
2424
import org.openqa.selenium.io.FileHandler;
25-
import org.openqa.selenium.io.IOUtils;
2625
import org.openqa.selenium.net.Urls;
2726

2827
import java.io.BufferedReader;
2928
import java.io.File;
3029
import java.io.FileNotFoundException;
3130
import java.io.FileOutputStream;
32-
import java.io.FileReader;
3331
import java.io.FileWriter;
3432
import java.io.IOException;
3533
import java.io.InputStream;
@@ -172,25 +170,6 @@ private static InputStream getSeleniumResourceAsStream(String resourceFile) {
172170
return LauncherUtils.class.getResourceAsStream(resourceFile);
173171
}
174172

175-
public static boolean isScriptFile(File aFile) {
176-
final char firstTwoChars[] = new char[2];
177-
FileReader reader = null;
178-
int charsRead;
179-
180-
try {
181-
reader = new FileReader(aFile);
182-
charsRead = reader.read(firstTwoChars);
183-
if (2 != charsRead) {
184-
return false;
185-
}
186-
return (firstTwoChars[0] == '#' && firstTwoChars[1] == '!');
187-
} catch (IOException e) {
188-
throw new RuntimeException(e);
189-
} finally {
190-
IOUtils.closeQuietly(reader);
191-
}
192-
}
193-
194173
// TODO(simon): Replace with something not in LauncherUtils
195174
public static void copySingleFile(File sourceFile, File destFile) {
196175
copySingleFileWithOverwrite(sourceFile, destFile, false);

Diff for: java/client/src/org/openqa/selenium/browserlaunchers/locators/FirefoxLocator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.collect.ImmutableList;
2222

2323
import org.openqa.selenium.Platform;
24-
import org.openqa.selenium.browserlaunchers.LauncherUtils;
2524
import org.openqa.selenium.os.CommandLine;
2625
import org.openqa.selenium.os.WindowsUtils;
2726
import org.openqa.selenium.remote.BrowserType;
@@ -163,7 +162,7 @@ public BrowserInstallation findBrowserLocation() {
163162
continue;
164163
}
165164

166-
if (LauncherUtils.isScriptFile(new File(executable))) {
165+
if (isScriptFile(new File(executable))) {
167166
LOGGER.warning("Caution: '" + executable + "': file is a script file, not a real executable." +
168167
" The browser environment is no longer fully under RC control");
169168
}

Diff for: java/client/src/org/openqa/selenium/browserlaunchers/locators/SingleBrowserLocator.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
package org.openqa.selenium.browserlaunchers.locators;
2020

21-
import org.openqa.selenium.browserlaunchers.LauncherUtils;
21+
import org.openqa.selenium.io.IOUtils;
2222
import org.openqa.selenium.os.CommandLine;
2323
import org.openqa.selenium.os.WindowsUtils;
2424

2525
import java.io.File;
26+
import java.io.FileReader;
27+
import java.io.IOException;
2628
import java.util.logging.Logger;
2729

2830
/**
@@ -163,7 +165,7 @@ protected BrowserInstallation retrieveValidInstallationPath(File launcher) {
163165
return null;
164166
}
165167

166-
if (LauncherUtils.isScriptFile(launcher)) {
168+
if (isScriptFile(launcher)) {
167169
log.warning("Caution: '" +
168170
launcher.getAbsolutePath() +
169171
"': file is a script file, not a real executable. The browser environment is no longer fully under RC control");
@@ -189,4 +191,23 @@ public String computeLibraryPath(File launcherPath) {
189191
return currentLibraryPath + File.pathSeparator + launcherPath.getParent();
190192
}
191193

194+
protected boolean isScriptFile(File aFile) {
195+
final char firstTwoChars[] = new char[2];
196+
FileReader reader = null;
197+
int charsRead;
198+
199+
try {
200+
reader = new FileReader(aFile);
201+
charsRead = reader.read(firstTwoChars);
202+
if (2 != charsRead) {
203+
return false;
204+
}
205+
return (firstTwoChars[0] == '#' && firstTwoChars[1] == '!');
206+
} catch (IOException e) {
207+
throw new RuntimeException(e);
208+
} finally {
209+
IOUtils.closeQuietly(reader);
210+
}
211+
}
212+
192213
}

0 commit comments

Comments
 (0)