1515// specific language governing permissions and limitations
1616// under the License.writeTo
1717
18- package org . openqa . selenium .remote ;
18+ package io . appium . java_client .remote ;
1919
2020import static com .google .common .collect .ImmutableMap .of ;
2121import static com .google .common .collect .ImmutableMap .toImmutableMap ;
3838import com .google .common .io .CharStreams ;
3939import com .google .common .io .FileBackedOutputStream ;
4040
41- import io .appium .java_client .remote .AndroidMobileCapabilityType ;
42- import io .appium .java_client .remote .IOSMobileCapabilityType ;
43- import io .appium .java_client .remote .MobileCapabilityType ;
44- import io .appium .java_client .remote .YouiEngineCapabilityType ;
4541import org .openqa .selenium .Capabilities ;
4642import org .openqa .selenium .ImmutableCapabilities ;
4743import org .openqa .selenium .json .Json ;
4844import org .openqa .selenium .json .JsonInput ;
4945import org .openqa .selenium .json .JsonOutput ;
46+ import org .openqa .selenium .remote .Dialect ;
5047import org .openqa .selenium .remote .session .CapabilitiesFilter ;
5148import org .openqa .selenium .remote .session .CapabilityTransform ;
5249import org .openqa .selenium .remote .session .ChromeFilter ;
5956import org .openqa .selenium .remote .session .StripAnyPlatform ;
6057import org .openqa .selenium .remote .session .W3CPlatformNameNormaliser ;
6158
62- import javax .annotation .Nullable ;
6359import java .io .Closeable ;
6460import java .io .IOException ;
6561import java .io .OutputStreamWriter ;
6662import java .io .Reader ;
6763import java .io .StringReader ;
6864import java .io .Writer ;
69- import java .util .*;
65+ import java .util .Arrays ;
66+ import java .util .Collection ;
67+ import java .util .HashMap ;
68+ import java .util .HashSet ;
69+ import java .util .LinkedList ;
70+ import java .util .List ;
71+ import java .util .Map ;
72+ import java .util .Objects ;
73+ import java .util .Queue ;
74+ import java .util .ServiceLoader ;
75+ import java .util .Set ;
76+ import java .util .TreeMap ;
7077import java .util .function .Function ;
7178import java .util .function .Predicate ;
7279import java .util .regex .Pattern ;
7380import java .util .stream .Collectors ;
7481import java .util .stream .Stream ;
82+ import javax .annotation .Nullable ;
7583
7684
77- public class NewSessionPayload implements Closeable {
85+ class NewAppiumSessionPayload implements Closeable {
7886
7987 private static final List <String > APPIUM_CAPABILITIES = ImmutableList .<String >builder ()
8088 .addAll (getAppiumCapabilities (MobileCapabilityType .class ))
@@ -88,11 +96,7 @@ public class NewSessionPayload implements Closeable {
8896 private static final String FIRST_MATCH = "firstMatch" ;
8997 private static final String ALWAYS_MATCH = "alwaysMatch" ;
9098
91- private final Set <CapabilitiesFilter > adapters ;
92- private final Set <CapabilityTransform > transforms ;
93- private final boolean forceMobileJSONWP ;
94-
95- private final static Predicate <String > ACCEPTED_W3C_PATTERNS = Stream .of (
99+ private static final Predicate <String > ACCEPTED_W3C_PATTERNS = Stream .of (
96100 "^[\\ w-]+:.*$" ,
97101 "^acceptInsecureCerts$" ,
98102 "^browserName$" ,
@@ -107,12 +111,16 @@ public class NewSessionPayload implements Closeable {
107111 .map (Pattern ::asPredicate )
108112 .reduce (identity -> false , Predicate ::or );
109113
114+ private final Set <CapabilitiesFilter > adapters ;
115+ private final Set <CapabilityTransform > transforms ;
116+ private final boolean forceMobileJSONWP ;
117+
110118 private final Json json = new Json ();
111119 private final FileBackedOutputStream backingStore ;
112120
113121 private static List <String > getAppiumCapabilities (Class <?> capabilityList ) {
114122 return Arrays .stream (capabilityList .getDeclaredFields ()).map (field -> {
115- field .setAccessible (true );
123+ field .setAccessible (true );
116124 try {
117125 return field .get (capabilityList ).toString ();
118126 } catch (IllegalAccessException e ) {
@@ -121,7 +129,7 @@ private static List<String> getAppiumCapabilities(Class<?> capabilityList) {
121129 }).filter (s -> !FORCE_MJSONWP .equals (s )).collect (toList ());
122130 }
123131
124- public static NewSessionPayload create (Capabilities caps ) throws IOException {
132+ public static NewAppiumSessionPayload create (Capabilities caps ) throws IOException {
125133 boolean forceMobileJSONWP =
126134 ofNullable (caps .getCapability (FORCE_MJSONWP ))
127135 .map (o -> Boolean .class .isAssignableFrom (o .getClass ()) && Boolean .class .cast (o ))
@@ -131,10 +139,10 @@ public static NewSessionPayload create(Capabilities caps) throws IOException {
131139 capabilityMap .remove (FORCE_MJSONWP );
132140 Map <String , ?> source = of (DESIRED_CAPABILITIES , capabilityMap );
133141 String json = new Json ().toJson (source );
134- return new NewSessionPayload (new StringReader (json ), forceMobileJSONWP );
142+ return new NewAppiumSessionPayload (new StringReader (json ), forceMobileJSONWP );
135143 }
136144
137- private NewSessionPayload (Reader source , boolean forceMobileJSONWP ) throws IOException {
145+ private NewAppiumSessionPayload (Reader source , boolean forceMobileJSONWP ) throws IOException {
138146 this .forceMobileJSONWP = forceMobileJSONWP ;
139147 // Dedicate up to 10% of all RAM or 20% of available RAM (whichever is smaller) to storing this
140148 // payload.
@@ -244,22 +252,22 @@ public void writeTo(Appendable appendable) throws IOException {
244252
245253 // Write the first capability we get as the desired capability.
246254 json .name (DESIRED_CAPABILITIES );
247- json .write (first , MAP_TYPE );
255+ json .write (first );
248256
249257 // And write the first capability for gecko13
250258 json .name (CAPABILITIES );
251259 json .beginObject ();
252260
253261 json .name (DESIRED_CAPABILITIES );
254- json .write (first , MAP_TYPE );
262+ json .write (first );
255263
256264 // Then write everything into the w3c payload. Because of the way we do this, it's easiest
257265 // to just populate the "firstMatch" section. The spec says it's fine to omit the
258266 // "alwaysMatch" field, so we do this.
259267 json .name (FIRST_MATCH );
260268 json .beginArray ();
261269 //noinspection unchecked
262- getW3C ().forEach (map -> json . write ( map , MAP_TYPE ) );
270+ getW3C ().forEach (json :: write );
263271 json .endArray ();
264272
265273 json .endObject (); // Close "capabilities" object
@@ -286,7 +294,7 @@ private void writeMetaData(JsonOutput out) throws IOException {
286294
287295 default :
288296 out .name (name );
289- out .write (input .<Object >read (Object .class ), Object . class );
297+ out .write (input .<Object >read (Object .class ));
290298 break ;
291299 }
292300 }
@@ -297,11 +305,9 @@ private void writeMetaData(JsonOutput out) throws IOException {
297305 * Stream the {@link Capabilities} encoded in the payload used to create this instance. The
298306 * {@link Stream} will start with a {@link Capabilities} object matching the OSS capabilities, and
299307 * will then expand each of the "{@code firstMatch}" and "{@code alwaysMatch}" contents as defined
300- * in the W3C WebDriver spec.
301- * <p>
302- * The OSS {@link Capabilities} are listed first because converting the OSS capabilities to the
303- * equivalent W3C capabilities isn't particularly easy, so it's hoped that this approach gives us
304- * the most compatible implementation.
308+ * in the W3C WebDriver spec. The OSS {@link Capabilities} are listed first because converting the
309+ * OSS capabilities to the equivalent W3C capabilities isn't particularly easy, so it's hoped that
310+ * this approach gives us the most compatible implementation.
305311 */
306312 public Stream <Capabilities > stream () throws IOException {
307313 // OSS first
@@ -399,9 +405,10 @@ public Object getValue() {
399405 @ Override
400406 public Object setValue (Object value ) {
401407 return stringObjectEntry .setValue (value );
402- }})
408+ }
409+ })
403410 .collect (toImmutableMap (Map .Entry ::getKey , Map .Entry ::getValue )))
404- .map (map -> ( Map < String , Object >) map );
411+ .map (map -> map );
405412 } else {
406413 fromOss = Stream .of ();
407414 }
0 commit comments