Skip to content

Commit 77048aa

Browse files
committed
Code clean up to use braces and java 7 features
1 parent 6e95553 commit 77048aa

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

java/client/src/org/openqa/selenium/firefox/internal/ClasspathExtension.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium.firefox.internal;
1919

20-
import com.google.common.io.Closeables;
2120
import com.google.common.io.Resources;
2221

2322
import org.openqa.selenium.WebDriverException;
@@ -53,13 +52,9 @@ public void writeTo(File extensionsDir) throws IOException {
5352
}
5453

5554
URL resourceUrl = Resources.getResource(loadResourcesUsing, loadFrom);
56-
OutputStream stream = null;
5755

58-
try {
59-
stream = new FileOutputStream(extractedXpi);
56+
try (OutputStream stream = new FileOutputStream(extractedXpi)){
6057
Resources.copy(resourceUrl, stream);
61-
} finally {
62-
Closeables.close(stream, false);
6358
}
6459
new FileExtension(extractedXpi).writeTo(extensionsDir);
6560
}

java/client/src/org/openqa/selenium/firefox/internal/FileExtension.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.FileReader;
3636
import java.io.IOException;
3737
import java.io.Reader;
38+
import java.io.UncheckedIOException;
3839
import java.util.Iterator;
3940
import java.util.Map;
4041

@@ -98,23 +99,22 @@ private String getExtensionId(File root) {
9899
File manifestJson = new File(root, "manifest.json");
99100
File installRdf = new File(root, "install.rdf");
100101

101-
if (installRdf.exists())
102+
if (installRdf.exists()) {
102103
return readIdFromInstallRdf(root);
103-
else if (manifestJson.exists())
104+
} else if (manifestJson.exists()) {
104105
return readIdFromManifestJson(root);
105-
else
106+
} else {
106107
throw new WebDriverException(
107-
"Extension should contain either install.rdf or manifest.json metadata file");
108-
108+
"Extension should contain either install.rdf or manifest.json metadata file");
109+
}
109110
}
110111

111112
private String readIdFromManifestJson(File root) {
112113
final String MANIFEST_JSON_FILE = "manifest.json";
113114
File manifestJsonFile = new File(root, MANIFEST_JSON_FILE);
114-
try {
115+
try (Reader reader = new FileReader(manifestJsonFile);
116+
JsonInput json = new Json().newInput(reader)) {
115117
String addOnId = null;
116-
Reader reader = new FileReader(manifestJsonFile);
117-
JsonInput json = new Json().newInput(reader);
118118

119119
Map<String, Object> manifestObject = json.read(MAP_TYPE);
120120
if (manifestObject.get("applications") instanceof Map) {
@@ -135,6 +135,8 @@ private String readIdFromManifestJson(File root) {
135135
return addOnId;
136136
} catch (FileNotFoundException e1) {
137137
throw new WebDriverException("Unable to file manifest.json in xpi file");
138+
} catch (IOException e) {
139+
throw new UncheckedIOException(e);
138140
}
139141
}
140142

0 commit comments

Comments
 (0)