mirror of
https://github.com/revanced/jadb.git
synced 2024-06-02 11:26:12 +02:00
#58 skeleton implemented
This commit is contained in:
parent
5c1561bf94
commit
ebbceb99d5
|
@ -1,32 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
|
||||||
<resourceExtensions />
|
|
||||||
<wildcardResourcePatterns>
|
|
||||||
<entry name="!?*.java" />
|
|
||||||
<entry name="!?*.form" />
|
|
||||||
<entry name="!?*.class" />
|
|
||||||
<entry name="!?*.groovy" />
|
|
||||||
<entry name="!?*.scala" />
|
|
||||||
<entry name="!?*.flex" />
|
|
||||||
<entry name="!?*.kt" />
|
|
||||||
<entry name="!?*.clj" />
|
|
||||||
</wildcardResourcePatterns>
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile default="true" name="Default" enabled="false">
|
|
||||||
<processorPath useClasspath="true" />
|
|
||||||
</profile>
|
|
||||||
<profile default="false" name="Annotation profile for jadb" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<processorPath useClasspath="true" />
|
|
||||||
<module name="jadb" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
<bytecodeTargetLevel>
|
|
||||||
<module name="jadb" target="1.7" />
|
|
||||||
</bytecodeTargetLevel>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<entry_points version="2.0" />
|
|
||||||
</component>
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
<component name="WebServicesPlugin" addRequiredLibraries="true" />
|
|
||||||
</project>
|
|
17
jadb.iml
17
jadb.iml
|
@ -1,17 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="library" name="junit-4.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
7
pom.xml
7
pom.xml
|
@ -39,6 +39,13 @@
|
||||||
<version>4.10</version>
|
<version>4.10</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.10</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
|
public class ConnectionToRemoteDeviceException extends Exception {
|
||||||
|
public ConnectionToRemoteDeviceException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
65
src/se/vidstige/jadb/HostConnectToRemoteTcpDevice.java
Normal file
65
src/se/vidstige/jadb/HostConnectToRemoteTcpDevice.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
|
import se.vidstige.jadb.entities.TcpAddressEntity;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class HostConnectToRemoteTcpDevice {
|
||||||
|
private final Transport transport;
|
||||||
|
|
||||||
|
public HostConnectToRemoteTcpDevice(Transport transport) {
|
||||||
|
this.transport = transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TcpAddressEntity connect(TcpAddressEntity tcpAddressEntity)
|
||||||
|
throws IOException, JadbException, ConnectionToRemoteDeviceException {
|
||||||
|
transport.send(String.format("host:connect:%s:%d", tcpAddressEntity.getHost(), tcpAddressEntity.getPort()));
|
||||||
|
verifyProtocolLevel();
|
||||||
|
verifyCommandLevel();
|
||||||
|
|
||||||
|
return tcpAddressEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyProtocolLevel() throws IOException, JadbException {
|
||||||
|
transport.verifyResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyCommandLevel() throws IOException, ConnectionToRemoteDeviceException {
|
||||||
|
String status = transport.readString();
|
||||||
|
new ResponseValidator(status).validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
final static class ResponseValidator {
|
||||||
|
private final static String SUCCESSFULLY_CONNECTED = "connected to";
|
||||||
|
private final static String ALREADY_CONNECTED = "already connected to";
|
||||||
|
|
||||||
|
private final String response;
|
||||||
|
|
||||||
|
public ResponseValidator(String response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validate() throws ConnectionToRemoteDeviceException {
|
||||||
|
if(!checkIfConnectedSuccessfully() && !checkIfAlreadyConnected()) {
|
||||||
|
throw new ConnectionToRemoteDeviceException(extractError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfConnectedSuccessfully() {
|
||||||
|
return response.contains(SUCCESSFULLY_CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfAlreadyConnected() {
|
||||||
|
return response.equals(ALREADY_CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractError() {
|
||||||
|
int lastColon = response.lastIndexOf(":");
|
||||||
|
if(lastColon != -1) {
|
||||||
|
return response.substring(lastColon, response.length());
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package se.vidstige.jadb;
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
|
import se.vidstige.jadb.entities.TcpAddressEntity;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -34,6 +36,16 @@ public class JadbConnection implements ITransportFactory {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TcpAddressEntity connectToTcpDevice(TcpAddressEntity tcpAddressEntity)
|
||||||
|
throws IOException, JadbException, ConnectionToRemoteDeviceException {
|
||||||
|
Transport transport = createTransport();
|
||||||
|
try {
|
||||||
|
return new HostConnectToRemoteTcpDevice(transport).connect(tcpAddressEntity);
|
||||||
|
} finally {
|
||||||
|
transport.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<JadbDevice> getDevices() throws IOException, JadbException {
|
public List<JadbDevice> getDevices() throws IOException, JadbException {
|
||||||
Transport devices = createTransport();
|
Transport devices = createTransport();
|
||||||
devices.send("host:devices");
|
devices.send("host:devices");
|
||||||
|
|
42
src/se/vidstige/jadb/entities/TcpAddressEntity.java
Normal file
42
src/se/vidstige/jadb/entities/TcpAddressEntity.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package se.vidstige.jadb.entities;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tcp address
|
||||||
|
*/
|
||||||
|
public final class TcpAddressEntity {
|
||||||
|
private final String host;
|
||||||
|
private final Integer port;
|
||||||
|
|
||||||
|
public TcpAddressEntity(String host, Integer port) {
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof TcpAddressEntity)) return false;
|
||||||
|
|
||||||
|
TcpAddressEntity that = (TcpAddressEntity) o;
|
||||||
|
|
||||||
|
if (!host.equals(that.host)) return false;
|
||||||
|
return port.equals(that.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = host.hashCode();
|
||||||
|
result = 31 * result + port.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
test/se/vidstige/jadb/HostConnectToRemoteTcpDeviceTest.java
Normal file
20
test/se/vidstige/jadb/HostConnectToRemoteTcpDeviceTest.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class HostConnectToRemoteTcpDeviceTest {
|
||||||
|
@Test
|
||||||
|
public void testNormalConnection() {
|
||||||
|
//mock()
|
||||||
|
|
||||||
|
//HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parserTest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import se.vidstige.jadb.*;
|
import se.vidstige.jadb.*;
|
||||||
|
import se.vidstige.jadb.entities.TcpAddressEntity;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -117,4 +118,10 @@ public class RealDeviceTestCases {
|
||||||
if (outputStream != null) outputStream.close();
|
if (outputStream != null) outputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConnectionToTcpDevice() throws IOException, JadbException, ConnectionToRemoteDeviceException {
|
||||||
|
TcpAddressEntity tcpAddressEntity = jadb.connectToTcpDevice(new TcpAddressEntity("127.0.0.1", 10001));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user