forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:remove jprotoc * fix:add dependency and license * fix:remove useless import * fix:checkstyle bug * fix:SonarCloud bug * refactor:remove a package path * fix:handle InterruptedException * refactor:modify license and format code * fix:checkstyle excluded * Add NOTICE * fix:remove unless notice * refactor:code format --------- Co-authored-by: Albumen Kevin <jhq0812@gmail.com> Co-authored-by: pengxiaoyu <pengxiaoyu@shengquganmes.com>
- Loading branch information
1 parent
c98c487
commit d0c41f5
Showing
27 changed files
with
1,445 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
## dubbo-complier | ||
|
||
> dubbo-complier supports generating code based on .proto files | ||
### How to use | ||
|
||
#### 1.Define Proto file | ||
|
||
greeter.proto | ||
```protobuf | ||
syntax = "proto3"; | ||
option java_multiple_files = true; | ||
option java_package = "org.apache.dubbo.demo"; | ||
option java_outer_classname = "DemoServiceProto"; | ||
option objc_class_prefix = "DEMOSRV"; | ||
package demoservice; | ||
// The demo service definition. | ||
service DemoService { | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
} | ||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} | ||
``` | ||
|
||
#### 2.Use dubbo-maven-plugin,rather than ```protobuf-maven-plugin``` | ||
|
||
now dubbo support his own protoc plugin base on dubbo-maven-plugin | ||
|
||
```xml | ||
<plugin> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-maven-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<configuration> | ||
<dubboVersion>3.3.0</dubboVersion> | ||
<dubboGenerateType>dubbo3</dubboGenerateType> | ||
<protocExecutable>protoc</protocExecutable> | ||
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact> | ||
</configuration> | ||
</plugin> | ||
|
||
``` | ||
|
||
#### 3.generate file | ||
|
||
```java | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dubbo.demo; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public final class DemoServiceDubbo { | ||
private static final AtomicBoolean registered = new AtomicBoolean(); | ||
|
||
private static Class<?> init() { | ||
Class<?> clazz = null; | ||
try { | ||
clazz = Class.forName(DemoServiceDubbo.class.getName()); | ||
if (registered.compareAndSet(false, true)) { | ||
org.apache.dubbo.common.serialize.protobuf.support.ProtobufUtils.marshaller( | ||
org.apache.dubbo.demo.HelloReply.getDefaultInstance()); | ||
org.apache.dubbo.common.serialize.protobuf.support.ProtobufUtils.marshaller( | ||
org.apache.dubbo.demo.HelloRequest.getDefaultInstance()); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
// ignore | ||
} | ||
return clazz; | ||
} | ||
|
||
private DemoServiceDubbo() {} | ||
|
||
public static final String SERVICE_NAME = "org.apache.dubbo.demo.DemoService"; | ||
|
||
/** | ||
* Code generated for Dubbo | ||
*/ | ||
public interface IDemoService extends org.apache.dubbo.rpc.model.DubboStub { | ||
|
||
static Class<?> clazz = init(); | ||
|
||
org.apache.dubbo.demo.HelloReply sayHello(org.apache.dubbo.demo.HelloRequest request); | ||
|
||
CompletableFuture<org.apache.dubbo.demo.HelloReply> sayHelloAsync(org.apache.dubbo.demo.HelloRequest request); | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
``` | ||
|
||
#### 4.others | ||
|
||
dubbo-maven-plugin protoc mojo supported configurations | ||
|
||
| configuration params | isRequired | explain | default | eg | | ||
|:----------------------|------------|------------------------------------------------|------------------------------------------------------------|----------------------------------------------------------------------------| | ||
| dubboVersion | true | dubbo version ,use for find Generator | ${dubbo.version} | 3.3.0 | | ||
| dubboGenerateType | true | dubbo generator type | dubbo3 | grpc | | ||
| protocExecutable | false | protoc executable,you can use local protoc.exe | | protoc | | ||
| protocArtifact | false | download protoc from maven artifact | | com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} | | ||
| protoSourceDir | true | .proto files dir | ${basedir}/src/main/proto | ./proto | | ||
| outputDir | true | generated file output dir | ${project.build.directory}/generated-sources/protobuf/java | ${basedir}/src/main/java | | ||
| protocPluginDirectory | false | protoc plugin dir | ${project.build.directory}/protoc-plugins | ./target/protoc-plugins | | ||
|
||
|
||
|
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
47 changes: 47 additions & 0 deletions
47
dubbo-compiler/src/main/java/org/apache/dubbo/gen/DubboGeneratorPlugin.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.gen; | ||
|
||
import com.google.protobuf.compiler.PluginProtos; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
|
||
public class DubboGeneratorPlugin { | ||
|
||
public static void generate(AbstractGenerator generator) { | ||
try{ | ||
PluginProtos.CodeGeneratorRequest request = PluginProtos.CodeGeneratorRequest.parseFrom(System.in); | ||
List<PluginProtos.CodeGeneratorResponse.File> files = generator.generateFiles(request); | ||
PluginProtos.CodeGeneratorResponse.newBuilder().addAllFile(files).setSupportedFeatures(PluginProtos.CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL.getNumber()).build().writeTo(System.out); | ||
}catch (Exception e){ | ||
try { | ||
PluginProtos.CodeGeneratorResponse.newBuilder().setError(e.getMessage()).build().writeTo(System.out); | ||
} catch (IOException var6) { | ||
exit(e); | ||
} | ||
}catch (Throwable var8) { | ||
exit(var8); | ||
} | ||
} | ||
|
||
public static void exit(Throwable e){ | ||
e.printStackTrace(System.err); | ||
System.exit(1); | ||
} | ||
} |
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.