-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:remove jprotoc #13145
Merged
Merged
feat:remove jprotoc #13145
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ebc4bc1
feat:remove jprotoc
sadfera cd80b21
fix:add dependency and license
sadfera a7efb3e
fix:remove useless import
sadfera 88a1017
fix:checkstyle bug
sadfera aeafe40
fix:SonarCloud bug
sadfera 8d174d7
refactor:remove a package path
sadfera a0cdd11
fix:handle InterruptedException
sadfera 16a6122
Merge branch '3.2' into feat_remove_jprotoc
sadfera 4327940
Merge branch '3.3' into feat_remove_jprotoc
sadfera 93b0e7c
Merge branch '3.3' into feat_remove_jprotoc
AlbumenJ 21c3532
refactor:modify license and format code
sadfera abd314c
fix:checkstyle excluded
sadfera 13747b7
Merge branch '3.3' into feat_remove_jprotoc
AlbumenJ 19d4b0e
Add NOTICE
8cc35da
fix:remove unless notice
ad1db84
Merge branch '3.3' into feat_remove_jprotoc
sadfera 0c00271
refactor:code format
2587d4a
Merge remote-tracking branch 'origin/feat_remove_jprotoc' into feat_r…
6b04b07
Merge branch '3.3' into feat_remove_jprotoc
sadfera 3219783
Merge branch '3.3' into feat_remove_jprotoc
sadfera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
## 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.2.7-SNAPSHOT</version> | ||
<configuration> | ||
<dubboVersion>3.2.7-SNAPSHOT</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.2.7-SNAPSHOT | | ||
| 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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.