Fix compile warnings and avoid usage of deprecated classes

Change-Id: Id84c79ab170c066ed40b24ca20816d7758470a07
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
index 6db2338..1aed6cf 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
@@ -38,7 +38,8 @@
 import org.kohsuke.github.GHMyself;
 import org.kohsuke.github.GitHub;
 import org.kohsuke.github.GitHubBuilder;
-import org.kohsuke.github.HttpConnector;
+import org.kohsuke.github.connector.GitHubConnector;
+import org.kohsuke.github.internal.GitHubConnectorHttpConnectorAdapter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,7 +64,7 @@
 
   private SortedSet<Scope> loginScopes;
   private final GitHubOAuthConfig config;
-  private final HttpConnector httpConnector;
+  private final GitHubConnector gitHubConnector;
 
   public GHMyself getMyself() throws IOException {
     if (isLoggedIn()) {
@@ -82,7 +83,7 @@
   @Inject
   public GitHubLogin(GitHubOAuthConfig config, GitHubHttpConnector httpConnector) {
     this.config = config;
-    this.httpConnector = httpConnector;
+    this.gitHubConnector = GitHubConnectorHttpConnectorAdapter.adapt(httpConnector);
   }
 
   public boolean isLoggedIn() {
@@ -141,7 +142,7 @@
     return new GitHubBuilder()
         .withEndpoint(config.gitHubApiUrl)
         .withOAuthToken(token.accessToken)
-        .withConnector(httpConnector)
+        .withConnector(gitHubConnector)
         .build();
   }
 
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/BatchImporter.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/BatchImporter.java
index f26188d..d359526 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/BatchImporter.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/BatchImporter.java
@@ -44,7 +44,7 @@
   }
 
   public synchronized void schedule(int idx, GitJob pullRequestImportJob) {
-    jobs.put(new Integer(idx), pullRequestImportJob);
+    jobs.put(Integer.valueOf(idx), pullRequestImportJob);
     executor.exec(pullRequestImportJob);
   }
 }
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
index 0e0e72d..25d953b 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
@@ -44,11 +44,8 @@
   private static final Logger LOG = LoggerFactory.getLogger(GitImporter.class);
 
   private final GitHubConfig config;
-  private final File gitDir;
   private final GerritApi gerritApi;
   private final OneOffRequestContext context;
-  private final String organisation;
-  private final String repository;
   private final File destinationDirectory;
   private final DynamicSet<ProjectDeletedListener> deletedListeners;
   private final ProjectCache projectCache;
@@ -75,14 +72,11 @@
     super(config.gitHubUrl, organisation, repository, gitHubRepoFactory);
     LOG.debug("GitHub Clone " + organisation + "/" + repository);
     this.config = config;
-    this.gitDir = config.gitDir.toFile();
 
     this.gerritApi = gerritApi;
     this.context = context;
-    this.organisation = organisation;
-    this.repository = repository;
     this.projectName = organisation + "/" + repository;
-    this.destinationDirectory = prepareTargetGitDirectory(gitDir, this.projectName);
+    this.destinationDirectory = prepareTargetGitDirectory(config.gitDir.toFile(), this.projectName);
     this.deletedListeners = deletedListeners;
     this.projectCache = projectCache;
     this.repoManager = repoManager;
@@ -128,10 +122,6 @@
     }
   }
 
