Fix master branch with Optional<ProjectState> from ProjectCache The Gerrit master branch has changed way ProjectCache works and the get() method returns now an Optional<ProjectState> instead of relying to null return values when the project doesn't exist. Change-Id: Ia97ffe46b65b76668b66e28a9ac0826d4826a9ec
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java index 5daa828..dc98f5d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java +++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/DownloadCommandUpdater.java
@@ -35,6 +35,7 @@ import com.google.inject.Singleton; import java.io.IOException; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.ObjectId; @@ -79,11 +80,12 @@ @Override public void run() { for (Project.NameKey p : projectCache.all()) { - ProjectState projectState = projectCache.get(p); - if (projectState != null) { - PluginConfig cfg = projectState.getConfig().getPluginConfig(pluginName); + Optional<ProjectState> projectState = projectCache.get(p); + if (projectState.isPresent()) { + PluginConfig cfg = projectState.get().getConfig().getPluginConfig(pluginName); for (String name : cfg.getNames()) { - installCommand(projectState.getProject().getNameKey(), name, cfg.getString(name)); + installCommand( + projectState.get().getProject().getNameKey(), name, cfg.getString(name)); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/ProjectDownloadCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/ProjectDownloadCommand.java index 10d0291..e011f04 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/download/command/project/ProjectDownloadCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/project/ProjectDownloadCommand.java
@@ -22,6 +22,7 @@ import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; import java.util.Map; +import java.util.Optional; public class ProjectDownloadCommand extends DownloadCommand { private final ProjectCache projectCache; @@ -50,9 +51,9 @@ Project.NameKey projectName = Project.nameKey(project); String command = commands.get(projectName); if (command == null) { - ProjectState projectState = projectCache.get(projectName); - if (projectState != null) { - for (ProjectState parent : projectState.parents()) { + Optional<ProjectState> projectState = projectCache.get(projectName); + if (projectState.isPresent()) { + for (ProjectState parent : projectState.get().parents()) { command = commands.get(parent.getProject().getNameKey()); if (command != null) { break;