Add SSH commands to query subscription states Change-Id: I986e67ebf49f8fb3fc03bf2a697473847ad7cd6f
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ProjectBranchKey.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ProjectBranchKey.java index 13734c6..899e340 100644 --- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ProjectBranchKey.java +++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ProjectBranchKey.java
@@ -20,6 +20,15 @@ private String project; private String branch; + public String getBranch() { + return branch; + } + + public String getProject() { + return project; + } + + public ProjectBranchKey(String project, String branch) { this.project = project; this.branch = branch;
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ShowSubscription.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ShowSubscription.java new file mode 100644 index 0000000..6837311 --- /dev/null +++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ShowSubscription.java
@@ -0,0 +1,51 @@ +// Copyright (C) 2015 Advanced Micro Devices, Inc. All rights reserved. +// +// 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.amd.gerrit.plugins.manifestsubscription; + +import com.google.gerrit.common.data.GlobalCapability; +import com.google.gerrit.extensions.annotations.RequiresCapability; +import com.google.gerrit.sshd.CommandMetaData; +import com.google.gerrit.sshd.SshCommand; +import com.google.inject.Inject; + +import java.util.Set; + +@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER) +@CommandMetaData(name = "show", description = "Show states of manifest-subscription") +public class ShowSubscription extends SshCommand { + + @Inject + private ManifestSubscription manifestSubscription; + + @Override + protected void run() throws UnloggedFailure, Failure, Exception { + stdout.println("Enabled manifest repositories:"); + + Set<String> repos = manifestSubscription.getEnabledManifestSource(); + Set<ProjectBranchKey> projects = manifestSubscription.getSubscribedProjects(); + + for (String repo : repos) { + stdout.println(repo); + } + + stdout.println(""); + stdout.println("Monitoring projects:"); + + for (ProjectBranchKey project : projects) { + stdout.println(project.getProject() + " | " + project.getBranch()); + } + + } +}
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/SshModule.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/SshModule.java index 76e0cd9..b0940eb 100644 --- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/SshModule.java +++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/SshModule.java
@@ -19,6 +19,6 @@ class SshModule extends PluginCommandModule { @Override protected void configureCommands() { - // command("my-command").to(MyCommand.class); + command(ShowSubscription.class); } }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md index 0073686..76d21dd 100644 --- a/src/main/resources/Documentation/about.md +++ b/src/main/resources/Documentation/about.md
@@ -63,3 +63,5 @@ * generates/xjc classes from DTD/XSD at build time * TODO add test verify include manifest have original project * TODO sub dir include manifest have same level include working + +
diff --git a/src/main/resources/Documentation/cmd-show.md b/src/main/resources/Documentation/cmd-show.md new file mode 100644 index 0000000..0ef5ad0 --- /dev/null +++ b/src/main/resources/Documentation/cmd-show.md
@@ -0,0 +1,16 @@ +@PLUGIN@ show +============== + +NAME +---- +@PLUGIN@ show - Show states of manifest-subscription + +SYNOPSIS +-------- +``` +ssh -p @SSH_PORT@ @SSH_HOST@ @PLUGIN@ show +``` + +ACCESS +------ +Caller must be a member of the privileged 'Administrators' group
diff --git a/src/main/resources/Documentation/cmd-start.md b/src/main/resources/Documentation/cmd-start.md deleted file mode 100644 index beecb90..0000000 --- a/src/main/resources/Documentation/cmd-start.md +++ /dev/null
@@ -1 +0,0 @@ -TODO: command documentation