-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Support for sending firefox addon directory as temporary in remote sessions #10566
Changes from 1 commit
a139724
b56a962
a3c5999
6550267
900643c
bf3c0a9
27fe0a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,15 @@ | |
import org.openqa.selenium.remote.ExecuteMethod; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.*; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.Base64; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import static org.openqa.selenium.remote.Browser.FIREFOX; | ||
|
||
|
@@ -77,7 +80,23 @@ public String installExtension(Path path, Boolean temporary) { | |
|
||
String encoded; | ||
try { | ||
encoded = Base64.getEncoder().encodeToString(Files.readAllBytes(path)); | ||
if (Files.isDirectory(path)){ | ||
Path extZip = Paths.get(path.getFileName().toString()+".zip"); | ||
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(extZip.toFile())); | ||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be fine if Path is not passed explicitly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing |
||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
zos.putNextEntry(new ZipEntry(path.relativize(file).toString())); | ||
Files.copy(file, zos); | ||
zos.closeEntry(); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
}); | ||
zos.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be done in a Try with Resources block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorporated the changes. Please check to verify and resolve :) |
||
encoded = Base64.getEncoder().encodeToString(Files.readAllBytes(extZip)); | ||
} | ||
else{ | ||
encoded = Base64.getEncoder().encodeToString(Files.readAllBytes(path)); | ||
} | ||
} catch (IOException e) { | ||
throw new InvalidArgumentException(path + " is an invalid path", e); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntelliJ tends to do this by default when optimizing imports. But it is good practice to avoid importing entire package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll correct that.