Merge branch 'stable-3.1'
Change-Id: I2c1e18b02c6f5cad3cc71a639449689a053a0e65
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..20c6c4a 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,17 @@
}
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 +148,14 @@
// 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 +269,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/validation/ItsValidateComment.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/validation/ItsValidateComment.java
index def8f4f..c5799d2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/validation/ItsValidateComment.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/validation/ItsValidateComment.java
@@ -108,7 +108,8 @@
sb.append(" Issue-Tracker");
details = sb.toString();
- ret.add(commitValidationFailure(synopsis, details, ItsExistenceCheckResult.DOESNT_EXIST));
+ ret.add(
+ commitValidationFailure(synopsis, details, ItsExistenceCheckResult.DOESNT_EXIST));
}
} else if (!itsConfig
.getDummyIssuePattern()
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..4dc46d3 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,10 @@
@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()) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
index 3379908..34068bb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfigTest.java
@@ -56,8 +56,8 @@
String enabled, String itsProject, String parentEnabled, String[] branches) {
ProjectState projectState = mock(ProjectState.class);
- when(projectCache.get(Project.nameKey("testProject"))).thenReturn(projectState);
- when(projectCache.get(Project.nameKey("parentProject"))).thenReturn(projectState);
+ when(projectCache.get(Project.nameKey("testProject"))).thenReturn(Optional.of(projectState));
+ when(projectCache.get(Project.nameKey("parentProject"))).thenReturn(Optional.of(projectState));
Iterable<ProjectState> parents;
if (parentEnabled == null) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheTest.java
index 6b83097..592722c 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheTest.java
@@ -36,6 +36,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import org.eclipse.jgit.lib.Config;
public class ItsRulesProjectCacheTest extends LoggingMockingTestCase {
@@ -90,7 +91,7 @@
ProjectLevelConfig projectLevelConfigPlugin = mock(ProjectLevelConfig.class);
when(projectLevelConfigPlugin.get()).thenReturn(new Config());
when(projectState.getConfig(RuleBaseKind.ITS.fileName)).thenReturn(projectLevelConfigPlugin);
- when(projectCache.checkedGet(Project.nameKey(TEST_PROJECT))).thenReturn(projectState);
+ when(projectCache.get(Project.nameKey(TEST_PROJECT))).thenReturn(Optional.of(projectState));
when(rulesConfigReader.getRulesFromConfig(any(Config.class)))
.thenReturn(ImmutableList.of(rule1))
.thenReturn(ImmutableList.of());
@@ -132,7 +133,7 @@
when(parentProjectState.getConfig(RuleBaseKind.ITS.fileName))
.thenReturn(parentProjectConfigPlugin);
when(projectState.parents()).thenReturn(FluentIterable.of(parentProjectState));
- when(projectCache.checkedGet(Project.nameKey(TEST_PROJECT))).thenReturn(projectState);
+ when(projectCache.get(Project.nameKey(TEST_PROJECT))).thenReturn(Optional.of(projectState));
when(rulesConfigReader.getRulesFromConfig(any(Config.class)))
.thenReturn(ImmutableList.of())