-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* stf-client version updated to 0.3.3 * Read parameters from an url with "connect -u <url>" command * Readme updated
- Loading branch information
Showing
26 changed files
with
91 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/main/java/com/github/e13mort/stf/console/commands/connect/DeviceConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 22 additions & 116 deletions
138
.../main/java/com/github/e13mort/stf/console/commands/connect/FileParamsDeviceConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,46 @@ | ||
package com.github.e13mort.stf.console.commands.connect; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.github.e13mort.stf.adapter.filters.StringsFilterDescription; | ||
import com.github.e13mort.stf.adapter.filters.StringsFilterParser; | ||
import com.github.e13mort.stf.client.DevicesParams; | ||
import com.github.e13mort.stf.client.FarmClient; | ||
import com.github.e13mort.stf.client.parameters.DevicesParams; | ||
import com.github.e13mort.stf.client.parameters.JsonDeviceParametersReader; | ||
import com.github.e13mort.stf.console.AdbRunner; | ||
import io.reactivex.Flowable; | ||
import io.reactivex.Notification; | ||
|
||
import org.reactivestreams.Publisher; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.logging.Logger; | ||
|
||
import io.reactivex.Flowable; | ||
import io.reactivex.Notification; | ||
|
||
class FileParamsDeviceConnector extends DeviceConnector { | ||
|
||
private final File paramsFile; | ||
private final ParametersReader reader; | ||
|
||
static DeviceConnector of(FarmClient client, AdbRunner adbRunner, Logger logger, File paramsFile) { | ||
return new FileParamsDeviceConnector(client, adbRunner, logger, () -> new JsonDeviceParametersReader().read(paramsFile)); | ||
} | ||
|
||
static DeviceConnector of(FarmClient client, AdbRunner adbRunner, Logger logger, URL paramsUrl) { | ||
return new FileParamsDeviceConnector(client, adbRunner, logger, () -> new JsonDeviceParametersReader().read(paramsUrl)); | ||
} | ||
|
||
FileParamsDeviceConnector(FarmClient client, AdbRunner adbRunner, Logger logger, File paramsFile) { | ||
private FileParamsDeviceConnector(FarmClient client, AdbRunner adbRunner, Logger logger, ParametersReader reader) { | ||
super(client, adbRunner, logger); | ||
this.paramsFile = paramsFile; | ||
this.reader = reader; | ||
} | ||
|
||
@Override | ||
protected Publisher<Notification<String>> createConnectionPublisher() { | ||
try { | ||
return connectWithParams(readParamsFromFile()); | ||
} catch (IOException e) { | ||
return connectWithParams(reader.read()); | ||
} catch (JsonDeviceParametersReader.JsonParamsReaderException e) { | ||
return Flowable.error(e); | ||
} | ||
} | ||
|
||
DevicesParams readParamsFromFile() throws IOException { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); | ||
final SimpleModule module = new SimpleModule(); | ||
module.addDeserializer(StringsFilterDescription.class, new StringFilterDescriptionDeserializer()); | ||
module.addDeserializer(String.class, new StrictStringDeserializer()); | ||
mapper.registerModule(module); | ||
return mapper.readValue(paramsFile, JsonDevicesParams.class); | ||
} | ||
|
||
static class JsonDevicesParams implements DevicesParams { | ||
|
||
@JsonProperty("names") | ||
private StringsFilterDescription nameFilterDescription; | ||
@JsonProperty | ||
private String abi; | ||
@JsonProperty | ||
private int api; | ||
@JsonProperty | ||
private int count; | ||
@JsonProperty | ||
private int minApi; | ||
@JsonProperty | ||
private int maxApi; | ||
@JsonProperty("providers") | ||
private StringsFilterDescription providerFilterDescription; | ||
@JsonProperty("serials") | ||
private StringsFilterDescription serialFilterDescription; | ||
|
||
@Override | ||
public boolean isAllDevices() { | ||
//there's no sense to be able to connect to unavailable devices | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getAbi() { | ||
return abi; | ||
} | ||
|
||
@Override | ||
public int getApiVersion() { | ||
return api; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return count; | ||
} | ||
|
||
@Override | ||
public StringsFilterDescription getNameFilterDescription() { | ||
return nameFilterDescription; | ||
} | ||
|
||
@Override | ||
public int getMinApiVersion() { | ||
return minApi; | ||
} | ||
|
||
@Override | ||
public int getMaxApiVersion() { | ||
return maxApi; | ||
} | ||
|
||
@Override | ||
public StringsFilterDescription getProviderFilterDescription() { | ||
return providerFilterDescription; | ||
} | ||
|
||
@Override | ||
public StringsFilterDescription getSerialFilterDescription() { | ||
return serialFilterDescription; | ||
} | ||
} | ||
|
||
static class StringFilterDescriptionDeserializer extends JsonDeserializer<StringsFilterDescription> { | ||
|
||
private StringsFilterParser parser = new StringsFilterParser(); | ||
|
||
@Override | ||
public StringsFilterDescription deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
final String value = p.getCodec().readValue(p, String.class); | ||
return parser.parse(value); | ||
} | ||
} | ||
|
||
static class StrictStringDeserializer extends JsonDeserializer<String> { | ||
|
||
@Override | ||
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
if (p.getCurrentToken() == JsonToken.VALUE_STRING) { | ||
return p.getText(); | ||
} | ||
throw ctxt.mappingException("Invalid token type: " + p.getCurrentToken()); | ||
} | ||
private interface ParametersReader { | ||
DevicesParams read() throws JsonDeviceParametersReader.JsonParamsReaderException; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
client/src/main/java/com/github/e13mort/stf/console/commands/connect/ParamsConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/main/java/com/github/e13mort/stf/console/commands/devices/DocumentsLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/test/java/com/github/e13mort/stf/console/BaseStfCommanderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.