Skip to content

Commit 639620e

Browse files
authored
Merge pull request #5 from vsbogd/add-maven-plugin-to-get-api
Add maven plugin to get api
2 parents ccae09d + ddfa381 commit 639620e

81 files changed

Lines changed: 1311 additions & 577 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,16 @@ jobs:
1818
steps:
1919
- checkout
2020

21-
# Download and cache dependencies
22-
- restore_cache:
23-
keys:
24-
- v1-dependencies-{{ checksum "pom.xml" }}
25-
# fallback to using the latest cache if no exact match is found
26-
- v1-dependencies-
27-
28-
- run: mvn dependency:go-offline
29-
30-
- save_cache:
31-
paths:
32-
- ~/.m2
33-
key: v1-dependencies-{{ checksum "pom.xml" }}
34-
3521
# get dependencies
3622
- run:
37-
name: Get dependencies
38-
command: |
39-
curl -L https://get.web3j.io | bash
40-
source $HOME/.web3j/source.sh
41-
./get_dependencies.sh
23+
name: Get web3j
24+
command: curl -L https://get.web3j.io | bash
4225
# run tests!
4326
- run:
44-
name: Run tests
45-
command: mvn test
27+
name: Build and run tests
28+
command: |
29+
source $HOME/.web3j/source.sh
30+
mvn install
4631
- run:
4732
name: Upload coverage
4833
command: bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
## How to build
1212

13-
Install dependencies for the first time:
13+
Install web3j for the first time:
1414
```
1515
curl -L https://get.web3j.io | bash
1616
source $HOME/.web3j/source.sh
17-
./get_dependencies.sh
1817
```
1918

2019
Build and test:

docs/class-diagram.plantuml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,19 @@ package io.singularitynet.sdk.client {
9797
SignerType getSignerType();
9898
String getSignerMnemonic();
9999
byte[] getSignerPrivateKey();
100+
Address getRegistryAddress();
101+
Address getMultiPartyEscrowAddress();
100102
}
101103

102104
class JsonConfiguration
103105
Configuration <|.. JsonConfiguration
104106

105107
interface DependencyFactory {
106108
Web3j getWeb3j();
107-
ContractGasProvider getContractGasProvider(Web3j web3j);
108109
IPFS getIpfs();
109110
Signer getSigner();
111+
Registry getRegistry();
112+
MultiPartyEscrow getMultiPartyEscrow();
110113
}
111114

112115
class ConfigurationDependencyFactory

docs/class-diagram.svg

Lines changed: 64 additions & 61 deletions
Loading

example/README.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,43 @@ $ mvn exec:java -Dexec.mainClass="io.singularitynet.sdk.example.CntkImageRecogni
6060

6161
1. Create new maven project, see https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
6262

63-
2. Get service API
63+
2. Use `snet-sdk-maven-plugin` to get protobuf API:
6464

65-
```sh
66-
$ mkdir -p src/main/proto
67-
$ snet service get-api-registry snet cntk-image-recon src/main/proto
6865
```
69-
70-
3. Add Java package option
71-
72-
```sh
73-
$ echo 'option java_package = "recognition";' >> src/main/proto/image_recon.proto
66+
<build>
67+
<plugins>
68+
...
69+
<plugin>
70+
<groupId>io.singularitynet</groupId>
71+
<artifactId>snet-sdk-maven-plugin</artifactId>
72+
<version>1.0-SNAPSHOT</version>
73+
74+
<executions>
75+
<execution>
76+
77+
<configuration>
78+
<orgId>snet</orgId> <!-- organization id -->
79+
<serviceId>example-service</serviceId> <!-- service id -->
80+
<outputDir>${project.build.directory}/proto</outputDir> <!-- output dir -->
81+
<javaPackage>io.singularitynet.service.exampleservice</javaPackage> <!-- java package for classes generated -->
82+
</configuration>
83+
84+
<goals>
85+
<goal>get</goal>
86+
</goals>
87+
88+
</execution>
89+
</executions>
90+
91+
</plugin>
92+
...
93+
</plugins>
94+
</build>
7495
```
7596

