Generalize affixManifest by making it functional
So that other operations such as branching or tagging projects
described by a manifest can be implemented later with code reuse.
Change-Id: Id8b838109e7c39de953d1591fcb8d5ce4b1bd39c
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestOp.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestOp.java
new file mode 100644
index 0000000..d6fbe5d
--- /dev/null
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestOp.java
@@ -0,0 +1,9 @@
+package com.amd.gerrit.plugins.manifestsubscription;
+
+import com.amd.gerrit.plugins.manifestsubscription.manifest.Project;
+import com.google.gerrit.server.git.GitRepositoryManager;
+
+public interface ManifestOp {
+ boolean apply(Project project, String hash, String name,
+ GitRepositoryManager gitRepoManager);
+}
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
index 687450d..d8e571d 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
@@ -223,13 +223,26 @@
defaultRef = manifest.getDefault().getRevision();
}
- affixManifest(gitRepoManager, manifest.getProject(), defaultRef, lookup);
+ ManifestOp op = new ManifestOp() {
+ @Override
+ public boolean apply(com.amd.gerrit.plugins.manifestsubscription.manifest.Project project,
+ String hash, String name,
+ GitRepositoryManager gitRepoManager) {
+ project.setRevision(hash);
+ project.setUpstream(name);
+ return true;
+ }
+ };
+
+ traverseManifestAndApplyOp(gitRepoManager, manifest.getProject(), defaultRef, op, lookup);
}
- private static void affixManifest(GitRepositoryManager gitRepoManager,
- List<com.amd.gerrit.plugins.manifestsubscription.manifest.Project> projects,
- String defaultRef,
- Table<String, String, String> lookup) {
+ private static void traverseManifestAndApplyOp(
+ GitRepositoryManager gitRepoManager,
+ List<com.amd.gerrit.plugins.manifestsubscription.manifest.Project> projects,
+ String defaultRef,
+ ManifestOp op,
+ Table<String, String, String> lookup) {
String ref;
String hash;
@@ -258,13 +271,12 @@
if (hash != null) {
lookup.put(projectName, ref, hash);
- project.setRevision(hash);
- project.setUpstream(ref);
+ op.apply(project, hash, ref, gitRepoManager);
}
}
if (project.getProject().size() > 0) {
- affixManifest(gitRepoManager, project.getProject(), defaultRef, lookup);
+ traverseManifestAndApplyOp(gitRepoManager, project.getProject(), defaultRef, op, lookup);
}
}
}