Adapt to ProjectCache interface change
Change-Id: Id2282d10193b0f99212fc8a9dd826254c3f730a8
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
index 08f73c5..a2ab203 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
@@ -94,16 +94,16 @@
}
public boolean isEnabled(Project.NameKey projectNK, String refName) {
- ProjectState projectState = projectCache.get(projectNK);
- if (projectState == null) {
+ Optional<ProjectState> projectState = projectCache.get(projectNK);
+ if (!projectState.isPresent()) {
log.error(
"Failed to check if {} is enabled for project {}: Project not found",
pluginName,
projectNK.get());
return false;
}
- return isEnforcedByAnyParentProject(refName, projectState)
- || (isEnabledForProject(projectState) && isEnabledForBranch(projectState, refName));
+ return isEnforcedByAnyParentProject(refName, projectState.get())
+ || (isEnabledForProject(projectState.get()) && isEnabledForBranch(projectState.get(), refName));
}
private boolean isEnforcedByAnyParentProject(String refName, ProjectState projectState) {
@@ -147,12 +147,12 @@
// Project association
public Optional<String> getItsProjectName(Project.NameKey projectNK) {
- ProjectState projectState = projectCache.get(projectNK);
- if (projectState == null) {
+ Optional<ProjectState> projectState = projectCache.get(projectNK);
+ if (!projectState.isPresent()) {
return Optional.empty();
}
return Optional.ofNullable(
- pluginCfgFactory.getFromProjectConfig(projectState, pluginName).getString("its-project"));
+ pluginCfgFactory.getFromProjectConfig(projectState.get(), pluginName).getString("its-project"));
}
// Issue association --------------------------------------------------------
@@ -266,7 +266,7 @@
private List<CommentLinkInfo> getCommentLinkInfo(final String commentlinkName) {
NameKey projectName = currentProjectName.get();
if (projectName != null) {
- List<CommentLinkInfo> commentlinks = projectCache.get(projectName).getCommentLinks();
+ List<CommentLinkInfo> commentlinks = projectCache.get(projectName).get().getCommentLinks();
return commentlinks.stream()
.filter(input -> input.name.equals(commentlinkName))
.collect(toList());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
index 72fe43f..9645429 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
@@ -98,7 +98,8 @@
@Override
public List<Rule> load(String projectName) throws IOException {
- ProjectState project = projectCache.checkedGet(Project.nameKey(projectName));
+ ProjectState project =
+ projectCache.get(Project.nameKey(projectName)).orElseThrow(() -> new IOException("Can't load " + projectName));
List<Rule> projectRules = readRulesFrom(project);
if (projectRules.isEmpty()) {
for (ProjectState parent : project.parents()) {