-  private boolean isNotEmpty(File destDirectory) {
-    return destDirectory.listFiles().length > 0;
-  }
-
   @Override
   public boolean rollback() {
     File gitDirectory = destinationDirectory;
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/MagicRefFoundException.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/MagicRefFoundException.java
index 263ee9d..42b7e36 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/MagicRefFoundException.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/MagicRefFoundException.java
@@ -15,6 +15,8 @@
 
 public class MagicRefFoundException extends GitException {
 
+  private static final long serialVersionUID = 1L;
+
   public MagicRefFoundException(String message) {
     super(message);
   }
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ProtectedBranchFoundException.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ProtectedBranchFoundException.java
index 221152f..c156150 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ProtectedBranchFoundException.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ProtectedBranchFoundException.java
@@ -16,6 +16,8 @@
 
 public class ProtectedBranchFoundException extends Exception {
 
+  private static final long serialVersionUID = 1L;
+
   public ProtectedBranchFoundException(String msg) {
     super(msg);
   }
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
index 52d7b34..da16dc2 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
@@ -191,7 +191,7 @@
                   pullRequestOwner,
                   revCommit,
                   getChangeMessage(pr),
-                  String.format(TOPIC_FORMAT, new Integer(pr.getNumber())));
+                  String.format(TOPIC_FORMAT, Integer.valueOf(pr.getNumber())));
           if (changeId != null) {
             prChanges.add(changeId);
           }
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/notification/PullRequestHandler.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/notification/PullRequestHandler.java
index 540b98a..361ccc2 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/notification/PullRequestHandler.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/notification/PullRequestHandler.java
@@ -46,7 +46,7 @@
     String action = payload.getAction();
     if (action.equals("opened") || action.equals("synchronize")) {
       GHRepository repository = payload.getRepository();
-      Integer prNumber = new Integer(payload.getNumber());
+      Integer prNumber = Integer.valueOf(payload.getNumber());
       PullRequestImporter prImporter = prImportProvider.get();
       String organization = repository.getOwnerName();
       String name = repository.getName();
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
index af644fe..810632a 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
@@ -20,7 +20,6 @@
 import com.google.gerrit.server.account.GroupBackend;
 import com.google.gerrit.server.config.SitePaths;
 import com.google.inject.Inject;
-import com.google.inject.Injector;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
@@ -52,24 +51,20 @@
     return null;
   }
 
-  private final Injector injector;
   private final List<Destination> configs;
 
   private final RemoteSiteUser.Factory replicationUserFactory;
   private final PluginUser pluginUser;
   private final GroupBackend groupBackend;
-  boolean replicateAllOnPluginStart;
   private final List<String> organisations;
 
   @Inject
   GitHubDestinations(
-      final Injector i,
       final SitePaths site,
       final RemoteSiteUser.Factory ruf,
       final GroupBackend gb,
       final PluginUser pu)
       throws ConfigInvalidException, IOException {
-    injector = i;
     pluginUser = pu;
     replicationUserFactory = ruf;
     groupBackend = gb;
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
index fc578af..0bb7e3e 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
@@ -25,7 +25,6 @@
 import com.google.gerrit.extensions.restapi.RawInput;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.ServerInitiated;
-import com.google.gerrit.server.account.AccountCache;
 import com.google.gerrit.server.account.AccountManager;
 import com.google.gerrit.server.account.AccountResource;
 import com.google.gerrit.server.account.AccountsUpdate;
@@ -65,7 +64,6 @@
   private final AddSshKey restAddSshKey;
   private final GetSshKeys restGetSshKeys;
   private final AccountManager accountManager;
-  private final AccountCache accountCache;
   private final PutPreferred putPreferred;
   private final PutName putName;
   private final Provider<AccountsUpdate> accountsUpdateProvider;
@@ -79,7 +77,6 @@
       final AddSshKey restAddSshKey,
       final GetSshKeys restGetSshKeys,
       final AccountManager accountManager,
-      final AccountCache accountCache,
       final PutPreferred putPreferred,
       final PutName putName,
       @ServerInitiated final Provider<AccountsUpdate> accountsUpdateProvider,
@@ -90,7 +87,6 @@
     this.restAddSshKey = restAddSshKey;
     this.restGetSshKeys = restGetSshKeys;
     this.accountManager = accountManager;
-    this.accountCache = accountCache;
     this.putPreferred = putPreferred;
     this.putName = putName;
     this.accountsUpdateProvider = accountsUpdateProvider;
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
index e47f161..b7fc801 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
@@ -101,7 +101,7 @@
           JsonArray prArray = new JsonArray();
           for (GHPullRequest pr : repoEntry.getValue()) {
             JsonObject prObj = new JsonObject();
-            prObj.add("id", new JsonPrimitive(new Integer(pr.getNumber())));
+            prObj.add("id", new JsonPrimitive(Integer.valueOf(pr.getNumber())));
             prObj.add("title", new JsonPrimitive(Strings.nullToEmpty(pr.getTitle())));
             prObj.add("body", new JsonPrimitive(Strings.nullToEmpty(pr.getBody())));
             prObj.add(
@@ -137,7 +137,7 @@
         if (githubRepo.isPresent()) {
           numPullRequests =
               collectPullRequestsFromGitHubRepository(
-                  numPullRequests, allPullRequests, gitRepo, ghRepoName, githubRepo);
+                  numPullRequests, allPullRequests, gitRepo, ghRepoName, githubRepo.get());
         }
       }
     }
@@ -149,13 +149,14 @@
       Map<String, List<GHPullRequest>> allPullRequests,
       Repository gitRepo,
       String ghRepoName,
-      Optional<GHRepository> githubRepo)
+      GHRepository githubRepo)
       throws IncorrectObjectTypeException, IOException {
     List<GHPullRequest> repoPullRequests = Lists.newArrayList();
 
     int count = numPullRequests;
     if (count < config.pullRequestListLimit) {
-      for (GHPullRequest ghPullRequest : githubRepo.get().listPullRequests(GHIssueState.OPEN)) {
+      for (GHPullRequest ghPullRequest :
+          githubRepo.queryPullRequests().state(GHIssueState.OPEN).list()) {
 
         if (isAnyCommitOfPullRequestToBeImported(gitRepo, ghPullRequest)) {
           repoPullRequests.add(ghPullRequest);
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
index 2cf6170..01a3d25 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
@@ -72,7 +72,7 @@
           repository.add("organisation", new JsonPrimitive(organisation));
           repository.add(
               "description", new JsonPrimitive(Strings.nullToEmpty(ghRepository.getDescription())));
-          repository.add("private", new JsonPrimitive(new Boolean(ghRepository.isPrivate())));
+          repository.add("private", new JsonPrimitive(Boolean.valueOf(ghRepository.isPrivate())));
           jsonRepos.add(repository);
           numRepos++;
         }