Merge changes from topic "proto-gen-binary"
* changes: Add test for Java API built from generated reviewdb.proto ProtoGenHeader.txt: Remove java_api_version option Move ProtoGen out of gerrit.war Add missing runtime_deps to gwtorm
This commit is contained in:
		
							
								
								
									
										14
									
								
								java/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								java/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
java_binary(
 | 
			
		||||
    name = "ProtoGen",
 | 
			
		||||
    srcs = ["ProtoGen.java"],
 | 
			
		||||
    resource_strip_prefix = "resources",
 | 
			
		||||
    resources = ["//resources/com/google/gerrit/proto"],
 | 
			
		||||
    visibility = ["//proto:__pkg__"],
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//java/com/google/gerrit/reviewdb:server",
 | 
			
		||||
        "//lib:args4j",
 | 
			
		||||
        "//lib:guava",
 | 
			
		||||
        "//lib:gwtorm",
 | 
			
		||||
        "//lib/jgit/org.eclipse.jgit:jgit",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
@@ -12,11 +12,11 @@
 | 
			
		||||
// See the License for the specific language governing permissions and
 | 
			
		||||
// limitations under the License.
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.pgm;
 | 
			
		||||
package com.google.gerrit.proto;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.base.Preconditions.checkState;
 | 
			
		||||
import static java.nio.charset.StandardCharsets.UTF_8;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.pgm.util.AbstractProgram;
 | 
			
		||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
			
		||||
import com.google.gwtorm.schema.java.JavaSchemaModel;
 | 
			
		||||
import java.io.BufferedWriter;
 | 
			
		||||
@@ -28,23 +28,37 @@ import java.io.PrintWriter;
 | 
			
		||||
import java.nio.ByteBuffer;
 | 
			
		||||
import org.eclipse.jgit.internal.storage.file.LockFile;
 | 
			
		||||
import org.eclipse.jgit.util.IO;
 | 
			
		||||
import org.kohsuke.args4j.CmdLineException;
 | 
			
		||||
import org.kohsuke.args4j.CmdLineParser;
 | 
			
		||||
import org.kohsuke.args4j.Option;
 | 
			
		||||
 | 
			
		||||
public class ProtoGen extends AbstractProgram {
 | 
			
		||||
public class ProtoGen {
 | 
			
		||||
  @Option(
 | 
			
		||||
      name = "--output",
 | 
			
		||||
      aliases = {"-o"},
 | 
			
		||||
      required = true,
 | 
			
		||||
      metaVar = "FILE",
 | 
			
		||||
      usage = "File to write .proto into")
 | 
			
		||||
    name = "--output",
 | 
			
		||||
    aliases = {"-o"},
 | 
			
		||||
    required = true,
 | 
			
		||||
    metaVar = "FILE",
 | 
			
		||||
    usage = "File to write .proto into"
 | 
			
		||||
  )
 | 
			
		||||
  private File file;
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int run() throws Exception {
 | 
			
		||||
    LockFile lock = new LockFile(file.getAbsoluteFile());
 | 
			
		||||
    if (!lock.lock()) {
 | 
			
		||||
      throw die("Cannot lock " + file);
 | 
			
		||||
  public static void main(String[] argv) throws Exception {
 | 
			
		||||
    System.exit(new ProtoGen().run(argv));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private int run(String[] argv) throws Exception {
 | 
			
		||||
    CmdLineParser parser = new CmdLineParser(this);
 | 
			
		||||
    try {
 | 
			
		||||
      parser.parseArgument(argv);
 | 
			
		||||
    } catch (CmdLineException e) {
 | 
			
		||||
      System.err.println(e.getMessage());
 | 
			
		||||
      System.err.println(getClass().getSimpleName() + " -o output.proto");
 | 
			
		||||
      parser.printUsage(System.err);
 | 
			
		||||
      return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    LockFile lock = new LockFile(file.getAbsoluteFile());
 | 
			
		||||
    checkState(lock.lock(), "cannot lock %s", file);
 | 
			
		||||
    try {
 | 
			
		||||
      JavaSchemaModel jsm = new JavaSchemaModel(ReviewDb.class);
 | 
			
		||||
      try (OutputStream o = lock.getOutputStream();
 | 
			
		||||
@@ -61,9 +75,7 @@ public class ProtoGen extends AbstractProgram {
 | 
			
		||||
        jsm.generateProto(out);
 | 
			
		||||
        out.flush();
 | 
			
		||||
      }
 | 
			
		||||
      if (!lock.commit()) {
 | 
			
		||||
        throw die("Could not write to " + file);
 | 
			
		||||
      }
 | 
			
		||||
      checkState(lock.commit(), "Could not write to %s", file);
 | 
			
		||||
    } finally {
 | 
			
		||||
      lock.unlock();
 | 
			
		||||
    }
 | 
			
		||||
							
								
								
									
										17
									
								
								javatests/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								javatests/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
load("//tools/bzl:junit.bzl", "junit_tests")
 | 
			
		||||
 | 
			
		||||
junit_tests(
 | 
			
		||||
    name = "proto_tests",
 | 
			
		||||
    srcs = glob(["*.java"]),
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//lib/truth:truth-proto-extension",
 | 
			
		||||
        "//proto:reviewdb_java_proto",
 | 
			
		||||
 | 
			
		||||
        # TODO(dborowitz): These are already runtime_deps of
 | 
			
		||||
        # truth-proto-extension, but either omitting them or adding them as
 | 
			
		||||
        # runtime_deps to this target fails with:
 | 
			
		||||
        #   class file for com.google.common.collect.Multimap not found
 | 
			
		||||
        "//lib:guava",
 | 
			
		||||
        "//lib/truth",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										31
									
								
								javatests/com/google/gerrit/proto/ReviewDbProtoTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								javatests/com/google/gerrit/proto/ReviewDbProtoTest.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
// Copyright (C) 2018 The Android Open Source Project
 | 
			
		||||
//
 | 
			
		||||
// Licensed 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 com.google.gerrit.proto;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.proto.reviewdb.Reviewdb.Change;
 | 
			
		||||
import com.google.gerrit.proto.reviewdb.Reviewdb.Change_Id;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class ReviewDbProtoTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void generatedProtoApi() {
 | 
			
		||||
    Change c1 = Change.newBuilder().setChangeId(Change_Id.newBuilder().setId(1234).build()).build();
 | 
			
		||||
    Change c2 = Change.newBuilder().setChangeId(Change_Id.newBuilder().setId(5678).build()).build();
 | 
			
		||||
    assertThat(c1).isEqualTo(c1);
 | 
			
		||||
    assertThat(c1).isNotEqualTo(c2);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -72,7 +72,11 @@ java_library(
 | 
			
		||||
    name = "gwtorm",
 | 
			
		||||
    visibility = ["//visibility:public"],
 | 
			
		||||
    exports = [":gwtorm-client"],
 | 
			
		||||
    runtime_deps = [":protobuf"],
 | 
			
		||||
    runtime_deps = [
 | 
			
		||||
        ":protobuf",
 | 
			
		||||
        "//lib/antlr:java-runtime",
 | 
			
		||||
        "//lib/ow2:ow2-asm",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
java_library(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								proto/BUILD
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								proto/BUILD
									
									
									
									
									
								
							@@ -8,3 +8,21 @@ java_proto_library(
 | 
			
		||||
    visibility = ["//visibility:public"],
 | 
			
		||||
    deps = [":cache_proto"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
genrule(
 | 
			
		||||
    name = "gen_reviewdb_proto",
 | 
			
		||||
    outs = ["reviewdb.proto"],
 | 
			
		||||
    cmd = "$(location //java/com/google/gerrit/proto:ProtoGen) -o $@",
 | 
			
		||||
    tools = ["//java/com/google/gerrit/proto:ProtoGen"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
proto_library(
 | 
			
		||||
    name = "reviewdb_proto",
 | 
			
		||||
    srcs = [":reviewdb.proto"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
java_proto_library(
 | 
			
		||||
    name = "reviewdb_java_proto",
 | 
			
		||||
    visibility = ["//javatests/com/google/gerrit/proto:__pkg__"],
 | 
			
		||||
    deps = [":reviewdb_proto"],
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								resources/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								resources/com/google/gerrit/proto/BUILD
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
filegroup(
 | 
			
		||||
    name = "proto",
 | 
			
		||||
    srcs = glob(
 | 
			
		||||
        ["**/*"],
 | 
			
		||||
        exclude = ["BUILD"],
 | 
			
		||||
    ),
 | 
			
		||||
    visibility = ["//visibility:public"],
 | 
			
		||||
)
 | 
			
		||||
@@ -14,7 +14,6 @@
 | 
			
		||||
 | 
			
		||||
syntax = "proto2";
 | 
			
		||||
 | 
			
		||||
option java_api_version = 2;
 | 
			
		||||
option java_package = "com.google.gerrit.proto.reviewdb";
 | 
			
		||||
 | 
			
		||||
package devtools.gerritcodereview;
 | 
			
		||||
		Reference in New Issue
	
	Block a user