Convert File.NameKey to AutoValue

Fixes this error when building in-tree with bazel:
 plugins/batch/src/main/java/com/google/gerrit/reviewdb/client/File.java:21: error: [strict] Using type com.google.gwtorm.client.StringKey from an indirect dependency (TOOL_INFO: "//java/com/google/gwtorm"). See command below **
   public static class NameKey extends StringKey<Branch.NameKey> {
                                       ^
I could have instead added the gwtorm dependency, but backporting this
sounded better to me.

Change-Id: If0110c1a391d67f2d70a3413b46e9ffe7c9e2c1c
diff --git a/.factorypath b/.factorypath
new file mode 100644
index 0000000..c1c6e82
--- /dev/null
+++ b/.factorypath
@@ -0,0 +1,3 @@
+<factorypath>
+    <factorypathentry kind="VARJAR" id="M2_REPO/com/google/auto/value/auto-value/1.7/auto-value-1.7.jar" enabled="true" runInBatchMode="false"/>
+</factorypath>
diff --git a/BUILD b/BUILD
index 0e08d92..f364456 100644
--- a/BUILD
+++ b/BUILD
@@ -5,6 +5,46 @@
     "gerrit_plugin",
 )
 
+load("@rules_java//java:defs.bzl", "java_library", "java_plugin")
+
+java_plugin(
+    name = "auto-annotation-plugin",
+    processor_class = "com.google.auto.value.processor.AutoAnnotationProcessor",
+    deps = [
+        "@auto-value-annotations//jar",
+        "@auto-value//jar",
+    ],
+)
+
+java_plugin(
+    name = "auto-value-plugin",
+    processor_class = "com.google.auto.value.processor.AutoValueProcessor",
+    deps = [
+        "@auto-value-annotations//jar",
+        "@auto-value//jar",
+    ],
+)
+
+java_library(
+    name = "auto-value",
+    exported_plugins = [
+        ":auto-annotation-plugin",
+        ":auto-value-plugin",
+    ],
+    visibility = ["//visibility:public"],
+    exports = ["@auto-value//jar"],
+)
+
+java_library(
+    name = "auto-value-annotations",
+    exported_plugins = [
+        ":auto-annotation-plugin",
+        ":auto-value-plugin",
+    ],
+    visibility = ["//visibility:public"],
+    exports = ["@auto-value-annotations//jar"],
+)
+
 gerrit_plugin(
     name = "batch",
     srcs = glob(["src/main/java/**/*.java"]),
@@ -17,4 +57,8 @@
         "Gerrit-SshModule: com.googlesource.gerrit.plugins.batch.ssh.SshModule",
     ],
     resources = glob(["src/main/resources/**/*"]),
+    deps = [
+        ":auto-value",
+        ":auto-value-annotations"
+    ],
 )
diff --git a/WORKSPACE b/WORKSPACE
index ac604b5..1dac920 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -22,5 +22,21 @@
 # Load release Plugin API
 gerrit_api()
 
+load("//tools/bzl:maven_jar.bzl", "GERRIT", "maven_jar")
+
+AUTO_VALUE_VERSION = "1.6.5"
+
+maven_jar(
+    name = "auto-value",
+    artifact = "com.google.auto.value:auto-value:" + AUTO_VALUE_VERSION,
+    sha1 = "816872c85048f36a67a276ef7a49cc2e4595711c",
+)
+
+maven_jar(
+    name = "auto-value-annotations",
+    artifact = "com.google.auto.value:auto-value-annotations:" + AUTO_VALUE_VERSION,
+    sha1 = "c3dad10377f0e2242c9a4b88e9704eaf79103679",
+)
+
 # Load snapshot Plugin API
 #gerrit_api_maven_local()
diff --git a/pom.xml b/pom.xml
index a9141b1..b1ea7c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@
   <properties>
     <Gerrit-ApiType>plugin</Gerrit-ApiType>
     <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion>
+    <auto-value.version>1.6.5</auto-value.version>
   </properties>
 
   <build>
@@ -64,6 +65,13 @@
           <source>1.8</source>
           <target>1.8</target>
           <encoding>UTF-8</encoding>
+          <annotationProcessorPaths>
+            <path>
+              <groupId>com.google.auto.value</groupId>
+              <artifactId>auto-value</artifactId>
+              <version>${auto-value.version}</version>
+            </path>
+          </annotationProcessorPaths>
         </configuration>
       </plugin>
     </plugins>
@@ -76,6 +84,12 @@
       <version>${Gerrit-ApiVersion}</version>
       <scope>provided</scope>
     </dependency>
+
+    <dependency>
+      <groupId>com.google.auto.value</groupId>
+      <artifactId>auto-value-annotations</artifactId>
+      <version>${auto-value.version}</version>
+    </dependency>
   </dependencies>
 
   <repositories>
