Use VersionedConfigFile from core This new class in core replaces the custom AbstractVersionedMetaData class that has been maintained in the task plugin. Release-Notes: skip Change-Id: Id55e658ec3735a59a8241e50a7654f8d1a9e5195
diff --git a/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java b/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java deleted file mode 100644 index 7997a05..0000000 --- a/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java +++ /dev/null
@@ -1,67 +0,0 @@ -// Copyright (C) 2013 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.server.git.meta; - -import com.google.gerrit.entities.BranchNameKey; -import java.io.IOException; -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.eclipse.jgit.lib.CommitBuilder; -import org.eclipse.jgit.lib.Config; - -/** Versioned Configuration file living in git */ -public class AbstractVersionedMetaData extends VersionedMetaData { - protected final BranchNameKey branch; - protected final String fileName; - protected Config cfg; - - public AbstractVersionedMetaData(BranchNameKey branch, String fileName) { - this.branch = branch; - this.fileName = fileName; - } - - @Override - protected String getRefName() { - return branch.branch(); - } - - protected String getFileName() { - return fileName; - } - - @Override - protected void onLoad() throws IOException, ConfigInvalidException { - cfg = readConfig(fileName); - } - - public Config get() { - if (cfg == null) { - cfg = new Config(); - } - return cfg; - } - - public BranchNameKey getBranch() { - return branch; - } - - @Override - protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { - if (commit.getMessage() == null || "".equals(commit.getMessage())) { - commit.setMessage("Updated configuration\n"); - } - saveConfig(fileName, cfg); - return true; - } -}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java index 1859b0d..18d8a5b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java +++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
@@ -16,7 +16,7 @@ import com.google.gerrit.common.Container; import com.google.gerrit.entities.BranchNameKey; -import com.google.gerrit.server.git.meta.AbstractVersionedMetaData; +import com.google.gerrit.server.git.meta.VersionedConfigFile; import com.googlesource.gerrit.plugins.task.util.Copier; import java.util.ArrayList; import java.util.Arrays; @@ -30,7 +30,7 @@ import java.util.stream.Collectors; /** Task Configuration file living in git */ -public class TaskConfig extends AbstractVersionedMetaData { +public class TaskConfig extends VersionedConfigFile { public enum NamesFactoryType { CHANGE, STATIC, @@ -235,7 +235,7 @@ public TaskConfig( BranchNameKey masqueraded, FileKey file, boolean isVisible, boolean isMasqueraded) { - super(masqueraded, file.file()); + super(masqueraded.branch(), file.file()); this.file = file; this.isVisible = isVisible; this.isMasqueraded = isMasqueraded;