76-
4. Write Java client app using sdk, see CntkImageRecognition.java as example
97+
3. Use `protobuf-maven-plugin` to generate Java stubs of service API:
98+
- [grpc-java README.md](https://github.com/grpc/grpc-java/blob/master/README.md)
99+
- [protobuf-maven-plugin documentation](https://www.xolstice.org/protobuf-maven-plugin/)
100+
101+
4. Write Java client app using sdk, see [CntkImageRecognition.java](./src/main/java/io/singularitynet/sdk/example/CntkImageRecognition.java) as example
77102

example/pom.xml

Lines changed: 43 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,33 @@
22

33
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
65

7-
<groupId>io.singularitynet</groupId>
6+
<parent>
7+
<groupId>io.singularitynet</groupId>
8+
<artifactId>snet-sdk-java-pom</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
813
<artifactId>snet-sdk-java-example</artifactId>
9-
<version>1.0-SNAPSHOT</version>
14+
<packaging>jar</packaging>
1015

1116
<name>snet-sdk-java-example</name>
1217
<description>SingularityNet Java SDK usage example</description>
1318
<!-- TODO: add link to the SDK tutorial -->
1419
<url>http://dev.singularitynet.io</url>
1520

16-
<properties>
17-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<maven.compiler.source>1.8</maven.compiler.source>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
21-
<!-- protobuf and grpc versions -->
22-
<protobuf.version>3.5.1</protobuf.version>
23-
<grpc.version>1.20.0</grpc.version>
24-
</properties>
25-
2621
<dependencies>
2722

2823
<dependency>
2924
<groupId>io.singularitynet</groupId>
3025
<artifactId>snet-sdk-java</artifactId>
31-
<version>1.0-SNAPSHOT</version>
3226
</dependency>
3327

3428
<!-- protobuf + grpc begin -->
3529
<dependency>
3630
<groupId>com.google.protobuf</groupId>
3731
<artifactId>protobuf-java</artifactId>
38-
<version>${protobuf.version}</version>
3932
</dependency>
4033
<dependency>
4134
<groupId>io.grpc</groupId>
@@ -52,32 +45,17 @@
5245
<dependency>
5346
<groupId>javax.annotation</groupId>
5447
<artifactId>javax.annotation-api</artifactId>
55-
<version>1.3.2</version>
5648
</dependency>
5749
<!-- protobuf + grpc end -->
5850

5951
<dependency>
6052
<groupId>junit</groupId>
6153
<artifactId>junit</artifactId>
62-
<version>4.12</version>
6354
<scope>test</scope>
6455
</dependency>
6556

6657
</dependencies>
6758

68-
<dependencyManagement>
69-
<dependencies>
70-
<!-- resolve grpc dependency versions from grpc one-->
71-
<dependency>
72-
<groupId>io.grpc</groupId>
73-
<artifactId>grpc-bom</artifactId>
74-
<version>${grpc.version}</version>
75-
<type>pom</type>
76-
<scope>import</scope>
77-
</dependency>
78-
</dependencies>
79-
</dependencyManagement>
80-
8159
<build>
8260

8361
<extensions>
@@ -89,16 +67,41 @@
8967
</extensions>
9068

9169
<plugins>
70+
9271
<plugin>
93-
<groupId>org.codehaus.mojo</groupId>
94-
<artifactId>exec-maven-plugin</artifactId>
95-
<version>1.4.0</version>
72+
<groupId>io.singularitynet</groupId>
73+
<artifactId>snet-sdk-maven-plugin</artifactId>
74+
<executions>
75+
<execution>
76+
<id>example-service</id>
77+
<configuration>
78+
<orgId>snet</orgId>
79+
<serviceId>example-service</serviceId>
80+
<outputDir>${project.build.directory}/proto</outputDir>
81+
<javaPackage>io.singularitynet.service.exampleservice</javaPackage>
82+
</configuration>
83+
<goals>
84+
<goal>get</goal>
85+
</goals>
86+
</execution>
87+
<execution>
88+
<id>cntk-image-recon</id>
89+
<configuration>
90+
<orgId>snet</orgId>
91+
<serviceId>cntk-image-recon</serviceId>
92+
<outputDir>${project.build.directory}/proto</outputDir>
93+
<javaPackage>io.singularitynet.service.cntkimagerecon</javaPackage>
94+
</configuration>
95+
<goals>
96+
<goal>get</goal>
97+
</goals>
98+
</execution>
99+
</executions>
96100
</plugin>
97101

98102
<plugin>
99103
<groupId>org.xolstice.maven.plugins</groupId>
100104
<artifactId>protobuf-maven-plugin</artifactId>
101-
<version>0.6.1</version>
102105
<configuration>
103106
<!-- artifact to download binary protobuf compiler -->
104107
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
@@ -108,6 +111,7 @@
108111
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
109112
<!-- to not recompile protobuf each time -->
110113
<checkStaleness>true</checkStaleness>
114+
<protoSourceRoot>${project.build.directory}/proto</protoSourceRoot>
111115
</configuration>
112116
<executions>
113117
<execution>
@@ -120,59 +124,12 @@
120124
</executions>
121125
</plugin>
122126

123-
</plugins>
124-
125-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
126-
<plugins>
127-
<plugin>
128-
<artifactId>maven-clean-plugin</artifactId>
129-
<version>3.1.0</version>
130-
</plugin>
131-
<plugin>
132-
<artifactId>maven-site-plugin</artifactId>
133-
<version>3.7.1</version>
134-
</plugin>
135-
<plugin>
136-
<artifactId>maven-project-info-reports-plugin</artifactId>
137-
<version>3.0.0</version>
138-
</plugin>
139-
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
140-
<plugin>
141-
<artifactId>maven-resources-plugin</artifactId>
142-
<version>3.0.2</version>
143-
</plugin>
144-
<plugin>
145-
<artifactId>maven-compiler-plugin</artifactId>
146-
<version>3.8.0</version>
147-
</plugin>
148-
<plugin>
149-
<artifactId>maven-surefire-plugin</artifactId>
150-
<version>2.22.1</version>
151-
<configuration>
152-
<trimStackTrace>false</trimStackTrace>
153-
</configuration>
154-
</plugin>
155-
<plugin>
156-
<artifactId>maven-jar-plugin</artifactId>
157-
<version>3.0.2</version>
158-
</plugin>
159-
<plugin>
160-
<artifactId>maven-install-plugin</artifactId>
161-
<version>2.5.2</version>
162-
</plugin>
163-
<plugin>
164-
<artifactId>maven-deploy-plugin</artifactId>
165-
<version>2.8.2</version>
166-
</plugin>
167-
</plugins>
168-
</pluginManagement>
169-
</build>
170-
171-
<reporting>
172-
<plugins>
173127
<plugin>
174-
<artifactId>maven-project-info-reports-plugin</artifactId>
128+
<groupId>org.codehaus.mojo</groupId>
129+
<artifactId>exec-maven-plugin</artifactId>
175130
</plugin>
131+
176132
</plugins>
177-
</reporting>
133+
</build>
134+
178135
</project>

example/src/main/java/io/singularitynet/sdk/example/CntkImageRecognition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import io.singularitynet.sdk.client.FixedPaymentChannelPaymentStrategy;
1010
import io.singularitynet.sdk.client.ServiceClient;
1111

12-
import recognition.RecognizerGrpc;
13-
import recognition.RecognizerGrpc.RecognizerBlockingStub;
14-
import recognition.ImageRecon.Input;
15-
import recognition.ImageRecon.Output;
12+
import io.singularitynet.service.cntkimagerecon.RecognizerGrpc;
13+
import io.singularitynet.service.cntkimagerecon.RecognizerGrpc.RecognizerBlockingStub;
14+
import io.singularitynet.service.cntkimagerecon.ImageRecon.Input;
15+
import io.singularitynet.service.cntkimagerecon.ImageRecon.Output;
1616

1717
public class CntkImageRecognition {
1818

example/src/main/java/io/singularitynet/sdk/example/ExampleService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import io.singularitynet.sdk.client.FixedPaymentChannelPaymentStrategy;
1010
import io.singularitynet.sdk.client.ServiceClient;
1111

12-
import example.service.CalculatorGrpc;
13-
import example.service.CalculatorGrpc.CalculatorBlockingStub;
14-
import example.service.ExampleService.Numbers;
15-
import example.service.ExampleService.Result;
12+
import io.singularitynet.service.exampleservice.CalculatorGrpc;
13+
import io.singularitynet.service.exampleservice.CalculatorGrpc.CalculatorBlockingStub;
14+
import io.singularitynet.service.exampleservice.ExampleService.Numbers;
15+
import io.singularitynet.service.exampleservice.ExampleService.Result;
1616

1717
public class ExampleService {
1818

example/src/main/proto/example_service.proto

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/src/main/proto/image_recon.proto

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)