19
19
import com .google .common .collect .ImmutableMap ;
20
20
21
21
import java .nio .charset .StandardCharsets ;
22
+ import java .util .AbstractMap ;
22
23
import java .util .Base64 ;
23
24
24
25
import static com .google .common .base .Preconditions .checkNotNull ;
26
+ import static io .appium .java_client .MobileCommand .PULL_FILE ;
27
+ import static io .appium .java_client .MobileCommand .PULL_FOLDER ;
25
28
26
- public interface PullsFiles extends ExecutesMethod {
29
+ public interface PullsFiles extends ExecutesMethod , CanRememberExtensionPresence {
27
30
28
31
/**
29
32
* Pull a file from the remote system.
@@ -38,11 +41,22 @@ public interface PullsFiles extends ExecutesMethod {
38
41
* @return A byte array of Base64 encoded data.
39
42
*/
40
43
default byte [] pullFile (String remotePath ) {
41
- String base64String = checkNotNull (
42
- CommandExecutionHelper .executeScript (this , "mobile: pullFile" , ImmutableMap .of (
43
- "remotePath" , remotePath
44
- ))
45
- );
44
+ final String extName = "mobile: pullFile" ;
45
+ String base64String ;
46
+ try {
47
+ base64String = checkNotNull (
48
+ CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName ,
49
+ ImmutableMap .of ("remotePath" , remotePath )
50
+ )
51
+ );
52
+ } catch (UnsupportedOperationException e ) {
53
+ // TODO: Remove the fallback
54
+ base64String = checkNotNull (
55
+ CommandExecutionHelper .execute (markExtensionAbsence (extName ),
56
+ new AbstractMap .SimpleEntry <>(PULL_FILE , ImmutableMap .of ("path" , remotePath ))
57
+ )
58
+ );
59
+ }
46
60
return Base64 .getDecoder ().decode (base64String .getBytes (StandardCharsets .UTF_8 ));
47
61
}
48
62
@@ -59,11 +73,22 @@ default byte[] pullFile(String remotePath) {
59
73
* @return A byte array of Base64 encoded zip archive data.
60
74
*/
61
75
default byte [] pullFolder (String remotePath ) {
62
- String base64String = checkNotNull (
63
- CommandExecutionHelper .executeScript (this , "mobile: pullFolder" , ImmutableMap .of (
64
- "remotePath" , remotePath
65
- ))
66
- );
76
+ final String extName = "mobile: pullFolder" ;
77
+ String base64String ;
78
+ try {
79
+ base64String = checkNotNull (
80
+ CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName ,
81
+ ImmutableMap .of ("remotePath" , remotePath )
82
+ )
83
+ );
84
+ } catch (UnsupportedOperationException e ) {
85
+ // TODO: Remove the fallback
86
+ base64String = checkNotNull (
87
+ CommandExecutionHelper .execute (markExtensionAbsence (extName ),
88
+ new AbstractMap .SimpleEntry <>(PULL_FOLDER , ImmutableMap .of ("path" , remotePath ))
89
+ )
90
+ );
91
+ }
67
92
return Base64 .getDecoder ().decode (base64String .getBytes (StandardCharsets .UTF_8 ));
68
93
}
69
94
0 commit comments