diff --git a/src/main/java/com/google/gerrit/entities/FileNameKey.java b/src/main/java/com/google/gerrit/entities/FileNameKey.java
new file mode 100644
index 0000000..d415278
--- /dev/null
+++ b/src/main/java/com/google/gerrit/entities/FileNameKey.java
@@ -0,0 +1,39 @@
+// Copyright (C) 2017 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.entities;
+
+import com.google.auto.value.AutoValue;
+import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.Project;
+
+/** An immutable reference to a file in gerrit repo. */
+@AutoValue
+public abstract class FileNameKey implements Comparable<FileNameKey> {
+  public static FileNameKey create(Branch.NameKey branch, String file) {
+    return new AutoValue_FileNameKey(branch, file);
+  }
+
+  public static FileNameKey create() {
+    return new AutoValue_FileNameKey(new Branch.NameKey(new Project.NameKey(null), null), null);
+  }
+
+  public abstract Branch.NameKey branch();
+  public abstract String file();
+
+  @Override
+  public final int compareTo(FileNameKey o) {
+    return file().compareTo(o.file());
+  }
+}
diff --git a/src/main/java/com/google/gerrit/reviewdb/client/File.java b/src/main/java/com/google/gerrit/reviewdb/client/File.java
deleted file mode 100644
index 78e2f84..0000000
--- a/src/main/java/com/google/gerrit/reviewdb/client/File.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2017 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.reviewdb.client;
-
-import com.google.gwtorm.client.StringKey;
-
-public class File {
-  /** An immutable reference to a file in gerrit repo. */
-  public static class NameKey extends StringKey<Branch.NameKey> {
-    private static final long serialVersionUID = 1L;
-
-    protected Branch.NameKey branch;
-    protected String fileName;
-
-    protected NameKey() {
-      branch = new Branch.NameKey(new Project.NameKey(null), null);
-    }
-
-    public NameKey(Branch.NameKey br, String file) {
-      branch = br;
-      fileName = file;
-    }
-
-    @Override
-    public String get() {
-      return fileName;
-    }
-
-    @Override
-    protected void set(String file) {
-      fileName = file;
-    }
-
-    @Override
-    public Branch.NameKey getParentKey() {
-      return branch;
-    }
-  }
-}
diff --git a/src/main/java/com/google/gerrit/server/git/meta/GitFile.java b/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
index ce9505e..4fe617d 100644
--- a/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
+++ b/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
@@ -15,8 +15,8 @@
 package com.google.gerrit.server.git.meta;
 
 import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.File;
 import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.FileNameKey;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.inject.Inject;
@@ -31,7 +31,7 @@
 /** A GitFile is a text file (UTF8) from a git repository */
 public class GitFile extends VersionedMetaData {
   public interface Factory {
-    GitFile create(@Assisted File.NameKey file);
+    GitFile create(@Assisted FileNameKey file);
   }
 
   protected final MetaDataUpdate.User metaDataUpdateFactory;
@@ -46,11 +46,11 @@
   public GitFile(
       MetaDataUpdate.User metaDataUpdateFactory,
       GitRepositoryManager repos,
-      @Assisted File.NameKey file) {
+      @Assisted FileNameKey file) {
     this.metaDataUpdateFactory = metaDataUpdateFactory;
     this.repos = repos;
-    this.branch = file.getParentKey();
-    this.file = file.get();
+    this.branch = file.branch();
+    this.file = file.file();
   }
 
   public String read() throws ConfigInvalidException, IOException, NoSuchProjectException {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
index d582af4..7290148 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
@@ -14,7 +14,7 @@
 package com.googlesource.gerrit.plugins.batch;
 
 import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.File;
+import com.google.gerrit.entities.FileNameKey;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.config.AllProjectsName;
 import com.google.gerrit.server.git.GitRepositoryManager;
@@ -106,7 +106,7 @@
     throw new NoSuchBatchException(id);
   }
 
-  protected File.NameKey getFileNameKey(String id) {
+  protected FileNameKey getFileNameKey(String id) {
     return getFileNameKey(getBranch(id));
   }
 
@@ -114,7 +114,7 @@
     return new Branch.NameKey(project, BATCHES_REF + id);
   }
 
-  protected File.NameKey getFileNameKey(Branch.NameKey branch) {
-    return new File.NameKey(branch, FILE_NAME);
+  protected FileNameKey getFileNameKey(Branch.NameKey branch) {
+    return FileNameKey.create(branch, FILE_NAME);
   }
 }
diff --git a/tools/bzl/maven_jar.bzl b/tools/bzl/maven_jar.bzl
new file mode 100644
index 0000000..ed1504d
--- /dev/null
+++ b/tools/bzl/maven_jar.bzl
@@ -0,0 +1,4 @@
+load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl", _gerrit = "GERRIT", _maven_jar = "maven_jar")
+
+maven_jar = _maven_jar
+GERRIT = _gerrit